Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Get started with IoT
development using MicroPython
Anna Gerber
MicroPython
• Python 3.x for microcontrollers
• Runs in 256k and 16k of RAM
• Features: REPL, filesystem, aims to be a
com...
Compatible Hardware
• pyboard
• TI CC3200 microcontrollers (e.g. WiPy)
• 16 bit PIC microcontrollers
• Teensy 3.1
• Unix (...
Which ESP8266 dev board?
• Adafruit Feather HUZZAH
ESP8266
• WeMos D1 mini
• NodeMCU
• Features:
• WiFi
• 4MB flash
• 80MH...
Adafruit Feather
HUZZAH ESP8266
• Built-in 100mA LiPo charger
• Fantastic docs and tutorials
• https://learn.adafruit.com/...
https://learn.adafruit.com/adafruit-feather-huzzah-esp8266/pinouts
WeMos D1 mini
• Low cost
• https://wiki.wemos.cc/
products:d1:d1_mini
NodeMCU DevKit
v1.0
• Open Source
Hardware
• http://nodemcu.com/
index_en.html
Preparation
• First install any USB-serial drivers required for
your board e.g. CP2104, CH341
• Install Python and esptool...
Flash the firmware
• Download the latest version (e.g. 1.9.1) of
MicroPython from GitHub releases:
– https://github.com/mi...
Connect to the board
• Connect to REPL via serial (i.e. USB):
– Default BAUD rate is 115200
– screen /dev/tty.SLAB_USBtoUA...
WebREPL
• You can upload / access the REPL over WiFi
• You’ll need to connect via a wired connection to
set it up:
import ...
Using the machine library
from machine import Pin
led = Pin(13, Pin.OUT)
led.on()
led.off()
Connect an LED
Read from a pin
from machine import Pin
button = Pin(12, Pin.IN, Pin.PULL_UP)
# Read the button value:
button.value()
Read from a button
Button program
Uploading code using the WebREPL
Analog sensors
• Only one ADC pin
• Max voltage of 1V – use a voltage divider
import machine
adc = machine.ADC(0)
adc.read...
Change the Wifi config
• Set the default wifi SSID and password on
startup by adding the config to main.py
import network
...
Neopixels
• WS2812B light source
– Chainable, individually addressable RGB LEDs
– Many formfactors (pixel, ring, bar, stri...
Other options for developing with
ESP8266
• NodeMCU Lua
– http://nodemcu.com/index_en.html
• Arduino IDE
– https://github....
Read more
• Anna’s blog:
– http://crufti.com/
• Twitter: @AnnaGerber
• Micropython ESP8266 Quick reference:
– https://docs...
Getting started with IoT development using MicroPython
Getting started with IoT development using MicroPython
Getting started with IoT development using MicroPython
Upcoming SlideShare
Loading in …5
×

Getting started with IoT development using MicroPython

859 views

Published on

Presented at the Brisbane and Gold Coast IoT meetup, July 2017.

MicroPython is a Free, Open Source implementation of Python 3.x that is designed to run on microcontrollers - the tiny embedded computers at the heart of many IoT devices. MicroPython is a valuable tool for rapidly prototyping device functionality and is a great way to get started with developing for the Internet of Things.

This presentation walks through the steps you'll need to follow to take your IoT ideas and make them into reality using MicroPython on ESP8266, including getting your microcontroller set up with MicroPython on-board and developing basic MicroPython programs to read from sensors and control actuators.

Published in: Technology
  • Be the first to comment

Getting started with IoT development using MicroPython

  1. 1. Get started with IoT development using MicroPython Anna Gerber
  2. 2. MicroPython • Python 3.x for microcontrollers • Runs in 256k and 16k of RAM • Features: REPL, filesystem, aims to be a compatible subset of Cpython & core libraries • machine library for hardware / GPIO • Open Source: MIT license • https://github.com/micropython/micropython
  3. 3. Compatible Hardware • pyboard • TI CC3200 microcontrollers (e.g. WiPy) • 16 bit PIC microcontrollers • Teensy 3.1 • Unix (for x86/x64/ARM/MIPS) • ESP8266 • ESP32 (experimental)
  4. 4. Which ESP8266 dev board? • Adafruit Feather HUZZAH ESP8266 • WeMos D1 mini • NodeMCU • Features: • WiFi • 4MB flash • 80MHz processor • 3.3V logic • Up to 11 digital I/O pins, 1 analog I/O pin • Support for (software) I2C, SPI
  5. 5. Adafruit Feather HUZZAH ESP8266 • Built-in 100mA LiPo charger • Fantastic docs and tutorials • https://learn.adafruit.com/ adafruit-feather-huzzah- esp8266/overview
  6. 6. https://learn.adafruit.com/adafruit-feather-huzzah-esp8266/pinouts
  7. 7. WeMos D1 mini • Low cost • https://wiki.wemos.cc/ products:d1:d1_mini
  8. 8. NodeMCU DevKit v1.0 • Open Source Hardware • http://nodemcu.com/ index_en.html
  9. 9. Preparation • First install any USB-serial drivers required for your board e.g. CP2104, CH341 • Install Python and esptool pip install esptool https://github.com/espressif/esptool • Erase the flash of the microcontroller if you have used it before: esptool.py --port /dev/tty.SLAB_USBtoUART erase_flash
  10. 10. Flash the firmware • Download the latest version (e.g. 1.9.1) of MicroPython from GitHub releases: – https://github.com/micropython/micropython/rel eases • Use esptool to upload the firmware file: • esptool.py --port /dev/tty.SLAB_USBtoUART --baud 460800 write_flash --flash_size=detect 0 ~/Downloads/esp8266-20170612-v1.9.1.bin
  11. 11. Connect to the board • Connect to REPL via serial (i.e. USB): – Default BAUD rate is 115200 – screen /dev/tty.SLAB_USBtoUART 115200 • Hit control-e to enter paste mode (to paste longer programs) • You can upload / manage the python program files on the board using ampy: – https://github.com/adafruit/ampy ampy --port /dev/tty.SLAB_USBtoUART put demo.py
  12. 12. WebREPL • You can upload / access the REPL over WiFi • You’ll need to connect via a wired connection to set it up: import webrepl_setup • You can enable it on boot or start it: import webrepl webrepl.start() • Join the device’s adhoc Wifi network: default password is micropythoN – http://micropython.org/webrepl/
  13. 13. Using the machine library from machine import Pin led = Pin(13, Pin.OUT) led.on() led.off()
  14. 14. Connect an LED
  15. 15. Read from a pin from machine import Pin button = Pin(12, Pin.IN, Pin.PULL_UP) # Read the button value: button.value()
  16. 16. Read from a button
  17. 17. Button program
  18. 18. Uploading code using the WebREPL
  19. 19. Analog sensors • Only one ADC pin • Max voltage of 1V – use a voltage divider import machine adc = machine.ADC(0) adc.read()
  20. 20. Change the Wifi config • Set the default wifi SSID and password on startup by adding the config to main.py import network ap=network.WLAN(network.AP_IF) ap.config(essid="mycustomssid", password="mypassword") • upload the main.py file • restart the microcontroller
  21. 21. Neopixels • WS2812B light source – Chainable, individually addressable RGB LEDs – Many formfactors (pixel, ring, bar, strip etc) – Each unit is connected via 3.3V, GND and data pin – Use external power if working with more than a few LEDs • See https://learn.adafruit.com/adafruit- neopixel-uberguide/overview
  22. 22. Other options for developing with ESP8266 • NodeMCU Lua – http://nodemcu.com/index_en.html • Arduino IDE – https://github.com/esp8266/Arduino • Espruino JS – https://www.espruino.com/EspruinoESP8266
  23. 23. Read more • Anna’s blog: – http://crufti.com/ • Twitter: @AnnaGerber • Micropython ESP8266 Quick reference: – https://docs.micropython.org/en/latest/esp8266/ esp8266/quickref.html

×