Arduino BLE programming
How to collect and publish data using Bluetooth Low Energy with Arduino
In this post, I illustrate how to operate BLE (Bluetooth Low Energy) with Arduino. As usual, physics being my field, I do not discuss a generic example (the equivalent of “Hello, World!”), but a concrete physics application. Sometimes, for brevity or clarity, I will not be rigorous, and purists may turn up their noses, but, as I read on a A. Zee’s books, “sometimes, too much rigor soon leads to rigor mortis”.
WARNING: I assume you are familiar with Arduino and C/C++ programming. If you are not, you will hardly understand the content of this article.
What I write here, applies to all species of Arduino that are compatible with the BLE protocol. I performed the tests with an Arduino MKR 1010 Wifi, measuring pressure and temperature using a BME280 sensor.
Let’s start with the definition of global variables and constants, and with the inclusion of the libraries (the code I propose has been partially extracted from the examples available in the libraries for Arduino Science Journal, from which I have removed a whole series of “distractors” to highlight the aspects related to ordinary operation).
#include <ArduinoBLE.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>…