[update] For those not owning a nucleo_f429zi, but willing to reproduce the demo, it's now working with Ethernet over USB. More info bellow
On 2017, I introduced to you zephyr Project, the open source RTOS supported by Linux Foundation.
Today, I’d like to share one part or Zephyr Ecosystem: its Micropython port.
mircopython is an “implementation of Python3, optimized to run on microcontrollers”.
A scripting language running on a microcontroller may seem weird, for a given task, it will be slower and have a larger footprint than usual C. But they are also quite powerful and easy to learn. Since you don’t need to compile, it allows quick prototyping and hardware evaluation and allows to go quickly from the idea to the prototype running on your board.
To demonstrate Micropython is powerful, I’d like to show you a http dashboard, running on a STM32F4. It has been developped with help of Paul Sokolovsky, who initiated zephyr port in Micropython.
A sensor shield is plugged onto the nucleo_f429zi board. PC and board are connected via Ethernet to the same local router.
Alternatively, you can also run the demo with a nucleo board with USB enabled and use ethernet over USB. This is for instance working with a nucleo_f412zg with user USB port connected to the PC.
With a browser, I connect to the board that runs a Micropython powered http server. Data collected from the sensor are displayed in the dashboard. Then, embedded java script preforms dynamic rendering of the web page:
- 2 gauges widget for humidity and temperature (collected by HTS221 sensor)
- Widget goes red when magnetic field is detected (byLIS3MDL magneto-sensor)
- Widget reproduces the board movement (thanks to LSM6DS0 accelerometer)
Here is a video (If you're having trouble to open it, copy the link and check it directly on the hosting website):
One nice part of Zephyr is that it provides an abstraction on hardware. Upper API does not depend on SoC. Since Micropython port relies on this upper API, it has no dependency with board. Which means it could run on any board already ported in Zephyr (as long as it has enough memory to sustain micropython binary).
By the way, footprint for this application is 200Kb of Flash and 60Kb of SRAM, so it would run on smaller parts and for instance on STM32F401CC (256K Flash, 64 K RAM). Though, for this exact application you'll need ethernet port...
To be able to run this demo, you need to install zephyr and micropython:
- Zephyr branch: https://github.com/erwango/zephyr/tree/sensor_dashboard_demo
- µPython branch: https://github.com/erwango/micropython/tree/sensorshield_dashboard (commit be19a7b)
Following are the instructions to reproduce the demo for Ubuntu users. Please refer to each project instructions for use on Windows.
$ cd ~/zephyt-project :
$ source zephyr-env.sh
$ cd ~/micropython/ports/zephyr :
$ make BOARD=nucleo_f429zi flash
$ make BOARD=nucleo_f412zg flash
In the board console:
>> import dashboard
If using ethernet, connect with your browser to the IP address printed in console:
>>> [net]/dhcpv4] [INF] handle_ack: Received: 10.0.0.3
Or, in case you're using ethernet over USB, you need to configure your PC to access new ethernet device (more info here), then connect the board with the address configured (192.0.2.1 in my case)
PS: Some hints, if you don’t want to download all branches available in my repo
If you don’t have a zephyr repo yet:
git clone –b sensor_dashboard_demo –single-branch https://github.com/erwango/zephyr
If you already have a zephyr repo:
git remote add erwango https://github.com/erwango/zephyr/
git fetch erwango sensor_dashboard_demo