In this post, I'll be introducing the ESP8266 NodeMCU chip and programming it with MicroPython. First thing is first...
How to get started with this device?
Figure: ESP8266 Chip on breadboard
PREREQUISITES
- Having a chip (ESP8266)
- A USB-to-micro-USB cable
- A PC (Windows preferably)
1- Power Up your chip
Plug in USB-micro USB cable to both chip and PC. USB-microUSB cable will be used for both powering up the chip and data transferring over it.
2- Download Firmware
Go to this URL (http://micropython.org/download#esp8266) [4] and download firmware. It is recommended to use latest and stable builds, not daily and experimental ones. Save the firmware file (.bin) that'll be flashed into the device to a known folder in your PC.
Figure: Web Page that firmware resides.
3- Loading Firmware to the Device
"esptool.py" will be used to write firmware to the device. This is also called as Flashing the firmware. If you already know different flashing program, you can use those programs as well.
i) Open command prompt and write "pip install esptool"
ii) Or Download it from github repository (https://github.com/espressif/esptool/) [5]
Figure: Installing esptool.py on local PC
Now that we have "esptool.py" installed on our local PC, we can use it to copy the firmware file we downloaded onto the chip. Before writing firmware to the flash memory of the chip, whole flash memory should be erased. To erase the flash of the chip, use below command by noting that COM number of your device might be different in your PC. Just replace it with the correct COM number.
esptool.py --port COM3 erase_flash
If you use an OS other than Windows (like Unix), serial COM might be like this: /dev/ttyUSB0
In that case, just replace the port expression in the command.
esptool.py --port /dev/ttyUSB0 erase_flash
Figure: Flash memory of the chip is erased.
An important note at this point is that you should be seeing your device as a Serial Port on Device Manager (i.e. COM3). If you see exclamation mark, instead of COMX, then you may need to install
USB to UART Bridge VCP Driver Software on your PC so that device could be detected as a Serial Interface. To install this sw, go to https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers [3].
Now that we erased the whole flash and ensured that nothing special is written on Flash that we don't desire to have, it is time to load firmware to the flash.
Open Command Prompt where firmware is saved (Shift + Right Click -> Open Command Prompt Here) and run below command:
esptool.py --port COM3 --baud 115200 write_flash --flash_size=detect -fm dio 0 FirmwareSw.bin
If the chip you use is not of a type NodeMCU, you can get rid of "-fm dio" part as well and end up with command below:
esptool.py --port COM3 --baud 115200 write_flash --flash_size=detect 0 FirmwareSw.bin
When command above is examined carefully, one can see that COM3 is used as a Serial Port, baud rate of the Serial Port is set as 115200, flash size is set to detected automatically etc. When above command is run, we see that the chip I used in this demo has 4 MB flash size as seen in Figure below.
Now, our chip is ready to be programmed using MicroPython.
TEST ENVIRONMENT
OS: Windows 10, 64-bit PC
Chip Used: ESP8266 NodeMCU (Flash Size 4 MB)
Firmware Used: esp8266-20171101-v1.9.3.bin
Some Tips:
- Don't use Powershell but Command Prompt if you use Windows 10 PC.
- Try using different baud rates while flashing your firmware if 115200 doesn't work for you.
- Do not forget to setup Serial Communication tools accordingly in terms of Baud rate and Com number.
- Make sure that your device is detected as Serial Interface by your PC.
- Static charges that you may accumulate on your body may give harm to the chip.
REFERRENCES:
[1] https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/intro.html
[2] https://dev.to/kenwalger/micropython-and-the-nodemcu-esp8266
[3] https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers
[4] http://micropython.org/download#esp8266
[5] https://github.com/espressif/esptool/
Comments
Post a Comment