100% found this document useful (1 vote)
234 views24 pages

RpiMakers Python On Microcontrollers May 12 2018

This document discusses using Python on microcontrollers like the ESP8266 and ESP32. Some key points: - Python allows for higher productivity than C/C++ but is less efficient in terms of memory and CPU usage. - MicroPython is an implementation of Python that runs on microcontrollers. It can be used through a REPL shell or by uploading Python files. - Examples demonstrate controlling an LED, building an IoT application with sensors, and running code at startup without the REPL. - CircuitPython is Adafruit's version which supports more boards but ESP8266/ESP32 support is currently lacking.

Uploaded by

saravanan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
234 views24 pages

RpiMakers Python On Microcontrollers May 12 2018

This document discusses using Python on microcontrollers like the ESP8266 and ESP32. Some key points: - Python allows for higher productivity than C/C++ but is less efficient in terms of memory and CPU usage. - MicroPython is an implementation of Python that runs on microcontrollers. It can be used through a REPL shell or by uploading Python files. - Examples demonstrate controlling an LED, building an IoT application with sensors, and running code at startup without the REPL. - CircuitPython is Adafruit's version which supports more boards but ESP8266/ESP32 support is currently lacking.

Uploaded by

saravanan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Python on Microcontrollers

ESP8266 ESP32

Adafruit ARM
micro:bit based boards

PyBoard
Python on Microcontrollers
• Higher productivity than C
• Shorter iterations
• Faster to learn than C/C++
Python on Microcontrollers
• Less efficient use of RAM, ROM, CPU
• Fewer drivers than Arduino C
Demo: Using the Python REPL

Micropython
Interpreter
Putty (runs
micropython
Putty talks directly to micropython REPL
programs)
• manually run a program
Demo 1: “hello world”
Demo 2: Control a LED
More REPL fun

• List capabilities: help(‘modules’)


• history
• completion with TAB
Run programs

Micropython
Interpreter
Ampy run (runs micropython
programs)

ampy –pCOMx -d1 run <python file>


Demo 3: Flash the LED
Build an IOT
Application

Node-RED
Sensor
Data
Dashboard

Light
Sensor

ESP8266 running Micropython


MQTT

MQTT = Message Queueing Telemetry Transport


I2C

Data
Clock

I2C =Inter-Integrated Circuit


Python Code for IOT
Application
Demo 4: IOT Application

Node-
Sensor RED
Data Dashboard

Light
Sensor

ESP8266 running Micropython


Autonomous Operation
• Copy program to file system
• “main.py” runs at startup

File System
put
Ampy main.py boot.py

ampy –pCOMx -d1 put <python file> main.py


CircuitPython
• 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
Documentation and Downloads
• http://docs.micropython.org/en/latest/esp8266/

• http://micropython.org/download
Solar weather station
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


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
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:
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”
WeMos D1 mini
Adafruit Feather HUZZAH ESP8266

SDA GPIO4 CHPD


SCL GPIO5 TX
GPIO2 RX
GPIO16 GPIO12 MISO
GPIO0 GPIO13 M0SI
GPIO15 GPIO14 SCK
GPIO13
GPIO12
GPIO14
USB 5
EN
BAT ADC
GND

3.3

You might also like