Connect NodeMCU from Raspberry Pi

Initial Connect

$ sudo apt install minicom
$ minicom -b 9600 -o -D /dev/serial0

Build Firmware

$ git clone https://github.com/nodemcu/nodemcu-firmware.git
$ docker run --rm -v $PWD/nodemcu-firmware:/opt/nodemcu-firmware marcelstoer/nodemcu-build
$ ls -lh nodemcu-firmware/bin/
total 3.0M  
-rw-r--r-- 1 root root  26K Sep 25 21:52 0x00000.bin
-rw-r--r-- 1 root root 334K Sep 25 21:52 0x10000.bin
-rw-r--r-- 1 root root 411K Sep 25 21:51 nodemcu_float_master_20160925-1350.bin
-rw-r--r-- 1 root root 970K Sep 25 21:51 nodemcu_float_master_20160925-1350.map
-rw-r--r-- 1 root root 398K Sep 25 21:52 nodemcu_integer_master_20160925-1350.bin
-rw-r--r-- 1 root root 912K Sep 25 21:52 nodemcu_integer_master_20160925-1350.map

Flash Firmware

  • Press and hold FLASH
  • Press and release RST
  • Wait for LED
  • Release FLASH
  • ... flashing ...
  • Press and release RST
$ sudo pip install esptool

$ esptool.py --port /dev/serial0 read_mac
esptool.py v1.1  
Connecting...  
MAC: 60:01:94:0b:a6:22

$ esptool.py --port /dev/serial0 chip_id
esptool.py v1.1  
Connecting...  
Chip ID: 0x000ba622

$ esptool.py --port /dev/serial0 flash_id
esptool.py v1.1  
Connecting...  
Manufacturer: ef  
Device: 4016

$ wget --content-disposition http://bbs.espressif.com/download/file.php?id=157

$ unzip ESP8266_NONOS_SDK_V1.5.4.1_patch_20160704.zip esp_init_data_default.bin

$ esptool.py --port /dev/serial0 write_flash -fm dio -fs 32m 0x00000 nodemcu_float_master_20160925-1350.bin 0x3fc000 esp_init_data_default.bin

Interactive Shell

$ minicom -b 115200 -o -D /dev/serial0
NodeMCU 1.5.4.1 build unspecified powered by Lua 5.1.4 on SDK 1.5.4.1(39cb9a32)  
lua: cannot open init.lua

> print('hello world')
hello world

> pin = 0
> gpio.mode(pin, gpio.OUTPUT)
> gpio.write(pin, gpio.HIGH)

> wifi.setmode(wifi.STATION)
> wifi.sta.config('MiWiFi', '********')
> wifi.sta.connect()
> print(wifi.sta.getip())
192.168.31.130  255.255.255.0   192.168.31.1

> file.format()