Using LV53L0X and Adafruit Bluefeather nRF52 - Having data type problems

Hi,

I am using the LV53L0X time of flight sensor and the bluefeather nRF52 boards. My goal is to be able to pass the time of flight data via bluetooth to the adafruit app. So far I've been able to get both modules working separately, i.e I can read the ToF data and I can also send serial data via bluetooth to the adafruit app.

I am now attempting to combine the code and pass in the ToF data to the bluetooth write function, instead of just whatever comes in from the serial port. Here are the functions that produce the ToF data and also the ble write:

  VL53L0X_RangingMeasurementData_t measure;
    
  Serial.print("Reading a measurement... ");
  lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!

  if (measure.RangeStatus != 4) {  // phase failures have incorrect data
    Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter);
  } else {
    Serial.println(" out of range ");
  }
    
  delay(100);
  // Forward data from HW Serial to BLEUART
  while (Serial.available())
  {
    // Delay to wait for enough input, since we have a limited transmission buffer
    delay(2);

    uint8_t buf[64];
    int count = Serial.readBytes(buf, sizeof(buf));
    bleuart.write( buf, count );
  }

So it seems that measure.RangeMilliMeter is a uint16_t and bleuart.write expects uint8_t array size of 64. I am really not sure what I need to do to parse the ToF data so .write function can handle it. I've tried splitting the ToF data into two 8 bit words, with

    uint8_t lsBits[64] = {(measure.RangeMilliMeter >> 8)};
    uint8_t msBits[64] = {(measure.RangeMilliMeter & 0xff)};

but it's not happy with this either, the display on the app is just gibberish.

Does anyone know how I can parse the measure.RangeMilliMeter data so that bleuart.write will accept it and not display gibberish on the app?

So it seems that measure.RangeMilliMeter is a uint16_t and bleuart.write expects uint8_t array size of 64.

You used println() to send the RangeMilliMeter property to the serial port, so it became a string. The write() method doesn't "expect" an array of 64 elements. You pass it such an array.

But, why are you using write()? You COULD use print() or println() just like you did when sending the string to the serial port.