Skip to main content

How to Setup ESP8266 NodeMCU with MicroPython?


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 UsedESP8266 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

Popular posts from this blog

How to Fill out a Cheque?

In this post, I will demonstrate how to fill out a cheque properly. You can have a cheque book either from your bank or any store. If you find these two suggestions expensive, you could also design and print out your own cheque. In Figure 1, a sample cheque is displayed and in Figure 2, some regions of the sample cheque are highlighted. Figure 1: Sample unfilled cheque. Figure 2: Some regions are highlighted in sample cheque. 1- Name and Address of Payer: Name and  address of the person who is the owner of this cheque and is filling out the cheque should be written in this region. 2- Date: For any official document, date is a mandatory field and hence you should write current date in this region. 3- Payee Name: Payee could be either a person or an organization (Store, Restaurant, Company, School etc.) You should write the name of the payee here explicitly. 4- Amount of Payment (Numeric): Exact amount of the payment should be w

Star Wars ASCIImation with Python - Windows

In this post, we'll watch a Star Wars movie in ASCII format. The only thing we need for this demo is Python-installed PC and internet connection. Figure : Screenshots from Python Command line while Star Wars is being streamed All credits gained in this demo will go to " blinkenlights.nl " [2] website, which broadcasts this ASCII movie using Telnet protocol on Port 23, and Python which makes socket implementation very easy for us. No authentication is needed for this broadcast. Anyone who is able to create a TCP socket and listens  blinkenlights.nl  on port 23 would be able to get this stream and display on their Python command line. CODE My main source for Python source code is [1]. What  code below does is simply importing Python "socket" library, create a socket, use " towel.blinkenlights.nl " address variable to create connection, receive data from socket and display it. While typing (copy/paste) code, be careful about indentatio

Internet of Things (IoT) with MicroPython

VIDEO LIVE DEMO Please check the link for Live DEMOs  SLIDES REFERENCES    [1] http://micropython.org/    [2] WebREPL: http://micropython.org/webrepl/    [3] Programming with MicroPython, Nicholas H. TollerWay    [4] http://dpgeorge.net/    [5] https://github.com/micropython/micropython    [6] https://www.youtube.com/watch?v=EvGhPmPPzko&t=1488s    [7] https://forum.micropython.org/viewtopic.php?t=744    ABBREAVIATIONS   REPL : Read Evaluate Print Loop