HC05 and pi pico

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
aks
Posts: 4
Joined: Sat Mar 20, 2021 8:19 am

HC05 and pi pico

Post by aks » Sat Mar 20, 2021 8:48 am

Hello everyone !

I just bought a pi pico and an HC05 for wireless communication to and from the pico.

I saw several YouTube videos where they seem to be doing things so easily, but that doesn't seem to work for me.

Pico is my first micro controller and I'm not sure what I'm doing wrong !

Connection;
hc05 vcc - vsys
tx and rx to GP0 and GP1 - tried interchanging them too !
ground - grnd


the code in Thonny:
from machine import Pin, UART

uart = UART(0, 9600)

while True:
# print('checking BT')
command = uart.readline()
print(command)

Here I get nothing, and the while loop does not repeat itself over and over. (if I uncomment the first line in the while clause, it doesn't print it over and over, but it runs only once ! if I print part.any() I get 0. Even then it doesn't run over and over in the while loop.) I don't understand what I'm doing wrong!


I saw this link to send hex from Mac to hc05 and print the send command in tonny. but it didn't work.

https://www.youtube.com/watch?v=0TzYDOIaDYA

I tried this, my android phone is a Samsung tab s6 lite. I also tried sending commands fromHC05 bluetooth controller app.
https://www.youtube.com/watch?v=vDJRMidEvhU&t=53s

I also tried to power it via an adaptor instead of the USB as I read that on usb connection the default SERIAL connection changes to bluetooth. But nothing works !

I understand that the idea is to get a string from the phone / pc to the BT module and then into the pico, with which we can control other other devices, based on the received string, write a logic like;
do this if command =='on led' or do that if command is 'something something'


any help is appreciated !
Thanks in advance !


Would be really great if you could give me a brief / guide me to a book / resource, where I can understand the communication protocols which we are using or some basics so I can interface devices without having to read online guides.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: HC05 and pi pico

Post by Roberthh » Sat Mar 20, 2021 10:15 am

The problem may be related to the uart.read() behavior, which was changed recently from blocking to non-blocking. You should use the latest daily build as firmware, and change the read loop into:

Code: Select all

while True:
    # print('checking BT')
    if uart.any():
        command = uart.readline()
        print(command)
Edit: reading the data sheet of the HC05, it tells that the default baud rate is 38400. So you may try different baud rates too.

aks
Posts: 4
Joined: Sat Mar 20, 2021 8:19 am

Re: HC05 and pi pico

Post by aks » Sat Mar 20, 2021 12:26 pm

Hello Roberthh !
Thank you for the quick reply !

I had tried this before and it didn't work, (i.e using it inside uart.any())

I went through the data sheet, and took the following baud dates that hc05 supports.
9600,19200,38400,57600,115200,230400,460800


Tried all of them, none work :(

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: HC05 and pi pico

Post by Roberthh » Sat Mar 20, 2021 12:47 pm

I had a unused HC05 in my drawer, so I pulled it out for a test, connecting it with a USB/Serial adapter to my PC. I could not bring it to live, until I pushed the little button on the board while powering it. Then it responded to commands at 38400 baud. Difference: while powered normally, the LED would flash fast. When started with the button pressed, the LED flashed slow. In any state the HC05 would not send anything until connected.
So in command mode you could send something like:
"AT\r\n" which should return "OK", or
"AT+VERSION?", which should return the version number.

aks
Posts: 4
Joined: Sat Mar 20, 2021 8:19 am

Re: HC05 and pi pico

Post by aks » Sun Mar 21, 2021 4:15 am

Hi Roberthh,

Once again thank you for the very quick response and for trying it out just for me !

Heres an update:
I can now send commands from the hc05 and am able to receive them in the android at 9600 bauds !!! :D :D :D

I got hc05 up on command mode(As you had suggeste) and tried to send commands in all of the bauds, with and without \n and \r, read or readlines() returns nothing :(((

aks
Posts: 4
Joined: Sat Mar 20, 2021 8:19 am

Re: HC05 and pi pico

Post by aks » Tue Mar 23, 2021 8:13 pm

Hello Roberthh and everyone,

I managed to solve the problem, I bought a new hc05 module and boom, everything worked normally !

I remember wiring the old hc05 incorrectly the first time I connected it, I had enquired with the seller who claimed that the module would not turn on if anything was wrong with it. And when it turned on, I assumed everything was OK, but I was wrong. The reason I enquired with the seller was that I had read online that the tx pin on the HC05 would get ruined if connected to 5v and I think ether that happened when I wired it incorrectly or it was a bad module.

It now receives strings throughout BT at 9600 bauds.

Thank you Roberthh for your help and time.
I hope this will help any1 else who has the same trouble, this is what I learnt;( Pls correct me if I'm wrong)
1. if u have the bauds wrong, you would still receive data, but it would come up as weird characters instead of what you sent to it. ( This what I experienced)
2. DO not connect 5v to HC05 tx pin it will turn on and not tx any data which will leave you baffled !

Jignesh12321
Posts: 1
Joined: Mon Jun 14, 2021 2:13 pm

Re: HC05 and pi pico

Post by Jignesh12321 » Mon Jun 14, 2021 2:22 pm

:?:
:roll:
does problem solved by just doing...

Code: Select all

if uart.any()
    data=uart.readline()
    print(data)
does there any requirement to change the baudrat or not

Post Reply