Playing with MicroPython and NodeMCU (esp8266).
Installing MicroPython on NodeMCU board.
A time ago i wanted to try MicroPython so i decided to get a NodeMCU board. Its a very cheap one, with a serial to usb chip integrated on the board, so no need to use an usb to serial converter.
The procedure was easy, i just followed the steps detailed at MicroPython documentation website.
For the records the steps i followed (on Ubuntu 17.04):
- Add your user to dialout group. You can use the command: sudo gpasswd --add ${USER} dialout . Then you have to log out and log in.
- Create a virtualenv to install esptool. I did it using python 3 with command: python3 -m venv ~/.virtualenvs/esp8266 . Then i activated the virtualenv with command: source ~/.virtualenvs/esp8266/bin/activate .
- Having activated esp8266 python virtualenv, i installed 'esptool' using pip. Just do: pip install esptool
- Then you will erase the current firmware installed on your NodeMCU. To do that, connect your NodeMCU board with a USB cable to your computer. Then use the command: esptool.py --port /dev/ttyUSB0 erase_flash
- Download latest MicroPython firmware from MicroPython Download Page and upload it to your NodeMCU board with the following command: esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 <replace_with_firmware_name.bin>. Output will be like:
esptool.py v2.0.1 Connecting.... Detecting chip type... ESP8266 Chip is ESP8266 Uploading stub... Running stub... Stub running... Changing baud rate to 460800If no errors are printed that's all! Now you have MicroPython on your NodeMCU board! :)
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Flash params set to 0x0040
Compressed 598432 bytes to 390604...
Wrote 598432 bytes (390604 compressed) at 0x00000000 in 8.7 seconds (effective 548.0 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting...
How to get a Python shell
- Install picocom: sudo apt install picocom
- Connect to ttyUSB0. @math:Downloads $ picocom /dev/ttyUSB0 -b115200
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
>>> import os
>>> os.uname()
(sysname='esp8266', nodename='esp8266', release='2.0.0(5a875ba)', version='v1.9.1-8-g7213e78d on 2017-06-12', machine='ESP module
with ESP8266')
WiFi
After a fresh install and boot the device configures itself as a WiFi access point (AP) that you can connect to. The ESSID is of the form MicroPython-xxxxxx where the x’s are replaced with part of the MAC address of your device (so will be the same everytime, and most likely different for all ESP8266 chips). The password for the WiFi is micropythoN (note the upper-case N). Its IP address will be 192.168.4.1 once you connect to its network.Links
Get or put files on MicroPython using AdaFruit Ampy command line toolNice docs about using MicroPython on NodeMCU on Learn Adafruit Documentation
Comentarios
Publicar un comentario