Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer...

32
MicroPython: Embedded programming for everyone Jim Mussared

Transcript of Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer...

Page 1: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

MicroPython:Embedded programming for everyone

Jim Mussared

Page 2: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

MicroPython

Python for microcontrollers

1

Page 3: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

○ It’s Python 3... but micro!● Able to run on CPUs like the Cortex M0● 256kiB flash, 16kiB RAM, 16MHz

○ Compilation happens on-device○ “Pythonic” access to low-level hardware (e.g. GPIO)

What is MicroPython?

Page 4: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

pyboard

Image: © George Robotics - https://micropython.org/store/

Page 5: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

BBC micro:bit2

Page 6: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

Image: Stuart Brady / Wikipedia / Public Domain

Page 7: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

Image © Grok Learning 2016

Page 8: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

○ LED matrix○ Accelerometer○ Magnetometer (compass)○ Temperature○ Buttons○ Bluetooth○ LiPo Battery header○ GPIO (+ SPI, I2C, UART, ADC)

BBC micro:bit

Images: © BBC micro:bit https://www.microbit.co.uk/about

Page 9: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

○ AUD $20-$25 each○ Compare to:

● Arduino Esplora ( ~ $80 )● Arduino Zero ( ~ $80 )● Arduino Leonardo ( ~ $40 )● Raspberry Pi Zero ( ~ $10 - $35 )● Raspberry Pi ( ~ $60 )● pyboard (~ $40 )

* Prices are highly variable across countries and stores. Not including Arduino clones.

BBC micro:bit

Page 10: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

○ Microsoft TouchDevelop○ Microsoft Block Editor○ CodeKingdoms Javascript○ and... MicroPython!

BBC micro:bit

Page 11: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

○ Motorized buggy○ Motor drivers○ Starter kits○ Prototyping boards○ Edge connector

micro:bit accessories

Image: © BBC micro:bit https://www.microbit.co.uk/about

Page 13: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

Demo

Page 14: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

ESP8266

IoT for $5

3

Page 15: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

Image © SparkFun / https://www.flickr.com/photos/sparkfun/16730689880 / CC

Page 16: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

○ Tiny. Cheap.○ Once configured, very easy to use

● Program over WiFi● Interactive REPL (serial + WiFi)

○ Library support for external components● e.g NeoPixels (LED strips)

○ WiFi! Both AP and Station.● IoT all the things!

ESP8266 features

Page 17: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

○ Hardware variations (ESP-01, ESP-12a, etc)● Hardware documentation is hard to find

○ Flash size● Beware of 4Mbit models. Need 8Mbit for MicroPython

○ Programming● Some boards have USB, otherwise there are programmers

○ Easy-to-use models (eg. ESP-01) have very few pins○ No binary distributions of MicroPython (yet)○ and...

ESP8266 gotchas

Page 18: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

3.3V

!!!!!!

ESP8266 gotchas

Page 19: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

○ Beware of “3.3V” FTDI boards○ Get a programmer or an all-in-one board○ Adafruit’s “Feather Huzzah” is a great example

● https://www.adafruit.com/products/2821

ESP8266 gotchas

Image © Adafruit Industries

Page 20: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

○ Angus Gratton: Free as in cheap gadgets: the ESP8266● linux.conf.au 2016● https://www.youtube.com/watch?v=Du1MtqsvSy4

○ Damien George: Scripting the Internet of Things● Pycon Australia 2016

○ Nick Moore: ESP8266 and MicroPython● PyCon Australia 2016

ESP8266

Page 21: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

Demo

Page 22: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

Building course content

Grokking out

4

Page 23: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

○ Grok teaches coding using structured, interactive courses.● Year-round courses● Competitions (courses with leaderboards)

○ Interactive notes and slides○ Comprehensive auto-marking○ Python 3, C++, Java, Bash, SQL, HTML/CSS, …○ All school levels, university and professional.

Grok Learning

Page 24: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

Demo

Page 25: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

○ Grok provides a sandbox to run your Python code○ Now does the same for micro:bit

● Runs the real micro:bit firmware● Interactive notes● Marker can interact with your code running on simulated device

Simulating the micro:bit

Page 26: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

Image © Grok Learning 2016

Page 27: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

Image © Grok Learning 2016

Page 28: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

Image © Grok Learning 2016

Page 29: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

Image © Grok Learning 2016

Page 30: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

Demo

Page 31: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

○ Starts October 31st 2016○ Newbies, Beginners, Intermediate and micro:bit

Grok Code Quest

Page 32: Embedded programming for everyone MicroPython&+micropython+(PyCon+... · LED matrix Accelerometer Magnetometer (compass) Temperature Buttons Bluetooth LiPo Battery header GPIO (+

ANY QUESTIONS?Web: http://groklearning.com/Twitter: @groklearningEmail: [email protected]