Sending Floats to BLE UART?

Hello Everyone!

I am working on a project where I capture EMG signals and the data is retrieved using SPI. I am receiving the data and converting the binary data back into volts and filtering it. The output is “filteredVoltage” which is a float.

I am using the https://www.adafruit.com/product/2479 Adafruit Bluefruit LE UART Friend module, and I want to send the “filteredVoltage” output through BLE. The data isn’t transferred to the BLE app correctly, I’m guessing because it may have trouble with float values.

How could I go about sending float data to BLE?

Serial Monitor output is the following (taking at random times):

The Plotter Output:

The pertaining lines of code:

void loop() {
  serialCommand.readSerial();
  sendSamples();
  ble.println(filteredVoltage);
}


inline void sendSamples(void) {
  if ((!isRdatac) || (numActiveChannels < 1) )  return;
  if (digitalRead(IPIN_DRDY) == HIGH) return;
  sendSample();
}

inline void sendSample(void) {
  digitalWrite(PIN_CS, LOW);
  register int numSerialBytes = (3 * (maxChannels + 1)); //  (3 * numActiveChannels(+1)) This will only display the active channels
  uint8_t returnCode = spiRec(serialBytes, numSerialBytes);
  digitalWrite(PIN_CS, HIGH);
  register unsigned int count = 0;
  encodeHex(sampleBuffer, (char *)serialBytes, numSerialBytes); // this returns sampleBuffer

  for (int i = 1, j = 0; i <= 8, j < 8; i++, j++)  // parsing serialBytes into respective channels
  {
    myData[j] = (uint32_t)(serialBytes[3 * i]) << 16 |
                (uint32_t)(serialBytes[3 * i + 1]) << 8 |
                (uint32_t)(serialBytes[3 * i + 2]);
  }

  // storing the binary data in individual channels, will be used for BLE.
  float Chan1 = myData[0];
  float Chan2 = myData[1];
  float Chan3 = myData[2];
  float Chan4 = myData[3];
  float Chan5 = myData[4];
  float Chan6 = myData[5];
  float Chan7 = myData[6];
  float Chan8 = myData[7];

  if (Chan1 > 8388607) { // IF > 0X7FFFFF = Negative number
    rawVoltageValue = (Chan1  - 16777215) * (4.8 / 16777215); // [(X - (2^24-1))] / [((2*VREF)/GAIN) /(2^24)-1]
    if (filter_flag == true) {
      High_Pass_Filter(rawVoltageValue * 1000);
    }
  }
  rawVoltageValue = (Chan1 * (4.8 / 16777215)); // IF <0X7FFFFF = Positive number
  if (filter_flag == true) {
    High_Pass_Filter(rawVoltageValue * 1000); // *1000 is for debugging purposes
  }
 // Serial.println(sampleBuffer);
  //Serial.println(myData & 0x00FFFFFF, HEX);
}


void High_Pass_Filter(double voltage) {           //  30 Hz IIR high-pass filter,
  filteredVoltage = highPassFilter.step(voltage); //  2nd Order Butterworth,
  Notch_Filter(filteredVoltage);                  //  Sampling rate = 250 HZ
}


void Notch_Filter(double voltage) {                //  60 Hz IIR notch filter,
  filteredVoltage = notchFilter.step(voltage);     //  2nd Order Butterworth,                                           
  Serial.println(filteredVoltage,2);              //  Lower corner = 59 Hz,
}                                                  //  Upper corner = 61 Hz,
                                                   //  Sampling rate = 250 HZ

If you KNOW the relevant lines of code, then fix the problem yourself.

From those snippets, it is not at all clear how you are sending data to the BLE device, or what the device is connected to.

But, until you can send a known, constant float value it is pointless to write sh*tloads of code to get varying float data from who knows where to send who knows how.

ericord: How could I go about sending float data to BLE?

There appears to be nothing wrong with your floats, so you might try connecting Bluetooth to the serial port, and goSerial.println(floatdata);It works for most people.