SlideShare ist ein Scribd-Unternehmen logo
1 von 26
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
compatible subset of Cpython & core libraries
• machine library for hardware / GPIO
• Open Source: MIT license
• https://github.com/micropython/micropython
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)
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
Adafruit Feather
HUZZAH ESP8266
• Built-in 100mA LiPo charger
• Fantastic docs and tutorials
• https://learn.adafruit.com/
adafruit-feather-huzzah-
esp8266/overview
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
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
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
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
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/
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
ap=network.WLAN(network.AP_IF)
ap.config(essid="mycustomssid", password="mypassword")
• upload the main.py file
• restart the microcontroller
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
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
Read more
• Anna’s blog:
– http://crufti.com/
• Twitter: @AnnaGerber
• Micropython ESP8266 Quick reference:
– https://docs.micropython.org/en/latest/esp8266/
esp8266/quickref.html

Weitere ähnliche Inhalte

Mehr von Anna Gerber

Data Visualisation Workshop (GovHack Brisbane 2014)
Data Visualisation Workshop (GovHack Brisbane 2014)Data Visualisation Workshop (GovHack Brisbane 2014)
Data Visualisation Workshop (GovHack Brisbane 2014)
Anna Gerber
 

Mehr von Anna Gerber (14)

International NodeBots Day Brisbane roundup (BrisJS)
International NodeBots Day Brisbane roundup (BrisJS)International NodeBots Day Brisbane roundup (BrisJS)
International NodeBots Day Brisbane roundup (BrisJS)
 
JavaScript Robotics
JavaScript RoboticsJavaScript Robotics
JavaScript Robotics
 
Intro to Electronics in Python
Intro to Electronics in PythonIntro to Electronics in Python
Intro to Electronics in Python
 
Data Visualisation Workshop (GovHack Brisbane 2014)
Data Visualisation Workshop (GovHack Brisbane 2014)Data Visualisation Workshop (GovHack Brisbane 2014)
Data Visualisation Workshop (GovHack Brisbane 2014)
 
Supporting Open Scholarly Annotation
Supporting Open Scholarly AnnotationSupporting Open Scholarly Annotation
Supporting Open Scholarly Annotation
 
Supporting Web-based Scholarly Annotation
Supporting Web-based Scholarly AnnotationSupporting Web-based Scholarly Annotation
Supporting Web-based Scholarly Annotation
 
Annotations Supporting Scholarly Editing (OA European Roll Out)
Annotations Supporting Scholarly Editing (OA European Roll Out)Annotations Supporting Scholarly Editing (OA European Roll Out)
Annotations Supporting Scholarly Editing (OA European Roll Out)
 
Annotation Tools (OA European Roll Out)
Annotation Tools (OA European Roll Out)Annotation Tools (OA European Roll Out)
Annotation Tools (OA European Roll Out)
 
Intro to data visualisation
Intro to data visualisationIntro to data visualisation
Intro to data visualisation
 
Annotations Supporting Scholarly Editing
Annotations Supporting Scholarly EditingAnnotations Supporting Scholarly Editing
Annotations Supporting Scholarly Editing
 
Getting started with the Trove API
Getting started with the Trove APIGetting started with the Trove API
Getting started with the Trove API
 
Intro to Java
Intro to JavaIntro to Java
Intro to Java
 
HackFest Brisbane: Discover Brisbane
HackFest Brisbane: Discover BrisbaneHackFest Brisbane: Discover Brisbane
HackFest Brisbane: Discover Brisbane
 
Using Yahoo Pipes
Using Yahoo PipesUsing Yahoo Pipes
Using Yahoo Pipes
 

Kürzlich hochgeladen

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 

Getting started with IoT development using MicroPython

  • 1. Get started with IoT development using MicroPython Anna Gerber
  • 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. 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. 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. Adafruit Feather HUZZAH ESP8266 • Built-in 100mA LiPo charger • Fantastic docs and tutorials • https://learn.adafruit.com/ adafruit-feather-huzzah- esp8266/overview
  • 7. WeMos D1 mini • Low cost • https://wiki.wemos.cc/ products:d1:d1_mini
  • 8. NodeMCU DevKit v1.0 • Open Source Hardware • http://nodemcu.com/ index_en.html
  • 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. 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. 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. 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. Using the machine library from machine import Pin led = Pin(13, Pin.OUT) led.on() led.off()
  • 15. Read from a pin from machine import Pin button = Pin(12, Pin.IN, Pin.PULL_UP) # Read the button value: button.value()
  • 16. Read from a button
  • 18. Uploading code using the WebREPL
  • 19. Analog sensors • Only one ADC pin • Max voltage of 1V – use a voltage divider import machine adc = machine.ADC(0) adc.read()
  • 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. 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.
  • 23.
  • 24.
  • 25. 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
  • 26. Read more • Anna’s blog: – http://crufti.com/ • Twitter: @AnnaGerber • Micropython ESP8266 Quick reference: – https://docs.micropython.org/en/latest/esp8266/ esp8266/quickref.html

Hinweis der Redaktion

  1. Runs on microcontrollers and other constrained environments 256K code space Compiler runtime
  2. Which microcontrollers run micropython? These ports have been developed Kickstarter in 2013 produced pyboard Kickstarter early 2016 for official ESP8266 support (on boards like Adafruit feather HUZZAH)
  3. Oficially supported by MicroPython kickstarter
  4. Only 1 ADC pin so use an exernal ADC if you need lots of analog inputs SPI I2C – communication protocols used to attach peripheral devices like sensors – same GPIO pins as Arduino for compatibilitiy – it’s software I2C so you can use any pins
  5. Designed to use with the NodeMCU firmware for programming with Lua
  6. Main.py is the program that runs after boot.py
  7. Solder wires onto strip