SlideShare a Scribd company logo
1 of 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

More Related Content

More from Anna Gerber

International NodeBots Day Brisbane roundup (BrisJS)
International NodeBots Day Brisbane roundup (BrisJS)International NodeBots Day Brisbane roundup (BrisJS)
International NodeBots Day Brisbane roundup (BrisJS)Anna Gerber
 
JavaScript Robotics
JavaScript RoboticsJavaScript Robotics
JavaScript RoboticsAnna Gerber
 
Intro to Electronics in Python
Intro to Electronics in PythonIntro to Electronics in Python
Intro to Electronics in PythonAnna 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
 
Supporting Open Scholarly Annotation
Supporting Open Scholarly AnnotationSupporting Open Scholarly Annotation
Supporting Open Scholarly AnnotationAnna Gerber
 
Supporting Web-based Scholarly Annotation
Supporting Web-based Scholarly AnnotationSupporting Web-based Scholarly Annotation
Supporting Web-based Scholarly AnnotationAnna Gerber
 
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)Anna Gerber
 
Annotation Tools (OA European Roll Out)
Annotation Tools (OA European Roll Out)Annotation Tools (OA European Roll Out)
Annotation Tools (OA European Roll Out)Anna Gerber
 
Intro to data visualisation
Intro to data visualisationIntro to data visualisation
Intro to data visualisationAnna Gerber
 
Annotations Supporting Scholarly Editing
Annotations Supporting Scholarly EditingAnnotations Supporting Scholarly Editing
Annotations Supporting Scholarly EditingAnna Gerber
 
Getting started with the Trove API
Getting started with the Trove APIGetting started with the Trove API
Getting started with the Trove APIAnna Gerber
 
HackFest Brisbane: Discover Brisbane
HackFest Brisbane: Discover BrisbaneHackFest Brisbane: Discover Brisbane
HackFest Brisbane: Discover BrisbaneAnna Gerber
 
Using Yahoo Pipes
Using Yahoo PipesUsing Yahoo Pipes
Using Yahoo PipesAnna Gerber
 

More from 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
 

Recently uploaded

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Recently uploaded (20)

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

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

Editor's Notes

  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