Unpacking the Wemos ESP32 Lolin32 Lite, testing the firmware MicroPython with a Raspberry Pi 3

A few weeks ago, Wemos launched its Lolin32 Lite based Espressif ESP32 module. The ESP32 used is the REV1 which corrects some bugs. It is a very compact development board (50*25.5*6.5 mm) compatible with the 2.54mm pitch of the breadboards. It is as narrow as the Wemos d1 mini (based on ESP8266) which allows to have a row of pins on each side of the card for wiring. The LoLi32 Lite is equipped with a standard LiPo battery connector standard PH-2 2.0mm. By default, the firmware MicroPython is pre-installed. This is an opportunity to discover this firmware. To learn more about the MicroPython firmware project, visit the official page here. The Wemos LoLin32 Lite is only sold by Wemos at its official AliExpress store. It costs $4.90 € (+ shipping costs).

Unpacking the Wemos LoLin32 Lite ESP32

I took advantage of the 11.11 sales to order a LoLin32 on AliExpress. Wemos practices very good prices on these development boards. There was no discount (not for Black Friday for that matter). The LoLin32 Lite is shipped in a simple bubble envelope. She arrived in 12 days, which is very correct as the end of year holidays approach. Wemos has a very well organized shipping service. The card arrives packed in an anti-static bag with a label in the name of the buyer. Unlike the Wemos d1 mini, the LoLin32 Lite comes with only one type of male connector (13 pins). As the map is narrow, we have a row of pins on each side on a breadboard. It is quite easy to find connectors with a male and female side on AliExpress or Banggood if needed.

LiPo battery with PH-2 2.0mm 2-pin connector, classic for drones and RC

This is a recurring problem with LiPo battery connectors used by development board manufacturers. For LoLin32, Wemos uses a JST 2.0 PH 2-Pin connector. I took the time to look for the full designation because it is still a problem. Luckily, you can easily find cables that can be used to modify a battery pack or a LiPo battery. Be careful not to reverse the polarity!

The JST 2.0 PH 2-Pin connector is widely used in RC toys and mini drones. It is often found on Hubsan or Eachine drones, for example. This is good news because it will also be very easy to find compatible batteries without having to hack. Only regret, it will be difficult to find batteries beyond 1200 mAh. A big advantage of the ESP32 being its very low consumption, it should not be too much problem. It remains to optimize the code to put the module to sleep and limit the sending of data to save the battery.

What is MicroPython?

MicroPython is a rewrite (implementation) of the Python language adapted to micro-controllers. It is an open source project launched by Damien George. The source code is available on GitHub here. This project initiated in 2013 was accompanied by a crowdfunding campaign on Kickstarter to launch the PyBoard development card. The project met with immediate success. Today, the PyBoard is a complete development card family that you can buy from the online store. You buy the PyBoard cards, you participate in the support of the project.

Only available for PyBoard, MicroPyton was later worn for other micro-controllers and therefore other card manufacturers. MicroPython is now available for ESP8266, ESP32, WiPy cards, STM32 (STM32F4) cards, Nucleo cards and Espruino Pico cards. To download the firmware that corresponds to your card, go to this page.

As its name suggests, we will code in Python instead of the usual C ++ or Lua code. Of course, not all Python instructions are available. Only commands that are useful for micro-controllers have been brought. All the commands are available on the online documentation.

MicroPython works with a file system or command interpreter called Read-Eval-Print Loop (REPL) available from a serial connection or from an internet browser (this will be WebREPL). It is convenient to test, discover the language and do maintenance operations (file management, connection to a WiFi network …).

For programming, we will use a simple text editor to write the scripts. Then simply copy the files on the card. Of course, it’s a very succinct presentation of MicroPython. We will discover it much better in the next tutorials.

For this first discovery, we will use a Raspberry Pi 3. We will see how to do Windows 10 in the next article). Here is a short video that introduces the concept quickly

MicroPython Test with Wemos LoLin32 Lite

Wemos delivers the LoLin32 Lite with MicroPython. This is the first time that Wemos has abandoned the NodeMCU firmware. It may be necessary to see a lack of interest in Lua language by the Makers. It is true that the impressive number of libraries and examples Arduino leaves little chance to other languages.

For this first tutorial, I suggest you start with the Raspberry Pi. Open a Terminal or connect to SSH from another computer. Connect the LoLin32 Lite to the USB port and run the following command to identify the USB port on which the ESP32 has just been plugged

We therefore know the USB port on which is connected the card (ttyUSB0) and USB converter / serial used by the card (CH341). It’s no secret that the controller is visible next to the micro-USB connector.

Install Python3, pip3 and rshell to communicate with MicroPython firmware

There are several ways to access the Python command interpreter (REPL). After having tested several, I find that the most reliable is rshell (GitHub page). rshell was developed in Python3, so we will install it and pip3 which will be used to install rshell

That’s it, all you have to do is connect to the LoLin32 Lite using the following command


The serial connection is established immediately. If it is not, press the RESET button on the card and start again.

Run the boards command to identify the connected adapter and the files present. As you can see, only the boot.py file is responsible for managing the boot of the card. We can also see the file system that is able to manage a tree.

First MicroPython script

Nothing better than an example to understand how the system works. Open a new Terminal (or SSH connection). Go to the /home/pi folder ( cd /home/pi ) and open a new file with the command nano blynk.py and paste the following code. This little script will just flash an LED connected to pin 19 of the ESP32.

Record with the key combination CTRL + X then Y (En) or O (Fr)

rshell does not support all Linux commands, such as nano.

Transfer and test the MicroPython script

From the rshell Terminal, we will copy the python script on the LoLin32 with the Linux cp command. The command ls followed by the map /pyboard allows to list the files present on the map

Perfect, just have to test!

Test the REPL interpreter

From the rshell Terminal, execute the REPL command to launch the MicroPython command interpreter. It is symbolized by the >>> prompt

To launch our script, we use the command import followed by the name of the script without the extension (py)

If there are no errors (code and wiring), the LED flashes immediately. Awesome ! To stop the script, use the CTRL + C combination. If the LED has remained lit, this is an opportunity to test the command interpreter to turn it off. Run the following lines one after the other.

How to start a script automatically when connecting the card?

The microPython firmware automatically launches the main.py script at power up. It’s easy, just rename the blynk.py script to main.py. This is an opportunity to play with the file system using REPL. We will import the OS module that contains all the file management commands (the documentation is here). Let’s start by listing the files

The rename command allows you to rename a file. We must put in quotation marks (‘) to avoid any error

Now press the RESET button on the map. A start-up report is displayed on the Terminal and the LED flashes immediately now!

As we are still connected to REPL, we can stop the execution of the main.py script with the CTRL + C combination. By cons, I have not yet found the command that can disconnect from REPL. You have to close the terminal for that.

Here, MicroPython is really a very simple language to take in hand, especially if you already have some notions in Python. If you have simple connected objects to realize (DHT22, accelerometer, servo motors, I2C sensors, PWM), MicroPython is a very interesting alternative to C++ and the Arduino IDE. You will see that on Windows, it’s even easier.

Subscribe to the weekly newsletter

No spam and no other use will be made of your email. You can unsubscribe anytime.

Tags:

DIY Projects