Community
cancel
Showing results for 
Search instead for 
Did you mean: 
JKabi
Novice
1,354 Views

Can't Communicate to Arduino code with phone by Bluetooth SPP on Intel® Edison

Followed this

https://software.intel.com/en-us/blogs/2015/05/19/communicate-to-arduino-code-with-your-android-phon... comment-1847213 IoT - Communicate to Arduino code with your Android* Phone by Bluetooth Serial Port Profile (SPP) on Intel® Edison | Int…

OS: MAC

Board : Intel® Edison

Phone : Samsung Galaxy Note 3

 

After uploading serial monitor is showing

"read error Bad file descriptor"

"open error No such file or directory"

bluetooth pin service is working well

Active: active (exited) EDISON systemd[1]: Started Bluetooth SPP and PIN service.

Can't connect Bluetooth spp pro app with edison without SPP-loopback.py

but its working well with SPP-loopback.py

Bluetooth spp pro APP doesn't ask for PIN. where to enter PIN 8888 ?

16 Replies
Pedro_M_Intel
Employee
92 Views

Hello jahanbabu,

These are the steps I used to create a SPP connection with Edison:

  • Setting Edison to run SPP server

 

vi /lib/systemd/system/bluetooth.service

Search for the following line:

ExecStart=/usr/lib/bluez5/bluetooth/bluetoothd -d

Change it for:

ExecStart=/usr/lib/bluez5/bluetooth/bluetoothd -C

  • Setting the SPP connection

For this test a Nexus 5 with the free app Bluetooth SPP Manager was used***

rfkill unblock bluetooth

bluetoothctl

agent DisplayYesNo

default-agent

scan on

#

# Discover your phone and find its MAC address

#

scan off

pair XX:XX:XX:XX:XX:XX

#

# XX:XX:XX:XX:XX:XX represents your phone's MAC address, when entering the commands remember to change it

# Say yes to everything on your Edison and hit the pair button on your phone

#

trust XX:XX:XX:XX:XX:XX

quit

sdptool add --channel=22 SP

rfcomm watch /dev/rfcomm0 22 > /dev/null &

bluetoothctl

discoverable on

quit

#

# Connect for your phone to the Edison establishing the SPP connection

#

cat /dev/rfcomm0

  • Closing the SPP connection

bluetoothctl

disconnect XX:XX:XX:XX:XX:XX

quit

If the connection is not closed this way the Edison may have issues and it will probably crash.

You could combine this to what I explain in or you could create an Arduino sketch that calls these commands and send the data to the Arduino serial port with the command "cat /dev/rfcomm0 > /dev/ttyGS0".

Peter.

JKabi
Novice
92 Views

OS: MAC

Board : Intel® Edison

Phone : Samsung Galaxy Note 3 & Sony Xperia P

there was "ExecStart=/usr/lib/bluez5/bluetooth/bluetoothd" not "ExecStart=/usr/lib/bluez5/bluetooth/bluetoothd -d"

anyway i changed that to "ExecStart=/usr/lib/bluez5/bluetooth/bluetoothd -C"

 

After uploading serial monitor is showing

"read error Bad file descriptor"

"open error No such file or directory"

^ this problem remains ...

 

 

But now i can connect to phone successfully,

and after sending text from phone its showing in terminal window but not in arduino serial monitor  

Pedro_M_Intel
Employee
92 Views

So the issue is only happening on the Arduino IDE side, right?

When did it happen? Was it when you established the SPP connection or when exactly? I found it weird since I tested it with a Nexus 5 and I had no issues sending data to the Arduino Serial Monitor.

Peter.

JKabi
Novice
92 Views

Yes the issue is only happening on the Arduino IDE side.

I am following your all procedure, then opening Bluetooth app pro App from phone

then connecting to edison board in CMD line mode

then performing this command "cat /dev/rfcomm0" on terminal

then sending text and that text is showing in my pc's terminal but not in serial monitor of arduino1.6.6 IDE

another problem is after uploading code successfully when opening serial monitor its showing rapidly

"read error Bad file descriptor"

"open error No such file or directory"

 

Pedro_M_Intel
Employee
92 Views

When you are trying to send data to the Arduino Serial Monitor remember to use the command cat "/dev/rfcomm0 > /dev/ttyGS0" otherwise the data will not be sent to the Serial Monitor.

Regarding the error you are seeing, when does it happen? Is it when you are trying to send the data to the Serial Monitor? Could you show us a screenshot of the error?

Peter.

JKabi
Novice
92 Views

Please check image below when use cat "/dev/rfcomm0 > /dev/ttyGS0"

cat /dev/rfcomm0 <- Showing text in terminal which is sends from phone

cat /dev/ttyGS0 <- Not showing text in terminal also not in serial monitor

JKabi
Novice
92 Views

JKabi
Novice
92 Views

when opening serial monitor its just showing

JKabi
Novice
92 Views

BT pin status

Pedro_M_Intel
Employee
92 Views

I see; I believe I now understand what's happening. You are opening the port /dev/rfcomm0 and then you are trying to open the port again. This might be caused by an issue within the Arduino code, how are you sending data to the serial monitor?

Peter.

JKabi
Novice
92 Views

these are my steps

1. Powering Edison board

2. Opening Arduino 1.6.6 IDE and uploading

3. performing this commands on Terminal/Putty

  • rfkill unblock bluetooth
  • bluetoothctl
  • agent DisplayYesNo
  • default-agent
  • scan on
  • #
  • # Discover your phone and find its MAC address
  • #
  • scan off
  • pair XX:XX:XX:XX:XX:XX
  • #
  • # XX:XX:XX:XX:XX:XX represents your phone's MAC address, when entering the commands remember to change it
  • # Say yes to everything on your Edison and hit the pair button on your phone
  • #
  • trust XX:XX:XX:XX:XX:XX
  • quit
  • sdptool add --channel=22 SP
  • rfcomm watch /dev/rfcomm0 22 > /dev/null &
  • bluetoothctl
  • discoverable on
  • quit

4.Opening Bluetooth spp pro App and connecting to board

5. performing this command cat /dev/ttyGS0

6. opening serial terminal on arduino IDE (That is starts showing read error Bad file descriptor ** open error No such file or directory)

7.Now sending text from phone, please check my first & second screenshot on previous comment.

cat /dev/rfcomm0 <- Showing text in terminal which is sends from phone

cat /dev/ttyGS0 <- Not showing text in terminal also not in serial monitor

What else should i do ?

Pedro_M_Intel
Employee
92 Views

As I mentioned in my previous post, the issue is probably that you are trying to open the serial port more than once. All the steps are fine up to step 5 where you open the ttyGS0 port, this port is the same used in the Arduino IDE in the serial monitor, hence this might be the reason why you are getting the error message "read error Bad file descriptor ** open error No such file or directory".

Skip step 5 and proceed with step 6, the error should not be present this time. Now on step 7 change the command "cat /dev/rfcomm0" for "cat /dev/rfcomm0 > /dev/ttyGS0", this time you should be able to see the data on the Arduino IDE's serial monitor.

Peter.

JKabi
Novice
92 Views

Thanks Peter its working "cat /dev/rfcomm0 > /dev/ttyGS0" 

only this command is sending data to arduino IDE serial monitor.

But this problem is Not solved though this is not problem

after uploading code successfully when opening serial monitor its showing rapidly

"read error Bad file descriptor"

"open error No such file or directory"

Here is my android code to control LEDPIN 13 on and off.

If i send text through serial monitor its working fine but if i send from phone then text is only showing in serial monitor not working. What is the difference here ?

int ledPin = 13;

int state = 0;

int flag = 0;

void setup() {

pinMode(ledPin, OUTPUT);

digitalWrite(ledPin, LOW);

Serial.begin(9600);

}

void loop() {

if(Serial.available() > 0){

state = Serial.read();

flag=0;

}

if (state == '0') {

digitalWrite(ledPin, LOW);

if(flag == 0){

Serial.println("LED: off");

flag = 1;

}

}

else if (state == '1') {

digitalWrite(ledPin, HIGH);

if(flag == 0){

Serial.println("LED: on");

flag = 1;

}

}

}

When sending "1","0" form Serial Monitor its showing LED : on, LED : off

but when sending from phone its just showing 1 0 1 0

Pedro_M_Intel
Employee
92 Views

What's happening is that you are sending data to the Serial Port (ttyGS0, Arduino Serial Monitor) when sending the Bluetooth SPP data and at the same time you are trying to send data to the same serial port on the Arduino code, both data can't be read at the same time I believe that's why the serial buffer is crashing, if you want to see all the data on the Arduino serial monitor, you will have to find a way to synchronize when the data is sent from the Arduino code and when it is sent from the SPP connection.

Peter.

JKabi
Novice
92 Views

I think you didn't get my problem. Upon code is working fine in UNO board. data is showing in Serial monitor also can read from board.

But in edison when sending "1" from phone its just showing 1 in serial monitor.

that means "state = Serial.read();" is not working.

Pedro_M_Intel
Employee
92 Views

I understand, but you have to remember that Edison has an internal OS that manages all of its actions. So, even though the Arduino sketch and the Linux script that manages Bluetooth are completely separate, they all handle the same resources and they both can't access the same serial port at the same time.

I mean, it makes perfect sense that your code works on an Arduino UNO, if you were only programming on the Arduino side of Edison then it would probably run just like on an Arduino, nevertheless you are also using the Linux side of Edison to enable Bluetooth and establishing a SPP connection. The part where they collapse is when you want to send data at the same time from the Arduino sketch and from the Linux script to the same serial port (ttyGS0, the Arduino Serial Monitor).

So, as I mentioned, you will have to synchronize when you are sending data to the serial port. What is happening with the behavior you are describing in your last post is that you are actually sending that data to the serial port, so you cannot both write and read that data at the same time, you will have to find a way to communicate Linux to Arduino in a different way.

I suggest you to read https://software.intel.com/en-us/blogs/2014/09/22/efficient-communication-between-arduino-and-linux-... Efficient communication between Arduino* and Linux native processes, that document talks about how to communicate between the Linux and Arduino sides of Intel boards, I believe it will be of much help for you.

Peter.