Thursday 16 November 2017

MicroPython + NodeMCU Getting Started


(0) sudo pip install esptool
(1) esptool.py --port /dev/ttyUSB0 erase_flash

esptool.py v2.1
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 7.8s
Hard resetting...

(2) esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 esp8266-20171101-v1.9.3.bin 

esptool.py v2.1
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Flash params set to 0x0040
Compressed 600888 bytes to 392073...
Wrote 600888 bytes (392073 compressed) at 0x00000000 in 8.9 seconds (effective 542.3 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting...

(3) picocom /dev/ttyUSB0 -b 115200

picocom v1.7

port is        : /dev/ttyUSB0
flowcontrol    : none
baudrate is    : 115200
parity is      : none
databits are   : 8
escape is      : C-a
local echo is  : no
noinit is      : no
noreset is     : no
nolock is      : no
send_cmd is    : sz -vv
receive_cmd is : rz -vv
imap is        : 
omap is        : 
emap is        : crcrlf,delbs,

Terminal ready

////////////////////////////////////////////////
I have to unplug and plug the USB back in. Resetting the device won't work. I got the following error message:

picocom v1.7

port is        : /dev/ttyUSB0
flowcontrol    : none
baudrate is    : 115200
parity is      : none
databits are   : 8
escape is      : C-a
local echo is  : no
noinit is      : no
noreset is     : no
nolock is      : no
send_cmd is    : sz -vv
receive_cmd is : rz -vv
imap is        : 
omap is        : 
emap is        : crcrlf,delbs,


FATAL: cannot open /dev/ttyUSB0: Device or resource busy

This could also be a bad usb cable. Use a good one with a data line on it.


///////////////////////////////////////////////////
///////////////////////////////////////////////////
///////////////////////////////////////////////////
Also you might need to press enter a few times to see the Python prompt:

.......
imap is        : 
omap is        : 
emap is        : crcrlf,delbs,

Terminal ready

>>> 
>>> 
>>> 

(4) Start playing around
Hookup an LED on D7 which is mapped to GPIO13.

>>> import machine
>>> pin = machine.Pin(13, machine.Pin.OUT)
>>> pin.on()
>>> pin.off()

You can see the LED goes on and off now. Happy tinkering!


ref:
https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/intro.html
https://dev.to/kenwalger/micropython-and-the-nodemcu-esp8266
http://www.instructables.com/id/MicroPython-Basics-Using-NodeMCU-ESP8266/
https://hackaday.com/2016/07/21/micropython-on-the-esp8266-kicking-the-tires/

No comments:

Post a Comment