Problems connecting to HC-05

I’m trying to follow this guide http://www.instructables.com/id/Modify- … /?ALLSTEPS but using my Pro Micro instead of a Uno R3.

As the Pro Micro doesn’t have a Pin 11, I changed the code to

SoftwareSerial BTSerial(10, 15); // RX | TX

and have Pin 10 wired to TXD on the HC-05 and Pin 15 wired to the RXD. VCC and GND are wired up correctly and Pin 9 is wired to the HC-05 Key pin. I connect the USB to the Pro Micro with the VCC to the HC-05 disconnected, as the guide says and then connect the VCC but the light on the HC-05 just flashes quickly, not every 2s as the guide says and using the Serial Monitor to send AT gets no response and just makes the light on the Pro Micro blink once.

I’d be grateful if anyone can help me with this.

Reading this http://arduino.cc/en/Guide/ArduinoLeona … noLeonardo it seems the Micro may user Serial for the USB communications and require the user of Serial1 for the hardware serial port.

I’m not actually using the hardware serial port with the code (pasted below) but does that mean I need to substitute Serial1 for Serial and BTSerial1 for BTSerial?

#include <SoftwareSerial.h>

 SoftwareSerial BTSerial(10, 11); // RX | TX

 void setup()
 {
   pinMode(9, OUTPUT);  // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
   digitalWrite(9, HIGH);
   Serial.begin(9600);
   Serial.println("Enter AT commands:");
   BTSerial.begin(38400);  // HC-05 default speed in AT command more
 }

 void loop()
 {

   // Keep reading from HC-05 and send to Arduino Serial Monitor
   if (BTSerial.available())
     Serial.write(BTSerial.read());

   // Keep reading from Arduino Serial Monitor and send to HC-05
   if (Serial.available())
     BTSerial.write(Serial.read());
 }

The code you pasted has your BTSerial on pins 10 and 11. Also in that code, you are using hardware Serial. I bet you see the statement “Enter AT Commands” in the monitor don’t you? That’s because that statement is being sent through hardware Serial. It doesn’t necessarily mean that you are connected to the HC-05.

codlink:
The code you pasted has your BTSerial on pins 10 and 11. Also in that code, you are using hardware Serial. I bet you see the statement “Enter AT Commands” in the monitor don’t you? That’s because that statement is being sent through hardware Serial. It doesn’t necessarily mean that you are connected to the HC-05.

Yeah sorry, that was the original code I just copied and pasted but as per my original post, I modified it to use pins 10 and 15 and couldn’t get it to work.

I don’t see anything in the monitor at all, not even “Enter AT Commands”.

EDIT: I tried changing all the Serial to Serial1, leaving the BTSerial as is but still get nothing.

Did you read through the comments on the instructibles page? At least one person tried a different serial port baud rate and got it to work. Might give it a try…

After messing around with it for a couple of hours I finally got it to work!! I did a bit differently…

I used Windows 8 plus Arduino 1.05 on a Arduino Uno R3

My particular HC-05 was defaulting to 38400 BAUD. Therefore I changed the Terminal emulation speed within Arduino Serial Monitor to 38400 + Both NL + CR on the bottom right.

Then changed the program to also be 38400 (ie, Serial.begin(38400):wink:

Looks like the speed mismatch wasn’t allowing it to work properly.

Also to get it into command mode, I followed the original instructions by applying the Vcc to the HC-05 after booting the Arduino Uno. You will know its in command mode when the LED blinks slowly on and off, around 2 seconds between on/off.

Once the HC-05 is in command mode you can then reboot the Arduino and mess withe the code to your hearts content, to get it to work. As long as you dont remove the power the HC-05 will stay in command mode (slow blink on the LED).

Hope it helps:)

dlotton:
Did you read through the comments on the instructibles page? At least one person tried a different serial port baud rate and got it to work. Might give it a try…

Thanks. I tried that but it didn’t help. It’s a bit confusing, as he refers to his HC-05 defaulting to 38400 but then change the Serial port to 38400. The article also mentions that the HC-05 defaults to 9600 but then has the code set to 38400. I’ve tried changing that to 9600 but still no joy.

I thought I might as well try using the standard serial pins with Serial1 instead of the BTSerial soft pins but that didn’t work using the following code either. I also added the “while (!Serial) ;” after reading this page http://arduino.cc/en/Guide/ArduinoLeona … noLeonardo which explains that any output sent to Serial will not wait for the Monitor to be opened and will thus be lost otherwise but that didn’t help either.

 void setup()
 {
   pinMode(9, OUTPUT);  // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
   digitalWrite(9, HIGH);
   Serial.begin(38400);
   while (!Serial) ;
   Serial.println("Enter AT commands:");
   Serial1.begin(9600);  // HC-05 default speed in AT command more
 }

 void loop()
 {

   // Keep reading from HC-05 and send to Arduino Serial Monitor
   if (Serial1.available())
     Serial.write(Serial1.read());

   // Keep reading from Arduino Serial Monitor and send to HC-05
   if (Serial.available())
     Serial1.write(Serial.read());
 }

If I use the following basic test code though, that works and I get “Hello World” show repeatedly in Monitor:

void setup()
{
 pinMode(RXLED, OUTPUT);  // Set RX LED as an output
 // TX LED is set as an output behind the scenes

 Serial.begin(9600); //This pipes to the serial monitor
 Serial1.begin(9600); //This is the UART, pipes to sensors attached to board
}

void loop()
{
 Serial.println("Hello world");  // Print "Hello World" to the Serial Monitor
 Serial1.println("Hello!");  // Print "Hello!" over hardware UART

 digitalWrite(RXLED, LOW);   // set the LED on
 TXLED0; //TX LED is not tied to a normally controlled pin
 delay(1000);              // wait for a second
 digitalWrite(RXLED, HIGH);    // set the LED off
 TXLED1;
 delay(1000);              // wait for a second
}

In fact, if I put

Serial.println(“Hello world”);

in the void loop() section of the HC-05 code, then that shows Hello World repeatedly in Monitor (in fact too frequently, as I didn’t put a delay in and it overloaded it) even if Serial is set to 9600 in the code but the Monitor is set to 38400. So perhaps Serial.println commands just aren’t meant to work in the void setup() section. Anyway, I know the serial port is outputting to the PC, so I just need to work out why the connection to the HC-05 isn’t working. I’ve noticed the HC-05 seems to go into AT mode, with the LED blinking every 2s, even if I powerup with the VCC connected already and I don’t seem to have to connect it after powering the Pro Micro as per the guide but maybe I only needed to do that once and it will stay in AT mode until it receives some specific mode.

Anyway, I’ll go and double-check the wiring. I’ve been using jumpers to avoid soldering until I’m certain which pins work but it’s probably best if I just solder them up to avoid any doubt.

Nope, even soldered up I’m getting nothing (I’m using pins 10 and 14 and have specified that in the code).

I know the Serial comms to the PC via USB works but it seems nothing’s going to/coming from the HC-05 and I’m not really sure how I can test that part further.

You should post all of your code, top-to-bottom, includes, instantiation of the serial port, everything.

There may be a problem with the BT module. You could try talking directly to the BT module from a terminal program on your computer if you have a USB<=>Serial converter.

That is all the code. Isn’t the Serial.begin line the initiation of the serial port?

I don’t have a USB<=>Serial converter but I think I’ve got another BT module I could try.

From the example code you had in your OP there’s an include for software serial and then an instatiation of the software serial object…

#include <SoftwareSerial.h>

 SoftwareSerial BTSerial(10, 11); // RX | TX

If you don’t have something like this in your code, that’s probably the issue, but I would have expected the compiler to complain.

dlotton:
From the example code you had in your OP there’s an include for software serial and then an instatiation of the software serial object…

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX




If you don't have something like this in your code, that's probably the issue, but I would have expected the compiler to complain.

That wasn’t in my recent code, as I was attempting to use the hardware Serial pins (Serial1) instead of software assigned ones, so I presumed there was no need to include either of those lines.

I tried my other BT module and no joy with that either. I could try with one of my Mega boards but the pinout is quite different on that. It has pins 9,10 and 11 but they’re in the Analog In section, so I’m not sure I can use those. There’s four sets of TX/RX 0,1,2 and 3 so maybe I could use one of those instead of BTSerial on 10 and 11 but I’m not sure if I can just use Serial1 to use RX/TX0 (on pins 0 and 1) like with the Micro or if I need to different code for the Mega.

doveman:
That wasn’t in my recent code, as I was attempting to use the hardware Serial pins (Serial1) instead of software assigned ones, so I presumed there was no need to include either of those lines.

Ah, okay.

Just a sanity check, you’ve got the module TX going to Arduino RX, and module RX going to Arduino TX, right?

If you can post a good photo of the connections a second set of eyes never hurts.

dlotton:

doveman:
That wasn’t in my recent code, as I was attempting to use the hardware Serial pins (Serial1) instead of software assigned ones, so I presumed there was no need to include either of those lines.

Ah, okay.

Just a sanity check, you’ve got the module TX going to Arduino RX, and module RX going to Arduino TX, right?

If you can post a good photo of the connections a second set of eyes never hurts.

Sure yeah. I’ve been using RX (Pro Micro pin 10)>HC-05 TX and TX (Pro Micro pin 14)->HC-05 RX and double-checked I haven’t got them the wrong way round each time I’ve rewired.

I just realised that the Mega re-uses the same pin numbering twice, for the Analog and Digital sections but I probably don’t need to use Digital pins 10 and 11 as I can use Serial1 (Pins 18 and 19) instead. Serial on pins 0 and 1 seems to be used for the Serial->USB http://arduino.cc/en/Main/arduinoBoardMega . With the Micro, Serial1 uses pins 0 and 1 but the USB bus is separate (using Serial) so in theory it should have been possible to communicate with the HC-05 using Serial1 but for some reason, neither that nor the software Serial on 10 and 14 worked.

Using this code with the Mega, I had problems initially but now it’s returning OK when I type AT in the Monitor, so I know the HC-05 is working and then I was able to configure it and pair it with the PC. It didn’t work with Serial1 set to 9600 baud though, only after I changed it to 38400, so clearly that’s the default on this particular board. Both the “Goodnight Moon” and the “Ready” messages appear as well, so there clearly isn’t a problem using Serial.println in the void setup section, so I don’t know why it wasn’t producing any output with the Micro. I’ll have another go with the Micro now, setting Serial to 57600 and BTSerial to 38400.

void setup()  
{
   pinMode(9, OUTPUT);  // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
   digitalWrite(9, HIGH);
   Serial.begin(57600);
   while (!Serial) {
     ; // wait for serial port to connect. Needed for Leonardo only
   }


   Serial.println("Goodnight moon!");

   // set the data rate for the SoftwareSerial port
   Serial1.begin(38400);
   Serial.println("Ready");
}

void loop() // run over and over
{
   if (Serial1.available())
     Serial.write(Serial1.read());
   if (Serial.available())
     Serial1.write(Serial.read());
}

One other thought to test the communication path to see if your serial ports are working…

Disconnect the BT module and loop back the TX to the RX on the port where the module was plugged in.

Run that original program and anything you type into the terminal should echo back to the terminal.

Oh well, Windows 8.1 has decided it’s not going to recognise my Pro Micro anymore (currently showing as USB\VID_1B4F&PID_9206&REV_0100&MI_00). Last time this happened, I had to boot into Windows 7 to get it working again as there doesn’t seem to be a suitable signed driver available for Win8 using that VID/PID (and I can’t just modify the inf to add it as then it doesn’t match the signed cat file). So I’ll have another go at that tomorrow.

dlotton:
One other thought to test the communication path to see if your serial ports are working…

Disconnect the BT module and loop back the TX to the RX on the port where the module was plugged in.

Run that original program and anything you type into the terminal should echo back to the terminal.

That’s a good idea, thanks. I’ll try that tomorrow.

Sorry for the delay, only just had time to get the Pro Micro sorted.

So trying the Pro Micro with

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 14); // RX | TX

void setup()  
{
   Serial.begin(57600);
   while (!Serial) {
     ; // wait for serial port to connect. Needed for Leonardo only
   }


   Serial.println("Goodnight moon!");

   // set the data rate for the SoftwareSerial port
   BTSerial.begin(38400);
   Serial.println("Ready");
}

void loop() // run over and over
{
   if (BTSerial.available())
     Serial.write(BTSerial.read());
   if (Serial.available())
     BTSerial.write(Serial.read());
}

doesn’t even get me either of the println messages in Serial Monitor, which I did get when testing with the Mega. So it seems there’s an issue with writing to Serial in “void setup” with the Pro Micro but not with the Mega. If I put " Serial.println(“Ready”);" in “void loop” then that does get printed, so it is outputting to Serial OK.

I’m not sure what code to use to output to BTSerial.write and then read from BTSerial.read (with the two pins connected) and print that to Serial. I tried

   Serial.println("Ready");
   BTSerial.write("loopback");
   Serial.write(BTSerial.read());
   delay(2000);

but that just prints Ready and then -1 and repeats.

I also tried

   Serial.println("Ready");
   BTSerial.println("loopback");
   Serial.println(BTSerial.read());
   delay(2000);

and some other alternative combinations of BTSerial.x and Serial.x to no avail.

I tried this as well

void loop() // run over and over
{
  Serial.println("Ready");
  if(BTSerial.available())
  {
    byte a=BTSerial.read();
    Serial.write(a);
  }
  if(Serial.available())
  {
    byte a=Serial.read();
    BTSerial.write(a);
  }
  delay(2000);
}

but that doesn’t reprint anything I type and send in Serial Monitor but just prints Ready every 2s.

EDIT: OK, I just read that this won’t work as the SoftwareSerial interface is only half duplex, so I’m not sure how to test this. http://forum.arduino.cc/index.php/topic,214848.0.html

Well I thought I might as well just try it again and it’s working now with the Pro Micro :slight_smile:

I used a slightly different code but I don’t think that’s significant, as the other code worked fine with the Mega. Maybe just using the Mega before somehow kickstarted it.

    #include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 14); // RX | TX

void setup()
{
  pinMode(9, OUTPUT);  //HC-05 pin 34 (key pin) 
  digitalWrite(9, HIGH);  // 5V sur Key pour activer le mode commande AT
  Serial.begin(9600);
  Serial.println("AT commandes:");
  BTSerial.begin(38400);  // HC-05 vitesse par défaut pour la commande AT
}

void loop()
{
  // lecture des commandes AT par le serial port(9600)
  if (BTSerial.available()) Serial.write(BTSerial.read());

  // envoie à HC-05 de commandes AT saisi
  if (Serial.available()) BTSerial.write(Serial.read());
}

So I got the BT module working with the Pro Micro but now I need to adapt the attached code to output to the BT instead of over the USB.

I tried adding

SoftwareSerial BTSerial(10, 14); // RX | TX

and changing all the Serial. commands (read, write, etc) to BTSerial. Then I found I couldn’t use the same name in each of the tabs (config.h, etc), so I tried defining a new one for each tab, i.e. BTSerial1, BTSerial2 and using that in those tabs instead of Serial. but it didn’t work.

Would anyone be able to help me get it working please?

So I stumbled upon this thread while having similar problem, but with HC-05 module. So because I have too much free time on my hands during finals (no I don’t) I decided to create a small github repo that might help someone sometime. https://github.com/Sackhorn/HC-05-Pro-Micro-Hookup