Go Down

Topic: HC05 communication (Read 303 times) previous topic - next topic

TEAC

Hello everyone, I am trying to understand how bluetooth communication works between two HC05 modules. I have set all AT commands, configured it all correctly. Double checked the address bindings, the roles and everything there is yet when I'm going to test a simple code such as lighting a LED using a button I cant. I have taken prints of my code, my circuit and what shows up in the serial monitor. Can anyone help me with this?


blh64

when you use Serial.write(), it sends the value down the wire.  You are sending the integer 100, which is hex 0x64 or ascii 'd' which is what you are seeing on the serial monitor.

If you want to talk to a HC05 module, you typically use the SoftwareSerial library and connect it to different pins.  The build int hardware Serial monitor is on pins 0 and 1 and connect to the Serial Monitor.

Nick_Pyner

I don't know anything about LEDs but your problem may simply be mechanical. The serial monitor is just a passenger in the system which tells you what is going on, but all it has done so far is tell you that you have sent data to the port. Clearly, you know what you are doing with hardware serial and, assuming that you have indeed properly configured the modules, i.e. received an OK, the wiring must be kosher. I think you can get a bit further down the path of proof by connecting serial monitor to the slave, and putting a plain
Serial.print(val);
in there to see if you have actually received the signal.

TEAC

when you use Serial.write(), it sends the value down the wire.  You are sending the integer 100, which is hex 0x64 or ascii 'd' which is what you are seeing on the serial monitor.

If you want to talk to a HC05 module, you typically use the SoftwareSerial library and connect it to different pins.  The build int hardware Serial monitor is on pins 0 and 1 and connect to the Serial Monitor.
OH the ASCII part makes sense now, but I do not know anything about the software serial library, what does it do or how does it work?

TEAC

I don't know anything about LEDs but your problem may simply be mechanical. The serial monitor is just a passenger in the system which tells you what is going on, but all it has done so far is tell you that you have sent data to the port. Clearly, you know what you are doing with hardware serial and, assuming that you have indeed properly configured the modules, i.e. received an OK, the wiring must be kosher. I think you can get a bit further down the path of proof by connecting serial monitor to the slave, and putting a plain
Serial.print(val);
in there to see if you have actually received the signal.
Thats another problem, even when writing the letter D on the Master monitor it is not reading anything on the slave one. At first I thought it was the baud rate but it is the same, then I checked again if they were paired which they are. I really dont know what to do. I am 100% sure the connections are done right

blh64

OH the ASCII part makes sense now, but I do not know anything about the software serial library, what does it do or how does it work?
I would suggest you google it, download it and look at the examples that come with it.

You can use the library to create a serial connection on different pins other than the hardware pins (0,1).  This will enable you to print out debug statements to the serial hardware and see them on the Serial Monitor while communicating with the other HC05 modules.

If you just user the serial hardware, you have to choose to use it for serial communication to the PC or the HC05 module.  It can't do both at the same time.

Nick_Pyner

#6
Jun 15, 2019, 07:02 pm Last Edit: Jun 15, 2019, 07:17 pm by Nick_Pyner
Thats another problem, even when writing the letter D on the Master monitor it is not reading anything on the slave one. At first I thought it was the baud rate but it is the same, then I checked again if they were paired which they are. I really dont know what to do. I am 100% sure the connections are done right
Your code suggests you are using a button on Arduino to send the letter D, i.e. you are not using the serial monitor. Is that correct? If so, it is quite OK to use hardware serial, indeed it is advantageous to do so as it is proving your code is kosher. You do not need software serial, indeed, unless you have two serial peripherals, it is usually just a resources-wasting refuge for the lazy and incompetent. You succeeded in uploading the code, so you know what you are doing with hardware serial - obviously.

The baud rate you use is the baud rate you configured Bluetooth to use, no exceptions. If you didn't configure it, it is the default rate, which I have never known to be anything other than 9600. If it IS something else, the supplier would surely have told you.

When you sent the AT commands to configure one HC-05 as master, you should have had some response. If you did, your wiring is kosher. If not, it is suss.

So far, I understand you have proven

1. All wiring is kosher

2. All code is uploaded OK

3.  master software is OK

4. Contrary to assertions above, you can have the serial monitor running, but note that you cannot send anything with it, just observe, but that is all you need anyway.

IF neither LED is fast flashing 2Hz, the connection has been made. If not, check the Martyn Currey website.

Have you tried the monitor on the slave, as suggested? Finally, if you do this and have Bluetooth disconnected, you should be able to prove the code and LED by sending D from the monitor.

As things are, I submit that all your problems are at the slave end.





TEAC

Your code suggests you are using a button on Arduino to send the letter D, i.e. you are not using the serial monitor. Is that correct? If so, it is quite OK to use hardware serial, indeed it is advantageous to do so as it is proving your code is kosher. You do not need software serial, indeed it is usually just a resources-wasting refuge for the lazy and incompetent.  You succeeded in uploading the code, so you know what you are doing with hardware serial - obviously.

The baud rate you use is the baud rate you configured Bluetooth to use, no exceptions. If you didn't configure it, it is the default rate, which I have never known to be anything other than 9600. If it IS something else, the supplier would surely have told you.

When you sent the AT commands to configure one HC-05 as master, you should have had some response. If you did, your wiring is kosher. If not, it is suss.

So far, I understand you have proven

1. All wiring is kosher

2..All code is uploaded OK

3.  master software is OK

4. Contrary to suggestion, you can have the serial running, but note that you cannot send anything with it, just observe.

IF neither LED is flashing 2Hz, the connection has been made.

Have you tried the monitor on the slave, as suggested?





I am using a button to control an LED via Bluetooth, that button when pressed uses the function Serial.write(100); to print 100 to the serial monitor but I have understood that 100 that I'm writing is a Hex code and that is why it shows the letter d. What I don't know is how to print the actual number "100" to the monitor and read it on the slave monitor.
The modules are flashing in sync so I am sure they are paired, the only struggle is that I am not being capable of sending an integer value to the slave Arduino.
I can give the example of using that integer value to analogWrite() on the LED and control its luminosity but I can't get any data

Nick_Pyner

#8
Jun 16, 2019, 02:33 am Last Edit: Jun 16, 2019, 02:58 am by Nick_Pyner
I'm not sure what sort of problem this is any more.
If you want to print 100 on the monitor the code is
Serial.print("100"):
in the master, but it seems irrelevant anyway, and what you really need is a signal, any signal, in the slave, and it appears that you haven't tried looking there yet.

I can't comment on sending data to Arduino but it has just occurred to me that the following snippet might work, and will prove a lot if it did.
Code: [Select]

//in Setup
String readString; 

//in loop
  while (Serial.available())
  {
    delay(3); 
    char c = Serial.read();
    readString += c;
  }// end while

  if (readString.length() >0)
  { 
    digitalWrite(led,HIGH);   
   readString=""; 
   } // end if

whereby it doesn't matter what is sent, as long as something is sent - and received. For better information on serial input, try here.
http://forum.arduino.cc/index.php?topic=396450.0
as this may be where the real problem lies. I don't think it really matters what you send, so long as you can handle what you receive.

Go Up