ESP8266, Programming, Python, Tech

MicroPython on NodeMCU V3 / ESP8266

I’m a big fan of Python. It’s easy to use and quite powerful. When I heard that there is Python firmware for microcontrollers I had to try it.

The NodeMCU V3 board I used looks like this:

71ainkxuyil._sx425_


Here are instructions to flashing the MicroPython firmware:

NOTE: The following instructions are to be executed on Linux. I used a Ubuntu virtual machine to do this.

1. Open a Bash terminal

2. Create a new folder “esp” and go inside it

3. Download the new firmware from http://micropython.org/download under the section titled “Firmware for ESP8266 boards”. Click on the file that looks like “esp8266-20190125-v1.10.bin”.

4. Install the “esptool” firmware flashing tool:

sudo pip install esptool

5. Connect the ESP board to your computer

6. Check which port the board is connected by executing “dmesg” and you should see something like this:Capture1

Look at the line which says “…now attached to…” and note that device name, eg ttyUSB0.

7. Execute the command to erase the flash memory. Remember to change the device name to whatever it is on your computer

sudo esptool.py --port /dev/ttyUSB0 erase_flash

You should see this:

Capture2

8. Execute the command to flash the new firmware

esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect -fm dio 0 esp8266-20170108-v1.8.7.bin

You should see this:

Capture3

9. That’s it!


Here are the instructions to check the new firmware:

1. Install picocom

sudo apt install picocom

2. Run picocom

sudo picocom /dev/ttyUSB0 -b115200

You should see this:
Capture4

3. That’s it!

NOTE: Hit Ctrl + A + X to exit picocom.


Woo hoo! Good luck 🙂

Advertisements
ESP8266, NodeMCU

NodeMCU and Nokia 5110 LCD

I’m using a NodeMCU 1.0 (ESP8266/ESP-12E) and a Nokia 5110 LCD (driven by PCD8544). Both are 3.3V so you can connect them directly. The following libraries are required:

  • Adafruit GFX Library
  • Adafruit PCD8544 Nokia 5110 LCD library

NOTE 1: The code in the library needs for this to work because it doesn’t include support for the ESP8266. The code change is small don’t worry, it is explained below.

NOTE 2: This method uses the hardware SPI on the NodeMCU. I tried using the software SPI and it didn’t work for me.

Here are the steps:

  1. Open Arduino IDE
  2. Click on Tools and then Manage Libraries
  3. Search for “Adafruit”
  4. Install “Adafruit GFX Library” and “Adafruit PCD8544 Nokia 5110 LCD library”
  5. Go to directory where the libraries are installed (normally C:\Users\USERNAME\Documents\Arduino\libraries\Adafruit_PCD8544_Nokia_5110_LCD_library)
  6. Edit Adafruit_PCD8544.cpp
  7. Look for the line “#include <avr/pgmspace.h>” and replace with this:
#ifdef ESP8266
  #include 
#else
  #include 
#endif
  1. Edit Adafruit_PCD8544.h
  2. Look for the line “#ifdef __SAM3X8E__” and add this before the “#else” line:
#elif defined(ESP8266)
  typedef volatile uint32_t PortReg;
  typedef uint32_t PortMask;  
  1. From the Examples menu, open the “Adafruit PCD8544 Nokia 5110 LCD library\pcdtest” sketch. This sketch is a demo of the graphics capabilities.
  2. Look for the line “Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);” and comment it out
  3. Look for the line “// Adafruit_PCD8544 display = Adafruit_PCD8544(5, 4, 3);” and uncomment it and change it “Adafruit_PCD8544 display = Adafruit_PCD8544(D0, D1, D2);”
  1. Connect the wiring like this:
Nokia LCD--------------NodeMCU
SCLK-------------------D5
MOSI-------------------D7
D/C--------------------D0
RST--------------------D2
SCE--------------------D1
GND--------------------GND
VCC--------------------3V3
  1. Compile and download
  2. Voila! 🙂

TIP: I noticed that the display was a bit dark. I fixed it by changing the contrast from 50 to 40. Look for the line “display.setContrast(50);” in the setup routine.

Arduino, ESP8266, NodeMCU, Programming

NodeMCU ESP8266 CP1202 Programming (Blink)

This is the tutorial for programming the NodeMCU CP1202 board using the Arduino IDE. The code that will be used is the Blink example. And the board that I’m using looks like this.

Image result for cp1202 nodemcu

Here are the steps I followed:

  1. Install the drivers from https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers
  2. Download the ESP8266 board information for Arduino
    1. Open the Arduino IDE
    2. Click on the File menu and then Preferences
    3. In the Additional Boards Manager URLs, enter this: http://arduino.esp8266.com/stable/package_esp8266com_index.json
    4. Click Ok
    5. Click on the Tools menu, click Boards and then click Boards Manager
    6. Wait for it to download the new boards information
    7. Search for ESP8266 and install it
  3. From the Tools menu, select the following:
    1. Board: NodeMCU 1.0 (ESP-12E Module)
    2. Flash Size: 4M (3M SPIFFS)
    3. CPU Frequency: 80MHz
    4. Upload Speed: 115200
    5. Port: (whichever COM port it is)
    6. Erase Flash: Sketch Only
  4. From the File menu, click Examples, click ESP8266 and then click Blink
  5. Compile and download
  6. Voila! 🙂