1 2 Previous Next 16 Replies Latest reply on Dec 7, 2015 4:50 PM by Intel_Peter Branched to a new discussion.

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

    jahanbabu

      Followed this

      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 ?

        • 1. Re: Can't Communicate to Arduino code with phone by Bluetooth SPP on Intel® Edison
          Intel_Peter

          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 Automatically connect to a device through Bluetooth 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.

          1 of 1 people found this helpful
          • 2. Re: Can't Communicate to Arduino code with phone by Bluetooth SPP on Intel® Edison
            jahanbabu

            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

            • 3. Re: Can't Communicate to Arduino code with phone by Bluetooth SPP on Intel® Edison
              Intel_Peter

              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.

              • 4. Re: Can't Communicate to Arduino code with phone by Bluetooth SPP on Intel® Edison
                jahanbabu

                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"


                • 5. Re: Can't Communicate to Arduino code with phone by Bluetooth SPP on Intel® Edison
                  Intel_Peter

                  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.

                  • 6. Re: Can't Communicate to Arduino code with phone by Bluetooth SPP on Intel® Edison
                    jahanbabu

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

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

                    rfcomm.png

                     

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

                    • 8. Re: Can't Communicate to Arduino code with phone by Bluetooth SPP on Intel® Edison
                      jahanbabu

                      when opening serial monitor its just showing

                      Untitled.png

                      • 10. Re: Can't Communicate to Arduino code with phone by Bluetooth SPP on Intel® Edison
                        Intel_Peter

                        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.

                        • 11. Re: Can't Communicate to Arduino code with phone by Bluetooth SPP on Intel® Edison
                          jahanbabu

                          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 ?

                          • 12. Re: Can't Communicate to Arduino code with phone by Bluetooth SPP on Intel® Edison
                            Intel_Peter

                            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.

                            • 13. Re: Can't Communicate to Arduino code with phone by Bluetooth SPP on Intel® Edison
                              jahanbabu

                              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;

                              }

                              }

                              }

                               

                              Screen Shot 2015-11-28 at 1.48.27 PM.png

                               

                              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

                              • 14. Re: Can't Communicate to Arduino code with phone by Bluetooth SPP on Intel® Edison
                                Intel_Peter

                                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.

                                1 2 Previous Next