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 board 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 board 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 board 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 board. The project met with immediate success. Today, the PyBoard is a complete development board family that you can buy from the online store. You buy the PyBoard boards, you participate in the support of the project.
Only available for PyBoard, MicroPyton was later worn for other micro-controllers and therefore other board manufacturers. MicroPython is now available for ESP8266, ESP32, WiPy boards, STM32 (STM32F4) boards, Nucleo boards and Espruino Pico boards. To download the firmware that corresponds to your board, 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 board. 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
dmesg | grep ttyUSB [5253941.605452] usb 1-1.2: ch341-uart converter now attached to ttyUSB0
We therefore know the USB port on which is connected the board (ttyUSB0) and USB converter / serial used by the board (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
sudo apt-get -y install python3 sudo apt-get -y install python3-pip sudo pip3 install rshell
That’s it, all you have to do is connect to the LoLin32 Lite using the following command
rshell --buffer-size = 30 -p /dev/ttyUSB0
The serial connection is established immediately. If it is not, press the RESET button on the board and start again.
Connecting to / dev / ttyUSB0 ... Welcome to rshell. Use Control-D to exit. /home/pi>
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 board. We can also see the file system that is able to manage a tree.
/home/pi> boards pyboard @ /dev/ttyUSB0 connected Dirs: /boot.py
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.
import utime import machine pin19 = machine.Pin(19, machine.Pin.OUT) while True: pin19.value(1) utime.sleep_ms(500) pin19.value(0) utime.sleep_ms(500)
Record with the key combination CTRL + X then Y (En) or O (Fr)
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 board /pyboard allows to list the files present on the board
cp blynk.py /pyboard ls /pyboard blynk.py boot.py
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
/home/pi> repl Entering REPL. Use Control-X to exit. > MicroPython v1.9.2-443-g236297f4 on 2017-11-24; ESP32 module with ESP32 Type "help()" for more information. >>>
To launch our script, we use the command import followed by the name of the script without the extension (py)
>>> import blynk
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 board?
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
>>> import os >>> os.listdir() ['blynk.py', 'boot.py'] >>>
The rename command allows you to rename a file. We must put in quotation marks (‘) to avoid any error
>>> os.rename('blynk.py','main.py') >>> os.listdir() ['boot.py', 'main.py']
Now press the RESET button on the board. A start-up report is displayed on the Terminal and the LED flashes immediately now!
>>> ets Jun 8 2016 00:22:57 rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:2 load:0x3fff0018,len:4 load:0x3fff001c,len:4332 load:0x40078000,len:0 load:0x40078000,len:10992 entry 0x4007a6c4 W (65) rtc_clk: Potentially bogus XTAL frequency: 35 MHz, guessing 40 MHz I (360) cpu_start: Pro cpu up. I (360) cpu_start: Single core mode I (361) heap_init: Initializing. RAM available for dynamic allocation: I (364) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM I (370) heap_init: At 3FFDCD60 len 000032A0 (12 KiB): DRAM I (376) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM I (382) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM I (389) heap_init: At 4008FC7C len 00010384 (64 KiB): IRAM I (395) cpu_start: Pro cpu start user code I (189) cpu_start: Starting scheduler on PRO CPU.
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.


- ESP32, GPIO pins and associated functions. I/O, PWM, RTC, I2C, SPI, ADC, DAC
- M5Stack Atomic GPS. ESP32 TinyGPS++ tracker, GPX export on SD card, visualization on Google Maps or VSCode
- How to store data on a micro SD card. Arduino code compatible ESP32, ESP8266
- Getting started Arduino. Receive commands from the serial port (ESP32 ESP8266 compatible)
- C++ functions print•println•printf•sprintf for Arduino ESP32 ESP8266. Combine•format → serial port
- C++ String functions. concat•c_srt•indexOf•replace•subString… for Arduino, ESP32, ESP8266
Very nice articles. Any reason you use HTTP with Domoticz and not MQTT?
Hi Richard. Both solutions are good. The goal of the tutorial was to mount how to do with HTTP requests. You’re absolutely right, we can do the same thing with MQTT. On the other hand it requires to install an MQTT server. As I tried to make home automation as accessible as possible, I preferred to use HTTP. See you soon. Have a good holiday season: D