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.