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.