0

I've been working with two HC-05 (master and slave) to send data between two arduino unos. I have them to where they should be connected - blinking in unison every 2 seconds, but I can't send any data between the two correctly. Even if I send something simple the slave device receives -1 or a backwards ? followed by k. Below is the code sending the data.

Master:

void setup() 
{
  //-----------Initial standard setup----------------
  // initialize serial communications at 38400 bps:
  Serial.begin(38400); //Needed for HC-05
}

void loop() 
{
 // if(Serial.available() >0)
    Serial.println("Hi");



  delay(100);
}

Slave:

void setup() 
{
  //-----------Initial standard setup----------------
  // initialize serial communications at 38400 bps:
  Serial.begin(38400); //Needed for HC-05
}

void loop() 
{
  //double temp = 0;
  if(Serial.available() >0)
  {
    auto temp = Serial.read();
    Serial.print(temp);
  }

  delay(100);
}

Here is basic code.

The serial connections are running while still connected to my computer, but I would assume that my computer wouldn't try to communicate things as well; however, if the computer does transmit then any suggestions for a way around this would be great. Any known fixes or suggestions for why it isn't receiving properly would be appreciated as well - I might not be fully understanding the serial communication or transmission as I've never worked with bluetooth modules before.

  • I forgot to mention that I am running at 38400 baud and I have changed my USB outputs to 38400 as well. – Aruss Jul 5 '18 at 20:09
  • Please include a minimal working example, that shows your problem and can be compiled for testing. These small code snippets aren't enough to find the problem. – chrisl Jul 5 '18 at 21:31
  • @chrisl Below should be the most basic transfer between the two. – Aruss Jul 6 '18 at 15:04
  • The HC-05s will not connect automatically. You have to use AT commands to pair them and establish a connection in your code. There are many examples in that in the internet. Try some of them. I cannot write a detailed answer about that, because I don't know enough about the HC-05s AT commands. Maybe another user can give more information. – chrisl Jul 6 '18 at 18:14
  • @chrisl They are already bound directly using the slave address. I've also tried using software serial to avoid interference between usb and device transmission, but that doesn't work. I have figured out that -1 means the device is receiving no data transmission though it is listening. Any suggestions from here? – Aruss Jul 6 '18 at 19:54

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.