Arduino boards are open source microcontroller (MCU) boards for building and prototyping digital devices. These boards can be programmed with C/C++ programming languages using standard Arduino API. I bought my first Arduino Nano 33 BLE board to study how to use Bluetooth with embedded systems and to gain some experience with Arduino devices at the same time. The board is based on NINA-B306 Bluetooth 5 module, incorporating Nordic Semiconductor’s nRF52840 MCU. MCU is a 32-bit Arm Cortex-M4 running at 64 MHz and having 256 KB of RAM and 1MB of flash memory. There is also LSM9DS1 Inertial Measurement Unit (IMU) sensor connected to the MCU with a I2C bus.
After finally receiving my board (component shortage..), my Arduino journey started from an Arduino Integrated Development Environment (IDE) installation. I followed a quick start guide to get the board connected, installed a board support package with board manager and then suggested libraries – ArduinoBLE for the BLE functions and Arduino_LSM9DS1 for the IMU. This was really easy.
Arduino is using sketches to write the code – something I wasn’t familiar with before this. You are able to include library headers in your own sketch. Arduino libraries are extensions to the standard Arduino API. Libraries often contain more complex code, to read some sensors for example. If one is more used to the low level coding, it feels strange at first to write only setup and loop functions to get the code up and running. But it was also refreshing for a change to get something done quickly without huge amount of things to setup manually. So, just verify and upload and we are good to go. :)
Because the LEDs are the thing for me, I started to follow a tutorial to control RGB LED using Bluetooth and the mobile phone application. Tutorial code creates a BLE service to control digital output (Bluetooth peripheral) based on the data send from the mobile phone (Bluetooth central). Using serial monitor, I can see the log output while running the tutorial code:
As I was able to run this tutorial without problems I decided to extend it with the IMU sensor data. Accelerometer is the most easiest one to test when having device connected to your PC with cables so I used only that one for this trial. To get IMU working, I first included the header for that library and added IMU.begin() call to the setup function to setup IMU sensor. In the loop function, accelerometer data will be read if Bluetooth central is still connected and when there is accelerometer data available. I did not find any good Unique Universal Identifier (UUID) for this data so I just used a 128-bit custom UUID. I added new characteristics for accelerometer data, an integer value providing tilting information and updated that one when there is new information available. Here is the result:
Arduino has really nice tutorials and documentation. It was really easy to get started developing code for my new board. On the other hand, many details are hidden under the hood. I wasn’t aware what was the MCU clock frequency, how could I change it, can I use MCU low power modes or would I been able to fork another thread or loop function to run accelerometer measurements without mixing it to the LED control code. That is something I need to figure out in normal every day work. But I didn’t care about that as everything worked like a charm without problems. Maybe I will try my Arduino board with Zephyr next..