Arduino receiving incorrect serial data from HC-05

Hello,

I have a HC-05 connected to an Arduino-nano via software serial. I’m using the HC-05 to receive input from a bluetooth gamepad. The gamepad sends its input as a single byte, which the HC-05 transmits to the Arduino.

Problem is, the Arduino is not receiving the correct data from the HC-05. If the controller is transmitting “0” the Arduino receives a random mix of “10”, “13”, and “48” (but never 0).

I’ve connected the HC-05 directly to my PC using my USB to Serial and have verified that the HC-05 is receiving and transmiting the correct data from the controller. So the problem is somewhere in the connection between the HC-05 and the arduino.

I’ve tried both software and hardware serial, and both have the same behavior.

Here is my code:

#include <SoftwareSerial.h>

// Setup software serial for Bluetooh. RX = 10, TX = 11
SoftwareSerial bSerial (10, 11);

int controllerPins[] = {2, 3, 4, 5, 6, 7, 8, 9};

void setup() {
  Serial.begin(9600);
  bSerial.begin(9600);
  for(int i = 0; i < 8; i++) {
    pinMode(controllerPins[i], OUTPUT);
  }
}

void ProcessInput(byte input) {
  for(int i = 0; i < 8; i++) {
    digitalWrite(controllerPins[i], !(input >> i & 1));
  }
} 

void loop() {
  if(bSerial.available()) {
    int data = bSerial.read();
    Serial.println((byte) data);
    ProcessInput((byte) data);
  }
  
}

I’ve tried this without the cast to byte and with Serial.readBytes() with no luck.

The connections are as follows:

HC-05 ----- Arduino

GND → GND
VCC → VCC (3.3v)
TX → pin 10 (software serial RX)
RX → pin 11 (software serial TX)

Any thoughts would be greatly appreciated!

10 = line feed
13 = carriage return

both "invisible" characters

48 (decimal) = '0'

I'd say it is working.

http://www.asciitable.com

Gah, of course. I changed my receive function to Serial.parseInt() and it works fine.

Thanks!