The article received an update on

After working my way through the Embedded Rust books I did some research. I looked at ways to get the Bluetooth radio working on the nRF52833, the MCU on the Micro:bit board. From this research it is clear that the way to go is to use the crates from the Embassy project.

Embassy is a project that consist of many crates, but most notably it provides an async/await executor. With this you can run a fixed number of tasks concurrently on embedded devices. The project makes async an alternative to using a real-time operating system (RTOS). It also claims that this is a more efficient way of running concurrent tasks. The reason being that the executor in a async-await framework do not have to guess when a task is ready to continue its execution.

To better understand this route I worked through RustyBits YouTube video From Zero to Async in Embedded Rust. In the video he guides you through building a basic async/await executor from scratch to run concurrent tasks on an embedded device. It is a truly great video that showcase different options to implementing a system which allows for concurrent execution of tasks.

The video concludes by introducing the Embassy executor and a couple of other Embassy crates. By using the Embassy crates, the complexity and the lines of code of the project are significantly reduced. The exercise truly demonstrates the value of the Embassy crates in non-trivial embedded systems.

Embassy also provides crates with Rust bindings for nRF SoftDevice, Nordic Semiconductor’s certified Bluetooth stack. It is exactly what I need for this project. As a side note, there is also an Embassy crate called TrouBLE under development. The goal of this crate is to implement a complete Bluetooth stack in Rust and having it certified.

RustyBits continues his Embedded Rust series with more Embassy videos. He even goes on to develop a project, moxi, which looks surprisingly similar to what I have in mind.

That is great!

It means I have an expert to learn from and show me how to make it work if I get stuck. However, I am not going to follow along with the videos, I will try to develop this project on my own and only peek at his code if I can't figure something out on my own. Then when I have my first working prototype, I can use his project to learn how to improve my work.

From what I can tell without looking at the code and the videos, the system RustyBits develops looks like this:

  graph LR;
	s[CO2 Sensor] -- I2C --> nRF52833;
	nRF52833 -- BLE --> m[Mobile phone];

My project is slightly different since I want to connect the sensor to Home Assistant:

  flowchart LR;
	s[CO2 Sensor] -- I2C --> nRF52833;
	nRF52833 -- BLE --> ha[Home Assistant];

In the next session I will finally start building the project!

Thank you for reading.

Resources