Sending Accelerometer Data via BLE to Computer

Hello all,

My Setup -
Arduino Nano 33 BLE -Adafruit Powerboost 100c - lipo

Project -
Attaching these 3 in a housing to a weight lifting bar, and when the bar is lifted, send the accelerometer data to my computer to analyze.

I have been able to use the sample accelerometer code to get the XYZ. But this is while sill connected to my computer, I have yet to figure out how to send the data when the unit is disconnected from my computer.

I have LightBlue installed on my computer for BLE detection

Is this possible?

Yes, this is possible. There are many tutorials on line that should help get you started.

Thank you jremington, I have searched YouTube and the arduono boards and plain google and have only gotten as far as adding the Bluetooth scanner on my phone. But cannot seem to get to the point where I can go wireless. Everything needs to be plugged in.

1 Like

First you have to solve the problem of communication between the Nano and something else, using Bluetooth, or at least, how to perform one way data transmission from the Nano to the other thing.

So far, you've mentioned a computer with "LightBlue" and some unnamed phone. That doesn't give us much to go on.

Google can help, but you might find this post useful. Be sure to read all the way to the end. How to send datas with BLE?

1 Like

Thank you for the suggestions, I found LightBlue as a BLE scanning program to connect my Arduino to my computer via ble. I use BLE 4.0 on my phone to connect and see the data from the Nano.

I have been able to connect my nano with both my computer via (LightBlue) and phone (via BLE scanner) running this code

#include <ArduinoBLE.h>
BLEService batteryService("1101");
BLEUnsignedCharCharacteristic batteryLevelChar("2101", BLERead | BLENotify);

void setup() {
Serial.begin(9600);
while (!Serial);

pinMode(LED_BUILTIN, OUTPUT);
if (!BLE.begin()) 
{
Serial.println("starting BLE failed!");
while (1);
}

BLE.setLocalName("BatteryMonitor");
BLE.setAdvertisedService(batteryService);
batteryService.addCharacteristic(batteryLevelChar);
BLE.addService(batteryService);

BLE.advertise();
Serial.println("Bluetooth device active, waiting for connections...");
}

void loop() 
{
BLEDevice central = BLE.central();

if (central) 
{
Serial.print("Connected to central: ");
Serial.println(central.address());
digitalWrite(LED_BUILTIN, HIGH);

while (central.connected()) {

      int battery = analogRead(A0);
      int batteryLevel = map(battery, 0, 1023, 0, 100);
      Serial.print("Battery Level % is now: ");
      Serial.println(batteryLevel);
      batteryLevelChar.writeValue(batteryLevel);
      delay(200);

}
}
digitalWrite(LED_BUILTIN, LOW);
Serial.print("Disconnected from central: ");
Serial.println(central.address());
}

This is running while the nano is connected to my computer and I have the serial monitor open. But once I unplug the nano and connect it to the pawer boost and the lipo battery I cannot connect to the nano and see the data.

BLE is a protocol designed for low power not bandwidth. You should not send raw data to your PC. You have a powerful processor in your Arduino. Use the processor to analyze your data and then send condensed information to your devices. e.g., number of lifts or whatever information you would like to get. That is what smart sensors for running, cycling ... do.

If you want some raw data while you are developing you can make use of the internal RAM to buffer some data. This will allow you to collect some data at whatever speed your sensor provides it and send it via BLE at the bandwidth available.

Can you post the code you have so far and let us know what your current issue is?

Did you try the examples that come with the ArduinoBLE library?

For your case I recommend you look at:

File -> Examples -> ArduninoBLE -> Peripheral -> Battery Monitor

This line will make your sketch wait for the Serial Monitor to open. Simply comment it out.

Thank you Klaus_K

Awesome! Back on the right tracks!

I am able to disconnect from my computer and see the accelerometer data. Although it comes out in an interesting format, different from how it was in the serial monitor. In LightBlue is is showing up 0x0000C6Bc Where in the serial monitor is shows up something similar to 1.00 0.78 0.21 etc

Thanks agin for your help Klaus

The Serial Monitor formats the data and understands data types. In Light Blue the data is just a bunch of bytes.
Note that the order of bytes is different in Light Blue as well. BLE will send LSB first. All the BLE apps I have tested show you the bytes in the order received.
When you print a number in Serial Monitor as HEX LSB will be on the right.

Thank you Klaus.

I will try to have all the formulas into the code instead of sending the data to my computer and putting them into excel to calculate.

Once I have the code calculate everything I need, how would I send it to my computer and be able to interoperate the bytes as as an understandable data?

Would it be easier to use a SD card to store the data or send over wifi or regular bluetooth perhaps?

The support for BLE is not great on PCs. Most of the development for BLE targets mobile phones and tablets.

I just started using the web browser to connect my Windows 10 PC with BLE devices. This requires knowledge in HTML, CSS and advanced JavaScript. It looks quite promising. I can connect and start notification to update multiple single value characteristics. I still need to figure out how to write to characteristics and create some graphs. I guess I need to look for some JavaScript library for plotting science graphs.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.