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’s functions to send accelerometer data and quaternions over Bluetooth Low Energy (BLE from now on).
We’ll look in detail at:
- Why Processing?
- Used Libraries
- UUID and Characteristic
- Connection To Device
- Get Data Stream
- Plot
- Final Considerations
We choose processing because it’s a diffused software sketchbook, simple and easy to start with. It offers Java and Android compatiblity, and usually it’s possible to port an application from Java to Android with little-to-no change in coding.
A lot of hobbyists use Processing, so it’s easy to find support, sketches and libraries, as well as in depth tutorials and communities.
Used LibrariesThis example uses a few essential libraries:
- Android
- Java.util.ByteBuffer
- Java.nio.ByteOrder
- Blepdroid
We’ll focus on Blepdroid while other libraries are not the aim of this post.
BlepdroidThis library is developed specifically for Processing in the Android environment. Blepdroid is available here.
UUID and CharacteristicAs we have seen in the previous part, we send data from our Tactigon board with a specific UUID. We have to use the same Identifier in this code to be able to intercept it and read associated Characteristic value.
This is the static String declaration:
public static String TACTIGON_QUAT_CHAR_STRING = “7ac71000-503d-4920-b000-acc000000001”;
Connection To DeviceThe onDeviceDiscovered()
function verifies if the discovered BLE device is The Tactigon board or another one.
To listen to the characteristic, we have to call for onServiceDiscovered()
. This function scans for available Characteristic and, if available, sets the listener to the one with TACTIGON_QUAT_UUID uuid.
The onCharacteristicChanged()
function will pull data out of the Characteristic byte[] data, reordering byte values to be able to plot them.
Once you've obtained the right data to plot, a shift in the plot arrays is executed, freeing a position for the last gathered value. The arrays are now ready to be plotted on the charts by the draw() function.
Final ConsiderationsThis Processing sketch is just a simple way to get data and print on an Android screen. By using more advanced algorithms and Processing functions, it’s possible to integrate a gesture controller.
Stay tuned for more Tactigon’s code!
Comments