Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit...
Transcript of Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit...
![Page 1: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/1.jpg)
Python on Microcontrollers
ESP8266 ESP32
micro:bit
Adafruit ARM
based boards
PyBoard
![Page 2: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/2.jpg)
• Higher productivity than C
• Shorter iterations
• Faster to learn than C/C++
Python on Microcontrollers
![Page 3: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/3.jpg)
• Less efficient use of RAM, ROM, CPU
• Fewer drivers than Arduino C
Python on Microcontrollers
![Page 4: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/4.jpg)
Demo: Using the Python REPL
Putty
Micropython Interpreter (runs micropython programs)
Putty talks directly to micropython REPL • manually run a program
![Page 5: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/5.jpg)
Demo 1: “hello world”
![Page 6: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/6.jpg)
Demo 2: Control a LED
![Page 7: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/7.jpg)
More REPL fun
• List capabilities: help(‘modules’)
• history
• completion with TAB
![Page 8: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/8.jpg)
Run programs
Ampy run
Micropython Interpreter (runs micropython programs)
ampy –pCOMx -d1 run <python file>
![Page 9: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/9.jpg)
Demo 3: Flash the LED
![Page 10: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/10.jpg)
Light
Sensor
ESP8266 running Micropython
Sensor
Data Dashboard
Node-RED
Build an IOT Application
![Page 11: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/11.jpg)
MQTT
MQTT = Message Queueing Telemetry Transport
![Page 12: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/12.jpg)
I2C
Data
Clock
I2C =Inter-Integrated Circuit
![Page 13: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/13.jpg)
Python Code for IOT Application
![Page 14: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/14.jpg)
Demo 4: IOT Application
Light
Sensor
ESP8266 running Micropython
Sensor
Data Dashboard
Node-
RED
![Page 15: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/15.jpg)
Autonomous Operation
Ampy main.py boot.py
File System
put
• Copy program to file system
• “main.py” runs at startup
ampy –pCOMx -d1 put <python file> main.py
![Page 16: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/16.jpg)
• Adafruit’s version of Micropython
• Excellent documentation
• Very active development
• Today: Support for ESP8266 and ESP32 is lacking
• Future: CircuitPython will likely be the preferred version
• https://learn.adafruit.com/welcome-to-circuitpython/what-is-circuitpython
CircuitPython
![Page 17: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/17.jpg)
• http://docs.micropython.org/en/latest/esp8266/
• http://micropython.org/download
Documentation and Downloads
![Page 18: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/18.jpg)
Solar weather station
![Page 19: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/19.jpg)
Installing Micropython on ESP8266 Step 1. Install USB-> Serial Driver • Install USB driver for board (WEMOS D1 mini) :
• https://wiki.wemos.cc/downloads
• Install USB driver for board (adafruit) : • https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-
drivers
Note: Python 3 needs to be installed
![Page 20: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/20.jpg)
Installing Micropython on ESP8266 Step 2. Install micropython firmware • open CMD shell • Install Esptool: “pip install esptool” • Plug in ESP8266 to USB: • Determine virtual COMxx port:
– Use Device Manager on Windows
• Erase flash: “esptool.py --port COMxx erase_flash” • Download latest stable version of Micropython binary
– http://micropython.org/download
• Install Micropython binary: – Adafruit:
• “esptool.py --port COMxx --baud 115200 write_flash 0 esp8266-20171101-v1.9.3.bin”
– WEMOS mini: • “esptool.py --port COMxx --baud 115200 write_flash –fm dout 0 esp8266-20171101-
v1.9.3.bin”
https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/intro.html
![Page 21: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/21.jpg)
Installing Micropython on ESP8266 Step 3. Install and Configure Putty • Install Putty from
– https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
• Configure Putty:
![Page 22: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/22.jpg)
Installing Micropython on ESP8266 Step 4. Install Ampy • Tutorial
– https://github.com/adafruit/ampy
• Run Ampy: – Ampy –pCOMx –d1 ls
– Ampy –pCOMx –d1 run <python file>
• Where COMx is USB comm port … e.g COM4. See Windows Device Manager, in the Ports topic
Troubles?: see file in package: “Preparing for Makerspace IoT Class - Nov 2017.pdf”
![Page 24: Python on Microcontrollers - VicPiMakers · Python on Microcontrollers ESP8266 ESP32 micro:bit Adafruit ARM based boards ... ROM, CPU •Fewer drivers than Arduino C Python on Microcontrollers](https://reader030.fdocuments.in/reader030/viewer/2022040607/5ebf848070676a29e00f815e/html5/thumbnails/24.jpg)
3.3
GND
RESET
MISO
ADC
SCK
M0SI
RX
TX
CHPD
EN
USB 5
BAT
GPIO16
GPIO15
GPIO0
GPIO2
SCL
SDA
GPIO13
GPIO14
GPIO12
Adafruit Feather HUZZAH ESP8266
GPIO5
GPIO4
GPIO12
GPIO14
GPIO13