Arduino Giga BLE and WT901SDCL-BT50 sensor

Hello everyone. I'm a bit new using this Arduino Giga board paired with this sensor : WT901SDCL-BT50. It's a 9-axis IMU and I'm using it for a robotic application involving Exoskeleton on the lower limbs. I was trying to make sense of the communication protocol to better extract all the data and display it on the serial monitor every time it refresh which I think it's approximately 20Hz, but I'm having issues because it connects but doesn't show the data. Can I receive some guidance? This is the closest program I have got.

#include <ArduinoBLE.h>

void setup() {
Serial.begin(9600);
while (!Serial)
;
// begin initialization
if (!BLE.begin()) {
Serial.println("starting Bluetooth® Low Energy module failed!");
}
Serial.println("Bluetooth® Low Energy Central - Peripheral Explorer");
// start scanning for peripherals
BLE.scan();
}

void loop() {
// check if a peripheral has been discovered
BLEDevice peripheral = BLE.available();

if (peripheral) {
// discovered a peripheral, print out address, local name, and advertised service
Serial.print("Found ");
Serial.print(peripheral.address());
Serial.print(" '");
Serial.print(peripheral.localName());
Serial.print("' ");
Serial.print(peripheral.advertisedServiceUuid());
Serial.println();

// see if peripheral is a WTSDCL
if (peripheral.localName() == "WTSDCL") {
  int len = 28;
  byte value[len];
  // stop scanning
  BLE.stopScan();
  // peripheral connected, read data
  while (1) {
    // Process the received data
    processData(value, len);
    delay(2000);
  }
}

}
}

// Function to process received data
void processData(byte *data, int len) {
static byte dataBuffer[28];
static int bufferIndex = 0;

for (int i = 0; i < len; i++) {
byte b = data[i];

if (b == 0x55) {    // Check for packet start
  bufferIndex = 1;  // Next byte is flag
  dataBuffer[0] = b;
} else if (bufferIndex > 0 && bufferIndex < sizeof(dataBuffer)) {
  dataBuffer[bufferIndex++] = b;
  if (bufferIndex == sizeof(dataBuffer)) {  // Packet complete
    if (!processPacket(dataBuffer)) {
      Serial.println("Failed to process packet");
    }
    bufferIndex = 0;
  }
}

}
}

// Function to process a complete packet
bool processPacket(byte *packet) {
if (packet[0] != 0x55 || packet[1] != 0x61) {
Serial.println("Invalid packet");
return false;
}

// Extract data from the packet
int ax = ((packet[3] << 8) | packet[2]);
int ay = ((packet[5] << 8) | packet[4]);
int az = ((packet[7] << 8) | packet[6]);
int wx = ((packet[9] << 8) | packet[8]);
int wy = ((packet[11] << 8) | packet[10]);
int wz = ((packet[13] << 8) | packet[12]);
int roll = ((packet[15] << 8) | packet[14]);
int pitch = ((packet[17] << 8) | packet[16]);
int yaw = ((packet[19] << 8) | packet[18]);

// Convert to physical units
float ax_g = ax / 32768.0 * 16.0;
float ay_g = ay / 32768.0 * 16.0;
float az_g = az / 32768.0 * 16.0;

float wx_dps = wx / 32768.0 * 2000.0;
float wy_dps = wy / 32768.0 * 2000.0;
float wz_dps = wz / 32768.0 * 2000.0;

float roll_deg = roll / 32768.0 * 180.0;
float pitch_deg = pitch / 32768.0 * 180.0;
float yaw_deg = yaw / 32768.0 * 180.0;

// Output data to Serial Monitor
Serial.print("Acceleration (g): ");
Serial.print(ax_g);
Serial.print("\t");
Serial.print(ay_g);
Serial.print("\t");
Serial.print(az_g);
Serial.print("\n");

Serial.print("Angular Velocity (°/s): ");
Serial.print(wx_dps);
Serial.print("\t");
Serial.print(wy_dps);
Serial.print("\t");
Serial.print(wz_dps);
Serial.print("\n");

Serial.print("Angle (°): ");
Serial.print(roll_deg);
Serial.print("\t");
Serial.print(pitch_deg);
Serial.print("\t");
Serial.print(yaw_deg);
Serial.print("\n\n");

return true;
}

Can you guide me on what I'm doing wrong here?

WT901SDCL-BT50 Communication Protocol.pdf (568.1 KB)

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