Some Background
Arduino is one of the most interesting controller to use with all the different sensor modules available on the market. Sooner or later you will need to integrate a specific sensor in order to build something needed for your life or for your job, so it
could be very cool to anticipate some work testing some of the main sensors and technologies you can encounter in the future. In this specific project I used a GPS module, a Sonar and a BlueTooth module to build an indipendent box. This box is powered by two lipo batteries
and results will be displayed on a smal led panel.
The name multidimensional comes from different aspects of this project. First of all it uses different sensors so it impacts different 'Dimension' of the word.
Last but not least it uses two interesting components available on the basic Arduino 101. The GPS and the accellerometer.
Thanks to these two components we can evaluate the space surrounding it in all the dimension (X-Y-Z and speed)
So, before to start here the description of the components used:
1) A plastic Box. I bought one in a stove shop. It is a box used to contain food
2) Arduino 101 (We need it for the accellerometer and to use the BLE protocol to transmit information)
3) A
GPS Module
4) 2 Lipo batteries (buy the model with circuit breaker in order to avoid problem during discharge process)
5) 2.5 inch OLED Display
6) Sonar sensor (HCSR04 is the one I use in this project)
7) Libraries and Source code to run arduino 101
Front View
GPS in action
The Sonic sensor in action to measure distance
With the Arduino/Genuino 101, it is possible to start using the BLE protocol to communicate and interact with other devices like smartphones and tablet
Bluetooth 4.0 includes both traditional Bluetooth, now labeled "Bluetooth Classic", and the new Bluetooth Low Energy (Bluetooth LE, or BLE).
BLE is optimized for low power use at low data rates, and was designed to operate from simple lithium coin cell batteries.
Originally this protocol was created
to be used in smartwatches liek the pibble or like the Apple Iwatch. Obviously it can be used for different pourpose.
Unlike standard bluetooth communication basically based on an asynchronous serial connection (UART) a Bluetooth LE radio acts like a community bulletin board.
The computers that connect to it are like community members that read the bulletin board. Each radio acts as either the bulletin board or the reader.
If your radio is a bulletin board (called a peripheral device in Bluetooth LE parlance) it posts data for all radios in the community to read.
If your radio is a reader (called a central device in Blueooth LE terms) it reads from any of the bulletin boards (peripheral devices) that have information about which it cares.
You can also think of peripheral devices as the servers in a client-server transaction, because they contain the information that reader radios ask for. Similarly, central devices
are the clients of the Bluetooth LE world because they read information available from the peripherals.
Think of a Bluetooth LE peripheral device as a bulletin board and central devices as viewers of the board. Central devices view the services, get the data, then move on.
Each transaction is quick (a few milliseconds), so multiple central devices can get data from one peripheral.
The information presented by a peripheral is structured as services, each of which is subdivided into characteristics. You can think of services as the notices on a bulletin board, and characteristics as the individual paragraphs of those notices.
If you're a peripheral device, you just update each service characteristic when it needs updating and don't worry about whether the central devices read them or not.
If you're a central device, you connect to the peripheral then read the boxes you want. If a given characteristic is readable and writable, then the peripheral and central can both change it.
Notify
The Bluetooth LE specification includes a mechanism known as notify that lets you know when data's changed. When notify on a characteristic is enabled and the sender writes to it, the new value is automatically sent to the receiver, without the receiver explicitly issuing a read command.
This is commonly used for streaming data such as accelerometer or other sensor readings. There's a variation on this specification called indicate which works similarly, but in the indicate specification, the reader sends an acknowledgement of the pushed data.
The client-server structure of Bluetooth LE, combined with the notify characteristic, is generally called a publish-and-subscribe model.
Update a characteristic
Your peripheral should update characteristics when there's a significant change to them. For example, when a switch changes from off to on, update its characteristic. When an analog sensor changes by a significant amount, update its characteristic.
Just as with writing to a characteristic, you could update your characteristics on a regular interval, but this wastes processing power and energy if the characteristic has not changed.
Read/write/notify/indicate
There are 4 things a central device can do with a characteristic:
-Read: ask the peripheral to send back the current value of the characteristic. Often used for characteristics that don't change very often, for example characteristics used for configuration, version numbers, etc.
-Write: modify the value of the characteristic. Often used for things that are like commands, for example telling the peripheral to turn a motor on or off.
-Indicate and Notify: ask the peripheral to continuously send updated values of the characteristic, without the central having to constantly ask for it.
In order to use the BLE function from Arduino 101 you need to start including the right header:
#include
Then you need to create instances and characteristics. In the following code I created the instance of the peripheral and declared a service
to distribute the accellerometer data coming from the 101 accellerometer. For the accellerometer service I will create 3 carachteristics (Yaw, Pitch and Roll)
BLEPeripheral blePeripheral; // create peripheral instance
BLEService AccellerometerService("F000AA1-0451-4000-B000-000000000000"); // create service
//Yaw, Pitch and Roll Charactheristics (Only read and Notify)
BLEFloatCharacteristic YawCharacteristic("F000AA11-0451-4000-B000-000000000000", BLERead | BLENotify);
BLEFloatCharacteristic PitchCharacteristic("F000AA12-0451-4000-B000-000000000000", BLERead | BLENotify);
BLEFloatCharacteristic RollCharacteristic("F000AA13-0451-4000-B000-000000000000", BLERead | BLENotify);
Following you will see the inizialization code and the start of the ble service
blePeripheral.setLocalName("Accellerometer");
blePeripheral.setDeviceName("VicSensorCentral");
// set the UUID for the service this peripheral advertises:
blePeripheral.setAdvertisedServiceUuid(AccellerometerService.uuid());
// add service and characteristics
blePeripheral.addAttribute(AccellerometerService);
blePeripheral.addAttribute(YawCharacteristic);
blePeripheral.addAttribute(PitchCharacteristic);
blePeripheral.addAttribute(RollCharacteristic);
YawCharacteristic.setValue(0);
PitchCharacteristic.setValue(0);
RollCharacteristic.setValue(0);
// advertise the service
blePeripheral.begin();
From now on the service is live and you can read it using a debugger or using a read service built in another application
If you want to check if a device is connected (just to save time not writing information on carachteristics) you can use the following sentences
BLECentral central = blePeripheral.central();
// if a central is connected to peripheral:
if (central) { ...
Once you want to write a carachteristics you will simply need to invoke the SetValue function
YawCharacteristic.setValue(filter.getYaw());
PitchCharacteristic.setValue(filter.getPitch());
RollCharacteristic.setValue(filter.getRoll());
in this case the filter structure is the Magdwik structure used to read the CurieIMU accellerometer values. But it returns a long value so you can use it for anything you want to distribute over the BLE protocol.
Functions I described are the ones needed to run the multidimensional box. Obviously you have many additional functions implemented in the BLE protocol.
Now that you have clear how the BLE protocol works you can procede reading how the
GPS and accellerometer sensor are working in the multidimensional box.