Quetzacoal
Posts: 5
Joined: Fri Apr 27, 2018 10:04 am

How to easily connect bluetooth as an UART python + C

Mon Jun 21, 2021 10:57 am

Hello,

I had a project from university which was to connect 2 raspberries using bluetooth, one had to be programmed in C and the other in python.

Tricky...

Well, my first thought was to connect both raspberries using the integrated BT, unluckily there was no easy way to access the communication channel with C.

So I though about using an HC-06.

One pi was connecting with blueman to the HC-06 and creating a port named rfcomm0, and then in the other I found a tutorial that teach me how to connect it as ttyAMA0.

There's a problem, ttyAMA0 is not a serial communication like for example the one you get in an arduino with software serial or the one you get in raspberry pico such as the UART. I was getting A LOT of garbage in the C program and couldn't understand why.

I was about to give up as I couldn't find any tutorial explaining how to make the HC-06 behave as I wanted. Luckily I found a tutorial that teach me that the port which is doing the serial communication that I want is not ttyAMA0 but ttyS0!!!!!!! So I dissabled Serial Console from preferences and enabled Serial Port. It looks like it works now, C is not getting garbage anymore, now it's getting bytes as intended.

The system is as follows, C > rfcomm > HC06 > Integrated BT > ttyS0 > python

I hope this can help other people in the future!!!!

Qtz

Return to “Other projects”