Serial.read problem for bluetooth when using Arduino pin0 as RX. Very puzzling.

Hi

I have a bluetooth HC05 board attached to the Arduino (Duemilanove 328) at pins 0 and 1. (RX to TX and v.v.) In this configuration and this one alone I cannot get serial read /serial available commands to do anything.(There is no response to inputs using either Tera Term or the Arduino Serial Monitor) Every other way of connecting the HC05 to pins on the Arduino using software serial works fine. USB connection works fine.

There are plenty of ways that communication between bluetooth and Arduino can break down but I think I have eliminated all of them. It's a puzzle.

The wiring is correct - HC05 TX to Board RX (pin0) and HC05 RX to Board TX (pin1) (with a voltage splitter on the HC05 RX). The HC05 itself is working fine. When I use software serial I can happily use any other pair of pins as RX and TX - at the same baud rate (9600) - and serial read and print both work the way they should. I can even make it work if I make pin 0 the Tx and pin 1 the RX!

The board is being programmed correctly (I remove the RX to HC05 connection when uploading.)

When I communicate over a USB connection there are no problems at all. The normal pin0 RX / pin 1 TX configuration works (I can do both serial read and print) as does any software serial rearrangement.

I have reuploaded the standard Firmata. I am trying every test sketch I can find or come up with myself. Serial.println commands are fine but Serial.available and Serial.read produce no result when HC05 TX is connected to Board RX (pin0) and v.v. (And to repeat Serial.available and Serial.read both work if I use software serial to make pin0 the TX and pin1 the RX)

I need the normal 'pin0 as RX pin1 as TX' configuration to work in order to fit with someone else's code.

Any suggestions? Thanks

In this configuration and this one alone I cannot get serial read /serial available commands to do anything.(There is no response to inputs using either Tera Term or the Arduino Serial Monitor)

Perhaps you have a code problem.

I had a similar problem, but on a Mega and the problem was only on HWSerial 1, 2 and 3, not 0, and with a HC-05 mounted on a JY-MCU board v1.06.

I doubt it will solve your problem, but if you have the same board (1.06), try to add this in setup():

pinMode( 0, INPUT_PULLUP );

zoomkat:
Perhaps you have a code problem.

Thanks for answering so quickly. I don’t think the code is the problem. I have run a lot of different test sketches with the problem described above showing up with 100% consistency. To reassure you, here’s an example:

char INBYTE;
int  LED = 13; // LED on pin 13
#include <SoftwareSerial.h>

#define rxPin 1
#define txPin 0

SoftwareSerial mySerial(rxPin, txPin); 

void setup() {
  mySerial.begin(9600); 
  pinMode(LED, OUTPUT);
}

void loop() {
  mySerial.println("Press 1 to turn Arduino pin 13 LED ON or 0 to turn it OFF:");
  while (!mySerial.available());   // stay here so long as COM port is empty   
  INBYTE = mySerial.read();        // read next available byte
  if( INBYTE == '0' ) digitalWrite(LED, LOW);  // if it's a 0 (zero) tun LED off
  if( INBYTE == '1' ) digitalWrite(LED, HIGH); // if it's a 1 (one) turn LED on
  delay(50);
}

That runs fine on both USB and HC05 but this

char INBYTE;
int  LED = 13; // LED on pin 13


void setup() {
  Serial.begin(9600); 
  pinMode(LED, OUTPUT);
}

void loop() {
  Serial.println("Press 1 to turn Arduino pin 13 LED ON or 0 to turn it OFF:");
  while (!Serial.available());   // stay here so long as COM port is empty   
  INBYTE = Serial.read();        // read next available byte
  if( INBYTE == '0' ) digitalWrite(LED, LOW);  // if it's a 0 (zero) tun LED off
  if( INBYTE == '1' ) digitalWrite(LED, HIGH); // if it's a 1 (one) turn LED on
  delay(50);
}

only works on a USB connection

joblog: That runs fine on both USB and HC05 but this

  Serial.begin(9600); 
  pinMode(LED, OUTPUT);
}

only works on a USB connection

It seems a dumb question, but is the USB disconnected when you try using it with bluetooth?

guix: I had a similar problem, but on a Mega and the problem was only on HWSerial 1, 2 and 3, not 0, and with a HC-05 mounted on a JY-MCU board v1.06.

I doubt it will solve your problem, but if you have the same board (1.06), try to add this in setup():

pinMode( 0, INPUT_PULLUP );

I have tried that guix and, sadly, it didn't work but nonetheless I'm convinced it has to be the answer.

Your description of the problem and Erich Styger's description on the link you posted in your own topic, sound too similar to what I'm seeing for it to be something else.

Could you post the full setup section of some of your own code that implements this solution just to be sure I'm not making some obvious mistake in my attempt? Thanks

Nick_Pyner: It seems a dumb question, but is the USB disconnected when you try using it with bluetooth?

Definitely. And after every sequence of disconnection imaginable.

There isn't anything else in my code but that line...

So this was not working:

void setup()
{
  Serial1.begin( 38400 );
}

void loop()
{
  if ( Serial1.available() > 0 )
  {
    Serial1.println( (char)Serial1.read() );
  }
}

but this worked

void setup()
{
  pinMode( 19, INPUT_PULLUP );
  Serial1.begin( 38400 );
}

void loop()
{
  if ( Serial1.available() > 0 )
  {
    Serial1.println( (char)Serial1.read() );
  }
}

Anyway it was just a test, I didn't actually use it, my HC-05 is connected to Serial (RX0, TX0) so that I can program my Mega wirelessly. Here is my setup basically: |500x226

What is the board version of your HC-05? And can you try with a Mega ?

I can't help you more with your problem, but you should try remove or make a hole in the heatshrink tube and connect your Arduino RX directly to the BT module's TX, bypassing the board as he did on that website. If you can't or don't want to solder on that tiny pad, just firmly hold a wire against it.

guix: There isn't anything else in my code but that line...

So this was not working:

void setup()
{
  Serial1.begin( 38400 );
}

void loop() {  if ( Serial1.available() > 0 )  {    Serial1.println( (char)Serial1.read() );  } }




but this worked


void setup() {  pinMode( 19, INPUT_PULLUP );  Serial1.begin( 38400 ); }

void loop() {  if ( Serial1.available() > 0 )  {    Serial1.println( (char)Serial1.read() );  } }




Anyway it was just a test, I didn't actually use it, my HC-05 is connected to Serial (RX0, TX0) so that I can program my Mega wirelessly. Here is my setup basically:
[![|500x226](http://i.solidfiles.net/4c042229f9.png)](http://i.solidfiles.net/4c042229f9.png)

What is the board version of your HC-05? And can you try with a Mega ?

I can't help you more with your problem, but you should try remove or make a hole in the heatshrink tube and connect your Arduino RX directly to the BT module's TX, bypassing the board as he did on that website. If you can't or don't want to solder on that tiny pad, just firmly hold a wire against it.

You're a genius guix, simple as. The direct connection worked. (Still no luck with INPUT_PULLUP).

Thanks a million.

Good :)

Now try to figure why this is happening, that is obviously something about the BT module's board (and again, is there a version number marked on that board?) ...

Out of curiousity, did you try

pinMode( 0, INPUT );

?

We never know :P

guix: Good :)

Now try to figure why this is happening, that is obviously something about the BT module's board (and again, is there a version number marked on that board?) ...

Out of curiousity, did you try

pinMode( 0, INPUT );

?

We never know :P

There's nothing marked on the board. I bought it over a year ago on ebay. Its a RS232 TTL HC-05.

Here's the current version of the link. http://www.ebay.com/itm/30ft-Wireless-Bluetooth-RF-Transceiver-Module-serial-RS232-TTL-HC-05-for-arduino-/310540196588 I don't know if any of the specs have changed.

There's a generally available schematic for the RS232 although who knows if this one has been altered.

I tried

pinMode( 0, INPUT );

and even

pinMode( 0, INPUT );
digitalWrite(0, HIGH);

I have sent for this which should be plain sailing.

Thanks again

#include <SoftwareSerial.h>

#define rxPin 1
#define txPin 0

Why the f**k would you do software serial on the hardware serial pins? If you are going to use the hardware serial pins, use the hardware serial instance!