BleuIO integration (Part2)
Introduction
After following the steps in our previous post Integrating BleuIO with Adafruit Feather RP2040 for Seamless BLE Applications and trying out the Adafruit TinyUSB Library Example serial_host_bridge it is now time for a more practical example. This example is going to show you how to connect real sensors to the Feather, read the values and have it command the BleuIO to advertise them.
Basically you could say that you are going to create a autonomous BLE beacon that advertise the current temperature, humidity etc.
For this example we are using a Gas sensor BME680 and a OPT3002 Light-to-Digital Sensor.
Requirements
- Adafruit Feather RP2040 Board
- BleuIO – Bluetooth Low Energy USB Dongle
- Arduino IDE
- A Gas sensor BME680
- A OPT3002 Light-to-Digital Sensor
- Our example project [Download from GitHub]
Arduino Libraries
The libraries can easily be installed through the Arduino IDE:
Open Library Manager by clicking the Library Manager icon to the left or go through menu: Sketch>Include Libraries>Manage Libraries…
Search for Adafruit_BME680, and install the Adafruit_BME680 Library
- Search for ClosedCube OPT3002, and install the ClosedCube OPT3002 library
Connecting I2C sensors
- Connect four wires (at a minimum) for each I2C device.
- Power the device with 3.3V, then a ground wire.
- And a SCL clock wire, and and a SDA data wire.
Running the example
- Make sure the BleuIO Dongle is connected to the Feather RP2040 Board.
- Connect the Feather RP2040 Board to your computer using the USB cable.
- Make sure the Feather RP2040 Board is selected aswell as the correct COM port in the dropdown menu.
- (Optional) Change the frequency the sensors are read and advertising data updated, in the code
// How often we read the sensors and update the advertings message
(in seconds)
#define READ_UPDATE_FREQUENCY 5
- Click the Upload button.
Done! The dongle should now be advertising the sensor values. (If you just plugged in the Feather it may take about 10 seconds before advertising starts as the BleuIO bootloader opens and closes)
- (Optional) Open Serial Monitor. You can open the Serial Monitor from the menu: Tools>Serial Monitor
You should now see the output from the project.
Scanning the results
To see the results you can use any BLE scanner app.
Here we use nRF Connect:
The data in the red box is our sensor values:
0x006203EB001700170041
When we parse the hex into decimal values we get:
Light: 0x0062 = 98 uW/cm2
Pressure: 0x03EB = 1003 hPa
Temperature: 0x0017 = 23 Celcius
Humidity: 0x0017 = 23 %Rh
Gas Resistance: 0x0041 = 65 KOhms