Assign variables to char array

// send IMU data
void sendSensorData() {
  float eulers[3];
  float gyroacc[5];
  unsigned char accelCalibStatus = 0;   //Variable to hold the calibration status of the Accelerometer
  unsigned char magCalibStatus = 0;   //Variable to hold the calibration status of the Magnetometer
  unsigned char gyroCalibStatus = 0;    //Variable to hold the calibration status of the Gyroscope
  unsigned char sysCalibStatus = 0;   //Variable to hold the calibration status of the System (BNO055's MCU)
  
  // read orientation x, y and z eulers
  IMU.readEulerAngles(eulers[0], eulers[1], eulers[2]);
  // Send 3x eulers over bluetooth as 1x byte array 
  imuCharacteristic.setValue((byte *) &eulers, 12);
  
  // read angular velocity around x, y and z-axis
  IMU.readGyroscope(gyroacc[0], gyroacc[1], gyroacc[2]);
  // read acceleration in x, y and z-direction
  IMU.readAcceleration(gyroacc[3], gyroacc[4], gyroacc[5]);
  gyroacc[3] = gyroacc[3] * 9.81;
  gyroacc[4] = gyroacc[4] * 9.81;
  gyroacc[5] = gyroacc[5] * 9.81;
  // Send 3x eulers over bluetooth as 1x byte array 
  GyroAccCharacteristic.setValue((byte *) &gyroacc, 24);
  
  bno055_get_accelcalib_status(&accelCalibStatus);  //To read out the Acceleration Calibration Status (0-3)
  bno055_get_magcalib_status(&magCalibStatus);      //To read out the Magnetometer Calibration Status (0-3)    
  bno055_get_magcalib_status(&gyroCalibStatus);     //To read out the Gyroscope Calibration Status (0-3) 
  bno055_get_syscalib_status(&sysCalibStatus);      //To read out the System Calibration Status (0-3)
  
  unsigned char sendCalibration[] = {accelCalibStatus, magCalibStatus, gyroCalibStatus, sysCalibStatus};
  CalibrationCharacteristic.setValue((byte *) &sendCalibration, 4);
}

Dear Arduino community,
I am facing issue sending a 4-byte char array via BLE. The BLE function in general does it job. I suppose the problem lies in the char array itself. I have the variables for my calibration status which take numbers between 0 and 3. Those variables should be assigned to the array containing the 4 calibration status. This array is then send to the central. The central receives 0 0 0 0 whereas 3 3 3 3 would be expected for the calibrated sensor.
I am not very versed in C and the research about pointers did not lead me to a solution. Any help on this issue would be very much appreciated. Thanks upfront!
Kind regards
Chris

does How to create array to store pin assignments? address your issue

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