11 Replies Latest reply on Oct 17, 2016 1:18 PM by Intel Corporation

    Galileo Gen 2 GPIO configuration won't change

    azraelazamoth

      hi,

       

      i'm struggling to update a value of the GPIO pin 29 to 1, getting the below error (no metter what i do):

      root@galileo:~# echo -n "29" > /sys/class/gpio/export

      -sh: echo: write error: Device or resource busy

      root@galileo:~# echo -n "1" > /sys/class/gpio/gpio29/value

      -sh: echo: write error: Operation not permitted

       

      a little background:

      i have an Adafruit gyro (L3GD20) connected to my Galileo, i'm running a python program that reads from this sensor,

      the gyro is connected to 5V, GND, and A4(SCL) and A5(SDA).

       

      this was working perfectly until something went wrong with the board and since then i'm getting errors in my python code (test_project is my program file):

      Traceback (most recent call last):

        File "test_project3.py", line 240, in <module>

          main()

        File "test_project3.py", line 236, in main

          inits()

        File "test_project3.py", line 60, in inits

          s.Set_PowerMode("Normal")

        File "/home/root/L3GD20.py", line 392, in Set_PowerMode

          self.__writeToRegister(self.__REG_RW_CTRL_REG1, self.__MASK_CTRL_REG1_PD, 1)

        File "/home/root/L3GD20.py", line 28, in __writeToRegister

          current = self.__i2c.read_byte_data(self.__slave, register)  # Get current value

        File "/usr/lib/python2.7/site-packages/pysmbus-0.1-py2.7.egg/smbus.py", line 75, in read_byte_data

          ioctl(self.fd, I2C_SMBUS, msg)

      IOError: [Errno 121] Remote I/O error

       

      as you can see the program fails on reading from the pins when calling to smbus.

       

      i suspect that changing the value of gpio29 to 1, shuold fix this issue, but i can't change the value of this gpio,

       

      any thoughts?

       

      thanks!

        • 1. Re: Galileo Gen 2 GPIO configuration won't change
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          Hi azraelazamoth,

          You mention that you had your setup working perfectly until something went wrong with the board. What exactly happened that caused this error? The write error: Device or resource busy”, appears when you attempt to export a GPIO that is already exported. To see the list of GPIOs already exported you have to access to the directory /sys/class/gpio/ and use the command ls.

          I’d suggest you to reflash your image and double check your Python script was not altered and run the program again. Also, make sure the sensor is receiving the correct signals from the galileo. You can check those signals with an oscilloscope.

          We’ll be waiting for your response.

          -Sergio
           

          • 2. Re: Galileo Gen 2 GPIO configuration won't change
            azraelazamoth

            hello Sergio,

             

            thank you for your reply,

             

            the GPIO29 is alraedy exported, i've already checked with ls on /sys/class/gpio/. thing is that doing unexport does not release the GPIO, when i do Unexport and then export again the GPIO29 gives the same error message:Device or resource busy.

             

            what i believe caused this is that i've tried to make the Wifi (PCIe 6235 card) work, and for that i've tried to install compat-drives and backport, to make the iwlwifi driver work properly (this is a whole another issue, not related to this thread, but might be the reason for this tread ).

             

            after installing those packages, everything that was working properly before, is gone bad, meaning the GPIO pins configuration and such.

             

            what do you mean by reflash the image?

             

            i've created a fresh SD card with only IOT DEV KIT on it, nothing else, inserted into the Galileo, and it still has the same error.

            i guess i've screwed up something with the pin configuration.

             

            Alex.

            • 3. Re: Galileo Gen 2 GPIO configuration won't change
              Intel Corporation
              This message was posted on behalf of Intel Corporation

              Hi Alex,

              Thank you for your reply. By reflashing the image I mean to delete the contents of your SD card and write the image to it once again. To do this, format the SD card in FAT32. Then you said you created the SD card with only the IoT dev kit. To do this and have a fresh install follow this guide https://software.intel.com/en-us/get-started-galileo-windows-step1 . If you’re looking for information to connect to Wi-Fi you can also check https://software.intel.com/en-us/get-started-galileo-windows-step4 .

              Let us know your results.

              -Sergio
               

              • 4. Re: Galileo Gen 2 GPIO configuration won't change
                azraelazamoth

                Hi Sergio,

                 

                i have done exactly what you sugges, ive created a totally new SD card with the intel iot dev kit.

                 

                when ive inserted the SD into the Galileo, i had the same error.

                 

                therefore i assume the issue is not with the image on the SD, but something with the board maybe.

                 

                any other ideas?

                 

                thanks,

                Alex

                • 5. Re: Galileo Gen 2 GPIO configuration won't change
                  Intel Corporation
                  This message was posted on behalf of Intel Corporation

                  To change specifically the value of gpio29 I ran these commands:
                  echo out > /sys/class/gpio/gpio29/direction
                  echo 1 > /sys/class/gpio/gpio29/value

                   

                  The first command changes the GPIO from an input to an output. It is configured as an input by default. Now, the second command works and allows the gpio to be set to 1. In this case, there’s no need to use the parenthesis on the 1 in the echo command.

                   

                  Let us know if this works for you and if you’re able to change the GPIO value.

                   

                  -Sergio

                  • 6. Re: Galileo Gen 2 GPIO configuration won't change
                    azraelazamoth

                    hi Sergio,

                     

                    thanks for your answer, unfortunately, seems it is not related to the problem.

                    i've manged to get my python program to work and get values from the L3GD20 Gyro over I2C (connected to A4 and A5), BUT! i've managed to do this with python in the linux environment only after i've successfully uploaded the arduino IDE sketch for the Gyro (Adafruit_L3GD20_test).

                    i assume it means that my python program is not configuring the I2C correctly, while the Arduino sketch does it right.

                     

                    here's the error i get when i run the python program, without running the Arduino sketch first:

                    Traceback (most recent call last):

                      File "test_project4.py", line 298, in <module>

                        main()

                      File "test_project4.py", line 294, in main

                        inits()

                      File "test_project4.py", line 62, in inits

                        s.Set_PowerMode("Normal")

                      File "/home/root/L3GD20.py", line 392, in Set_PowerMode

                        self.__writeToRegister(self.__REG_RW_CTRL_REG1, self.__MASK_CTRL_REG1_PD, 1)

                      File "/home/root/L3GD20.py", line 28, in __writeToRegister

                        current = self.__i2c.read_byte_data(self.__slave, register)  # Get current value

                      File "/usr/lib/python2.7/site-packages/pysmbus-0.1-py2.7.egg/smbus.py", line 75, in read_byte_data

                        ioctl(self.fd, I2C_SMBUS, msg)

                    IOError: [Errno 121] Remote I/O error

                     

                     

                    when i first upload the sketch and then run the python, the python program works fine:

                     

                    the updated gyro values are:    0.00    0.00    0.09

                    ('sensor status:', True)

                    0.18

                    updated micvalue is 0.18

                    the updated gyro values are:    0.00    0.00    0.00

                    ('sensor status:', True)

                    0.13

                    updated micvalue is 0.13

                    the updated gyro values are:    0.00    0.00    0.00

                    ('sensor status:', True)

                    0.27

                    updated micvalue is 0.27

                    the updated gyro values are:    0.04    0.03   -0.41

                    ('sensor status:', True)

                    0.25

                    updated micvalue is 0.25

                    the updated gyro values are:    0.06   -0.06    0.89

                    ('sensor status:', True)

                    the updated gyro values are:    0.06   -0.06    0.89

                    ('new sensor status:', True)

                     

                    if i do i2cdetect -r -y 0 without first running the Arduino sketch, i get nothing.

                    when i run it after uploading the sketch, i get the expected result:

                         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f

                    00:          -- -- -- -- -- -- -- -- -- -- -- -- --

                    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

                    20: -- -- -- -- -- UU UU UU -- -- -- -- -- -- -- --

                    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

                    40: -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- --

                    50: -- -- -- -- UU UU UU UU -- -- -- -- -- -- -- --

                    60: -- -- -- -- -- -- -- -- -- -- -- 6b -- -- -- --

                    70: 70 -- -- -- -- -- -- --

                     

                    any ideas what i might be missing in my python program?

                     

                    thanks

                    Alex,

                    • 7. Re: Galileo Gen 2 GPIO configuration won't change
                      Intel Corporation
                      This message was posted on behalf of Intel Corporation

                      Thank you for providing additional information to this case. I was not aware there was an Arduino sketch involved. I’d like to know, was the Arduino sketch running before the Python code stopped working on your first reply or have you just started to use it from the latest reply and forward? Is your goal to read from the sensor using just the Python code directly from Linux? It’s hard to say what could be missing from the code just by looking at that error. Could you attach both the Arduino and the Python code? Are these sample codes or custom codes?

                      We’ll be waiting for your response.

                      -Sergio
                       

                      • 8. Re: Galileo Gen 2 GPIO configuration won't change
                        azraelazamoth

                        hi Sergio,

                        C:\Users\alex\Documents\Arduino\test_project4.py

                        i wasn't using the Arduino Sketch at all before i've started getting those errors,

                        during the troubleshooting of the errors it came through my mind to try running the sketch, it wasn't working at the beginning either, but i got it working eventually ( was playing with the pin configuration), one the sketch started working i went back to the Linux and then the python also worked.

                         

                        attached is the sketch and the python program,

                        in order for the python to work you have to install wiringX86, smbus and L3GD20 (attached, but you might need some additional files from Adafruit to run this) files.

                        another thing that you'll need is ffmpeg, but that's not mandatory

                         

                        the code is pretty custom, and the final goal is to use everything through python and Linux (to start working at the second the Galileo is on - Bash).

                         

                        thanks,

                        Alex

                        • 9. Re: Galileo Gen 2 GPIO configuration won't change
                          Intel Corporation
                          This message was posted on behalf of Intel Corporation

                          We’ll do some research and contact you as soon as we have more information.

                          -Sergio
                           

                          • 10. Re: Galileo Gen 2 GPIO configuration won't change
                            Intel Corporation
                            This message was posted on behalf of Intel Corporation

                            The issue with the code seems to be directly related to the I2C interface. You mentioned that the Python script might not be setting up the I2C correctly and that's why it works only when the Arduino script runs. The Arduino sketch seems to be configuring the I2C interface correctly. You’re using the library wiringx86 to manage the IO. That library is not supported by us, and has been developed by EmutexLabs: https://emutex.com/educational/72-introduction-to-wiring-x86-for-intel-galileo-gen2-and-intel-edison-arduino . I’d recommend you to use the MRAA library instead. You can take a look here https://github.com/intel-iot-devkit/mraa . At the end you can see the API Documentation of Python. In your code, you’re importing it but it doesn’t seem like you’re using it. The code is quite long, so I’d recommend to isolate this I2C issue by writing a new Python script using the MRAA library to setup the I2C interface. Once you’re able to set the I2C using MRAA, I’d start to adapt this approach for the entire code. It’s more difficult to debug an issue like this one if we are working with a code like this big.

                            Keep us updated on your progress.

                            -Sergio
                             

                            • 11. Re: Galileo Gen 2 GPIO configuration won't change
                              Intel Corporation
                              This message was posted on behalf of Intel Corporation

                              Hi Alex,

                              Do you still need assistance with this case?

                              -Sergio