Breathe-rs - An air quality monitor based on Knurling sessions

Published on 5 min read
Open Source Project
Knurling icon
A tool set to develop embedded applications faster.
Details ❤️ Sponsor

    Breathe-rs - An air quality monitor based on Knurling sessions

    A device with an e-paper screen displaying time, date, CO2 level, temperature, humidity, and a status indicator

    NOTE: This is a guest post by Matous Hybl (@hyblmatous on Twitter). Matous participated in the first Knurling Session, and shared his experience with us.

    When Knurling-rs was announced back in August, I was really excited as it meant some new energy for the embedded Rust ecosystem. probe-run and defmt promised the modern approach required to push the field forward. The Knurling-rs tools suddenly meant great user experience: Using probe-run for program flashing removed the hassle of maintaining various IDE configs. defmt made monitoring of real-time systems very comfortable as I experienced when I developed a firmware for motor controllers based on a Cortex-M0 using the knurling tools for my master's thesis.

    When Ferrous Systems also announced the first Knurling Sessions with the goal of building a simple air quality monitor based on the SCD30 sensor and the NRF52 dev-kit, I immediately bought the required parts and patiently waited for the sessions to be released.

    The knurling sessions showed how easy it is to work with embedded Rust and hardware in general and how the ecosystem has evolved over time. This became clear to me when CRC calculation is needed for sensor communication. Instead of having to develop it myself, it was possible to just use a crate from and make it available on embedded systems just by enabling the no_std feature.

    My version of the air quality monitor diverges from the original in hardware and software. I'll point out some of the highlights:


    Let’s first have a look at the hardware of my take on the air quality monitor. I began the development on the NRF dev-kit but slowly realized that this wasn’t the right hardware for my purposes. The dev-kit has its advantages like the integrated debugger or the radio. But it is really large and the majority of the components on it belong to the J-Link part and not the NRF part. Therefore I decided to replace the NRF dev-kit with the STM32F4 Black Pill board. Porting the existing code to the STM32 was easy thanks to various abstractions that the embedded-hal provides. Now I was able to develop the air quality monitor as a small and compact device.

    To be able to stick to this goal I also needed to avoid the breadboard and wires. I decided to create a PCB (Printed Circuit Board) for it in Kicad. My own design offers the following features:

    • Compact size around the size of the e-paper display
    • User buttons
    • Beeper for signalizing too high carbon dioxide levels
    • RTC for displaying time
    • USB-C for power and time configuration (provided by the Black Pill)
    • Connector for adding an ESP-01 in the future to allow for remote atmospheric data harvesting.

    The final PCB design can be seen in the following picture:

    A rendered circuit board

    On the left we can see the buttons alongside with two LEDs, the buzzer and the ESP-01 connector. In the upper part of the board there is the RTC. On the right side, we can see the connector to the display and the SCD30 sensor. I then produced the PCB by milling and soldered the components on it.

    This is the assembled circuit board:

    An assembled circuit board

    All parts were then placed into a 3D printed case. The look of the finished device can be seen in the picture at the top of the article.


    The software for my air quality monitor was developed using the RTIC framework for concurrency instead of the superloop of the original instructions. Using RTIC you can achieve real-time to some extent: tasks run in precise times, immediate notification of events like a pressed button and non-blocking hardware reads and writes e.g. using UART.

    This way I was able to spawn several timed tasks:

    • reading sensor data (every two seconds)
    • rendering display content (every 20 seconds)
    • blinking the integrated LED (every 0.1 seconds)
    • beeping the buzzer
    • processing packets from USB to set the date

    Apart from the obvious air quality measurement and rendering, the firmware also takes care of utilizing the integrated USB controller as a virtual COM port, which can be used to set the time on the device.

    The displayed CO2 concentration values are filtered using simple averaging. The display also shows the current time and date and also a simple graphic indicator indicating the CO2 level using a smiley face:

    The smiley face is * happy when the CO2 concentration is below 1000 ppm * neutral when the CO2 concentration is between 1000 ppm and 1500 ppm * sad when the concentration is higher than 1500 ppm

    Credits for this feature belong to my girlfriend.

    Check out Matous' work on github.


    I plan to fully implement the support for the ESP-01 as discovering the fluctuation of CO2 concentration could have quite an impact on my family’s health.

    I really enjoyed working on the air quality monitor and I hope that its beeping and indication will help me live a healthier life.

    Currently I am finishing my master’s thesis where I am developing a dual channel stepper motor controller with the use of embedded Rust and knurling tools. I don’t really see myself coming back to other tools or programming languages for bare-metal systems. The embedded Rust ecosystem that provides so many great tools and drivers that brought embedded development to the 21st century! I am also tremendously grateful for the communities surrounding embedded Rust and knurling: They are awesome and extremely helpful whenever you come across any issue.

    About me

    My name is Matous Hybl (@hyblmatous on Twitter). I am a master’s student of cybernetics at the Brno University of Technology where I also work as a software developer for our reconnaissance robots. My passions are mobile robots, embedded systems and pushing these two fields forward.

    Sponsor this work

    Knurling-rs is mainly funded through GitHub sponsors. Sponsors get early access to the tools we are building and help us to support and grow the knurling tools and courses. Thank you to all of the people already sponsoring our work through the Knurling project!