Menu

Bluetooth HC-05 configuration

Andy
2016-03-03
2016-04-29
  • Andy

    Andy - 2016-03-03

    Hi Robert,
    Thanks for your huge effort for the community. I used your focuser together with ASCOM for some time now and it works like a charm.

    Recently I wanted to upgrade my setup to Bluetooth. On Win7 I then had the problem that the module was not recognized properly I only had one (incommung) COM port and no outgoing one and no SPP. So I could not connect the focuser.

    Then I tested it with good old Win XP. Here pairing with the HC-05 works pefectly, I get both COM ports and SPP. Running your main application I can connect to the arduino but somehow the commands are not recognized. Here some lines from the log file:

    29.02.2016 11:25:34: myFocuser Version: MyFocuser ©RB Brown 2014-2015: 1.7.2.7
    
    29.02.2016 11:25:34: Load: Started
    29.02.2016 11:25:34: Load: Adding comports to list
    29.02.2016 11:25:34: stepmodeListBox:
    29.02.2016 11:25:34: stepmodeListBox: saving new stepmode
    29.02.2016 11:25:38: Connect: Setting readtimeout to 5000
    29.02.2016 11:25:38: Connect:  Attempt to open serial port
    29.02.2016 11:25:40: Connect: Check if serial port opened
    29.02.2016 11:25:40: Connect: Comport=isOpen
    29.02.2016 11:25:40: Connect: Comport Opened, wait 3s
    29.02.2016 11:25:40: Connect: Opened Serial port COM5
    29.02.2016 11:25:40: Connect: Delay on Connect = 3
    29.02.2016 11:25:43: Connect: sendcmd GF# to get version
    29.02.2016 11:25:43: CommandString Send: :GF#
    29.02.2016 11:25:43: CommandString: awaiting response: GF#
    29.02.2016 11:25:43: CommandString: response recd: GF#: :GF
    29.02.2016 11:25:43: CommandString: Firmware::GF
    29.02.2016 11:25:43: Connect: Comport=connected
    29.02.2016 11:25:43: Connect: calling CommandString(:GM#)
    29.02.2016 11:25:43: CommandString Send: :GM#
    29.02.2016 11:25:43: CommandString awaiting response: GM#
    29.02.2016 11:25:43: CommandString response recd: GM#: :GM
    29.02.2016 11:25:43: WARNING: Invalid Focuser Response: 
    Requested Max Steps :GM# = :GM
    System.FormatException: Could not find any recognizable digits.
       at System.ParseNumbers.StringToLong(String s, Int32 radix, Int32 flags, Int32* currPos)
       at System.Convert.ToInt64(String value, Int32 fromBase)
       at myFocuser.Focuser.CommandString(String Command)
    29.02.2016 11:25:43: Connect: back from CommandString(:GM#)
    29.02.2016 11:25:43: Connect: calling CommandString(:GP#)
    29.02.2016 11:25:43: CommandString Send: :GP#
    29.02.2016 11:25:43: CommandString awaiting response: GP#
    29.02.2016 11:25:43: CommandString response recd: GP#: :GP
    29.02.2016 11:25:43: WARNING: Invalid Focuser Response: 
    Requested focuser position :GP# = :GP
    System.FormatException: Could not find any recognizable digits.
       at System.ParseNumbers.StringToLong(String s, Int32 radix, Int32 flags, Int32* currPos)
       at System.Convert.ToInt64(String value, Int32 fromBase)
       at myFocuser.Focuser.CommandString(String Command)
    29.02.2016 11:25:43: Connect: back from CommandString(:GP#)
    

    Do you know why I get these Errors?

    I also tried to program the HC-05 differently, tested the SLAVE and SLAVE LOOP mode, played around with baud rates but I never managed to get it running.

    Could you please tell us what the exact configuration of the HC-05 module needs to be. Which mode, baudrate etc?

    The test setup was an Arduino UNO R3, HC-05 and the EasyDriver. USB Connection worked with the Firmware under both Operating systems.

    Thanks

    Andreas

     
  • brownrb

    brownrb - 2016-03-03

    Hi andreas
    No response was receieved (or if it was, it was simply an echo of the tranmitted command, which seems strange).

    Just retested using an HC-05, it works even if the board rate is changed, at both 9600 and 57600.
    So you have to be talking to the wrong port or the HC-05 is not paired or the HC-05 was not installed properly or the HC05 to Nano connections.

    I have the pin labelled RXD on the HC05 going to D11 via a 150 ohm resistor

    I have the pin labelled TXD on the HC05 going to D10 via a 150 ohm resistor

    I have the pin labelled VCC on the HC05 going to 5V on the Nano

    I have the pin labelled GND on the HC05 going to GND on the Nano

    If you dont have 150 ohm resistor then 100 Ohm is fine.

    Are you sure the HC05 is paired with the PC, and you used the default passkey of 1234 when pairing.
    When first recognized it will create two virtual comports, mine were com7 and com8. One of those works, the other does not. For me Com7 works.

    Under the bluetooth options click the tab which says "Com Ports" and you should see the ports listed. The attachment shows what mine looks like when I have the BT-HC05 working. It shows outgoing port as com7, so that is the one I use (as it is the focuser which initiates the connection by sending commands - ie outgoing)

    When you first connect the HC05 you will get to choose if a virtual port is to be used, you must answer yes at that time (see pdf)

    I created a new version of the Winapp to test different baud rates and it works fine with them all, so it has to be your connection that is the issue.

    Let me know whats next after checking the above

     

    Last edit: brownrb 2016-03-03
  • brownrb

    brownrb - 2016-03-03

    The new app with adjustable baud rate. The Nano uses 9600 so that is the value to be used when using usb cable. If using BT, it works fine at 9600 and 57600
    Cheers
    R

     
  • brownrb

    brownrb - 2016-03-03

    You do not need to play with the mode or AT+ commands or any such like. The HC-05 only needs 4 wires to connect as shown above. All the other wires and library and such can be safely ignored. Trying to use those only helps to stuff things up. Note this only works with an HC-05 device (not an HC-06) and you will see if its an HC-05 once its recognized and paired with the computer

     
  • Andy

    Andy - 2016-03-04

    Hi Robert,

    Thanks for the fast answer! I checked again the wiring of the modules and the pairing. It is the same as you have but still even if I you your new program with all different Baud rates, the connection is established but then no response or just an echo as before.

    I then reset my Module with AT+ORG, this sets the module to Baud 38400,0,0 PW 1234 Mode 0 (Slave) device name: H-C-2010-06-01. Here I found that I can establish pairing trough Windows and I get the two ports, but I can not connect to the foccuser trough your application anymore. This is only possible in Mode 2 (Slave-loop).

    I think you are using the HC-05 on a breakout board. I have the HC-05 module only so I have a voltage divider on RX (1+2kOhm) to level the Arduino output 5V on Pin 11 down to 3.3V. Might this be the problem?

     
  • Andy

    Andy - 2016-03-04

    Hi Robert,

    Thanks for the fast answer! I checked again the wiring of the modules and the pairing. It is the same as you have but still even if I you your new program with all different Baud rates, the connection is established but then no response or just an echo as before.

    I then reset my Module with AT+ORGL, this sets the module to Baud 38400,0,0 PW 1234 ROLE 0 (Slave) device name: H-C-2010-06-01. Here I found that I can establish pairing trough Windows and I get the two ports, but I can not connect to the foccuser trough your application anymore. This is only possible in ROLE 2 (Slave-loop).

    I think you are using the HC-05 on a breakout board. I have the HC-05 module only so I have a voltage divider on RX (1+2kOhm) to level the Arduino output 5V on Pin 11 down to 3.3V. Might this be the problem?

     

    Last edit: Andy 2016-03-04
  • brownrb

    brownrb - 2016-03-04

    So according to thet image you would be using Com18.

    I never used anyting at all. I just connected the BT adapter as I stated earlier. I never used any AT+ commands or anything else. As stated, just connected it with 120 ohm between the RX and TX lines, exactly like I said. Nothing else.

    Then just powered the focuser controller with 12v, ran the application, selected com7 and away it went quite happily.

    I have 4 wires (dupont header) that come out of my case, and they connect straight to the HC05 (the two resistors are inside the case on the PCB). Insde the case the 4 wires goto the BT header on the PCB.

    So I took the HC-05 out of the packet from ebay, connected it as said, powered up the focuser, went through the windows pairing and the virtual com port, ran the focuser app and away it went.

    Connection does not necessarily mean to the "focuser" in WIndows when connecting to a com port. The myFocuserPro application attempts to open a serial port, and if it says connected, doesnt mean its a myfocuser controller. There is no "check" as such, just the fact thet windows opened the port. So it could be any port but not necessaily the correct one.

    I would recommend deleting the BT HC05 connection and virtual cum ports in windows and going through the thing again?

    Or if you have a spare UNO, just breadboard the UNO and the HC-05 as per my wiring in previous message with 150 0hm resistors and see if that works? No need to run any AT+ commands or such. It is possible that running some of those may have altered the state of your HC-05, I dont know. Is there an equiv AT+ command to reset the thing? I never looked at any AT commands at all.

    The other thing might be to try and holld the EN pin high via a 10K pullup?
    I never used the EN or STATE or KEY pins, just the 4 wires VCC/GND/TXD/RXD

     
  • brownrb

    brownrb - 2016-03-04

    For me if I "connect" to com1 or com8, it says conencted and then it fails because there is no respose. If I connect to com7 it works.

     
  • Andy

    Andy - 2016-03-07

    Hi Robert

    Thanks for all your help! Finally I managed to connect to the Arduino using Bluetooth. I had to play around quite some time but I think in the end the settings of my computer were wrong.

    For all users using the original HC_05 Bluetooth module HC_05 here some hints how to establish a connection:

    D10 of the Arduino has to be connected to TX of the HC_05
    D11 has to be connected to a voltage divider so eg a 2k Resistor followed by a 1k Resistor going to GND. There where both resistors come together, connect this point with RX of the HC_05.

    If you are familiar to AT commands the right settings would be
    AT+ROLE=0 // slave role
    AT+UART=9600,0,0 // Set the Baudrate
    AT+INIT // Initalize the SPP profile lib
    AT+PSWD=1234 // Set the pairing password

    To program the HC_05 connect D9 of the Arduino to Pin 34 (PIO11) of the HC_05 and set it to HIGH.

     
  • brownrb

    brownrb - 2016-03-07

    Hi Andy
    Thanks for posting that, i am sure it will be of help to others.

    Ive actually purchased 4, all from the same supplier, and they all worked straight out the box and I never had to so any of that. I guess there are a lot of variations between HC-05.

    Ive actually purchased 4, all from the same supplier, and they all worked

    Once, again, thanks, glad to hear you have success
    Robert

     
  • Danny

    Danny - 2016-04-28

    Hi,

    Firstly thank you for putting this project online, I have reached the stage where I had a working focuser via USB connection, and have been trying to include bluetooth functionality to it. I am using the nano and DRV8825 with NEMA17PG27 and can drive the focuser through ASCOM with APT. However I have had no success over BT, the LED on the HC05 seems to indicate connection by flashing slowly but does not connect. I am running Win10 64 bit and have tried to reestablish bluetooth comms several times. I have used the voltage divider connection method mentioned above as well as 150 ohm resistor on breakout board. I have also confirmed the module setting via AT also previously mentioned. Any advice you can suggest would be really appreciated. Thanks Dan

     
  • brownrb

    brownrb - 2016-04-29

    Hi Danny
    I thought you had it going on BT before?

    I also have Win10 x64, and have never needed to issue an AT command to it. All I ever did was connect pwr/gnd and TXD/RXD. And it jumps into life at either 9600 or 57600. Note the Arduino code has a btSerial.begin(9600) which works, but then I just set the winapp to 57600 and click connect. I found the arduino had to initialize it to 9600 for it to work, but once the arduino code was rinnong i could connect at 57600

    What I would probably do is strip the program right down to basics, with an Arduino program that reads the BT serial port and just uses a normal serial.print statement to print out (which you can use the serial monitor with).

    I am now using a 2K/1K resistor on the transmit to the BT.

    So that arrangement would be usb-controller (for use with serial debug) and pc=hc05 via bluetooth.
    I would use something like termite to open the com port of the bt and then sust send some random text to the bt and have the arduino recieve it and echo it out

    I have attached example test file which will echo bt received data on the lcd. SO you can load this straight into the focuser.

    So connect controller via usb, load program into controller, after download complete, start termite and open up the bt comport and type a command "somethinng less that 8 charavcters, like GP etc, and it should go onto the LCD if the BT is working. Actuallu with the lcd showing the recd command you dont need the serial port monitor at all.

     

    Last edit: brownrb 2016-04-29
  • brownrb

    brownrb - 2016-04-29

    And termite

     
  • brownrb

    brownrb - 2016-04-29

    Have you tried removing the HC05 in windows and then pairing again? I know it uses a different com port when reinstalling the driver. I had to do this when I used a different HC-05?

    I do a video and post it working... that might help?

     
  • Danny

    Danny - 2016-04-29

    Hi Robert,

    Thanks for the advice, I took it back to basics, with just the controller and the HC05 and a simple program to get an LED switching based on text send from the computer (I use a program called Docklight). This worked so I tried the latest version of Myfocuser2 with just the Nano and BT module direct to each other with no resistors in the circuit, and managed to get the connection to the Nano - although an expection dialog came up shortly after. I will hopefully get some time over the weekend to have a go with this and will let you know. Thanks again for your help.

    Danny

     
  • brownrb

    brownrb - 2016-04-29

    Please download latest firmware 158 which i uploaded last night to address GX bug.

    Also, enable logging in the windows app and if you get another exception send me the logfile as well as the approx time at which the exception occured (as the log file can be quite huge this helps me find it quicker

    Here is a link to the video I did a few minutes ago.

    https://www.dropbox.com/s/3bye8ixc9z7i5mc/BT-HC05.mp4?dl=0

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.