Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bluetooth serial port access on raspberry pi 3b #9

Open
ghost opened this issue Nov 29, 2018 · 27 comments
Open

bluetooth serial port access on raspberry pi 3b #9

ghost opened this issue Nov 29, 2018 · 27 comments
Assignees
Labels
enhancement New feature or request

Comments

@ghost
Copy link

ghost commented Nov 29, 2018

Hi, I created a sample bluetooth controlled led using piduino library. Below is the code is executed. How can I include rfcomm in the below code ? I am able to run the code, but not able to control the LED using android via bluetooth.

#include <Piduino.h>

int led = 21;
int data = 0;

void setup()

{

pinMode(led, OUTPUT);
Serial.begin(9600);

}

void loop()
{

data = Serial.read();
if(data == '1')
{
digitalWrite(led, HIGH);
}

if(data == '0')
{
digitalWrite(led, LOW);
}

}

@epsilonrt
Copy link
Owner

I think that a test is missing if Serial.available (), but it should still work because the read () function is non-blocking and returns -1 if nothing is available.
Are you sure you have configured the serial port correctly (by default it is used to display kernel messages):
https://www.raspberrypi.org/documentation/configuration/uart.md
The first thing to do is to watch with minicom if you receive the serial port information ...
With Codelite you can put a breakpoint and see what your program does.
Could you copy me the result of pinfo?

@ghost
Copy link
Author

ghost commented Nov 30, 2018

Here is my pinfo result

Name : RaspberryPi 3B
Family : RaspberryPi
Database Id : 27
Manufacturer : Sony
Board Revision : 0xa02082
SoC : Bcm2710 (Broadcom)
Memory : 1024MB
GPIO Id : 3
PCB Revision : 1.2
Serial Ports : /dev/ttyAMA0

@ghost
Copy link
Author

ghost commented Nov 30, 2018

Yes, I removed the console=serial0,115200 from my cmdline.txt file but still I was not able to send data to my pi with android.

instead of Serial.begin() can i use the rfcomm in the code ? If yes, how ?

@ghost
Copy link
Author

ghost commented Nov 30, 2018

I want to use RPi 3 bluetooth to receive data instead of using a HC-05. And from what I know is, Serial.read() is used to receive data from a serial bluetooth device like HC-05. How can I use my rfcomm port to receive data using Piduino library ?

@epsilonrt
Copy link
Owner

Okay,
Do characters appear in minicom?
minicom -b9600 -D /dev/ttyAMA0

@ghost
Copy link
Author

ghost commented Nov 30, 2018

I haven't checked minicom, but I connect my android to rfcomm and I executed cat /dev/rfcomm0, I saw characters

@ghost
Copy link
Author

ghost commented Nov 30, 2018

How can I open rfcomm in arduino code instead of Serial.read() ?

@epsilonrt
Copy link
Owner

epsilonrt commented Nov 30, 2018

Can you confirm that the characters are coming to /dev/ttyAMA0 ? Serial is by default connected to ttyAMA0 ...

@epsilonrt
Copy link
Owner

As long as you do not confirm that the characters are displayed in minicom on the raspberry pi, we can not progress ...

@ghost
Copy link
Author

ghost commented Nov 30, 2018

Should I change any commands in cmdline.txt and config.txt to make minicom work properly ?

@ghost
Copy link
Author

ghost commented Nov 30, 2018

Do I need any serial adapter or can I use my HC-05 module ?

@epsilonrt
Copy link
Owner

Could you explain to me clearly what are the raspberry pi UART0_TXD and UART0_RXD pins connected to?

@epsilonrt
Copy link
Owner

That's the result of
capture d ecran de 2018-11-30 09-31-56
ASCIIPing on a Raspberry Pi 3 (same model as yours). Piduino works very well.
20181130_093341

@epsilonrt
Copy link
Owner

Sur le raspberry pi 3, UART0 est utilisé par défaut pour le bluetooth pour le désactiver il faut avoir ça dans /boot/config.txt :

#enable_uart=1
dtoverlay=pi3-disable-bt

@ghost
Copy link
Author

ghost commented Nov 30, 2018

No, I want to communicate via raspberry pi bluetooth

@ghost
Copy link
Author

ghost commented Nov 30, 2018

Okay, sorry I'll make it clear. I want to use raspberry pi bluetooth. How can I use serial.read() with on-board raspberry pi bluetooth ?

@epsilonrt
Copy link
Owner

Ok, I understand now.
I have never used bluetooth on a Raspberry Pi 3.
What is the name of the /dev file ?

Currently pinfo only displays /dev/ttyAMA0 which has nothing to do with your bluetooth link, it is normal that you do not receive anything ! Piduino uses libudev to detect serial ports and will create the necessary SerialX objects. I did not consider this requirement in my development.

@epsilonrt
Copy link
Owner

I do not have time right now to develop new features (very specific to Raspberry Pi 3), but I would probably do it.

What is certain is that as long as you will not be able to display in minicom the characters received on the bluetooth serial link, you will not be able to make a program waiting for the characters on the serial port ...

@epsilonrt epsilonrt added the enhancement New feature or request label Nov 30, 2018
@epsilonrt epsilonrt self-assigned this Nov 30, 2018
@epsilonrt epsilonrt changed the title rfcomm error bluetooth serial port access on raspberry pi 3b Nov 30, 2018
@ghost
Copy link
Author

ghost commented Nov 30, 2018

Okay, so then how can I use HC-05 via piduino ?

@epsilonrt
Copy link
Owner

I do not know this device, do you have a link?

@ghost
Copy link
Author

ghost commented Nov 30, 2018

@epsilonrt
Copy link
Owner

Ok, seen.
Yes, of course.
You need to turn off the bluetooth in /boot/config.txt as above.

@ghost
Copy link
Author

ghost commented Nov 30, 2018

Okay. Can i call python code in piduino code ?

@epsilonrt
Copy link
Owner

No, Arduino is C++ ! that goes against the goal pursued by Piduino.

@epsilonrt
Copy link
Owner

the example of your tutorial should work perfectly by adding #include <Piduino.h> and assigning the correct pin to the led. bye.

@ghost
Copy link
Author

ghost commented Nov 30, 2018

Okay. Thank you Professor!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant