Go Down

Topic: HC-05 Bluetooth - AT commands via a script? (Read 1 time) previous topic - next topic

rj77

Jan 27, 2017, 12:21 am Last Edit: Jan 27, 2017, 12:35 am by rj77
Hi, I have found quite a few tutorials (e.g. link) that describe how to put an HC-05 into command mode using the button & then to use the Serial Monitor to send  do AT commands e.g. AT+NAME=blah

However, I was wondering if it is possible to do this programmatically i.e. without the need for sending the commands in via the USB serial?

Can I just make a software serial for the bluetooth and do the commands from within the script?

For example, following the link from before, if I did e.g.

mySerial.write("AT+NAME=blah");

I tried this and I couldn't get it to work. Should it?
I also tried  e.g. mySerial.println, 

Thanks for any insights...

Riva

Did you wait for a reply from the HC-05 after sending each command and maybe check it was the reply your looking for?
Don't PM me for help as I will ignore it.

rj77

Well I can't seem to connect to it when it is in Command Mode so I'm not sure...

Riva

Well I can't seem to connect to it when it is in Command Mode so I'm not sure...
To put the HC-05 into command mode pin 34 must be high as the device is powered up. Depending on if/what baseplate your using this pin 34 may be broken out and called KEY/EN. You may also need to ensure it is fed with a 3.3V signal as some baseplate's don't voltage level shift this.

Also be aware the baud rate used for command mode is fixed at 38400 so you need to use this serial speed.

There are several sites dealing with this subject and a quick google found this that may help.
Don't PM me for help as I will ignore it.

rj77

Yes, those are the sorts of guides i have read. That's all fine, but what if I want to do the commands from in the code?

Nick_Pyner

I think you should check to make sure the LED is confirming you are in AT mode.
All you need are the AT commands in setup with delay(2000); between them, and an empty loop. I believe it would be better to use a JY-MCU backboard for this so that the KEY switching is also under Arduino control, rather than a manual button.

Riva

Yes, those are the sorts of guides i have read. That's all fine, but what if I want to do the commands from in the code?
Read #1 again. In your code you will need to wait enough time for the sent command to execute before sending the next command or wait for a response (and maybe check the response is what you expected) before sending the next command.
Don't PM me for help as I will ignore it.

Go Up