Skip to content

emlyon/Micropyhton-ESP8266-guide

 
 

Repository files navigation

MicroPython for ESP8266 Quick Guide


What is MicroPython

MicroPython is a lean and efficient implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimised to run on microcontrollers and in constrained environments.

Installing Micropython on ESP8266

Download MicroPython latest firmware (.bin file) from MicroPython downloads. Download MicroPython firmware

Download NodeMCU PyFlasher from releases page (works for windows and mac). Download NodeMCU PyFlasher

NodeMCU PyFlasher doesn't have to be installed, just double-click it and it'll start. Select serial port form list, and MicroPython firmware (.bin file) on your computer. Then click Flash NodeMCU button. (NodeMCU PyFlasher was designed with NodeMCU in mind but it does a great job flashing MicroPython on esp8266 boards.) NodeMCU PyFlasher

Using the Python REPL prompt

Launch Arduino, set the port of your board and open the Serial monitor.
Set line ending on NL and CR and baudrate on 115200 baud.
You should be presented with a MicroPython prompt and can now run some MicroPython code on your ESP8266.
Let’s make sure it is working with the obligatory test: type print("hello pyboard!") and press [ENTER]. REPL prompt

Using MicroPython

You've successfully installed MicroPython on your board, congrats! Let's dig in a bit more. Keep the Serial monitor open and type:
import machine # this will add access to hardware
You can get info on any command by typing help(cmd) ie: help(machine)

import machine  
led = machine.Pin( 0, machine.Pin.OUT )
led.on()
led.off

machine — functions related to the hardware

WebREPL

Instead of using Serial, we can control our board via a web interface:

  • Type import webrepl_setup in order to start the WebREPL daemon on startup.

  • Type E to enable on boot, then type a password, finally type y to reboot your board.
    webREPL setup

  • We can now see a new SSID being broadcast from our board.
    networks

  • Download the webREPL files here and extract them, then open up webrepl.html

  • Connect to the Micropython SSID with the micropythoN password. Be careful, you'll lose internet connectivity at this point!
    networks

  • Open up webrepl.html from the webREPL files. You should see the ws://192.168.4.1:8266/ address by default in the connect window. Click connect, and enter the password you set earlier. You now have access to your Micropython-enabled ESP8266 board via wifi!

import machine  
import time
led = machine.Pin( 0, machine.Pin.OUT )
while( True ):
    led.on()
    time.sleep( 0.5 )
    led.off()
    time.sleep( 0.5 )

You can escape from this loop by hitting [Ctrl]+[C]

CircuitPython

Adafruit is releasing a different flavor of MicroPython named CircuitPython. You can find documentation here:

Revert to NodeMCU

If you want to revert your board to NodeMCU, latest firmware updates can be found on github: nodemcu/nodemcu-firmware.
And you can get a build here by simply entering your email and click Start your build.

Sources

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published