#24 NodeMCU: Begin with MicroPython Programming (LED Blinking)

IoT Tutorial #24 [ NodeMCU Tutorials #9 ]
NodeMCU ESP8266 comes with Lua firmware by default.

In order to run the python code on nodeMCU ESP8266, you need to change the firmware of NodeMCU ESP8266 from Lua (Default) to MicroPython firmware, steps are given in the previous post.

Here, I will demonstrate how to run Python / MicroPython program on NodeMCU ESP8266 for first time.


Problem Statement:  

Blink LED connected to the NodeMCU using Python programming.

Requirement:

1. NodeMCU ESP8266 Board
2. micro USB cable
3. LED
4. Resistor - 1k
5. Female to male relimate - 2 Nos.
6. Internet connection

NOTE: LED+ is Connected to D5 of NodeMCU ESP8266




Steps:

    1. Flash Fresh MicroPython firmware using NodeMCU Flasher (Click here to Check how) > Close Flasher

    2. Make below mentioned connections:
      LED       NodeMCU (ESP8266)
      LED+  to  D5
      LED-  to  gnd

    3. Keep NodeMCU connected > Open ESPlorer > A new ESPlorer window will open.
      "Port" must be automatically detected there. Set Baud_rate = 115200
      Go to settings > Select "Firmware" > Tick radio button of "MicroPython" and again click on "Script".

      NOTE: If PORT is not getting detected then you need to install drivers:
      https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers

      Click on "Open" to Check the firmware version of nodemcu.
      then click "RST" button on NodeMCU.

      It will show the Firmware version...


    4. Copy following code and Place it in the left black window of ESPlorer and save it with .py extension:
      import time
      import machine
      
      pin = machine.Pin(14, machine.Pin.OUT)   #D5 pin
      
      pin1 = machine.Pin(2, machine.Pin.OUT)    #Built-in LED
      pin2 = machine.Pin(16, machine.Pin.OUT)   #Built-in LED
      
      while True:
          pin.on() 
          time.sleep(1)
          pin.off()
          time.sleep(1)

    5. Then Click on "Send to ESP"

    6. LED Connected to D5 pin of NodeMCU should Blink with 1 sec delay....as
    7. You must have observed, for blinking LED connected to pin D5 on NodeMCU, We have use no. "14" in the programming, that is because Actual pin numbers and and Pin no. written on the board (for the ease of work) are different.
      Follow below mentioned pin mapping while working on Python program using NodeMCU ESP8266:
      static const uint8_t D0   = 16;
      static const uint8_t D1   = 5;
      static const uint8_t D2   = 4;
      static const uint8_t D3   = 0;
      static const uint8_t D4   = 2;
      static const uint8_t D5   = 14;
      static const uint8_t D6   = 12;
      static const uint8_t D7   = 13;
      static const uint8_t D8   = 15;
      static const uint8_t D9   = 3;
      static const uint8_t D10  = 1;




For Better understanding you can watch demonstration video given below:

Downloads:

Download link is given in the Description of the YouTube video shown below.

Demonstration:








--------------------------------------------------------------------------------

Click here to see more codes for Raspberry Pi 3 and similar Family.
&
Click here to see more codes for NodeMCU ESP8266 and similar Family.
&
Click here to see more codes for Arduino Mega (ATMega 2560) and similar Family.

Feel free to ask doubts in the comment section. I will try my best to solve it.
If you find this helpful by any mean like, comment and share the post.
This is the simplest way to encourage me to keep doing such work.

Thanks and Regards,
-Akshay P. Daga

Post a Comment (0)
Previous Post Next Post