11 Replies Latest reply on Sep 7, 2016 12:47 PM by Intel Corporation

    Edison + DS4

    Cristi_Sava

      Hello,

      After reading a lot about Bluetooth, Edison and stuff I finally got Ds4 to autopair with my Edison. So far so good but now I really don't know what to do next... Basically I want Ds4 to do something trought Edison (blink a led, spin a motor etc) but I don't know how to program...I found a driver GitHub - TXBDan/DS4driver: Sony DS4 controller for Intel Edison but I don't know how to use it, I tried XDK, Eclipse with no positive result. All I need is someone to describe how to turn on the pin 13 led when I press a DS4 button and I think I can figure out the rest. Also, I don't know any programing but I really want to learn C++, just to do stuff like this. I mapped all the DS4buttons using Evtest in Ubuntu because I don't know how to install it on Edison. Other option is to buy an Arduino Uno+ usb host shield+dongle but I really want to do it with Edison.

        • 1. Re: Edison + DS4
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          Hello Cristi_Sava,
           
          I actually have worked on a very similar project to yours (in fact it's pretty much the same... I'm working on a guide, it should be published soon), since you have already managed to pair, connect and map the buttons of the controller when using evtest, you only need to interpret the signals the evtest script sends you and turn them into a blinking led, a moving servo, etc. For this, you will have to understand how evtest works so you can find which variable is the one that contains this information so you can use it on your project. This will depend on the version of evtest that you are using since newer versions of this software are different than earlier ones and if you are using a different version than mine, I may confuse you.
           
          On version 1.23 of evtest you should look for names[ev[i].type][ev[i].code] and ev[i].value, they contain the signal name and the signal value respectively. If you add mraa to the evtest code, you will be able to take this data and turn it into something that can be interpret by the board. For example I made my Edison turn its on board led on when the X signal was pressed and to turn it off when it was released. I hope this information helps.
           
          Peter.

          • 2. Re: Edison + DS4
            Intel Corporation
            This message was posted on behalf of Intel Corporation

            Hi Cristi_Sava,

            The guide I mentioned above can be found in http://www.intel.com/content/www/us/en/support/boards-and-kits/intel-edison-boards/000020389.html. Try it and let me know if you run into any issue, I'll gladly help you if that's the case.

            Peter.

            • 3. Re: Edison + DS4
              Cristi_Sava

              Hello Peter,

               

              After upgrading to last image I found that if you pair and trust the DS4 then Edison will autopair and connect everytime it boots up without the help of other scripts.

              Now, what can I  do to make the evtest /eventX run automatically after the ds4 is connected to Edison?

              • 4. Re: Edison + DS4
                Intel Corporation
                This message was posted on behalf of Intel Corporation

                Hi Cristi_Sava,
                 
                I suggest you to create a system service that helps you with that task. I have also written a document on how to create a system service. You can find it in https://communities.intel.com/docs/DOC-111103.
                 
                Let me know if this helps you.
                -Peter.

                • 5. Re: Edison + DS4
                  Cristi_Sava

                  Hi Peter,

                   

                  In /home/root/ I have the evtest program that I manually compiled with gcc evtestDS4.c -o evtestDS4 –lmraa. If I send the command ./evtest /dev/input/event2 after the ds4 is connected it works, led is on when btn X is pressed.

                   

                  I created the runevtest.service:

                   

                  [Unit]

                  Description=runevtest
                  Requires=bluetooth.target
                  After=bluetooth.target

                   

                  [Service]
                  Type=simple
                  RemainAfterExit=true
                  Restart=on-failure
                  ExecStart=/home/root/evtest /dev/input/event2
                  Environment="HOME=/home/root"
                  WorkingDirectory=/home/root/

                   

                  [Install]
                  WantedBy=multi-user.target

                   

                  Enabled it with systemctl and after reboot and ds4 connected I get this:

                   

                  root@Edison:~# systemctl status runevtest -l
                  ● runevtest.service - runevtest
                     Loaded: loaded (/lib/systemd/system/runevtest.service; enabled)
                     Active: active (exited) (Result: exit-code) since Fri 2016-08-26 09:14:40 UTC; 2min 23s ago
                    Process: 258 ExecStart=/home/root/evtest /dev/input/event2 (code=exited, status=1/FAILURE)
                  Main PID: 258 (code=exited, status=1/FAILURE)
                     CGroup: /system.slice/runevtest.service

                  Aug 26 09:14:40 Edison systemd[1]: Started runevtest.
                  Aug 26 09:14:40 Edison libmraa[258]: libmraa version v1.2.3 initialised by user 'root' with EUID 0
                  Aug 26 09:14:40 Edison libmraa[258]: edison: Arduino board detected
                  Aug 26 09:14:40 Edison libmraa[258]: libmraa initialised for platform 'Intel Edison' of type 2
                  Aug 26 09:14:40 Edison evtest[258]: evtest: No such file or directory
                  Aug 26 09:14:40 Edison systemd[1]: runevtest.service: main process exited, code=exited, status=1/FAILURE

                   

                  Any idea where is the problem?

                   

                  Thanks,

                  Cristi

                  • 6. Re: Edison + DS4
                    Intel Corporation
                    This message was posted on behalf of Intel Corporation

                    I believe the reason why this is happening is because you are setting evtest to start to run on boot but at that time event2 doesn't exist as the DS4 hasn't been connected yet, therefore it will not be able to run evtest correctly. You should add to your service a part where it waits until the DS4 is connected.
                     
                    Also, I can see that you are starting evtest directly from the service but you could use it to start a shell script that includes both the part where Edison waits for the DS4 and the part where it starts evtest.
                     
                    I hope this information helps.
                    -Peter.

                    • 7. Re: Edison + DS4
                      Cristi_Sava

                      Hello Peter,

                       

                      I am aware that evtest is not starting because event2 doesn't exist until connection with ds4 but I assumed that the service will start all over again until connection.

                      "You should add to your service a part where it waits until the DS4 is connected." - I really don't know how to do this, I know that is the key - wait for connection and start the evtest after- but I don't know how to put that in a script. I searched internet but all I found is how to connect and now Edison is doing this automatically.

                       

                      Can you please help with the "waiting for connection" part?

                      Thanks,

                      Cristi

                      • 8. Re: Edison + DS4
                        Intel Corporation
                        This message was posted on behalf of Intel Corporation

                        Hi Cristi_Sava,

                         

                        I suggest you to use a script similar to the following in order to wait until /event2/ is created:

                         

                        #!/bin/bash
                        x=0
                        a=$(find /dev/input/ -maxdepth 1 -type d -print| wc -l)
                        while [ $x = 0]
                        do
                             if [ "$a" = "3" ]
                             then
                                  echo "done"
                                  #do bluetooth stuff
                                  x=$(( $x + 1 ))
                             else
                                  echo "sleep"
                                  sleep 5
                                  a=$(find /dev/input/ -maxdepth 1 -type d -print| wc -l)
                             fi
                        done
                        

                         

                        I hope this helps you.
                        -Peter.

                        • 9. Re: Edison + DS4
                          Intel Corporation
                          This message was posted on behalf of Intel Corporation

                          Hi Cristi_Sava,

                          Do you have any updates about this? Did the script above helped you?

                          Do you still need help?

                          -Peter.

                          • 10. Re: Edison + DS4
                            Cristi_Sava

                            Hello Peter,

                             

                            I'm still trying to understand all those commands so I can make the script, as I said I'm a newbie  in programming and I try to understand everything with logic; meanwhile my job is taking a lot of my time so the advance is slow... there are a lot of commands and a lot to read about them so it will take a while.

                            Anyway thanks for help and when I'll have the script I'll post it and we'll see if it will do the job or if it will need modifications.

                            Many thanks,

                            Cristi

                            • 11. Re: Edison + DS4
                              Intel Corporation
                              This message was posted on behalf of Intel Corporation

                              Please let us know when you have an update, we'll be more than glad to help you in case you have any other doubts.

                              -Peter.