1 2 Previous Next 16 Replies Latest reply on Mar 10, 2015 11:19 AM by DiegoV_Intel

    gpio on serial1 with arduino expansion board

    Mysticmindset

      I am having some issue with setting up gpio. When i go to try to set up the pins i get:

      root@edison:~# echo -n "214" > /sys/class/gpio/export

      sh: write error: No such device

       

      I get a device busy error when using any that are listed below.

      I have a 5volt oscilloscope and get nothing when trying to send serial data.

       

       

       

      :/sys/class/gpio# ls

      export       gpio134      gpio224      gpio241      gpio258      gpio45

      gpio12       gpio14       gpio225      gpio242      gpio259      gpio46

      gpio124      gpio165      gpio226      gpio243      gpio260      gpio47

      gpio125      gpio182      gpio227      gpio248      gpio261      gpio48

      gpio126      gpio183      gpio228      gpio249      gpio262      gpio49

      gpio127      gpio216      gpio229      gpio250      gpio263      gpiochip0

      gpio128      gpio217      gpio232      gpio251      gpio27       gpiochip216

      gpio129      gpio218      gpio233      gpio252      gpio28       gpiochip232

      gpio13       gpio219      gpio234      gpio253      gpio40       gpiochip248

      gpio130      gpio220      gpio235      gpio254      gpio41       unexport

      gpio131      gpio221      gpio236      gpio255      gpio42

      gpio132      gpio222      gpio237      gpio256      gpio43

      gpio133      gpio223      gpio240      gpio257      gpio44

      root@edison:/sys/class/gpio#

        • 1. Re: gpio on serial1 with arduino expansion board
          DiegoV_Intel

          Hello Mysticmindset,

           

          Please take a look at the commands below. They configure the Serial1 to send and receive data at 9600 bauds. Please test it and let me know if it works for you.

           

          The busy error: sh: write error: Device or resource busy, appears when you attempt to export a GPIO when it is already exported. So it is fine, some GPIOs are already exported by default. If you get that error message when you try the commands below just go ahead with the next one.

           

          #Pin 0 - RX
          echo -n "130" > /sys/class/gpio/export # rx (input)
          echo -n "248" > /sys/class/gpio/export # output enable
          echo -n "216" > /sys/class/gpio/export # pullup enable
          echo -n "214" > /sys/class/gpio/export
          
          
          echo low > /sys/class/gpio/gpio214/direction 
          echo low > /sys/class/gpio/gpio248/direction 
          echo in > /sys/class/gpio/gpio216/direction 
          echo mode1 > /sys/kernel/debug/gpio_debug/gpio130/current_pinmux
          echo in > /sys/class/gpio/gpio130/direction 
          echo high > /sys/class/gpio/gpio214/direction
          
          
          #Pin 1 - TX
          echo -n "131" > /sys/class/gpio/export # tx (output)
          echo -n "249" > /sys/class/gpio/export # output enable
          echo -n "217" > /sys/class/gpio/export # pullup enable
          echo -n "214" > /sys/class/gpio/export
          
          
          echo low > /sys/class/gpio/gpio214/direction 
          echo high > /sys/class/gpio/gpio249/direction 
          echo in > /sys/class/gpio/gpio217/direction 
          echo mode1 > /sys/kernel/debug/gpio_debug/gpio131/current_pinmux
          echo out > /sys/class/gpio/gpio131/direction 
          echo high > /sys/class/gpio/gpio214/direction
          
          
          stty -F /dev/ttyMFD1 9600 # set the baudrate
          

           

          To read and write you can use these commands once the port is configured:

           

          cat /dev/ttyMFD1        # To read
          echo "1" > /dev/ttyMFD1 # To write
          

           

          Regards,

          Diego.

          • 2. Re: gpio on serial1 with arduino expansion board
            Mysticmindset

            Thank you for the information. I will go and try this later today.

             

            On another note is there a way to use this serial data In arduino ide/ arduino sketch.

             

            I'm using a program called motion with a usb camera for tracking. In theory I can output data to the serial device I'm trying to setup and worst case use an arduino to use that data to control pan/tilt. The hardware uses 4 wires with 2 for each motor of the pan/tilt device. A pwm signal to one of the wires of the motor controles speed in that direction.

            • 3. Re: gpio on serial1 with arduino expansion board
              Mysticmindset

              Here is my output from the commands you gave me. I only have the time a the moment to input them but not test the outcome. I have a feeling it will work. Thank you for your help.

               

               

              root@edison:~# echo -n "130" > /sys/class/gpio/export # rx (input)

              sh: write error: Device or resource busy

              root@edison:~# echo -n "248" > /sys/class/gpio/export # output enable

              root@edison:~# echo -n "216" > /sys/class/gpio/export # pullup enable 

              root@edison:~# echo -n "214" > /sys/class/gpio/export

              sh: write error: Device or resource busy

              root@edison:~# echo low > /sys/class/gpio/gpio214/direction  

              root@edison:~# echo low > /sys/class/gpio/gpio248/direction

              root@edison:~# echo in > /sys/class/gpio/gpio216/direction

              root@edison:~# echo mode1 > /sys/kernel/debug/gpio_debug/gpio130/current_pinmux

              root@edison:~# echo in > /sys/class/gpio/gpio130/direction  

              root@edison:~# echo high > /sys/class/gpio/gpio214/direction

              root@edison:~# echo -n "131" > /sys/class/gpio/export # tx (output) 

              sh: write error: Device or resource busy

              root@edison:~# echo -n "249" > /sys/class/gpio/export # output enable 

              root@edison:~# echo -n "217" > /sys/class/gpio/export # pullup enable 

              root@edison:~# echo -n "214" > /sys/class/gpio/export

              sh: write error: Device or resource busy

              root@edison:~# echo low > /sys/class/gpio/gpio214/direction

              root@edison:~# echo high > /sys/class/gpio/gpio249/direction

              root@edison:~# echo in > /sys/class/gpio/gpio217/direction

              root@edison:~# echo mode1 > /sys/kernel/debug/gpio_debug/gpio131/current_pinmux

               

              root@edison:~# echo out > /sys/class/gpio/gpio131/direction  

              root@edison:~# echo high > /sys/class/gpio/gpio214/direction 

              root@edison:~# stty -F /dev/ttyMFD1 9600 # set the baudrate 

              root@edison:~# 

              root@edison:~#

              • 4. Re: gpio on serial1 with arduino expansion board
                Mysticmindset

                I am still not getting serial data. I used an arduino UNO and wired it the same as my edison arduino breakout shield. While uploading code to the UNO i get spikes but with the edison i get nothing. I am thinking of reseting the edison to factory.

                • 5. Re: gpio on serial1 with arduino expansion board
                  DiegoV_Intel

                  Hello Mysticmindset,

                   

                  About this:

                  On another note is there a way to use this serial data In arduino ide/ arduino sketch.

                  Yes, you can use it with the Arduino IDE as well. This serial port is label as Serial1 in the Arduino IDE and the pins are the IO0 for Rx and the IO1 for Tx. Let me know if you have further questions on this.

                   

                   

                  Now, regarding your last post, how are you testing it? It would be great if you can post a picture showing how you are wiring the board.

                   

                  Could you post a screenshot of the output you got from the Arduino UNO and from Edison?

                   

                  Regards,

                  Diego.

                  • 6. Re: gpio on serial1 with arduino expansion board
                    Mysticmindset

                    I will see what I can do with getting you a shot of what I am seeing on my o scope. The scope is a usb device I use with my windows desktop. I do everything concerning the edison with my macbook. I did notice late last night is that it seems like after I did those commands the web cam I have hooked up to the USB port on the arduino expansion board isn't found. I haven't put any time into diagnosis but when I run motion it won't connect. Some background is that I have been mostly on the yoco part of learning with the edison. I have only been working with Linux command line for about a month and don't know very much about using it, just what I learn hear and a little from a friend of mine. I am using alext's repo with motion installed and working. The connection with the o scope is black to ground and red to tx I beleive to be pin 1. Thank you for your help.

                    • 7. Re: gpio on serial1 with arduino expansion board
                      DiegoV_Intel

                      Hello Mysticmindset,

                       

                      Were you able to set up the Serial1? Please take a look at the outputs I got below. I configured the Serial1 (pins 0 and 1) using two ways: from Arduino IDE and from Linux terminal. The Tx signal is the pin 1 and the Rx signal the pin 0.

                       

                      Using the Arduino IDE:

                      SerialMonitor.JPG

                      output1.JPG

                      output2.JPG

                       

                      I set the Serial1 using the Arduino IDE, check the code I used below.

                      void setup() {
                        Serial.begin(9600);   // "Serial" correspond to the Serial Monitor of the IDE
                        Serial1.begin(9600);  // "Serial1" correspond to the pins 0 and 1
                        
                        Serial.println("Sending data through Serial1 (IO1 - Tx)");
                      }
                      
                      
                      void loop() {
                        Serial1.print("Test");
                        Serial.println("String 'test' sent");
                        
                        delay(30); // Delay of 30 msec before send data again
                      }
                      

                       

                      Using the Linux terminal:

                      output3Linux.JPG

                       

                      Using this way I ran the commands I posted before to setup the Serial port. Remember that you have to run these following commands to write and read from the port after it has been configured:

                      cat /dev/ttyMFD1             # To read  
                      echo "Test" > /dev/ttyMFD1   # To write
                      

                       

                      In both tests I sent the string "Test".

                       

                      Regards,

                      Diego.

                      • 8. Re: gpio on serial1 with arduino expansion board
                        Mysticmindset

                        I have been trying to get this to work. I take my edison out on the road with me during my dayjob but do not have my o-scope. What scope are you using for the screen shots. I will get to some more testing tonight.

                        • 9. Re: gpio on serial1 with arduino expansion board
                          DiegoV_Intel

                          Hello Mysticmindset,

                           

                          I'm using the Logic Analyzer "Logic 8". You can check more details here: https://www.saleae.com/?gclid=CKasvZeJ_sMCFYOSfgod_wgAFA

                           

                          Regards,

                          Diego.

                          • 10. Re: gpio on serial1 with arduino expansion board
                            Mysticmindset

                            O-SCOPE SNAPSHOT1.jpg

                            Ok here is a snapshot of my o-scope using your arduino sketch and an arduino MEGA ADK. When i ran the same sketch on my mac with the edison connected i got similar results. The trouble i see is in terminal using your linux comands. Then i get nothing.

                            • 11. Re: gpio on serial1 with arduino expansion board
                              DiegoV_Intel

                              Hello Mysticmindset,

                               

                              Does your scope show data in real time? In my case, I use a logic analyzer that takes data for a sample period and then it shows the captured data. I have to run the command echo "Test" > /dev/ttyMFD1 while the logic analyzer is in the sample period. If I run the command before or after the period sample I won't see any results. I'm guessing that is your case.

                               

                              Please try the shell script attached. Run it in the Edison terminal. It should work and you should see an output like this:

                              Capture1Shell.JPG

                              Capture2Shell.JPG

                               

                              Regards,

                              Diego.

                              • 12. Re: gpio on serial1 with arduino expansion board
                                Mysticmindset

                                Screen Shot 2015-02-28 at 9.00.14 AM.png

                                My scope does do real time but does not work on OS X so i will be looking into the one you use. I just tried that script and it seems to communicate with my arduino mega. I can't thank you enough for your help!! If you could give me a description of what it is that fixed my problem as it has only been a month or so that i have been learning command line and the edison.

                                • 13. Re: gpio on serial1 with arduino expansion board
                                  Mysticmindset

                                  So now it seems like the serial gpio works but edison will not connect to my usb web cam. I am not sure at what point this happened because in the time I have been working on the gpio I have not tested the web cam untill now. I am just wondering if the script you sent me to change the gpio had an effect on the usb host port. Yes I am aware of the switch on the arduino expansion board and had it switched toward the usb connection I am using.

                                  • 14. Re: gpio on serial1 with arduino expansion board
                                    DiegoV_Intel

                                    Hi Mysticmindset,

                                     

                                    The new script I posted does the same thing as I suggested you before. It configures the GPIOs for the serial communication with the same commands I posted in an earlier reply. The only difference is that after the configuration is done the script remains sending data in a while loop. That is why you see a lot of "Test" string in the screen.

                                     

                                    About the web cam, the script doesn't have any effect on the USB at all.  However, if you run the script, it will enter an infinite while loop and it will keep sending the "Test" string until you press "Ctrl+c" to cancel the process. So, since the script is running an infinite while loop you won't be able to do anything else. The script was just to test the serial communication but it shouldn't be used for the real application.

                                     

                                    I hope my explanation has been clear enough. If you still have further questions about the script don't hesitate to ask.

                                     

                                    Regards,

                                    Diego.

                                    1 2 Previous Next