Serial.begin() refuses to work properly

Hello,

I'm starting to play with Arduino(Uno). As the first project I came up with a simple display of data received by OBD2 adapter. The connection is via bluetooth and a problem occurs here.

I'm using hc-05 bt module set as master, baud rate is set to standard 9600. Ofc i'm using voltage divider on rx pin. Pins are connected rx--rx/tx--tx but i've tried to mix it.

I've used three different slave devices - i could send and receive data on both sites on serial monitor, so everything works fine... on blank sketch.

If i add Serial.begin(9600) on setup, data sent from slave is not showing on Arduino's serial monitor(but still works in opposite direction). It looks like tx connection is disabled.

Where's my begginer mistake? Please help :confused:

isox:
Where's my begginer mistake? Please help :confused:

Failure to read the guidelines at the top of this forum and posting your code so we can see it

I have read the guidelines but as i said theres nothing more than serial.begin

void setup(){
  Serial.begin(9600);
} 

void loop(){
}

I'm confused. You expect a sketch that performs no input/output to communicate?

So you're saying that the code you posted with the Serial.begin() taken out and loaded to the Arduino displays information from Bluetooth on the the serial monitor. That's not possible.

It may be that you originally had some other code that did that and then you loaded that do-nothing code over it.

Perhaps your mistake is in thinking that loading new code to the Arduino ADDS to any existing code. It doesn't. It wipes out any existing code replacing it with the new code. If the new code says "do nothing" that's what happens.

Steve

I explained it too weakly. By communication i mean manual text sending from serial monitor and seeing it on the second serial terminal. I think only modules are used for this.

  1. master ---> slave //works always
  2. slave ---> master //works only on blank sketch

Thats why i'm wondering why 2) stops working after applying code above

How do you have this wired up? A diagram would help.

It sounds as though you have wired serial ports on the two modules together so that whatever goes out on serial from the terminal is seen by both of them. What do you intend the Arduino to do?


I want to send commands to slave device and receive respond on Arduino. With serial.print() in code, part with receiving respond is impossible atm

What are the resistors for ?
There’s no need for a pull down, or current limiting in this application.

You may find it easier to use SoftwareSerial to talk to the slave so that you can debug using hardware serial. Also, it the master and slave are to talk to each other you'll need TX->RX and vice versa.

What are the resistors for ?

5V to 3.3V logic level conversion, as required.

ahh ok, the HC05 is 3V3..
Sorry abt that distraction.

The HC05 is powered from 5V ?
I’ve never used one.

lastchancename:
ahh ok, the HC05 is 3V3..
Sorry abt that distraction.

The HC05 is powered from 5V ?
I’ve never used one.

Yes, it has an on board 3.3V voltage regulator.

wildbill:
You may find it easier to use SoftwareSerial to talk to the slave so that you can debug using hardware serial. Also, it the master and slave are to talk to each other you'll need TX->RX and vice versa.

Holy moly SoftwareSerial worked perfectly. Thank you all for help!

Working code:

#include "SoftwareSerial.h"
SoftwareSerial mySerial (2,3); // RX--TX

void setup ()
{
  Serial.begin(9600);
  mySerial.begin(9600);
}
void loop ()
{
  while (mySerial.available () > 0){
    Serial.print ((char)mySerial.read ());
  }
  while (Serial.available () > 0){
    mySerial.write ((char)Serial.read ());
  }
}

TBH, I have no idea what was going on here.
I can only guess it was a slow April Fool's Joke. :fearful: