This series of articles will explain how to use the Tactigon’s integrated sensors and communication interfaces to create a simple gesture controller.
In this article we’re going to learn how to use simple Tactigon functions to send accelerometer data and quaternions over Bluetooth Low Energy (BLE from now on).
We’ll look in detail at:
- Used Libraries
- UUID and Characteristic
- Buffer
- Final Considerations
This example uses a few essential libraries:
- tactigon_led.h
- tactigon_imu.h
- IMU_main.h
- tactigon_BLE.h
The first three libraries have been analyzed in the first part of this series; we now will discover tactigon_BLE.h library.
tactigon_BLE.hThis library is dedicated to the integrated BLE module. It provides a few types needed to create a communication between two devices.
T_BLE is the BLE Manager (bleManager instance in this example); it handles UUID, Characteristics and their buffer. In the next examples, we’ll see other methods of this class, handling connection and its status.
UUID is the universally unique identification, which, associated with a characteristic, allows it to be identified by external devices.
T_BLE_Characteristic is the characteristic class. It needs an UUID and length in bytes of the payload it will transmit.
UUID and CharacteristicIn the setup function we created an uuid
with the uuid.set()
method. The UUID needs to be unique at application level.
The String "7ac71000-503d-4920-b000-acc000000001
" used is unique since we use only this in our sketch.
We set the Characteristic (bleChar instance) with the bleManager.addNewChar()
method, which instantiates a new Characteristic object by providing an UUID and the data length in byte (14 in this example).
With the condition:
if(GetCurrentMilli() >= (ticks +(1000 / 50))) { ticks = GetCurrentMilli();
//acquisition
//buffering
//transmission
}
We let sensor acquisition, buffering and transmission happen at 50Hz.
BufferAn unsigned char array (also 14 bytes in size) is used as a buffer for the characteristic. With memcpy, we prepare this buffer filling with sensor data.
memcpy(&buffData[0], &qData.q0, 2);
This execution of memcpy copies the memory area pointed by qData.q0, 2 bytes long in the memory area pointed by buffData[0]. It’s a binary operation, so data type is not relevant.
Same applies for other Quaternions and Accelerometer data in this example.
Data TransmissionOnce the buffer has been prepared with all needed information, bleChar.update(buffData)
function is called. This function notifies bleChar that a buffer is ready for transmission. The library will transmit it as soon as possible.
This sketch is another step towards the creation of a gesture monitor with the Tactigon. In the next article, we’ll look at how to receive and use data sent by this sketch in the Processing environment.
Stay tuned for more Tactigon’s code!
Comments