SlideShare a Scribd company logo
1 of 35
Program all the things
How to develop IoT devices using
MicroPython
Anna Gerber
About me
• Senior Backend Developer at
Console Connect (Node.js)
• Teach coding and robotics
workshops and classes
• Maker / hobbyist
Pet project
Getting started developing IoT devices
• Design architecture & select language,
development tools/platform
• Select hardware (sensors, actuators, dev
board)
• Develop programs to read from sensors &
control actuators
• Develop programs to communicate with other
devices or services that process / analyze data
MicroPython
• Python 3.x for microcontrollers
• 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
SELECTING HARDWARE
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:
https://learn.adafruit.com/adafruit-
feather-huzzah-esp8266/overview
• WeMos D1 mini:
https://wiki.wemos.cc/products:d1:d1
_mini
• NodeMCU:
http://nodemcu.com/index_en.html
• 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
• Feature Huzzah has built in 100mA LiPo
charger
https://learn.adafruit.com/adafruit-feather-huzzah-esp8266/pinouts
Incremental prototyping
• Design the desired interactions
• Work out what components you'll need
• Develop a basic program for each individual
component (e.g. read from button , play
sound on buzzer, display pattern on LEDs)
• Develop networking / communication
• Use REPL to interactively tweak timings /
behaviour
Pet Circuit
Preparing the board
• 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
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
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/
Uploading code using the WebREPL
DEVELOPING PROGRAMS
Button on pin 12
Using machine library: read from a pin
from machine import Pin
button = Pin(12, Pin.IN, Pin.PULL_UP)
# Read the button value:
button.value()
Poll button value
Analog sensors
• Only one ADC pin
• Max voltage of 1V – use a voltage divider
import machine
adc = machine.ADC(0)
adc.read()
Piezo Buzzer on pin 14
Using the machine library
from machine import Pin, PWM
import time
C5 = 523
D5 = 587
E5 = 659
piezo = PWM(Pin(14, Pin.OUT), freq=440, duty=512)
tune = [E5, D5, C5, D5, E5, E5, E5]
for tone in tune:
piezo.freq(tone)
time.sleep(0.5)
piezo.deinit()
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
Neopixel ring on pin 2
Loading additional libraries
• Many additional components supported through
third party libraries e.g. OLED display supported
by SSD1306:
https://github.com/adafruit/micropython-
adafruit-ssd1306
– Download the mpy file from releases
– Upload to board using ampy or WebREPL
ampy --port /dev/tty.SLAB_USBtoUART put ssd1306.mpy
import ssd1306import machine
i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
COMMUNICATION
Basic web server (1/2)
Basic web server (2/2)
MQTT
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
Why MicroPython?
• Clean, intuitive programs
• Great for teaching
• Interactive REPL ideal for experimentation &
rapid prototyping
• Edge computing
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

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Recently uploaded (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

Program all the things - How to develop IoT devices using MicroPython

  • 1. Program all the things How to develop IoT devices using MicroPython Anna Gerber
  • 2. About me • Senior Backend Developer at Console Connect (Node.js) • Teach coding and robotics workshops and classes • Maker / hobbyist Pet project
  • 3. Getting started developing IoT devices • Design architecture & select language, development tools/platform • Select hardware (sensors, actuators, dev board) • Develop programs to read from sensors & control actuators • Develop programs to communicate with other devices or services that process / analyze data
  • 4. MicroPython • Python 3.x for microcontrollers • 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
  • 6. 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)
  • 7. Which ESP8266 dev board? • Adafruit Feather HUZZAH ESP8266: https://learn.adafruit.com/adafruit- feather-huzzah-esp8266/overview • WeMos D1 mini: https://wiki.wemos.cc/products:d1:d1 _mini • NodeMCU: http://nodemcu.com/index_en.html • 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 • Feature Huzzah has built in 100mA LiPo charger
  • 9. Incremental prototyping • Design the desired interactions • Work out what components you'll need • Develop a basic program for each individual component (e.g. read from button , play sound on buzzer, display pattern on LEDs) • Develop networking / communication • Use REPL to interactively tweak timings / behaviour
  • 11.
  • 12. Preparing the board • 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
  • 13. 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
  • 14. 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
  • 15. 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
  • 16. 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/
  • 17. Uploading code using the WebREPL
  • 20. Using machine library: read from a pin from machine import Pin button = Pin(12, Pin.IN, Pin.PULL_UP) # Read the button value: button.value()
  • 22. Analog sensors • Only one ADC pin • Max voltage of 1V – use a voltage divider import machine adc = machine.ADC(0) adc.read()
  • 23. Piezo Buzzer on pin 14
  • 24. Using the machine library from machine import Pin, PWM import time C5 = 523 D5 = 587 E5 = 659 piezo = PWM(Pin(14, Pin.OUT), freq=440, duty=512) tune = [E5, D5, C5, D5, E5, E5, E5] for tone in tune: piezo.freq(tone) time.sleep(0.5) piezo.deinit()
  • 25. 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
  • 27.
  • 28. Loading additional libraries • Many additional components supported through third party libraries e.g. OLED display supported by SSD1306: https://github.com/adafruit/micropython- adafruit-ssd1306 – Download the mpy file from releases – Upload to board using ampy or WebREPL ampy --port /dev/tty.SLAB_USBtoUART put ssd1306.mpy import ssd1306import machine i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4)) oled = ssd1306.SSD1306_I2C(128, 64, i2c)
  • 32. MQTT
  • 33. 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
  • 34. Why MicroPython? • Clean, intuitive programs • Great for teaching • Interactive REPL ideal for experimentation & rapid prototyping • Edge computing
  • 35. 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. We hear a lot of hype around the Internet of Things - how that myriad of interconnected smart devices monitoring and actuating our everyday activities will transform our lives toward a blissful state of automation. But when IoT rules the world, do you want to have to rely on third parties to provide all of these devices and to define all of the features available within your connected life? Being able to develop your own IoT devices as well as customize existing devices and applications is becoming a critical skill.
  2. About me:I teach weekly kids coding/robotics classes and I used MicroPython successfully with my students last year. I have also taught introductory IoT classes using Arduino (C++) and Node.js for both kids and adults The context of my talk is a particular project I've been building (it's a healthy habits tracking "pet", built with ESP8266 that is designed to motivate me to develop healthier lifestyle habits. custom IoT device acts as a personal assistant that helps to track and transform personal habits like keeping fit. So my talk is fairly applied - it's a walk through of how I built the project and why I think MicroPython is great for rapidly prototyping IoT projects.
  3. The steps I will cover The first two will depend on you requirements In my pet project : Single device communicating to cloud service over MQTT
  4. What is MicroPython?MicroPython is a Free, Open Source implementation of Python 3.x that is designed to run in constrained environment like 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. 256K code space, 16K memory Compiler runtime
  5. high level tips on selecting hardware / architecture / IoT networking technologies etc based on project requirements and why I chose the ones I did for my project
  6. 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)
  7. Excellent docs Open source libraries & Adafruit tutorials
  8. 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
  9. Requirements: remind me to do exercise (lights, sound) Allow me to record when I do it in response (button)
  10. Main.py is the program that runs after boot.py
  11. Use Pulse Width Modulation to create different tones with buzzer
  12. Solder wires onto strip
  13. Use an MQTT broker like mosquitto