Ir al contenido principal

Playing with NodeMCU and MicroPython

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):
  1. 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.
  2. 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 .
  3. Having activated esp8266 python virtualenv, i installed 'esptool' using pip. Just do: pip install esptool
  4. 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
  5. 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 460800
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... 
If no errors are printed that's all! Now you have MicroPython on your NodeMCU board! :)

How to get a Python shell

  1. Install picocom: sudo apt install picocom
  2. 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 tool
Nice docs about using MicroPython on NodeMCU on Learn Adafruit Documentation

Comentarios

Entradas populares de este blog

Running Spotify on a C.H.I.P

I have an old audio player that mostly didnt work. AM, FM and the CD player didn't worked, but Line In audio Yes! So, i decided to check out if it was possible to use a C.H.I.P  (it has a Line out audio port) install Spotify on it and if possible, control it remotly using a web browser. Good news! It was possible and it works excellent! How to do it 1- First, i followed this howto: https://bbs.nextthing.co/t/howto-spotify-on-chip/17660  Just in case the post is deleted or something, here is a screenshot capture: 2- As a mopidy web client i installed Mopidy Iris: https://github.com/jaedb/Iris/wiki/Getting-started#installing That's all!    Here a video with the result:

Arrancar a programar Python en OpenBSD

Bueno, esto es bien facil. Lo primero que debemos configurar es la variable de entorno PKG_PATH que es utilizada por pkg_add . pkg_add es la utilidad para instalar paquetes en OpenBSD. Por ejemplo, yo guarde en el archivo .profile de mi home lo siguiente: export PKG_PATH=ftp://ftp.openbsd.org.ar/pub/OpenBSD/5.0/packages/ amd64 Ojo al piojo con lo que va detras de la ultima trailing slash, en mi caso puse amd64 puesto que es la version de OpenBSD que instale en mi compu, vos lo podes saber con el comando: $ machine -a Perfecto, hecho esto preguntamos con la utilidad pkg_info -Q que versiones de python tenemos disponibles: # pkg_info -Q python                                                                                                                       biopython-1.50p1 dbus-python-0.84.0p0 (installed) ... python-2.4.6p10 python-2.5.4p13 python-2.7.1p9 (installed) ... Perfecto, usamos pkg_add para instalar (a mi me aparece como instalada porque bue

Setting up React Native on Ubuntu 17.04

React native seems to be very promising, so i decided to give it a try. Steps to get it running: 1- Install ubuntu dependencies: sudo apt install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386 If you dont install those dependencies, probably when building your react native project, you will get an error saying: "java.io.IOException: Cannot run program "/home/edvm/Code/Android/Sdk/build-tools/23.0.1/aapt" (in directory "/home/edvm/Code/github/edvm/react/AwesomeProject"): error=2, No such file or directory" 2- Just follow steps detailed at  Getting started . 3- When you finish step 2, you will be able to build and run your react native project using your android smartphone. Steps to accomplish that are detailed at Running on Device . That's all, short post just for the records.