HC-06 + Arduino Micro - receiving strange values over bluetooth serial

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!

I haven't found a solution to this, but since I just want to enable or disable some particular functionality using Bluetooth, I've decided just to select "Y" and "N" (yes and no) for the on / off commands. These are appearing as ASCII 16 ('Y') and 12 ('N'), which should be something else entirely. This sort of solution may be useful for others who encounter this issue.

Nevertheless, I'm still really keen to find a solution to the problem. If anyone has any ideas as to why this is happening, that would be great.

By the way, I'm using Windows 10 Pro Tech Preview (build 9926). Maybe there's some sort of issue with COM ports or my Bluetooth driver on Windows 10? Hopefully it is something less dramatic...

Try this

void loop() {
  if (Serial1.available() > 0) {
    byte b = Serial1.read();
    Serial.print("DEC = "); Serial.print(b, DEC); Serial.print(" , ");
    Serial.print("BIN = "); Serial.print(b, BIN); Serial.println;
  }

and do post exactly what your sketch outputs..

Thanks for the response Pito. I send 0, 1, 2, 3, Y and N and got the following output from my sketch:

DEC = 32 , BIN = 100000
DEC = 32 , BIN = 100000
DEC = 32 , BIN = 100000
DEC = 34 , BIN = 100010
DEC = 16 , BIN = 10000
DEC = 12 , BIN = 1100

Any ideas?