Integrating BleuIO with Teensy 4.1 – Scanning and Decoding HibouAir Sensor Data (Part 2)

In the previous project, we focused on getting Teensy 4.1 working as a USB Host for the BleuIO. The goal was simple: remove the PC from the equation and prove that a microcontroller could directly control BleuIO and communicate over BLE using AT commands.

This project builds on that foundation and does something practical with it. Instead of manually sending commands and observing responses, we now create a complete scanner that automatically detects nearby HibouAir sensors, reads their BLE advertisement data, decodes it, and prints meaningful environmental values in real time.

At this point, the system stops being a connectivity demo and becomes an actual application.

Hardware Requirements

Software Requirements

Install ArduinoJson

This project uses ArduinoJson to parse scan results from BleuIO.

In Arduino IDE:

  1. Open Library Manager
  2. Search for arduinojson
  3. Install version 7.x or compatible

ArduinoJson is required to deserialize the JSON scan data received from BleuIO.

How it Works

The architecture remains the same as in Part 1, but now it is used with purpose.

Teensy operates in USB Host mode and communicates directly with BleuIO. BleuIO handles all Bluetooth Low Energy scanning internally and outputs scan results as structured JSON strings over USB serial. Teensy receives those strings, parses the JSON content, extracts the manufacturer-specific payload, and decodes it into usable values.

Conceptually, the flow looks like this:

Teensy 4.1 (USB Host + Application Logic)

BleuIO (BLE Scanning Engine)

BLE Advertisement Data (JSON)

HibouAir Decoder

Readable Environmental Measurements

The important thing to notice here is that Teensy never deals with BLE packets directly. There is no radio handling, no GAP or GATT management, and no BLE stack integration. Everything related to Bluetooth stays inside BleuIO. The microcontroller simply receives structured scan results and processes them like any other data stream.

Automatic Startup and Scanning

When the firmware starts, it configures BleuIO automatically. It disables command echo, enables verbose mode, and then sends a filtered scan command:

AT+FINDSCANDATA=FF5B07

This tells BleuIO to report only devices containing the HibouAir manufacturer identifier. From that moment, scan results begin arriving continuously as JSON lines.

Each line contains fields such as the device address and a data field containing the manufacturer payload in hex format. That hex string is where the sensor readings are encoded.

Parsing the JSON Data

Since scan data arrives asynchronously, the project includes a small USB serial line reader. It buffers incoming characters until a newline is detected, ensuring that we always attempt to parse complete JSON messages.

The ArduinoJson library is used to deserialize each line into a JsonDocument. Once deserialized, we check that the expected scan fields are present. If so, we extract the hex-encoded manufacturer payload and pass it to the HibouAir decoder.

At this stage, the data is still raw — just a long hex string representing packed bytes from the BLE advertisement.

Decoding the HibouAir Advertisement Payload

The core of this project is the HibouAir structure. Instead of manually extracting bytes in the main loop, the decoding logic is encapsulated in a dedicated class.

The constructor receives the JSON document, extracts the data field, and interprets the hex string as a packed binary structure. Using offsetof() ensures that the correct byte offsets are used, and helper functions convert the hex pairs into integers. Because the BLE advertisement uses little-endian ordering, some fields require byte swapping before they become meaningful.

Once decoded, the class provides clean accessor functions such as:

  • getTemp()
  • getHum()
  • getBar()
  • getCo2()
  • getPM2_5()

These functions already return properly scaled values. For example, temperature is divided by 10 to convert from raw integer format to degrees Celsius.

This separation keeps the application logic simple. The main loop only needs to create a HibouAir object and call show_sensor() to print the values.

Example Output

When running the project with a nearby HibouAir sensor, the Serial Monitor shows structured environmental readings like this:

Sensor ID: 22008C
Light: 14 Lux
Pressure: 1007.3 hPA
Temperature: 22.9 C
Humidity: 14.1 %rh
CO2: 508 ppm

For particulate matter devices, additional values appear:

PM 1.0: 0.0 ug/m3
PM 2.5: 1.2 ug/m3
PM 10: 2.5 ug/m3

This output is generated directly from BLE advertisements without establishing a connection to the sensor. The sensors simply broadcast their measurements, and the system passively collects and decodes them.

GitHub Repository

The complete source code for this project is available here:

https://github.com/smart-sensor-devices-ab/bleuio-teensy-hibouair-scanner

You can clone the repository, install the ArduinoJson library through the Arduino IDE Library Manager, upload the sketch to Teensy 4.1, and run it immediately. The code is modular and organized so you can reuse the USB line reader, the HibouAir decoder, or the scanning logic in your own applications.

With this foundation in place, several natural extensions become possible. You could store measurements on an SD card, publish them via MQTT, expose them through a REST interface, or even build a complete air-quality gateway. The BLE side does not need to change.

Share this post on :

Integrating BleuIO with Teensy 4.1 for Seamless BLE Applications

In this project, we will show how to integrate BleuIO with Teensy 4.1 to create Seamless BLE Applications. The goal is to turn the Teensy into a USB Host controller that communicates directly with BleuIO through a simple Arduino sketch, allowing us to create BLE applications without implementing a full BLE stack on the microcontroller.

By the end of this project, you will have a fully functional embedded BLE platform where Teensy 4.1 acts as the application controller and BleuIO handles all Bluetooth Low Energy communication internally. You will be able to send AT commands from Teensy to scan for BLE devices, connect to them, read characteristics, and build your own BLE-based solutions. More importantly, you will gain a reusable architecture that can serve as the foundation for industrial gateways, IoT devices, monitoring systems, or custom embedded products.

Why We Chose Teensy 4.1

The Teensy 4.1 is built around the powerful NXP i.MX RT1062 ARM Cortex-M7 processor running at 600 MHz. This makes it one of the fastest microcontrollers compatible with the Arduino ecosystem. Its high clock speed, large memory capacity, and hardware floating point support allow it to handle complex logic, real-time data processing, and communication tasks with ease.

What makes Teensy 4.1 particularly ideal for this project is its USB Host capability. Since BleuIO is a USB device, it requires a host controller to operate independently of a PC. Teensy 4.1 provides exactly that. It allows us to connect BleuIO directly to the microcontroller and build a fully standalone BLE system. The board’s performance headroom ensures stable communication, fast response handling, and scalability for advanced applications.

Rather than choosing a minimal low-power MCU, we selected Teensy 4.1 because it bridges the gap between traditional microcontrollers and more complex application processors. It gives developers flexibility, speed, and reliability in embedded BLE projects.

Project Requirements

To build this project, you will need:

Project Architecture Overview

The system architecture is straightforward. Teensy 4.1 operates as a USB Host and communicates directly with the BleuIO dongle over serial. BleuIO then manages all Bluetooth Low Energy communication with nearby BLE devices. This separation of responsibilities simplifies development significantly. Teensy focuses on application logic, while BleuIO handles the BLE stack internally.

Teensy 4.1 (USB Host)
        ↓
BleuIO USB Dongle
        ↓
BLE Devices

How the Project Works – Step-by-Step

Step 1: Install Arduino IDE and Teensy Support

First download the Arduino 2.x.x IDE from Arduino’s website. All versions 2.0.4 and later are supported. Versions 2.3.0 or later are recommended, due to improvements in Boards Manager. 

To install Teensy on Arduino IDE 2.x, click File > Preferences (on MacOS, click Arduino IDE > Settings). 

In the main Arduino window, open Boards Manager by clicking the left-side board icon, search for “teensy”, and click “Install”. 

Step 2: Configure USB Type

Teensy supports multiple USB configurations. Under Tools → USB Type, select the appropriate mode so the board can manage serial communication while operating with USB Host functionality. Teensyduino is also compatible with many Arduino libraries

Step 3: Upload the Sketch

The source code for this project, USBtoUSBHostSerial.ino sketch, is publicly available on GitHub: https://github.com/smart-sensor-devices-ab/bleuio_Teensy_host

Upload the provided USBtoUSBHostSerial.ino sketch to the Teensy 4.1 using the Arduino IDE. This sketch initializes the USB Host interface and establishes a communication bridge between the Teensy and the BleuIO dongle. Once programmed, the Teensy essentially becomes a serial terminal for BleuIO, allowing you to type AT commands through the Arduino Serial Monitor and receive responses in real time.

Instead of embedding complex BLE logic in the microcontroller firmware, the sketch focuses on maintaining stable USB communication and forwarding user commands to the dongle. BleuIO processes these commands internally and returns structured responses. This design keeps the firmware clean, modular, and easy to expand.

Why This Approach Is Powerful

Developing BLE applications directly on microcontrollers traditionally requires integrating a BLE stack, managing connection states, handling security layers, parsing protocol events, and debugging complex timing issues. This process can be time-consuming and hardware-dependent. Each microcontroller family often requires a different SDK, stack configuration, and maintenance strategy.

By using BleuIO, this complexity is dramatically reduced. BLE functionality is abstracted behind a simple AT command interface. The microcontroller does not need to manage low-level BLE operations. Instead, it communicates using straightforward serial commands while BleuIO takes care of scanning, connecting, reading characteristics, and maintaining protocol compliance internally. This modular architecture makes the system portable across hardware platforms and reduces firmware complexity, development time, and maintenance effort.

GitHub Repository

The source code for this project, USBtoUSBHostSerial.ino sketch, is publicly available on GitHub:

https://github.com/smart-sensor-devices-ab/bleuio_Teensy_host

This project is shared as a public example to demonstrate how BleuIO can be integrated into high-performance embedded systems. It is intentionally simple in structure so that developers can clearly understand the architecture and reuse it in their own applications.

By combining the computational power of Teensy 4.1 with the modular BLE capabilities of BleuIO, we created a clean and scalable embedded architecture. This project highlights how BLE integration does not need to be complicated. With the right approach, developers can focus on innovation and application logic rather than low-level protocol management.

Share this post on :