In the previous two articles (unpacking the Wemos LoLin32 Lite under MicroPython and reinstalling the MicroPython firmware), we briefly discovered the MicroPython firmware pre-installed on the Wemos LoLin32 Lite. MicroPython is a port of the Python language adapted to micro-controllers. We have an interpreter (REPL and WebREPL from a browser) as well as a file system that can manage scripts. The command interpreter REPL (or WebREPL) is perfect to do tests, take control of the environment and do maintenance operations (WiFi configuration, script management, stop a script …) but it’s far from ‘an editor.
Fortunately, the Dfrobot team has developed a simple and very effective small code editor (IDE). It can even install the MicroPython firmware as soon as you plug in a new development board. It supports boards based on ESP32, ESP8266, Pyboard, WyPi and Micro: bit of the BBC. We will discover all of this now
Install uPyCraft on Windows
At the moment the uPyCraft IDE is only available for Windows. I tested it on a Windows 10 64-bit without any crashes. The versions for macOS and Linux are announced but the link is not yet active. The source code is unfortunately not available for download, so we can not adapt and compile the code for other platforms. The uPiCraft download page is here. uPiCraft comes as an executable that requires no installation. It is very convenient to carry on a USB key.
Install the MicroPython firmware on an ESP8266 or ESP32
If you have not yet tested the firmware MicroPython, it may be the moment. Get an ESP8266 or ESP32 board. Here I used a Wemos d1 mini. Plug the board into a USB port and launch uPiCraft. In the Tools menu, open the Serial submenu and select the COM port to which the board is connected. uPiCraft is able to install firmware on ES8266, ESP32-based boards as well as on BBC microbit boards.
There are two methods to install the firmware. The first is to connect to the board by clicking on the connection icon (be careful, the icon is reversed).
If the firmware is not detected, a window opens and offers to install it. The second method is to call the Burn Firmware installation utility from the Tools menu.
Several options are available:
- You must indicate the type of board : ESP8266, ESP32 or microbit
- You can erase the flash memory, the erase_flash command from the esptool.py tool. It is preferable
- Enter the COM port if multiple boards are connected. Be careful not to fool you, the best is to unplug the other boards!
- uPicraft is able to retrieve the latest available firmware version for the selected board. An internet connection is necessary for this
- Otherwise, we can indicate the path to a recovered firmware directly on the official site of MicroPython here
We finish by launching the installation of the firmware.
Features offered by uPiCraft
uPiCraft behind its simple interface provides all the features we already know about the command line tools rshel (presented in this tutorial) or ampy of Adafruit. The huge advantage of uPiCraft is to be able to develop directly on the board. You can at any time upload (Download) or upload and execute (Download And Run) the script. We also have access to the file system. You can navigate the folder tree and perform
We have a workspace that allows us to manage projects.
File menu options are very classic. In addition to the functions of creation, opening and saving of files, one also finds the menu Examples which groups the examples by categories. Some examples are simple shortcuts that show the example that uses the desired function. The flush Directory option refreshes folders and files in the side navigation bar. This is useful when manually adding or moving files into the workspace. This is also the only time we have at the moment to organize the files in the workspace. You have to go through the Windows file manager to manually move the files into the project folders.
uPiCraft is a simple editor but has a syntax check (Check Syntax option).
If you want to get started in the development of connected objects in MicroPython, you must absolutely test uPiCraft. The code editor is able to check the syntax and indicate the lines concerned in case of error. The communication with the board is totally transparent. You can start or stop a script at any time (with the F5 key). The boot.py boot script is very easy to modify. Finally uPiCraft offers some libraries that lack the firmware (temperature measurements ds18b20, HT1632, MLX90614, OLED screen SSD1306, MQTT …). There are also some examples to take in hand the language. It is accessed from the File menu. The list of examples is changed according to the development board selected in the Tools -> Board menu.
Icon bar and context menu
Finally, we have a menu bar that includes some commands:
- Create a new script
- Open a file
- Save current file
- Send and launch the script on the board
- Stop the running script on the board
- Connection / disconnection to the board via the serial port (note, the icon is reversed
- Cancel (Undo) / redo (Redo)
- Check syntax
- Clear the console
Finally, we have a contextual menu to perform the operations on the files. It is opened by right clicking on a file. The menu allows you to:
- Run: run the script execution
- Open: get the script and open it in the editor.
- Close: Closes the file in the editor. Attention, there is no verification. If changes have been made to the file, you must already save them and send the file with the Download option from the Tools menu.
- Delete: clears the file
- Default Run: uPiCraft creates a main.py file (launched automatically when the board is started) and creates a link to the file to launch it when the board is started. It’s a good way to structure your project instead of coding everything in the main.py script. Here’s an example of an exec script call exec(open(‘./demo.py’).read(),globals())
- Rename: to rename the file
- New Dir: to create a new folder
Note on handling files
As we have just seen, the new scripts are saved in the workspace. To send them on the board, you can proceed in 3 ways:
- From the Tools menu
- Download to upload
- DownloadAndRun to upload and execute it directly
- With the help of the mouse, you can directly drag the file onto the device. It is not possible to move a complete folder in this version
A small example to finish
Nothing better than a small example to conclude this article. Go to the File menu and in the Basic examples, open the Blynk script. Change the pin. Here, I connected the LED on pin D4 which corresponds to the GPIO2. If necessary, here is the spindle location of the ESP8266. Unlike ESP8266 programming in C++ with the Arduino IDE, there is no pin boardping. For example, you should indicate 2 instead of D4.
#hardware platform: FireBeetle-ESP8266 import time from machine import Pin led=Pin(2,Pin.OUT) while True: led.value(1) time.sleep(0.5) led.value(0) time.sleep(0.5)
Make sure you are connected to the ESP8266 and press F5 to upload and start the script. The LED should start flashing immediately. To interrupt the script, place the cursor in the console at the bottom of the screen and press CTRL + C.
If the LED remains on, execute the following commands
>>> from machine import Pin >>> led=Pin(2,Pin.OUT) >>> led.value(0)
That’s it, I hope you’ll want to try MicroPython now. It is an extremely powerful language and quite simple to handle. In the next tutorial we will see how to manage the WiFi connection.
- ESP32 MicroPython project with several DS18B20 probes, publish the measurements to Domoticz using the HTTP JSON API
- OLED display SSD1306 in MicroPython, example with a I2C digital barometer BME280 (or BMP180)
- MicroPython tutorial, manage WiFi connection at startup on ESP8266 / ESP32
- uPiCraft, a MicroPython IDE dedicated to the development of IoT based on ESP8266, ESP32, microbit, pyBoard
- How to reinstall the MicroPython firmware on an ESP8266 or ESP32 with the esptool.py script
- Unpacking the Wemos ESP32 Lolin32 Lite, testing the firmware MicroPython with a Raspberry Pi 3