Skip to content

Commit 4c8991b

Browse files
committed
docs: Move more into Sphinx, add external modules, mention MicroPython 1.25
1 parent d4fde73 commit 4c8991b

6 files changed

Lines changed: 296 additions & 112 deletions

File tree

README.md

Lines changed: 27 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ Builds on [emlearn](https://emlearn.org), a C99 library for Machine Learning on
1717
## Status
1818
**Minimally useful**
1919

20-
- Tested *working* on `x64` (Unix port) and `xtensawin` (ESP32/ESP32-S3/etc).
21-
- Currently not supported: [armv6m/Cortex-M0/RP2040](https://github.com/emlearn/emlearn-micropython/issues/19)
22-
and [RISC-V/ESP32-C3/ESP32-C6](https://github.com/emlearn/emlearn-micropython/issues/35)
20+
- Initial set of Machine Learning and Digital Signal Processing modules available, including example projects.
21+
- Supports most MicroPython ports using runtime installable native modules
22+
- Primarily tested on `x64` (Unix port) and `xtensawin` (ESP32/ESP32-S3/etc).
23+
- Some devices only supported using external, notably armv6m/Cortex-M0/RP2040
24+
- Not yet supported: [RISC-V/ESP32-C3/ESP32-C6](https://github.com/emlearn/emlearn-micropython/issues/35)
2325

2426
## Features
2527

@@ -35,7 +37,7 @@ and [RISC-V/ESP32-C3/ESP32-C6](https://github.com/emlearn/emlearn-micropython/is
3537
- Operates on standard `array.array` data structures
3638
- Models can be loaded at runtime from a file in disk/flash
3739
- Highly efficient. Inference times down to 100 microseconds, RAM usage <2 kB, FLASH usage <2 kB
38-
- Pre-built binaries available for most architectures.
40+
- Pre-built native modules available for most common architectures `xtensawin`.
3941

4042
## Examples
4143

@@ -46,109 +48,36 @@ and [RISC-V/ESP32-C3/ESP32-C6](https://github.com/emlearn/emlearn-micropython/is
4648

4749
## Documentation
4850

49-
Complete [documentation on ReadTheDocs](https://emlearn-micropython.readthedocs.io/en/latest/user_guide.html).
51+
Complete usage [documentation on ReadTheDocs](https://emlearn-micropython.readthedocs.io/en/latest/user_guide.html).
5052

51-
## Prerequisites
5253

53-
Minimally you will need
54-
55-
- Python 3.10+ on host
56-
- MicroPython 1.24+ running onto your device
54+
## Citations
5755

58-
#### Download repository
56+
If you use `emlearn-micropython` in an academic work, please reference it using:
5957

60-
Download the repository with examples etc
61-
```
62-
git clone https://github.com/emlearn/emlearn-micropython
58+
```tex
59+
@misc{emlearn_micropython,
60+
author = {Jon Nordby},
61+
title = {{emlearn-micropython: Efficient Machine Learning engine for MicroPython}},
62+
month = aug,
63+
year = 2023,
64+
doi = {10.5281/zenodo.8212731},
65+
url = {https://doi.org/10.5281/zenodo.8212731}
66+
}
6367
```
6468

65-
## Usage
66-
67-
Start with the instructions in [XOR example](./examples/xor_trees/).
68-
69-
70-
## Supported versions
71-
72-
At any given point in time, emlearn-micropython only provides pre-built binaries for one MicroPython version.
73-
In general we strongly encourage people to use the latest version.
74-
There are no long-term-support or bugfix versions, at this point.
75-
If you build from source, the current version of emlearn-micropython might also work on a couple of MicroPython versions around the time, but this is not guaranteed.
76-
77-
| MicroPython | emlearn-micropython |
78-
|------------------| ------------------ |
79-
| 1.24.x | master |
80-
| 1.24.x | 0.7.0 |
81-
| 1.23.x | 0.6.0 |
82-
83-
#### Find architecture and .mpy version
84-
85-
The correct .mpy files to use depend on the CPU architecture of your microcontroller,
86-
as well as the MicroPython version.
87-
88-
| MicroPython version | .mpy version |
89-
|---------------------| ------------- |
90-
| 1.23.x | 6.3 |
91-
| 1.24.x | 6.3 |
92-
93-
94-
Identify which CPU architecture your device uses.
95-
You need to specify `ARCH` to install the correct module version.
96-
97-
| ARCH | Description | Examples |
98-
|---------------|-----------------------------------|---------------------- |
99-
| x64 | x86 64 bit | PC |
100-
| x86 | x86 32 bit | |
101-
| armv6m | ARM Thumb (1) | Cortex-M0 |
102-
| armv7m | ARM Thumb 2 | Cortex-M3 |
103-
| armv7emsp | ARM Thumb 2, single float | Cortex-M4F, Cortex-M7 |
104-
| armv7emdp | ARM Thumb 2, double floats | Cortex-M7 |
105-
| xtensa | non-windowed | ESP8266 |
106-
| xtensawin | windowed with window size 8 | ESP32 |
107-
108-
Information is also available in the official documentation:
109-
[MicroPython: .mpy files](https://docs.micropython.org/en/latest/reference/mpyfiles.html#versioning-and-compatibility-of-mpy-files)
11069

11170

112-
## More learning resources
71+
## Developing
11372

114-
emlearn-micropython and emlearn has been covered in the following presentations.
73+
For those that wish to hack on emlearn-micropython itself.
11574

116-
- Microcontrollers + Machine Learning in 1-2-3 (PyData Global 2024).
117-
[Slides etc](https://github.com/jonnor/embeddedml/tree/master/presentations/PyDataGlobal2024)
118-
- Sensor data processing on microcontrollers with MicroPython and emlearn (PyConZA 2024).
119-
[Slides etc](https://github.com/jonnor/embeddedml/tree/master/presentations/PyConZA2024)
120-
- 6 years of open source TinyML with emlearn - a scikit-learn for microcontrollers (TinyML EMEA 2024)
121-
[YouTube video](https://www.youtube.com/watch?v=oG7PjPMA3Is) |
122-
[Slides etc](https://github.com/jonnor/embeddedml/tree/master/presentations/TinymlEMEA2024)
123-
- emlearn - Machine Learning for Tiny Embedded Systems (Embedded Online Conference 2024).
124-
[Youtube video](https://www.youtube.com/watch?v=qamVWmcBdmI) |
125-
[Slides etc](https://github.com/jonnor/embeddedml/tree/master/presentations/EmbeddedOnlineConference2024)
126-
- Machine Learning on microcontrollers using MicroPython and emlearn (PyCon DE & PyData Berlin 2024).
127-
[Slides etc](https://github.com/jonnor/embeddedml/tree/master/presentations/PyDataBerlin2024) |
128-
[YouTube video](https://www.youtube.com/watch?v=_MGm8sctqjg&t=1311s&pp=ygUSZW1sZWFybiBtaWNyb3B5dGhv).
75+
#### Download the code
12976

130-
Here is an overview of resources for [TinyML in general](https://tinyml.seas.harvard.edu/courses/).
131-
132-
## Benchmarks
133-
134-
#### UCI handwriting digits
135-
136-
UCI ML hand-written digits datasets dataset from
137-
[sklearn.datasets.load_digits](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_digits.html).
138-
8x8 image, 64 features. Values are 4-bit integers (16 levels). 10 classes.
139-
140-
Running with a very simple RandomForest, 7 trees.
141-
Reaches approx 86% accuracy.
142-
Tested on Raspberry PI Pico, with RP2040 microcontroller (ARM Cortex M0 @ 133 MHz).
143-
144-
![Inferences per second](./benchmarks/digits_bench.png)
145-
146-
NOTE: over half of the time for emlearn case,
147-
is spent on converting the Python lists of integers into a float array.
148-
Removing that bottleneck would speed up things considerably.
149-
150-
151-
## Developing locally
77+
Clone the repository using git
78+
```
79+
git clone https://github.com/emlearn/emlearn-micropython
80+
```
15281

15382
#### Prerequisites
15483
These come in addition to the prequisites described above.
@@ -159,13 +88,13 @@ See [MicroPython: Building native modules](https://docs.micropython.org/en/lates
15988
We assume that micropython is installed in the same place as this repository.
16089
If using another location, adjust `MPY_DIR` accordingly.
16190

162-
You should be using MicroPython 1.24 (or newer).
91+
You should be using MicroPython 1.25 (or newer).
16392

16493
#### Build
16594

16695
Build the .mpy native module
16796
```
168-
make dist ARCH=armv6m MPY_DIR=../micropython
97+
make dist ARCH=xtensawin MPY_DIR=../micropython
16998
```
17099

171100
Install it on device
@@ -180,18 +109,4 @@ To build and run tests on host
180109
make check
181110
```
182111

183-
## Citations
184-
185-
If you use `emlearn-micropython` in an academic work, please reference it using:
186-
187-
```tex
188-
@misc{emlearn_micropython,
189-
author = {Jon Nordby},
190-
title = {{emlearn-micropython: Efficient Machine Learning engine for MicroPython}},
191-
month = aug,
192-
year = 2023,
193-
doi = {10.5281/zenodo.8212731},
194-
url = {https://doi.org/10.5281/zenodo.8212731}
195-
}
196-
```
197112

docs/external_modules.rst

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
.. Places parent toc into the sidebar
3+
:parenttoc: True
4+
5+
.. _external_modules:
6+
7+
===============================
8+
External modules
9+
===============================
10+
11+
An alternative, much simpler, installation method is as :ref:`native_modules` (recommended).
12+
13+
This method is more complicated, as it requires building MicroPython from scratch.
14+
Therefore it is only recommended for 1) platforms which do not support native modules,
15+
and 2) advanced users.
16+
17+
Supported versions
18+
===========================
19+
20+
For general information about supported MicroPython versions, see :ref:`support`.
21+
In principle, external modules should work on any hardware/port of MicroPython.
22+
23+
24+
Prerequisites
25+
===========================
26+
27+
External modules are included into the build process of MicroPython itself.
28+
That means that you must have a MicroPython build environment set up,
29+
including neccesary build toolchains et.c.
30+
This process is specific for each MicroPython port.
31+
Refer to the relevant port/X/README.md in the `micropython git repository <https://github.com/micropython/micropython/>`_ for the setup.
32+
33+
Always make sure that you can succesfully build and run the vanilla firmware
34+
(no external modules), before you add in emlearn-micropython.
35+
36+
You need a git checkout of emlearn-micropython.
37+
For example as a git submodule in your project.
38+
39+
::
40+
git clone https://github.com/emlearn/emlearn-micropython.git
41+
42+
43+
Include external modules in build
44+
===================================
45+
46+
emlearn-micropython contains both C modules, as well as Python modules.
47+
Therefore it is neccesary to use both the options *USER_C_MODULES* and *FROZEN_MANIFEST*.
48+
49+
For details on this process, see official MicroPython documentation on
50+
`building with external modules <https://docs.micropython.org/en/latest/develop/cmodules.html>`_.
51+
52+
53+
Example build
54+
----------------
55+
56+
For platforms that use a cmake-based build system.
57+
58+
::
59+
make USER_C_MODULES=./emlearn-micropython/src/micropython.cmake \
60+
FROZEN_MANIFEST=./emlearn-micropython/src/manifest.py \
61+
CFLAGS_EXTRA='-Wno-unused-function -Wno-unused-function'
62+
63+
64+
For platforms that use a Makefile-based build.
65+
66+
::
67+
68+
make USER_C_MODULES=./emlearn-micropython/src/ \
69+
FROZEN_MANIFEST=./emlearn-micropython/src/manifest.py \
70+
CFLAGS_EXTRA='-Wno-unused-function -Wno-unused-function'
71+
72+
73+
Combining multiple modules
74+
---------------------------
75+
76+
If you want to add more C modules and/or frozen manifest,
77+
you will need to create your own `manifest.py` and `micropython.cmake` files.
78+
Use the ones in emlearn-micropython as a starting point.
79+
80+

docs/more.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,39 @@ This includes:
2424
Presentations
2525
====================
2626

27+
emlearn-micropython has been covered in the following presentations.
28+
29+
30+
Microcontrollers + Machine Learning in 1-2-3
31+
------------------------------------------------------------------
32+
33+
Presented at PyData Global 2024, by Jon Nordby
34+
35+
`Video recording (YouTube) <https://www.youtube.com/watch?v=nCmBJJHGQKo&pp=ygUUcHlkYXRhIGdsb2JhbCBub3JkYnk%3D>`_.
36+
37+
`Slides and notes <https://github.com/jonnor/embeddedml/tree/master/presentations/PyDataGlobal2024>`_.
38+
39+
40+
MicroPython - Python for microcontrollers and embedded linux
41+
-------------------------------------------------------------------------
42+
43+
Presented at FOSDEM 2025, by Jon Nordby.
44+
Has a section on emlearn-micropython.
45+
46+
`Video recording (YouTube) <https://www.youtube.com/watch?v=8Ao7DsTkpS4>`_.
47+
48+
`Slides and notes <https://github.com/jonnor/embeddedml/tree/master/presentations/FOSDEM2025>`_.
49+
50+
51+
Sensor data processing on microcontrollers with MicroPython and emlearn
52+
-------------------------------------------------------------------------
53+
54+
Presented at PyConZA 2024, by Jon Nordby.
55+
56+
Video recording: coming...
57+
58+
`Slides and notes <https://github.com/jonnor/embeddedml/tree/master/presentations/PyConZA2024>`_.
59+
2760

2861
Machine Learning on microcontrollers using MicroPython and emlearn
2962
------------------------------------------------------------------
@@ -33,3 +66,10 @@ Presented at PyCon DE & PyData Berlin 2024, by Jon Nordby.
3366
`Video recording (YouTube) <https://www.youtube.com/watch?v=_MGm8sctqjg>`_.
3467

3568
`Slides and notes <https://github.com/jonnor/embeddedml/tree/master/presentations/PyDataBerlin2024>`_.
69+
70+
71+
Other resources
72+
====================
73+
Here is an overview of resources for `TinyML in general <https://tinyml.seas.harvard.edu/courses/>`_.
74+
75+

0 commit comments

Comments
 (0)