Bluetooth HC05

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
rankor
Posts: 38
Joined: Sun Nov 30, 2014 12:38 am

Re: Bluetooth HC05

Post by rankor » Fri Dec 05, 2014 11:37 pm

Something happened there but I don't know what.

I plugged in the key to pin Y12 (ADC) and set that to an output pin and then set it high and try to write.
Can't I use the ADC like that?

rankor
Posts: 38
Joined: Sun Nov 30, 2014 12:38 am

Re: Bluetooth HC05

Post by rankor » Sat Dec 06, 2014 12:00 am

>>> from pyb import UART
>>> uart=UART(3,9600)
>>> pyb.repl_uart(uart)
>>> uart.send('AT+PIN3456')
>>>
>>> y4=pyb.Pin('Y4',pyb.Pin.OUT_PP)
>>> y4.low()
>>> uart.send('AT+PIN3456')
>>>
>>> y4.high()
>>> ERO:0
File "<stdin>", line 1, column 4
SyntaxError: invalid syntax
>>> ERO:0
File "<stdin>", line 1, column 4
SyntaxError: invalid syntax
>>> ERO:0)ERO:0

rankor
Posts: 38
Joined: Sun Nov 30, 2014 12:38 am

Re: Bluetooth HC05

Post by rankor » Sat Dec 06, 2014 1:08 am

I have also found different tutorials saying different things.

is PIn change:
"AT+PINXXXX"
or
"AT+PSWD=XXXX"

I can set the module in different modes because I can see the LED blink differently (1Hz, 2Hz).

What does pyb.repl_uart(uart) do? can I use that on Ubuntu, meaning I can get a repl to just send uart commands on Ubuntu?

misskniss
Posts: 1
Joined: Sat Dec 06, 2014 5:33 am

Re: Bluetooth HC05

Post by misskniss » Sat Dec 06, 2014 6:28 am

If you are still having trouble with the bluetooth module, I was able to get this working as well. I am on OSX but it might translate just fine to Ubuntu. I followed a bunch of the information here in the thread and have used these little modules before on the Espruino/javascript board.

Y9 (TX) --> BT RX
Y10 (RX) --> BT TX
3V3 --> BT VCC
(I am actually running my bluetooth module on a separate power circuit because of how I am running my small DC motors)
GND --> BT GND

Below is what I used to get started and ran the board on battery power.

Code: Select all

 # main.py
 # Bluetooth Example
 import pyb
 from pyb import ADC
 from pyb import Pin
 from pyb import UART
   
 left_motor = Pin('X1', Pin.OUT_PP)
 right_motor = Pin('X2', Pin.OUT_PP)
 uart = UART(3,9600)
 uart.init(9600, bits=8, stop=1, parity=None)
 pyb.repl_uart(uart)
 
 def lt():
    # really a driver is best for DC control but this will demo fine for testing
    # I have a transistor circuit tied in to switch a larger amount of current
    # for the motors. 
    right_motor.low()
    left_motor.high()
    pyb.delay(200)

 def rt():
    right_motor.high()
    left_motor.low()
    pyb.delay(200)
  
 def stop():
    right_motor.low()
    left_motor.low()
    pyb.delay(200)
 
 def go():
    right_motor.high()
    left_motor.high()
    pyb.delay(200)
Save the file and reset the board.

Pair you computer to the module. Use 1234 as the key:

Pull up the repl via the bluetooth connection:

Code: Select all

screen /dev/tty.HC-05-DevB  //(or ls /dev/tty.HC-05... to find it first )
Pair your Android phone to the module. Use 1234 as the key:
I am currently using an android phone with Bluetooth Terminal (by Next Prototypes) with the NewLine Code setting for send and recv set to CR_LF in the preferences.

With the above code on the board I can just type to move my little bot around & use the repl as usual with my phone:

Code: Select all

>>> go() 
>>> stop()
>>> lt()
>>> rt()
Here is a video: https://drive.google.com/file/d/0B9k3eD ... sp=sharing
Last edited by misskniss on Mon Dec 08, 2014 6:08 am, edited 1 time in total.

rankor
Posts: 38
Joined: Sun Nov 30, 2014 12:38 am

Re: Bluetooth HC05

Post by rankor » Sun Dec 07, 2014 1:39 pm

I tried again:

I set the KEY pin high just as it boots.

JYMCU goes into AT mode (I can see from LED flashing).

However I cannot get a proper response from the JYMCU on my AT commands.

If I read the bus I get b'0', thats all.

If I send 'AT' I get no response.

rankor
Posts: 38
Joined: Sun Nov 30, 2014 12:38 am

Re: Bluetooth HC05

Post by rankor » Sun Dec 07, 2014 3:36 pm

So I have the Key connected to 3v3 and Vcc to Vin. The JYMCU boots into AT mode because the LED blinks slower. I have baud set at 38400 which it should have in this mode. I can't for the life of me figure out what I am doing wrong.
I have Rx on the JYMCU connected to the Tx of the pyboard(Y9) and the Tx of the JYMCU connected to the Rx of the pyboard(Y10). Y9 and Y10 => uart 3.
I have tried with both my JYMCU modules, same result.

I switched to using UART instead, still same result.

I have tried setting KEY pin high from the start and after start (using baud=9600 instead for the uart). Nothing works. I guess there is a simple detail I have wrong, that's all but this is really frustrating.

from pyb import UART

uart = UART( 3, 38400 )

btn = pyb.Switch()

lcd = pyb.LCD( 'X' )
lcd.light( True )

blue = pyb.LED( 4 )

response = 'NA'

while True:
if btn():
blue.on()

uart.send( 'AT\r\n' ) # Tried with and without the delimiting '\r\n', same result (no answer)

try:
response = uart.recv(1)
except Exception:
response = "exception"

blue.off()

lcd.fill( 0 )
lcd.text( 'R: ' + response, 10, 10, 1 )
lcd.show()

Post Reply