SlideShare a Scribd company logo
Getting Started with Embedded Python
(MicroPython and CircuitPython)
@iAyanPahwa/iayanpahwa
About Me
Embedded Software
Engineer at Mentor
Graphics - A Siemens
Business
Part time blogger
Full time maker
Mentor Graphics is world
leader in Electronics Design
Automation(Tools Business).
I work for Automotive
Embedded Software Division,
which deals in providing
custom solutions, OS and
BSP for IVI and ADAS
systems.
Contact: https://iayanpahwa.github.io
People who are really
serious about software
should make their own
hardware
- Alan Kay
Motivation
-
@iAyanPahwa/iayanpahwa
Motivation
@iAyanPahwa/iayanpahwa
What is MicroPython
The MicroPython project is an open source
implementation of Python 3 that includes a small
subset of the Python standard libraries, and is
optimised to run on microcontrollers with constrained
environments like limited ROM, RAM and processing
power. It came about after a successful Kick-starter
campaign by Damien George.
@iAyanPahwa/iayanpahwa
Python 3
IoT
(Devices)
Microcontrollers
In a NutShell
@iAyanPahwa/iayanpahwa
Opportunities
@iAyanPahwa/iayanpahwa
@iAyanPahwa/iayanpahwa
~20MHz System Clock
~32Kb RAM
~16MB ROM
Single Core
Register Level Access
Microcontrollers
@iAyanPahwa/iayanpahwa
MicroPython
- A small stripped down version on Python3 which runs as firmware on microcontrollers,
exposes all the low level modules, acting as an operating system.
- It is packed full of advanced features such as an interactive prompt, arbitrary precision
integers, closures, list comprehension, generators, exception handling and more.
- Yet it is compact enough to fit and run within just 256k of code space and 16k of RAM.
- MicroPython aims to be as compatible with normal Python as possible to allow you to
transfer code with ease from the desktop to a microcontroller or embedded target.
- Python APIs for low level hardware modules- GPIOs, UART, PWM, ADC, i2c, SPI.
- Runs directly on bare-metal or under OS env or as emulator.
@iAyanPahwa/iayanpahwa
Python vs μPython vs Arduino
Refer: https://github.com/micropython/micropython/wiki
@iAyanPahwa/iayanpahwa
Boards Supported
@iAyanPahwa/iayanpahwa
The PyBoard
The ESP8266
160Kb RAM
802.11 b/g/n
4MB Flash
GPIO, ADC, I2c, SPI
@iAyanPahwa/iayanpahwa
Functions & Libraries Supported
@iAyanPahwa/iayanpahwa
Interaction
Serial REPL (115200 BAUD RATE)
WEB REPL, works over LAN
File System mounts on host
Tools to transfer source code(ex: AMPY)
Emulation on linux host
Unicorn web based emulator
@iAyanPahwa/iayanpahwa
Interaction: Serial
Loading uP on ESP8266 board
Install esptool - pip install esptool
Download uP firmware.bin from GitHub release pages for
your board.
Erase flash - esptool.py --port /path/to/ESP8266
erase_flash
Flash uP firmware - esptool.py --port /path/to/ESP8266 --
baud 460800 write_flash --flash_size=detect 0 firmware.bin
Connect Serial console - screen /dev/tty… 115200
@iAyanPahwa/iayanpahwa
Interaction: WebREPL
Setting up WebREPL
> import webrepl_setup
> Enter ‘E’ to enable it
> Enter and confirm password(defaults
micropythoN)
> Enter ‘y’ to reboot and save changes
@iAyanPahwa/iayanpahwa
Interaction: WebREPL
@iAyanPahwa/iayanpahwa
Interaction: Unicorn
https://micropython.org/unicorn
@iAyanPahwa/iayanpahwa
Interaction: Live
https://micropython.org/live
@iAyanPahwa/iayanpahwa
Interaction: Emulator
@iAyanPahwa/iayanpahwa
(DEMO)
HELLO WORLD OF ELECTRONICS
@iAyanPahwa/iayanpahwa
Interaction: Hello WORlD
// Classic way of Blinking LED
#include “Board_Defination_File.h”
int main(void)
{
while(1){
DDRB |= (1 << 7);
PORTB |= (1 << 7);
_delay_ms(1000);
PORTB &= ~(1 << 7);
_delay_ms(1000);
}
}
// Make Pin Output
// Send logic 1 to the pin
//Send logic 0 to the pin
@iAyanPahwa/iayanpahwa
Interaction: h3llO WORlD
> from machine import Pin
> from time import sleep
# Make Pin behave as output
> led = Pin(2, Pin.OUT)
> while True:
# Send digital logic 1 to the pin
> led.on()
> sleep(1)
# Send digital logic 0 to the pin
> led.off()
> sleep(1)
MicroPython Way
@iAyanPahwa/iayanpahwa
Interaction: Advance
File System on Flash to store:
WiFi credentials (SSID, PASSOWRD)
boot.py - POST operations
main.py - main executable
You can mount the fs over network, or
transfer files over webREPL or tools like
AMPY.
@iAyanPahwa/iayanpahwa
CircuitPython
https://github.com/adafruit/circuitpython
Adafruit fork of MicroPython maintained for
educational purpose around boards sell by
Adafruit industries.
Centred Around ATMEL SAMD21 and ESP8266 SoCs.
Various new modules added like capacitive touch
APIs, Sound outputs, USB HID etc.
Bluetooth Low energy support with newly
supported NRF SoC port.
DISCLAIMER: The stunts will be performed by experts
under expert supervision and no matter how many times
you test before, chances of live demo failures are
incalculable :P
SHOW TIME
@iAyanPahwa/iayanpahwa
DEMOS
@iAyanPahwa/iayanpahwa
Temperature and Humidity Measurement
> import dht, machine
> from time import sleep
# Make Pin behave as output
> d = dht.DHT11(machine.Pin(4))
> while True:
# Measure temp and humidity
> d.measure()
# Print Values
> d.temperature()
> d.humidity()
> sleep(2)
@iAyanPahwa/iayanpahwa
NeoPixel
* 1 wire to control multiple LEDs, color and
brightness.
* 8-bit format for Red, Green, Blue
* RRGGBB
* 0-ff or 0-255
NeoPixel
> import machine, neopixel
# Initialize GPIO and number of pixels
> np = neopixel.NeoPixel(machine.Pin(4), 8)
# Set a Pixel color in RGB format
> np[0] = (255, 0, 0)
>np.write()
@iAyanPahwa/iayanpahwa
Thank You
@iAyanPahwa
/iayanpahwa

More Related Content

PPTX
Splunk Dashboarding & Universal Vs. Heavy Forwarders
PDF
Bonfire API #1 APIのリトライ処理
PPTX
Security: Odoo Code Hardening
PPTX
Splunk for Enterprise Security and User Behavior Analytics
PDF
File upload-vulnerability-in-fck editor
PPTX
Cyber Defense Matrix: Revolutions
PPTX
Deploying & Scaling your Odoo Server
PDF
Intel TSX について x86opti
Splunk Dashboarding & Universal Vs. Heavy Forwarders
Bonfire API #1 APIのリトライ処理
Security: Odoo Code Hardening
Splunk for Enterprise Security and User Behavior Analytics
File upload-vulnerability-in-fck editor
Cyber Defense Matrix: Revolutions
Deploying & Scaling your Odoo Server
Intel TSX について x86opti

What's hot (20)

PDF
Cpu pipeline basics
PPTX
Best Practices for Password Creation
PPTX
システムパフォーマンス勉強会#5
PDF
User centric machine learning for cyber security operation center
PPTX
Continuous Automated Red Teaming (CART) - Bikash Barai
PPTX
FA概論
PDF
GitOpsではじめるKubernetes CI/CD Pipeline
PPTX
Open source SOC Tools for Home-Lab
PDF
ExcelとPythonによる社会インフラシステムの設定ファイルの自動生成
DOCX
Sophos XG FIREWALL SSL VPN Configuration
PPTX
実行統計による実践的SQLチューニング
PPTX
Vulnerability Assesment
PDF
Improving the performance of Odoo deployments
PDF
C++でNVMeと(*´Д`)ハァハァ 戯れていたら一年経ってた。
PDF
B 64484 ja-1-03
PDF
WEBSOCKET Protokolünün Derinlemesine İncelenmesi
PPTX
VoIP (Voice Over IP) güvenliği nasıl sağlanmaktadır?
PPTX
Ship code like a keptn
PPT
rsyncのちょっとイイ話
PDF
Cisco Catalyst 2960-X Series Switching Architecture
Cpu pipeline basics
Best Practices for Password Creation
システムパフォーマンス勉強会#5
User centric machine learning for cyber security operation center
Continuous Automated Red Teaming (CART) - Bikash Barai
FA概論
GitOpsではじめるKubernetes CI/CD Pipeline
Open source SOC Tools for Home-Lab
ExcelとPythonによる社会インフラシステムの設定ファイルの自動生成
Sophos XG FIREWALL SSL VPN Configuration
実行統計による実践的SQLチューニング
Vulnerability Assesment
Improving the performance of Odoo deployments
C++でNVMeと(*´Д`)ハァハァ 戯れていたら一年経ってた。
B 64484 ja-1-03
WEBSOCKET Protokolünün Derinlemesine İncelenmesi
VoIP (Voice Over IP) güvenliği nasıl sağlanmaktadır?
Ship code like a keptn
rsyncのちょっとイイ話
Cisco Catalyst 2960-X Series Switching Architecture
Ad

Viewers also liked (20)

PDF
PyCon_India_2017_MicroPython_Ayan
PDF
Raspberry home server
PDF
HPC DAY 2017 | Prometheus - energy efficient supercomputing
PDF
LinuxKit and OpenOverlay
PPTX
Java on the GPU: Where are we now?
PDF
HPC DAY 2017 | HPE Storage and Data Management for Big Data
PDF
HPC DAY 2017 | NVIDIA Volta Architecture. Performance. Efficiency. Availability
PDF
HPC DAY 2017 | HPE Strategy And Portfolio for AI, BigData and HPC
PDF
Database Security Threats - MariaDB Security Best Practices
PDF
HPC DAY 2017 | Accelerating tomorrow's HPC and AI workflows with Intel Archit...
PDF
Model Simulation, Graphical Animation, and Omniscient Debugging with EcoreToo...
PDF
Libnetwork updates
PDF
HPC DAY 2017 | Altair's PBS Pro: Your Gateway to HPC Computing
PDF
Latency tracing in distributed Java applications
PDF
GPU databases - How to use them and what the future holds
PDF
Design patterns in Java - Monitis 2017
PPTX
An Introduction to OMNeT++ 5.1
PPT
Drive into calico architecture
PDF
세션1. block chain as a platform
PyCon_India_2017_MicroPython_Ayan
Raspberry home server
HPC DAY 2017 | Prometheus - energy efficient supercomputing
LinuxKit and OpenOverlay
Java on the GPU: Where are we now?
HPC DAY 2017 | HPE Storage and Data Management for Big Data
HPC DAY 2017 | NVIDIA Volta Architecture. Performance. Efficiency. Availability
HPC DAY 2017 | HPE Strategy And Portfolio for AI, BigData and HPC
Database Security Threats - MariaDB Security Best Practices
HPC DAY 2017 | Accelerating tomorrow's HPC and AI workflows with Intel Archit...
Model Simulation, Graphical Animation, and Omniscient Debugging with EcoreToo...
Libnetwork updates
HPC DAY 2017 | Altair's PBS Pro: Your Gateway to HPC Computing
Latency tracing in distributed Java applications
GPU databases - How to use them and what the future holds
Design patterns in Java - Monitis 2017
An Introduction to OMNeT++ 5.1
Drive into calico architecture
세션1. block chain as a platform
Ad

Similar to Getting Started with Embedded Python: MicroPython and CircuitPython (20)

PPTX
IOT with Drupal 8 - Webinar Hyderabad Drupal Community
PPTX
Connected hardware for Software Engineers 101
PPTX
Raspberry Pi - Unlocking New Ideas for Your Library
PDF
Johnny-Five
PDF
SFScon 22 - Roberto Innocenti - Start Enjoy Yourself with Open Hardware POWER...
PDF
Raspberry pi Board Hardware & Software Setup
PPTX
PI-Phone Using Raspberry Pi-2
PPTX
PI-Phone Using Raspberry Pi-2
PPTX
Tac Presentation October 72014- Raspberry PI
PDF
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
PPTX
Capstone_Project.ppt
PDF
Raspberry pi pico projects raspberry pi projects
PDF
IoT: Internet of Things with Python
PDF
Rapid IoT Prototyping with Tizen on Raspberry Pi
PPTX
Raspberry pi
PPTX
Building your own RC Car with Raspberry Pi
PDF
A prototyping hardware for the real Internet of Things
PDF
Introduction to IPython & Notebook
PDF
Home Automation Using RPI
PDF
Iaetsd the universal brain for all robots
IOT with Drupal 8 - Webinar Hyderabad Drupal Community
Connected hardware for Software Engineers 101
Raspberry Pi - Unlocking New Ideas for Your Library
Johnny-Five
SFScon 22 - Roberto Innocenti - Start Enjoy Yourself with Open Hardware POWER...
Raspberry pi Board Hardware & Software Setup
PI-Phone Using Raspberry Pi-2
PI-Phone Using Raspberry Pi-2
Tac Presentation October 72014- Raspberry PI
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
Capstone_Project.ppt
Raspberry pi pico projects raspberry pi projects
IoT: Internet of Things with Python
Rapid IoT Prototyping with Tizen on Raspberry Pi
Raspberry pi
Building your own RC Car with Raspberry Pi
A prototyping hardware for the real Internet of Things
Introduction to IPython & Notebook
Home Automation Using RPI
Iaetsd the universal brain for all robots

More from Ayan Pahwa (6)

PDF
Kicad 101
PDF
IoT with circuitpython | CloudBadge
PDF
MQTT on Raspberry Pi - Basics
PDF
Basics of Embedded Systems / Hardware - Architectures
PDF
Using Linux in commercial products + Yocto Project touchdown
PDF
Reverse engineering IoT Devices
Kicad 101
IoT with circuitpython | CloudBadge
MQTT on Raspberry Pi - Basics
Basics of Embedded Systems / Hardware - Architectures
Using Linux in commercial products + Yocto Project touchdown
Reverse engineering IoT Devices

Recently uploaded (20)

PDF
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
REPORT: Heating appliances market in Poland 2024
PDF
Advanced Soft Computing BINUS July 2025.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
KodekX | Application Modernization Development
PDF
Omni-Path Integration Expertise Offered by Nor-Tech
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PPTX
Cloud computing and distributed systems.
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
SAP855240_ALP - Defining the Global Template PUBLIC.pdf
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
Transforming Manufacturing operations through Intelligent Integrations
NewMind AI Weekly Chronicles - August'25 Week I
Understanding_Digital_Forensics_Presentation.pptx
Review of recent advances in non-invasive hemoglobin estimation
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
MYSQL Presentation for SQL database connectivity
REPORT: Heating appliances market in Poland 2024
Advanced Soft Computing BINUS July 2025.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
madgavkar20181017ppt McKinsey Presentation.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
KodekX | Application Modernization Development
Omni-Path Integration Expertise Offered by Nor-Tech
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
Cloud computing and distributed systems.
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
SAP855240_ALP - Defining the Global Template PUBLIC.pdf

Getting Started with Embedded Python: MicroPython and CircuitPython

  • 1. Getting Started with Embedded Python (MicroPython and CircuitPython) @iAyanPahwa/iayanpahwa
  • 2. About Me Embedded Software Engineer at Mentor Graphics - A Siemens Business Part time blogger Full time maker Mentor Graphics is world leader in Electronics Design Automation(Tools Business). I work for Automotive Embedded Software Division, which deals in providing custom solutions, OS and BSP for IVI and ADAS systems. Contact: https://iayanpahwa.github.io
  • 3. People who are really serious about software should make their own hardware - Alan Kay Motivation - @iAyanPahwa/iayanpahwa
  • 5. What is MicroPython The MicroPython project is an open source implementation of Python 3 that includes a small subset of the Python standard libraries, and is optimised to run on microcontrollers with constrained environments like limited ROM, RAM and processing power. It came about after a successful Kick-starter campaign by Damien George. @iAyanPahwa/iayanpahwa
  • 6. Python 3 IoT (Devices) Microcontrollers In a NutShell @iAyanPahwa/iayanpahwa
  • 9. ~20MHz System Clock ~32Kb RAM ~16MB ROM Single Core Register Level Access Microcontrollers @iAyanPahwa/iayanpahwa
  • 10. MicroPython - A small stripped down version on Python3 which runs as firmware on microcontrollers, exposes all the low level modules, acting as an operating system. - It is packed full of advanced features such as an interactive prompt, arbitrary precision integers, closures, list comprehension, generators, exception handling and more. - Yet it is compact enough to fit and run within just 256k of code space and 16k of RAM. - MicroPython aims to be as compatible with normal Python as possible to allow you to transfer code with ease from the desktop to a microcontroller or embedded target. - Python APIs for low level hardware modules- GPIOs, UART, PWM, ADC, i2c, SPI. - Runs directly on bare-metal or under OS env or as emulator. @iAyanPahwa/iayanpahwa
  • 11. Python vs μPython vs Arduino Refer: https://github.com/micropython/micropython/wiki @iAyanPahwa/iayanpahwa
  • 14. The ESP8266 160Kb RAM 802.11 b/g/n 4MB Flash GPIO, ADC, I2c, SPI @iAyanPahwa/iayanpahwa
  • 15. Functions & Libraries Supported @iAyanPahwa/iayanpahwa
  • 16. Interaction Serial REPL (115200 BAUD RATE) WEB REPL, works over LAN File System mounts on host Tools to transfer source code(ex: AMPY) Emulation on linux host Unicorn web based emulator @iAyanPahwa/iayanpahwa
  • 17. Interaction: Serial Loading uP on ESP8266 board Install esptool - pip install esptool Download uP firmware.bin from GitHub release pages for your board. Erase flash - esptool.py --port /path/to/ESP8266 erase_flash Flash uP firmware - esptool.py --port /path/to/ESP8266 -- baud 460800 write_flash --flash_size=detect 0 firmware.bin Connect Serial console - screen /dev/tty… 115200 @iAyanPahwa/iayanpahwa
  • 18. Interaction: WebREPL Setting up WebREPL > import webrepl_setup > Enter ‘E’ to enable it > Enter and confirm password(defaults micropythoN) > Enter ‘y’ to reboot and save changes @iAyanPahwa/iayanpahwa
  • 23. (DEMO) HELLO WORLD OF ELECTRONICS @iAyanPahwa/iayanpahwa
  • 24. Interaction: Hello WORlD // Classic way of Blinking LED #include “Board_Defination_File.h” int main(void) { while(1){ DDRB |= (1 << 7); PORTB |= (1 << 7); _delay_ms(1000); PORTB &= ~(1 << 7); _delay_ms(1000); } } // Make Pin Output // Send logic 1 to the pin //Send logic 0 to the pin @iAyanPahwa/iayanpahwa
  • 25. Interaction: h3llO WORlD > from machine import Pin > from time import sleep # Make Pin behave as output > led = Pin(2, Pin.OUT) > while True: # Send digital logic 1 to the pin > led.on() > sleep(1) # Send digital logic 0 to the pin > led.off() > sleep(1) MicroPython Way @iAyanPahwa/iayanpahwa
  • 26. Interaction: Advance File System on Flash to store: WiFi credentials (SSID, PASSOWRD) boot.py - POST operations main.py - main executable You can mount the fs over network, or transfer files over webREPL or tools like AMPY. @iAyanPahwa/iayanpahwa
  • 27. CircuitPython https://github.com/adafruit/circuitpython Adafruit fork of MicroPython maintained for educational purpose around boards sell by Adafruit industries. Centred Around ATMEL SAMD21 and ESP8266 SoCs. Various new modules added like capacitive touch APIs, Sound outputs, USB HID etc. Bluetooth Low energy support with newly supported NRF SoC port.
  • 28. DISCLAIMER: The stunts will be performed by experts under expert supervision and no matter how many times you test before, chances of live demo failures are incalculable :P SHOW TIME @iAyanPahwa/iayanpahwa
  • 30. Temperature and Humidity Measurement > import dht, machine > from time import sleep # Make Pin behave as output > d = dht.DHT11(machine.Pin(4)) > while True: # Measure temp and humidity > d.measure() # Print Values > d.temperature() > d.humidity() > sleep(2) @iAyanPahwa/iayanpahwa
  • 31. NeoPixel * 1 wire to control multiple LEDs, color and brightness. * 8-bit format for Red, Green, Blue * RRGGBB * 0-ff or 0-255
  • 32. NeoPixel > import machine, neopixel # Initialize GPIO and number of pixels > np = neopixel.NeoPixel(machine.Pin(4), 8) # Set a Pixel color in RGB format > np[0] = (255, 0, 0) >np.write() @iAyanPahwa/iayanpahwa