MicroPython: Environment configuration, firmware burning

created at 07-09-2021 views: 2

Statement: As a beginner, I record the learning content in the form of notes. If there is a mistake, everyone is welcome to correct and criticize, thank you!

The development environment of this machine is MacOS Python3.6
The development steps under Windows may be slightly different

1. Select the desired development board

Here I chose esp32 and esp8266, which are more common and more playable.

board

esp8266 development board and schematic diagram

The picture above is the esp8266 development board and schematic diagram I used

2. Install USB to serial port driver

Make sure your development board has a micro usb interface or has been converted to usb by your own means to connect to your computer.

2.1 check the serial-to-USB chip model

The first thing to do is to check the serial-to-USB chip model on the development board to install the corresponding driver.

The chip of this section is CH340
You should can download the driver 
Install after downloading

2.2 Check whether the driver is valid

Type in the terminal under MacOS

ls  /dev/tty.*

View all files starting with tty. in the /dev directory
The results are as follows:

/dev/tty.Bluetooth-Incoming-Port
/dev/tty.MALS
/dev/tty.SOC
/dev/tty.usbserial-1460
/dev/tty.wchusbserial1460

/dev/tty.wchusbserial1460 is the development board we connected
The number may change with the plug, it is recommended to check it by yourself
The device appears in the form of a com port under Windows, please refer to materials on internet.

3. Choose a development tool

There are many choices of development tools, MuEditer, Thonny, and even Pycharm can install plug-ins to achieve MicroPython development.
This time, considering the usage habits of multiple systems and common tools. We first use a more primitive terminal to use the command line to develop.

I choose the terminal application that comes with Macos for development, and Windows can choose Putty.

After choosing the development tools, you need to install Rshell

Rshell This is a simple shell that runs on the host and uses MicroPython's original REPL to send python fragments to the pyboard to obtain file system information, and copy files to or from MicroPython's file system.

Rshell github project address 

3.1 Installation of rshell

Use pip to install, you need a python environment on this machine, you can use pip --version to check whether there is pip locally

pip install  rshell

In the linux environment, there may be problems with serial port permissions. For details, please refer to the readme document in github

At this point we have completed all the development environment deployments, wait for you to say that the development board has not written MicroPython firmware? Then let's start below.

4. Deploy MicroPython firmware

Deploy MicroPython firmware to the development board

4.1 Download firmware to local

4.1 Download firmware to local
esp8266 MicroPython official firmware download address: here

Official tutorial
Let's make it simple

4.2 Start to write firmware

Enter the path where the firmware was downloaded

Enter the following in the terminal
download tool

pip install esptool

Wipe cache

esptool.py --port /dev/tty.wchusbserial1460 erase_flash

The effect is as follows:

esptool.py v3.0
Serial port /dev/tty.wchusbserial1460
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 8c:aa:b5:59:30:90
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 3.3s
Hard resetting via RTS pin...
  • /dev/tty.wchusbserial1460 is the name of your device, you need to replace it yourself

Flash firmware

esptool.py --port /dev/tty.wchusbserial1460 460800 write_flash --flash_size=detect 0 esp8266-20170108-v1.8.7.bin
  • /dev/tty.wchusbserial1460 is the name of your device, you need to replace it yourself, esp8266-20170108-v1.8.7.bin is the name of the firmware you want to flash, and you can use the Tab key to complete it in the terminal

The effect is as follows

esptool.py v3.0
Serial port /dev/tty.wchusbserial1460
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 8c:aa:b5:59:30:90
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Flash params set to 0x0240
Compressed 632632 bytes to 415634...
Wrote 632632 bytes (415634 compressed) at 0x00000000 in 10.0 seconds (effective 505.2 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

4.3 Verify whether the programming is successful

Still terminal command

rshell -p /dev/tty.wchusbserial1460
  • dev/tty.wchusbserial1460 is the name of your device, you need to replace it yourself

effect:

Using buffer-size of 32
Connecting to /dev/tty.wchusbserial1460 (buffer-size 32)...
Trying to connect to REPL  connected
Retrieving sysname ... esp8266
Testing if ubinascii.unhexlify exists ... Y
Retrieving root directories ... /boot.py/
Setting time ... Jun 05, 2021 13:18:25
Evaluating board_name ... pyboard
Retrieving time epoch ... Jan 01, 2000
Welcome to rshell. Use Control-D (or the exit command) to exit rshell.

Then you can enter repl
A terminal similar to the Python interactive mode appears, you can enter after >>>

print("Hello MicroPython")

Display after carriage return

Hello MicroPython

At this point, your esp8266 has been successfully flashed into MicroPython.

Please log in to leave a comment.