Read bytes from hm-10 characteristic sent by Android app

Hello together,

in my project, I want to send data from my Android app via bluetooth 4.0 to my Arduino with hm-10 bluetooth module. For that I create a byte array in the Android app to send the data to the Arduino. But when I read the Serial input at the Arduino I get not the same bytes as in the Android App created.

In this example, I send a string as byte array to the Arduino. But later I want to send an object as byte array to the Arduino. At the Android side, I get a byte array with the value 97.

public void writeCharacteristic(){
        if(mBluetoothAdapter == null || mBluetoothGatt == null){
            Log.w(TAG, "BluetoothAdapter not initialized");
            return;
        }

        if(mBluetoothCharacteristic != null){
            byte[] stringBytes = "a".getBytes();
            mBluetoothCharacteristic.setValue(stringBytes);
            mBluetoothGatt.writeCharacteristic(mBluetoothCharacteristic);
        }
}

When I read the incoming data from the serial input I receive two bytes. The first one is 120 and the second one is 248. Why don’t I get the same values?

SoftwareSerial BTSerial(10, 11);

void setup() {
    Serial.begin(9600);
    BTSerial.begin(38400);
    Serial.println("<Arduino is ready>");
}

void loop() {
    
    if (BTSerial.available()) {
    byte receivedByte = BTSerial.read();

     Serial.println(receivedByte); 
    }

}

Thanks.

If you are sending characters, why are you not reading characters?

   char c = Serial.read();

Thank you for your anwer PaulS.

As I wrote above, I will send an object via bluetooth to the Arduino. The string in the example code is only for test purposes. So in the real system the string and the byte array of the string will be replaced by the byte array of an object.

So in the real system the string and the byte array of the string will be replaced by the byte array of an object.

What do you expect the Arduino to do with the byte array of an Android object?

The arduino should store the object e.g in an eeprom. He should also display the object attributes on a touchscreen. So the arduino should work as a central station that the App and the touchscreen can use the stored object values or add some new data to the arduino and his storage.

I solved the problem. I set the baud rate of the hm-10 module to 9600 instead of 38400. Now it works.