Using a Boron to read Accelerometer data

I am looking for some help regarding using a boron to read accelerometer data. The accelerometer I am using is inside the Minew E8 tag, but there is no data available on their website as to what it is. I have been successful in reading the X, Y, Z values of the accelerometer from the advertising data of the tag, but this only updates every 3 seconds or so(even after changing the advertising parameters using the BeaconSet+ App), and this is not fast enough. My question is would there be a way to create a new BLE service and characteristics that would contain the value of the X, Y, Z that would then be able to be read continuously once I connect my boron to the tag?

That characteristic would need to be programmed to the E8 tag and I doubt they made their device reprogrammable.

However, they might already have a characteristic you may be able to ask for the data once you are connected to its service(s).

2 Likes

I have tried exploring all the services of the tag and getting the values stored in the characteristics but when I try to print the values to the serial monitor they appear as random ascii characters. Would you know what form the data would be in?(like hex or int etc.)

That is very difficult to answer with neither such a tag nor an example of the data you get.
If it’s not readable text it’s most likely some binary data one needs to see as such (byte by byte with their numeric value - irrespective of the encoding of that value BIN, OCT, DEC or HEX the numeric value is always the same).

0b10100101 == 0245 == 165 == 0xA5

just different representation for 165 as we are used to write it :wink:

Thanks for the help. After using an Adafruit Feather board to scan for the tag I found the Adafruit BLE scan is much, much quicker(~0.1 - 0.5secs), allowing me to get the advertising data faster. When I was scanning with the Boron advertising packets seemed to only appear every ~3 or 4 secs. I would like to use the Boron due to its cloud features, so would you know why my BLE scan seems to take so long, or how to change the BLE scan parameters of the boron to make it quicker?

Have you tried BLE.scanWithFilter() to limit the devices being “watched” and also played with the scanParams to reduce the interval and/or window and/or timeout?

I wouldn’t be surprised if BLE.scan() would ignore repeated advertisements of the same device as long it cannot be certain to have found all other devices that may be available. Hence you could try to stop your scan as soon you found and read the device in question and start a new scan immediately to obtain a new value from the same device.

Yep I’ve been scanning with a filter of the address of the E8 tag so the boron is only returning the tag when it scans. I’ve tried editing the scanParams, here is my code:
int interval = 100;
BleScanParams params;
params.version = BLE_API_VERSION;
params.size = sizeof(BleScanParams);
params.interval = interval;
From my understanding this should set the scan interval to be 62.5ms. Just to check, which section does this code go in, the setup or the loop? I’ll try play around with the window and timeout next

Update: I have solved the speed issue by using a scan callback like so :

BLE.scan(scanResultCallback, NULL);

and this seems to get a callback every 100ms or so. In the function definition of the callback:

void scanResultCallback(const BleScanResult *scanResult, void *context);

there is the context field. Based on prior posts you have answered it seems you can pass extra data in using the context field. Could the context also be used to write to a variable? Since I am trying to get accelerometer data (6 values), could I initialise a vector like:

Vector int> accData(6);

and then pass the vector into the callback like :

BLE.scan(scanResultCallback, &accData);

then edit the values stored in the vector inside the callback function? Thanks for the help so far

1 Like

Yes, you can pass in a variable that can be used by the callback function.
You just need to make sure that this variable stays valid over the entire time the callback may be active - e.g. a global variable.