0

Hi I am making a sketch and circuit with a HC-05 BT receiver to upload sketches via Bluetooth to my Uno. This requires giving AT commands from the sketch. I would like to see the response from the HC-05 but so far I haven't got it to work. I want to view the response via the standard serial connection and serial monitor. The commands from the sketch are not being recognized by the HC-05 and I would like to see the HC-05 response to troubleshoot it.

If you have a minute would you mind giving me a tip? I would greatly appreciate it. See the ArdProgramModeOn() and Off functions at the end.

Thanks

int ATModePin = 2; // pin for HC-05 AT comand mode
int HC05powerPin = 3; // pin for powering HC-05 when high
char btserialrx; // data through from bt connection
char myChar; // data through serial port connection
#define rxPin 8 // HC-05 bt serial pin
#define txPin 9 // HC-05 bt serial pin
#include <SoftwareSerial.h>
SoftwareSerial btSerial(rxPin, txPin); // RX, TX
void setup() {
 pinMode(ATModePin, OUTPUT);
 pinMode(HC05powerPin, OUTPUT);
 pinMode(5, OUTPUT);
 Serial.begin(9600);  
 btSerial.begin(115200); 
 
 digitalWrite(HC05powerPin, HIGH);
 delay(2000);
 }
void loop() {
 while (btSerial.available()) {
  btserialrx = btSerial.read();
 }
 if(btserialrx == '1'){ // change to upload / reset mode
  Serial.println("switching to upload mode");
  ATModeOn();
  ArdProgramModeOn();
  ATModeOff();
  btserialrx = '0';
 }
 else if (btserialrx == '2'){ // change to normal mode
  Serial.println("switching to normal mode");
  ATModeOn();
  ArdProgramModeOn();
  ATModeOff();
  btserialrx = '0';
 }
}
void ATModeOn(){ // reset HC-05 and change HC-05 to AT Command Mode
 digitalWrite(5, HIGH);
 digitalWrite(ATModePin, HIGH); // AT command mode on upon reset
 delay(2000);
 digitalWrite(HC05powerPin, LOW); // hc-05 off
 delay(2000);
 digitalWrite(HC05powerPin, HIGH); // hc-05 on
 delay(2000);
} 
void ATModeOff(){ // reset HC-05 and return HC-05 to std. operation 
 digitalWrite(5, LOW);
 digitalWrite(ATModePin, LOW); // AT command mode off upon reset
 delay(2000);
 digitalWrite(HC05powerPin, LOW); // hc-05 off
 delay(2000);
 digitalWrite(HC05powerPin, HIGH); // hc-05 on
 delay(2000);
}
void ArdProgramModeOn(){
 btSerial.println("AT");
 delay(1000);
 btSerial.println("AT+POLAR=1,0"); // Arduino reset mode upon HC-05 connection for programming
 delay(1000);
 btSerial.println("AT+POLAR?"); // Arduino reset mode upon HC-05 connection for programming
 delay(2000);
 while (btSerial.available()) { // Show responses from HC-05
  myChar = btSerial.read();
  Serial.print(myChar);
 }
 delay(4000);
}
void ArdProgramModeOff(){
 btSerial.println("AT");
 delay(1000);
 btSerial.println("AT+POLAR=1,1"); // Arduino normal mode no reset upon HC-05 conection
 delay(1000);
 btSerial.println("AT+POLAR?"); // Arduino reset mode upon HC-05 connection for programming
 delay(2000);
 while (btSerial.available()) { // Show responses from HC-05
  myChar = btSerial.read();
  Serial.print(myChar);
 }
 delay(4000);
}
asked Apr 11, 2016 at 6:04

1 Answer 1

2

Unless you've manually set the btSerial speed, you need to be at the default for AT commands which is 38400 -> btSerial.begin(38400);

If you want to read regular Serial communication, you'll need to monitor 9600 -> btSerial.begin(9600);

If you are unable to to send commands, I feel as if you wouldn't have changed the default speeds.

I used this link as a reference with my project: Modify The HC-05 Bluetooth Module Defaults Using AT Commands

Lastly, you didn't mention whether or not you soldered a jumper wire to PIN 32 for your ArdProgramOff/On. Another reference for you as well: DIY Arduino Bluetooth Programming Shield

Hope my answer helps! Good luck!

answered Apr 11, 2016 at 7:40
2
  • Thanks for responding. The Make article is the one I followed to make the setup. I have wires soldered to the HC-05 32 and 34 pins for the reset signal and AT command mode. I pre--programmed HC-05 from the serial monitor to operate at 115200 baud to be able to upload to the Uno. In the example pages you sent the HC-05 and serial monitor are communicating at different baud rates but I guess a buffer handles that difference? Thanks. Commented Apr 12, 2016 at 2:18
  • Basically I'm wondering about the While loops to monitor serial received from the HC-05. I have one at the start of the loop, and then one in both functions (ArdProgramMode...) where I am sending commands to the HC-05 from the Uno sketch. Do you see a conflict in the code here, should this code design work correctly? Thanks. Commented Apr 12, 2016 at 2:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.