ESP8266 nodeMCU module to computer

Micropython ESP8266 nodemcu blink LED

Micropython ESP8266 implemented on nodemcu module step-by-step explanation. Micropython is an extension of python with libraries suited for ESP8266 module. It took us quite some time to understand the intricacies of ESP module. As soon as we kick started, we got fascinated with the fact that, we can program the ESP module with a python code. Henceforth, we have documented all the procedure to program micropython ESP8266. Hope this helps viewers to learn about the nuances of micropython ESP8266. This setup does not need or run on arduino IDE.

The setup explained here is quite simple and does not mandate arduino IDE. This procedure is assists python programmers to control and operate nodeMCU. Usually implemented for IoT based solutions. Micropython, inherently loaded with gamut of readily usable functions and procedures. This assists designers to focus more on the solution, rather than on the nuances of the hardware.

Micropython ESP8266 nodemcu:

Prerequisites:

  • You need 1 unit of nodemcu module
  • 1 USB cable connector
  • A computer / laptop to run the program (with python installed)
  • The procedure is done on a git environment (install git)

nodeMCU ESP8266 module in electrostatic pouchWe received the nodeMCU modules from online shopping. It comes packed in an electrostatic pouch.

It is advisable to use electrostatic strap belts while handling these devices. But in case you want to avoid investing time and effort on electrostatic devices, you can ignore for now.

 

ESP8266 nodeMCU module to computer

The connection of ESP8266 nodeMCU module is quite simple. All it needs is just an USB connector.

As soon as the USB wire is plugs in, a visible BLUE color light blink flickers on the PCB. This is an indication that the module you received should be working fine.

ESP8266 module comparison

ESP8266 module comparison. The nodeMCU modules comes in 2 flavors of USB driver. One with a CP2102 driver and the other with CH340 driver.

The driver ICs are the interface chip for the USB(master) and UART protocol.   However, ESP-8266 main core module is same in both the parts.

Micropython ESP8266 nodemcu programming steps:

Step 1: Download the ESP bin file and extract to a directory location

Download link for esp8266-20191220-v1.12.zip

micropython-ESP-bin-file
esp8266-20191220-v1.12.bin file

Step 2: Download software tool to flash esp8266-20191220-v1.12.bin file to nodeMCU

micropython-ESP8266-nodemcu-programming

2a) $ pip install esptools (this installs the necessary tool to flash the binary to nodeMCU)

2b) $ esptool.py.exe –port com3 erase_flash (this erases the internal flash memory) 

2c) $ esptool.py.exe -p com3 -b 115200 write_flash –flash_size=detect 0 /e/TOOLS/ESP-Node-MCU/esp8266-20191220-v1.12.bin

  • Flashes the binary to nodeMCU 
  • Via COM3 port
  • @ baud 115200 bps
  • The bin file path /e/TOOLS/ESP-Node-MCU/esp8266-20191220-v1.12.bin

Step 3: Microython code to blink on board LED

Micropython code example_led_blink.py
import utime as time
from machine import Pin
def main():
    #default condition LEDs are in glow state
    #led = Pin(16, Pin.OUT) # GPIO16 [D0] On board LED (bottom)
    #led = Pin(5, Pin.OUT) # GPIO5 [D1]
    #led = Pin(4, Pin.OUT) # GPIO5 [D2]
    #led = Pin(0, Pin.OUT) # GPIO0 [D3]
    led = Pin(2, Pin.OUT) # GPIO2 [D4] Onboard LED (top)
    enabled = False

    #led.on() #  <-- this line turns ON LED bright 
    #led.off() # <-- this line turns OFF the LED
    #utime.sleep_ms(2000) # <-- this halts the machine by 2 sec

    i = 0
    while i <= 10:
        i = i + 1
        if enabled:
            led.off()
        else:
            led.on()
        time.sleep_ms(200)
        enabled = not enabled
if __name__ == '__main__':
    main()


Step 4: Python method to access the nodeMCU unit from computer

4a) $ pip install adafruit-ampy

4b) ampy essential commands:

  • $ ampy -p com3 -b 115200 ls (directory listing of root)
  • $ ampy -p com3 -b 115200 put example_led_blink.py (loads the file on ESP8266 module)
  • $ ampy -p com3 -b 115200 run example_led_blink.py (runs the file on the module)

We will be publishing more advanced and implementable micropython codes.

Leave a Reply

Your email address will not be published. Required fields are marked *