Shop OBEX P1 Docs P2 Docs Learn Events
HC-05 Bluetooth not answering AT commands — Parallax Forums

HC-05 Bluetooth not answering AT commands

Hello, sorry for asking again a question...
I got a HC-05 bluetooth module on a FC-114 (state and enable pin) breakout board. I wired it the following way:
State -> NC
RX -> Propeller pin 27
TX -> Propeller pin 26
VCC -> +5V
Gnd -> Gnd
En -> NC
Pin34 -> + 3,3V (i soldered a wire to it)

What i do is, i disconect the VCC strip, power up my breadboard load my programm to the propeller, connect the vcc pin.
The bluetooth module goes to AT- mode, the leds begin to flash slowly (2 sec on, 2 off).
But when i send AT\r\n or anything else i do not get an answer. But what i noticed is, that if i send AT plus only $0d the module stops blinking. For me this means it receives data...?

Can anyone give me an advice? Thank you all


CON
_clkmode = xtal1 + pll16x 'For full 80 Mhz
_xinfreq = 5_000_000 'Use 5 MHz accurate crystal

OBJ
pst : "Parallax Serial Terminal"
Bt : "Parallax Serial Terminal"

PUB main | c
pst.Start(115_200)
bt.StartRxTx(26, 27, 0, 38_400)

repeat
c := pst.CharIn
bt.Char(c)
if(c == $0D)
bt.Char($0A)

repeat
waitcnt(clkfreq/2+cnt)
c := bt.CharIn
if(c>0)
pst.Char(c)
while c>0

Comments

  • AribaAriba Posts: 2,690
    CharIn blocks and waits until a character is received. So your second repeat loop will only end if the Bluetooth module sends a 0 character which is unlikely.

    Check first if something is in the receive buffer before you read a character:
        ...
    repeat
      if pst.RxCount > 0
        c := pst.CharIn
        bt.Char(c)
        if(c == $0D)
          bt.Char($0A)
    
      if bt.RxCount > 0
        c := bt.CharIn
        if(c <> $0A)
          pst.Char(c)
    
    Not sure if the LF ($0A) really needs to be filtered out for the PST.

    Andy
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    Just for clarification, were you literally sending, "AT\r\n" or were you sending, "AT", $0D, $0A?
  • Just for clarification, were you literally sending, "AT\r\n" or were you sending, "AT", $0D, $0A?

    I was sending "AT", $0D, $0A

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    Okay. Yeah, in most devices the linefeed isn't required for termination of the command. Not sure about your specific device.
  • AribaAriba Posts: 2,690
    Have you tried it with 9600 Baud? According this description this is the default rate if you not set the module into Command mode at startup.
    ...
    The default mode is DATA Mode, and this is the default configuration, that may work fine for many applications:
    
        Baud Rate: 9600 bps, Data : 8 bits, Stop Bits: 1 bit, Parity : None, Handshake: None
        Passkey: 1234
        Device Name: HC-05
    
    In some cases you may want to change some of the configuration setup values. There are two ways to get into Command Mode:
    
        Connect the KEY pin high before applying power to the module. This will put the module into command mode at 38400 baud. This is commonly used, and needed if you don't know the baud rate the module is set to. You can use the BlueToothCommandUtility (LINK) for this.
        Apply power to the module then pull the KEY pin high. This will enter command mode at the currently configured baud rate. This is useful if you want to send AT commands from a microcontroller as the KEY pin can be controlled from one of the microcontroller pins. BUT you need to know the currently configured Baud Rate.
    
    
    Commands are sent to the module in UPPERCASE and are terminated with a CR/LF pair.
    

    I have only worked with the HC-06 modules which are always in Slave mode and start with a 9600 Baudrate. Then you can change the Baudrate with a command.

    Andy

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    Ah, looks like it wants a CR/LF pair terminating a command.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2016-07-29 00:48
    I've used the HC-05 a lot with Propeller projects. I don't think a HC-05 Bluetooth module will respond to AT commands without the enable pin being set high.

    I have some code which uses the enable pin connected to on of the Prop I/O pins to set it to command mode. I'll post a copy here soon.

    Edit: Changed the phrasing of my post a bit.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2016-07-28 23:30
    Here are two Bluetooth utility programs I use with the HC-05.

    The HC-05's enable line needs to be connected to the I/O pin defined by the constant "BLUETOOTH_KEY".

    The Bluetooth module can be powered on with the Propeller. Any baud changes won't take effect until the Bluetooth module's power has been cycled.

    I tried to add enough debug statements to the code to make the programs relatively self explanatory.

    You'll notice the constants for a 10MHz crystal are used but the program will run just fine on Propellers using either a 10MHz crystal or a 5MHz crystal. I used some clock trick I learned (copied) from Phil to make the program automatically adjust to the crystal used (as long as it's either 5MHz or 10MHz).

    Many of the HC-05 AT commands are listed in the "bridge" program's debug statements.

    Both programs should find the current baud setting of the HC-05 module and let you know what this is. You don't have to know the baud setting of the module in advance.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2016-07-28 23:36
    BTW, the 38400 baud setting for AT commands only apply with the enable pin is active when the module is powered on. If the enable pin is made active after power up, the baud setting used with AT commands is the same as the baud setting in the normal state.

    Edit: I see the info Andy posted has this information about the two possible command baud settings. I hadn't seen this information prior to my experiments. I had to learn this the hard way.
  • Hello all together! Tanks for all the answers.

    No chance, it will not give me taht ok...

    @Duane Degn: Both programs are not able to talk to the module. Im having one of those with a push button on it. There is a VCC, GMD, RX, TX, State and one Enable pin. What i did was soldering a wire to pin 34 of the module. Seting it to high when the module powers on seems to put it to AT mode (led flashing slowly).

    I changed my code to the following
    CON
    _clkmode = xtal1 + pll16x 'For full 80 Mhz
    _xinfreq = 5_000_000 'Use 5 MHz accurate crystal

    OBJ
    pst : "Parallax Serial Terminal"
    Bt : "Parallax Serial Terminal"

    PUB main | c
    pst.Start(115_200)
    pst.Dec(bt.StartRxTx(26, 27, 0, 38_400))
    pst.NewLine

    DIRA |= (1<<25)
    OUTA |= (1<<25)

    repeat
    if pst.RxCount > 0
    pst.Str(string("loop"))
    pst.NewLine
    c := pst.CharIn
    bt.Char(c)
    if(c == $0D)
    bt.Char($0A)

    if bt.RxCount > 0
    c := bt.CharIn
    if(c > 0)
    pst.Char(c)

    The BT- module sends me endless $00, therefore i check if c > 0 when reading from bt

    Does anyone have an idea?
  • Here as a readable version of the code.

    I tryed with 38400 and 9600 baud.

    CON
    _clkmode = xtal1 + pll16x 'For full 80 Mhz
    _xinfreq = 5_000_000 'Use 5 MHz accurate crystal
    
    OBJ
    pst : "Parallax Serial Terminal"
    Bt : "Parallax Serial Terminal"
    
    PUB main | c
    pst.Start(115_200)
    pst.Dec(bt.StartRxTx(26, 27, 0, 9600))
    pst.NewLine
    
    DIRA |= (1<<25)
    OUTA |= (1<<25)
    
    repeat
      if pst.RxCount > 0
        pst.Str(string("loop"))
        pst.NewLine
        c := pst.CharIn
        bt.Char(c)
        if(c == $0D)
          bt.Char($0A)
    
      if bt.RxCount > 0
        c := bt.CharIn
        if(c > 0)
          pst.Char(c)
    
  • Duane DegnDuane Degn Posts: 10,588
    edited 2016-07-29 17:58
    csae8126 wrote: »
    @Duane Degn: Both programs are not able to talk to the module. Im having one of those with a push button on it.

    Sorry about that. I misread your original post and thought you wrote "without" breakout board.

    You'd need to do a bit of soldering to get my code to work with your board. I think you could get my code to work with your board if you added a connection from the Prop to the HC-05's enable pin. The button shouldn't interfere with the enable pin as long as it's not pressed.
    (Edit: It looks like you already did this.)



  • Made some tests:

    Connected the hc-05 via bluetooth to my pc.

    When i try
    repeat
      bt.Char("A")
      waitcnt(clkfreq/4+cnt)
    
    In putty on my pc i receive the chars...

    When i try to send from my pc to the propeller i just get $00. This indepenet if i enter something in putty or not. As soon as the bluetooth module is powered up it sends zeros.
    repeat
      if bt.RxCount > 0
        c := bt.CharIn
        if(c == 0)
          pst.Str(string(11,13,"Zero"))
          pst.NewLine
        elseif(c > 0)
          pst.Char(c)
        else
          bt.RxFlush
    

    Could anyone imagine what im doing wrong?
  • csae8126 wrote: »
    Pin34 -> + 3,3V (i soldered a wire to it)

    Is Pin 34 on the module still connected to 3.3V?

    It sounds like the module is able to send data to the PC over Bluetooth so I imagine you've disconnected the wire. Right?

    Which Propeller board are you using? What are you using as a power supply?

    Do you have a link to the Bluetooth module you purchased?

    It might help people diagnose the issue if you posted a photo of your setup.



  • Hello Duane Degn,

    Pin 34 is not connected any more.

    Im not using a Propeller board, i have a simple setup on a bread board. I use a laboratory power supply, delivering 5V. The bluetooth module is running direct on the 5V rail, as it has an voltage regulator on board. The power supply shoud be fine, because the whole setup is consuming not mire then 300 mA.

    I bought it on this website: http://www.arduitronics.com/product/55/bluetooth-serial-module-hc-05-master-slave-mode

    What i have to mention ist, that i have connected a prop plug on pins 31+30, an eeprom an pins 29+28, and on 27+26 the bluetooth module is connected.

    I try to draw me setup in eagle and upload it later.
  • csae8126 wrote: »
    What i have to mention ist, that i have connected a prop plug on pins 31+30, an eeprom an pins 29+28, and on 27+26 the bluetooth module is connected.

    Do you also have a 5MHz crystal?

    I know a lot of people disagree with me about this, but IMO, I think people are better off using a Propeller on a Parallax board like the Propeller Project Board. I just think there are just many more ways of hooking up a Propeller incorrectly on a breadboard than there are correct was of hooking things up.

    I personally use breadboards a lot (but with an external Propeller board). Sometimes it helps to pull up the circuit and move it to a different section of the breadboard. I've been surprised how many times moving a circuit to a different location has solved hard to troubleshoot problems.

    You might want to try communicating directly with the HC-05 with the Prop Plug. You should be able to send AT commands from the PC through the Prop Plug.

  • Yes i use the 5MHz crystall. I think my setup on the breadboard schould be fine, as i used it for other test bevore where i didnt have troubles.

    But it is a good idea to move it to a different section of the breadboard. Even tough a connectivity test worked out well.

    Il try it and let you know wheter it worked or not. If it should not work i hook that module up to an arduino and ill try it with that.
  • I gave it a try with an Arduino Board.
    Same result, rx on bluetooth module works fine, tx does not work at all.

    Im going to order a new hc-05 module, to see if it works with that.

    Il keep you up to date whats going on.
  • Hey csae,
    Just buy a cheap HC06 Bluetooth unit from ebay and use JonnyMac's BT Commander coding from this post.
    I found it to be robust and stable and I use it all the time as a controller.
    http://forums.parallax.com/discussion/159920/android-control-of-propeller-using-joystick-bt-commander-app-spin-code
  • Duane DegnDuane Degn Posts: 10,588
    edited 2016-08-01 15:44
    csae8126 wrote: »
    I gave it a try with an Arduino Board.
    Same result, rx on bluetooth module works fine, tx does not work at all.

    Im going to order a new hc-05 module, to see if it works with that.

    You might want to replace the solder on the tx pin.
    macrobeak wrote: »
    Just buy a cheap HC06 Bluetooth unit from ebay and use JonnyMac's BT Commander coding from this post.
    I found it to be robust and stable and I use it all the time as a controller.

    The HC-06 modules are fine but they are slave devices only. The HC-05 can be used either as a slave device or a master device. It's possible for use two HC-05 units for Prop to Prop communication. You can't use two HC-06 units this way.

    I don't think there is anything the HC-06 can do which the HC-05 can't but the HC-05 has many features lacking in the HC-06.

    I've used the HC-05 many times with the Propeller and it works fine with Joystick BT Commander.

    I know a lot of people (myself included) assumed the HC-06 was an upgrade to the HC-05. This is not the case. The HC-05 is a much more capable Bluetooth module than the HC-06. The only reason I can think of to use a HC-06 instead of a HC-05 is if the HC-06 cost significantly less than the HC-05.

  • csae8126csae8126 Posts: 14
    edited 2016-08-03 12:10
    Hello again.

    Today the new hc-05 arrived, put it back where the old one was and it works without any problems...
    So it was the module it self.

    I would like to say thank you to everyone who helped me at this topic!

    But i will try to resolder the TX-pin, to see if i can get the old one to work too...

Sign In or Register to comment.