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:
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
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")?
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.
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.
Same value received for several different characters. I can't see a pattern
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?
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.
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.
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.
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:
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.
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.