This was my first foray into app development using the MIT App Inventor 2. I've had several boards that communicate via Bluetooth Low Energy (BLE) and aside from nRF Connect app, I had no way of looking at the data. I finally decided to take the plunge and learn how to use MIT App Inventor so I had a framework in place for future apps using BLE. MIT App Inventor is fairly straightforward using block programming. It just took me a bit to get used to the functionality and interface.
This was also my first application using the Arduino Nicla Sense ME board. This is a relatively new board from the Arduino Pro series. See the link above for specs and functionality. It's pretty packed with four industrial grade sensors from Bosch Sensortec:
- BHI260AP motion sensor system with integrated AI
- BMM150 magnetometer
- BMP390 pressure sensor
- BME688 4-in-1 gas sensor with AI and integrated high-linearity, as well as high-accuracy pressure, humidity and temperature sensors.
I decided that my first application would be an Indoor Air Quality (IAQ) sensor to measure air quality and also eCO2 (estimated Carbon Dioxide) and send the data via BLE to a phone app. I also started the app reading temperature data but I saw the values were several degrees higher than ambient temperature so I think the sensor is being impacted by the board temperature.
There was a little bit of learning using the Nicla board and getting data because some changes to the Nicla library are required to get readings from the Bosch BSEC sensor:
- Despite what the documentation says, you need to use the
SENSOR_ID_BSEC_LEGACY
ID when you call SensorBsec in the Arduino sketch. - You need to go into Arduino_BHY2 > src > sensors > SensorTypes.h and change
SENSOR_DATA_FIXED_LENGTH
to 30.
Without the changes, I was not able to get readings for IAQ and eCO2 (they were just "0").
This documentation assumes that you know how to load libraries in Arduino (you need the Arduino_BHY2 library, and the Arduino_BHY2_Host if you are doing a host/slave setup). It also assumes basic knowledge of how to use MIT App Inventor 2. I've included both the Arduino and MIT App Inventor source files in this project.
Steps to get this running:
- Upload the Arduino sketch to your Nicla Sense ME board. When the sketch is uploaded and running, the LED light on the board will be red because it is not connected to a BLE device.
- Open the.aia file in MIT App Inventor. I just ran the application in Emulator mode on my phone (this is really cool by the way). You will also need the MIT AI 2 app on your Android phone. I believe there is now an iOS app as well.
- Once the app is running on your phone, connect to "Nicla2". The LED on the Nicla will turn green indicating that you have connected. You can also bring up a Serial console to see that you are connected and data is being collected.
- I noticed that it takes about 2-3 minutes for the Nicla to start transmitting accurate eCO2 and IAQ values. For those first couple minutes, there are default values of 500 for eCO2 and 25 for IAQ.
- You can see the historical values on the chart in the app.
- FUTURE CAPABILITY I'm also working on the ability to save the data to your phone so you can do further data analysis on it.
I hope you enjoyed this! It was fun to finally start using MIT App Inventor. It even prompted me to start using Android Studio to develop native Android apps. I'm looking forward to testing additional capabilities of the Nicla board, like counting steps, or determining if you are walking, on a bike, or in a car. This is capability that is built into Bosch's sensors so they seem pretty capable. Happy coding!
Comments