MicroPython presentation - PyConFr Lyon 2025 - Amine Bendahmane

AmineBendahmane 9 views 20 slides Nov 01, 2025
Slide 1
Slide 1 of 20
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20

About This Presentation

A presentation of MicroPython programming for IoT & embed systems.
As normal Python cannot be executed on small microcontrollers with no OS. The MicroPython language offers an alternative to enable a similar Python experience for developers.
The presentation present MicroPython, some example, p...


Slide Content

MicroPython
Python programming for Microcontrollers
Amine Bendahmane
Software Engineer
01-nov-2025
1

Python for Microcontrollers
What’s MicroPython
•A lightweight implementation of Python 3 optimized of Microcontrollers.
•Can run in microcontroller with just 16KB of RAM and no OS.
•Project started by Damien P. Georges at the end of 2013.
•Free and Open Source.
•Available under MIT license.
•Can be used for both personal and commercial purposes.
•Without sharing your source code.
2

Difference with a normal processor
Microcontrollers
•A small unit of computation and processing.
•It’s not a processor
•Usually no cache memory.
•No concurrency or multi-core capabilities.
•No operating system.
•Direct access to registers.
•Direct access to hardware: GPIO, I2C, SPI, UART
Atmega328P - 8-bit, 32KB flash
3

MicroPython is available on:
Microcontrollers
https://micropython.org/download
4

Standards and features
MicroPython language
•MicroPython is written in C99.
•Implements the Python 3.4 standard.
•Implements some selected features from Python 3.5 to 3.10 (as
of today – v1.26)
•MicroPython v2.0 is under development.
•Some feature have a different behaviour than CPython because
of the particularity of MicroControllers.
5

Quick examples
MicroPython language
Blink a LED
6

Quick examples
MicroPython language
Blink a LED Publish a MQTT message
7

Quick examples
MicroPython language
Blink a LED WIFI communicationPublish a MQTT message
8

Some useful libraries
Libraries
•Microfiied versions of some libraries.
•Focus on hardware control, not desktop-level data processing.
Not supported
(Out of context)
Reduced support
(limited capabilities)
Available
(light alternatives)
Pandas
Numpy
Matplotlib
Sqlite3
Threading
(experimental)
Asyncio
os
sys
array
random
socket
socket
collections
math
zlib
...etc
9

Some specific libs for MicroPython
Libraries
machine – hardware pins I/O
micropython - internals
network - communication
bluetooth – low level bluetooth
urequests - requests
ujson - json
ure - regex
vfs – virtual file system
cryptolib – cryptographic ciphers
10

Comparison with C/C++
Performances
•MicroPython has been demonstrated to be 2 to 5x slower than C/C++ (based on research papers).
•Some users in internet talk about 8~10x slower performance (no official source) ?
•Higher CPU usage => more power consuption
Plauska et al. 2023 - MDPI
https://doi.org/10.3390/electronics12010143
Samefors A. and Sundman F. 2023 [thesis]
Jonkoping University
11

How to speed up MicroPython code
Performances
•Precompile code into Byte Code.
•Generates .mpy files.
•Smaller files, faster loading.
•Can be imported like normal python code.
•Disable the REPL.
•Use the @micropython.native decorator for performance-critical functions.
•Comes with some limitation (check the official docs).
•Write C code for computational heavier operations.
12

Known MicroPython limitations
Memory usage
•Usually executed on reduced RAM devices.
•Large modules might not fit RAM memory.
•Same issues also with other programming languages (embed systems constraints).
•Fixed heap size.
•Might result in fragmented heap (from repeated objects creation).
•Memory exception is raised.
Free UsedUsed
13

Tips and solutions
Memory usage
Tips and solutions
•Avoid creating objects in loops.
•Reuse buffers instead of creating them.
•Use const() to avoid dictionary allocations.
•Use smaller variable types when possible.
•Monitor the heap memory (mem_info)
•Call the garbage collector manually when needed (gc.collect).
•Pre-compile libraries to byte code, or freeze them.
14

It depends on your type of application
When to use MicroPython ?
Good choice
•Rapid Prototyping
•Quick iteration and testing.
•Proof-of-concept development.
•Moderate performance requirements on
IoT applications
•Discrete sensor data collection.
•Network communication.
•Onboard screen data display.
•Simplifying operations
•Easy hardware interfacing.
•Educational projects.
•Home IoT projects.
15

It depends on your type of application
When to use MicroPython ?
Good choice
•Rapid Prototyping
•Quick iteration and testing.
•Proof-of-concept development.
•Moderate performance requirements on
IoT applications
•Discrete sensor data collection.
•Network communication.
•Onboard screen data display.
•Simplifying operations
•Easy hardware interfacing.
•Educational projects.
•Home IoT projects.
16
Bad choice
•Performance-Critical applications
•Real-time systems with strict
deadlines.
•High-frequency signal processing.
•Hight-computational operations.
•Energy-critical scenarios.
•Secure applications
•Code protection requirements.
•Large-scale industrial deployments.
•Already existing applications
•Industrial grade C++ / Rust code
already tested and deployed.

Integrate C code as MicroPython extensions
Or use both ?
MicroPython
High-level operations;
•User interaction (UI, buttons, keypads).
•Network communication
•Application logic.
17
C / C++ or RUST
Performance-critical operations;
•Signal processing.
•Computer vision.
•Cryptographic algorithms.
Benefits
•Rapid development where it matters
•Maximum performance for critical paths
•Leverage Python ecosystem and C efficiency

Pros and Cons
Summary
•Advantages
•Rapid prototyping.
•Interactive REPL.
•Easy hardware abstraction.
•Code portability across platforms.
•Lower barrier to entry level programers or hobbyists.
•Disadvantages
•Slower performances.
•Memory constraints.
•Lesser code protection.
18

Friendly community
Learn & Contribute
•Website:
www.micropython.org
•Github:
github.com/micropython/micropython
•Discord channel:
discord.gg/WjAV88XH
•IRC channel:
irc://freenode/micropython
19

Questions ?
Slides available at:
https://github.com/amineHorseman/my-talks
Get in touch:
https://linkedin.com/in/amine-bendahmane
https://medium.com/@aminehorseman
20