Hi,
I'm trying to figure out how to decode data I'm receiving through a HC-06 Bluetooth module via the Serial1 library. I'm using an Arduino Micro, though that may not make a difference.
Anyway, once the serial connections have been established, I wait for incoming bytes. Then I print their decimal and binary representation to the serial monitor.
void setup() {
Serial1.begin(9600); // Bluetooth communications
Serial.begin(9600); // USB communications
while (!Serial) {
; // wait for serial port to connect. Needed for Arduino Micro
}
Serial.println("Serial connection made (Arduino --> USB)");
while (!Serial1) {
; // wait for serial1 port to connect. Needed for Arduino Micro
}
Serial.println("Serial 1 connection made (Arduino <--> Bluetooth)");
}
void loop() {
if (Serial1.available() > 0) {
byte b = Serial1.read();
String quote = "'";
Serial.print("DEC = '"); Serial.print(b, DEC); Serial.print("', ");
Serial.print("BIN = '"); Serial.print(b, BIN); Serial.println("'");
}
}
I had expected that I would get ASCII codes back corresponding to what was sent. E.g. Send '1', receive '49', send 'a', receive '97'. See http://www.asciitable.com/
Unfortunately, I have no idea what it is I am receiving. Here's a sample:
Sent Received
Decimal Binary
0 32 100000
1 32 100000
2 32 100000
3 34 100010
4 32 100000
5 32 100000
6 36 100100
7 38 100110
8 48 110000
a 64 1000000
b 64 1000000
c 66 1000010
d 64 1000000
e 64 1000000
f 68 1000100
g 70 1000110
h 64 1000000
A 0 0
B 0 0
C 2 10
D 0 0
E 0 0
F 4 100
G 6 110
H 0 0
I 0 0
There is definitely a pattern, but I'm not sure what. It seems like the binary data is offset in some strange way.
If you have any ideas, I'd be really glad to hear them. Thanks!