Garbage values received through bluetooth connection

Hello everyone, currently I'm trying to send single text characters over a Bluetooth connection and I'm receiving weird values. For example I'll send the character D and receive Þ. Heres my Setup: I use my Microsoft surface 3 to send the text over Advanced Serial Port Monitor. I pair my surface with a HC-05 chip that's connected to my Arduino Uno. The Uno is connected via the built in usb and monitored over the IDE's serial port monitor(but connected to my desktop computer).
Here's my code:

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX
int counter = 0;
String incommingCommand;

void setup()
{
  pinMode(13, OUTPUT); //left wheel CH1A
  pinMode(3, OUTPUT); // left wheel CH1B
  pinMode(4, OUTPUT); //right wheel CH2A
  pinMode(5, OUTPUT); //right wheel CH2B

  Serial.begin(9600);
  BTSerial.begin(9600);
}

void loop()
{
  while(BTSerial.available() > 0)
  {
    char data = BTSerial.read();

    Serial.write(data);
  } 

}

The advanced serial port monitor is running at 9600 baud, 8 bits, no parity, 1 stop bits,500 auto delay with no end of string. My IDE monitor is running at 9600 baud with no line ending. The HC-05 is running on factory default settings(which is 9600 baud I'm pretty sure). I've attached a picture of my wiring and the HC-05 datasheet. Let me know if you need anymore information so I can get to the bottom of this :slight_smile:

HC-Serial-Bluetooth-Products-201104.pdf (938 KB)

instead of this:

    Serial.write(data);

see if you print what you expect when you use this:

    Serial.println(data);

BulldogLowell:
instead of this:

    Serial.write(data);

see if you print what you expect when you use this:

    Serial.println(data);

I've updated the code and uploaded it, still getting weird values. Check out my screenshots.

Capture1.PNG

Hi muku

Is your screenshot of the serial monitor output from using Serial.write(data) or Serial.println(data)?

If it is from Serial.write(data), then it would be helpful to see the results from Serial.println(data) as BulldogLowell suggested, with details of what character(s) you sent during the test.

If it is from Serial.println(data), then the problem may be between the Arduino and your PC. What happens if you add a simple Serial.println("hello world")?

Thanks

Ray

Its using Serial.println. See I would of thought that too but when I did an if statement to test if the value equaled D it didn't print the statement inside the if. Here's the new code with screenshots.

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX
int counter = 0;
String incommingCommand;

void setup()
{
  pinMode(13, OUTPUT); //left wheel CH1A
  pinMode(3, OUTPUT); // left wheel CH1B
  pinMode(4, OUTPUT); //right wheel CH2A
  pinMode(5, OUTPUT); //right wheel CH2B

  Serial.begin(9600);
  BTSerial.begin(9600);
}

void loop()
{
  while(BTSerial.available() > 0)
  {
    char data = BTSerial.read();

    Serial.println("Hello\n");
    Serial.println(data);
  } 

}

c2.PNG

Thanks, muku.

Could you try another test - change the print statement to the following.

Serial.println((byte)data);

And maybe test it for two or three different characters. It would be helpful to see if there is any pattern to the data you are getting or if it is truly random.

Well not the correct results with the cast but some interesting ones to say the least. Here's the code:

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX
int counter = 0;
String incommingCommand;

void setup()
{
  pinMode(13, OUTPUT); //left wheel CH1A
  pinMode(3, OUTPUT); // left wheel CH1B
  pinMode(4, OUTPUT); //right wheel CH2A
  pinMode(5, OUTPUT); //right wheel CH2B

  Serial.begin(9600);
  BTSerial.begin(9600);
}

void loop()
{
  while(BTSerial.available() > 0)
  {
    char data = BTSerial.read();

    Serial.println((byte)data);
  } 

}

c22.PNG

Same value received for several different characters. I can't see a pattern :frowning:

Just thinking about the hardware, how do you have the module connected to the Arduino? It's not easy to see all the connections in the image.

The HC-05 breakout board has six pins on the left hand side (as oriented in the image). Are they labelled on the bottom of the board? How are they linked to the Arduino?

I'm using a similar setup to the wiring in this article. http://www.instructables.com/id/Cheap-2-Way-Bluetooth-Connection-Between-Arduino-a/

In my setup its white ground, red 5v, tx green, rx orange. The weird thing my rx and tx have been backwards but ive been receiving data. If I put them in the right place I don't receive any data.

Looking at the image of your breadboard, the jumper leads seem to be connected to the breakout board in this order, from top to bottom:

White GND
Red VCC
Green TX output from the module
Yellow RX input to the module

The image in the tutorial you linked to has the connections to the breakout board in a different order. It shows the bottom of the breakout board but, if it were turned over, they would be from top to bottom:

RX
TX
GND
VCC

Sorry if I am jumping to the wrong conclusion. It could be that your breakout board has different connections.

It does heres what it looks like flipped around so its in the same order.

Thanks, muku. Sorry about the "red herring" :blush:

To confirm if the BT module serial port is working, disconnect the breakout board from the Arduino, and instead connect the TXD and RXD of the breakout board together. You should see the characters you send echoed back on the Advanced Serial Port Monitor.

If that works OK, and the wiring is correct, then the only other thing I can think to try is the baud rate on software serial. Maybe the module has been changed at some point from the default and is not operating at 9600. You could try common values like 4800 and 19200 in case one of them works.

Could you elaborate on the first paragraph? Do you want me to connect the rx and tx from the hc-05 directly to pins 10 and 11?

Connect the TXD and RXD of the BT breakout board together. Don't connect either of them to the Arduino.

But do keep the VCC and GND connections to the Arduino to power the breakout board.

This will test the BT module standalone. The data you send it will go out of the module on TXD and straight back in on RXD, so it should transmit the same character back to your Windows serial app.

And it should work even if the speed has changed to something other than 9600, since TXD and RXD will be working at the same speed.

Oh I understand. I screenshotted the results. Seems to be working find there?

Agreed. BT module looks good.

Suggest you now reconnect TX output from module to a different Arduino pin (e.g. pin 2) using a different jumper lead, just to eliminate possible hardware problems. Leave RX on module disconnected for now (and not looped to TX).

And then run your program again, having changed the pin definition:

SoftwareSerial BTSerial(2, 3); // RX | TX

I tried both things no luck. I'm confused on why I only get print from IDE when I have the software serial set to 2, 3 which is rx, tx, but my tx on the hc is in 2 and the rx is in 3. I've tried switch around wires but that's the only combination where I receive any kind of output when I send data.

how about the hardware serial on pins 0 and 1?

On the module, TX is named from the point of view of the module - it transmits out from the module, so is receive input on Arduino.

Sorry, not sure what else to suggest on the problem :frowning:

I've tried hardware serial I don't think it made a difference. Wasn't getting any output probably since I was trying to read and write from the same Serial. If anyone else has anymore suggestions let me know.