0
$\begingroup$

I'm trying to write AT commands to HC-05 module using Raspberry Pi Pico and MicroPython, nothing complicated. But for some reason my module doesn't respond. It works well in data mode and I'm able to send/receive messages from my phone via BT connection.

I've tried doing the same thing but using Arduino and my HC-05 was working. The module is blinking with interval of 2Hz so it's clearly in command mode.

Changing Baud Rate doesn't change anything.

Connecting TX to TX and RX to RX causes the first message to be b'\x00', otherwise nothing is returned.

My Code:

from machine import Pin,UART #importing PIN and PWM
import utime #importing time


#Defining UART channel and Baud Rate
uart = UART(0, 38400)

while True:
    command = input("COMM>")
    
    uart.write(command)
    utime.sleep(1)  # to make sure that HC-05 has time to respond
    print("checking", uart.any())
    
    if uart.any(): #Checking if data available
        data=uart.read() #Getting data
        data=str(data) #Converting bytes to str type
        print(data)

Ultimately I want to use AT+INQ to retrieve data about RSSI of nearby devices.

$\endgroup$
2
  • $\begingroup$ Typically when connecting two devices over UART, you connect the TX on one device to the RX on the other device, and vice-versa. $\endgroup$
    – Ben
    Jul 20, 2022 at 13:46
  • $\begingroup$ I've tried that, but unfortunately it doesn't work $\endgroup$
    – Omicron
    Jul 20, 2022 at 16:42

3 Answers 3

1
$\begingroup$

I have no idea why I couldn't write AT commands in MicroPython, but when I've switched to Rust everything works as expected. rp-hal is a great tool for embeded Rust on RP2040 microcontrolers.

I suspect that it'd work on C/C++ as well.

I also thank Ezward for trying to help.

$\endgroup$
0
$\begingroup$

You want to connect TX <-> RX and RX <-> TX. See https://www.instructables.com/Bluetooth-ModuleHC-05-With-Raspberry-Pi-Pico/

Here is another article that describes putting the HC-05 into AT mode, which involves driving the 'Key' pin high https://www.instructables.com/Modify-The-HC-05-Bluetooth-Module-Defaults-Using-A/

Also note the default baud rate is 9600; your code is assuming 34800 baud.

$\endgroup$
4
  • $\begingroup$ It works for data mode but I intend to send AT commands. I've tried connecting TX <-> TX and RX <-> RX because this connection worked on Arduino (Commands were send via Serial Monitor and USB connection) $\endgroup$
    – Omicron
    Jul 22, 2022 at 8:23
  • $\begingroup$ The default baud rate is 9600, so you can try that. Also you need to drive the 'key' pin high to enter AT so you can change the baud rate; I don't see any code in your example that is doing that. Again, I think you need to connect TX <-> RX and visa versa. The second resource I linked shows it working that way on Arduino as well. $\endgroup$
    – Ezward
    Jul 22, 2022 at 19:29
  • $\begingroup$ Yeah, thanks for your reply, but unfortunately I've tried it all and it didn't work. I'm also driving the key pin high by just simply connecting it to the same 3.3V that powers the module. I'm currently trying to do the same thing on Pico but using C++ instead of MicroPython. $\endgroup$
    – Omicron
    Jul 22, 2022 at 20:16
  • $\begingroup$ I also noticed the VCC for HC-05 is 3.6 to 5v, so perhaps it is flaky with 3.3v $\endgroup$
    – Ezward
    Jul 27, 2022 at 0:35
0
$\begingroup$

AT commands require '\r\n' for input. Try replacing uart.write(command + '\r\n') In addition, for better viewing, converting bytes to str type: data=str(data, 'UTF-8')

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.