How to get the Bluetooth module working (JYMCU...)?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
rankor
Posts: 38
Joined: Sun Nov 30, 2014 12:38 am

Re: How to get the Bluetooth module working (JYMCU...)?

Post by rankor » Fri Dec 05, 2014 10:13 pm

I continued in turbinreiters thread instead. better to keep it in one thread.

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

Re: How to get the Bluetooth module working (JYMCU...)?

Post by rankor » Sun Dec 07, 2014 5:59 pm

OK. I am so frustrated over here.

I just can't get AT commands to work. I can pair but my phone but not with my app so I can't send anything.

Is there a step after pairing, connecting?

Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: How to get the Bluetooth module working (JYMCU...)?

Post by Turbinenreiter » Sun Dec 07, 2014 7:35 pm

I'll try and figure it out tomorrow evening. We'r still a small community, so it can sometimes take a wile to get help.

Adam
Posts: 2
Joined: Thu Mar 05, 2015 6:58 am

Re: How to get the Bluetooth module working (JYMCU...)?

Post by Adam » Sun Mar 08, 2015 5:26 pm

Hey, I noticed you were having trouble trying to get the HC05 running with AT commands..... I was able to get it somewhat working (some progress) but its still above my head as to how it is not working properly , possibly a baudrate issue:

1.) I setup main.py as:

import pyb
from pyb import UART

uart = UART(1, 9600) # init with given baudrate
uart.init(9600, bits=8, stop=1, parity=None) # init with given parameters
pyb.repl_uart(uart)

2. I followed the AT Command Mode setup from an arduino tutorial....
http://www.instructables.com/id/Modify- ... /?ALLSTEPS

Once you have the 2 second flash in Command mode, that all you need but you can reference the page for AT commands

3. I used putty to connect to the pyboard

4. From whatever you are using ( for me its putty...) type in this line.
UART(1, baudrate=38400, bits=8, parity=None, stop=1, timeout=1000, timeout_char=1000, read_buf_len=64)

**** NOTE --> this baudrate WILL bug out the system but it will allow you to type in the AT command... ****


5. Write the following code on one line:

uart.write('AT+NAME?\r\n');print(uart.read())

You will need to scroll up to see the the name which should be HC05 .... .... Try other AT+commands to see if it works.


Happy Coding... and if you have already found a way... please share it with the community because this way is not effective and we would all like to know .


-- ADAM --

vikebo
Posts: 15
Joined: Sun Mar 15, 2015 8:15 pm
Location: Norway

Re: How to get the Bluetooth module working (JYMCU...)?

Post by vikebo » Sun Mar 22, 2015 10:06 pm

Hello,

I've also got one of the Bluetooth modules now and since I want to use a higher transfer rate than 9600 BPS, I have tested the AT mode. Tried to do everything from the MicroPython board since I may use the module with different boards and want them to do any required modifications on their own. Changing the name of the module seems to work both at 9600 BPS default rate and at 38400 BPS in the "rescue" mode if you forget the configured rate. Getting late, haven't tried anything else yet.

Connections:
X1 - HC-05 Key
X9 - HC-05 RXD
X10 - HC-05 TXD
GND - HC-05 GND
3V3 - HC-05 Vcc (cycle this pin before clicking switch)

Some code:

Code: Select all

import pyb

def bt_tx(data):
    # Transmit data, wait, check for received data and print it
    print('\nTransmitting: ', data)
    n = uart.write(data_tx)
    pyb.delay(100) # Maybe not needed
    data_rx = uart.read()
    print('\tReceived: ', data_rx)
    pyb.delay(100) # Maybe not needed

# rescue_mode = False
rescue_mode = True

sw = pyb.Switch()
pyb.LED(1).off()
pyb.LED(2).on()
p_key = pyb.Pin('X1', pyb.Pin.OUT_PP)

# AT mode can be initialised in two ways
# 1: Key-pin low at power up => use configured rate
# 2: Key-pin high at power up => use 38400 BPS
if(rescue_mode):
    p_key.high()
    # AT commands to be sent at 38400 BPS
    uart = pyb.UART(1, 38400)
else:
    p_key.low()
    # AT commands to be sent at configured BPS
    uart = pyb.UART(1, 9600)

print('Disconnect and reconnect power to bluetooth module')
print('Click switch')
# Red LED on HC-05 blinks fast in normal mode, slow in rescue mode

wait = True
while(wait):
    if sw():
        pyb.LED(1).on()
        pyb.LED(2).off()
        wait = False

p_key.high() # High for normal AT-mode

# Check if AT mode is working, module should respond with 'OK'
data_tx = 'AT\r\n'
bt_tx(data_tx)

# Ask module for version
data_tx = 'AT+VERSION?\r\n'
bt_tx(data_tx)

# Ask module for name
data_tx = 'AT+NAME?\r\n'
bt_tx(data_tx)

# Set new module name
data_tx = 'AT+NAME=MicroPython HC-05\r\n'
bt_tx(data_tx)

# Ask module for name
data_tx = 'AT+NAME?\r\n'
bt_tx(data_tx)
Output from shell after soft reboot (Ctrl-D):
  • >>>
    PYB: sync filesystems
    PYB: soft reboot
    Disconnect and reconnect power to bluetooth module
    Click switch

    Transmitting: AT

    Received: b'OK\r\n'

    Transmitting: AT+VERSION?

    Received: b'+VERSION:2.0-20100601\r\nOK\r\n'

    Transmitting: AT+NAME?

    Received: b'+NAME:HC-05\r\nOK\r\n'

    Transmitting: AT+NAME=MicroPython HC-05

    Received: b'OK\r\n'

    Transmitting: AT+NAME?

    Received: b'+NAME:MicroPython HC-05\r\nOK\r\n'
    Micro Python v1.3.10 on 2015-02-13; PYBv1.0 with STM32F405RG
    Type "help()" for more information.
    >>>

Ksanto
Posts: 3
Joined: Sun Jan 06, 2019 3:48 pm

Re: How to get the Bluetooth module working (JYMCU...)?

Post by Ksanto » Sun Jan 06, 2019 3:50 pm

Is this also possible with the newer modules like the hm-11 and hm-17?

Post Reply