GPIO Input wonky A F

Discussion in 'UDOO NEO' started by sgm, Jun 2, 2016.

  1. sgm

    sgm New Member

    Joined:
    Jun 2, 2016
    Messages:
    6
    Likes Received:
    0
    I was previously using another board and migrated to the UDOO for this project. Both run android. GPIO is not working the same across platforms.

    On the previous board, with GPIOXX set to 'in' through 'echo in > direction', I could change the voltage externally on the input pin and read this through the sysfs interface using 'cat value' in terminal.

    On the UDOO however, I can only change the value by changing the pin 'out', writing the value to it using 'echo 1 > value', and then reading it after setting it back to 'in' again. Why can't I set the value with an external voltage and read it through sysfs? This should be very simple.

    Note: I am using /sys/class/gpio/
    Side note:
    This page (http://www.udoo.org/docs-neo/Hardware_&_Accessories/GPIO.html) says the GPIOs are under '/gpio/pinXX' but there is no directory '/gpio', not any 'pinXX'. You must be under '/sys/class/gpio' using 'echo XX > export' to export gpio.
    What is this witchcraft?

    Note: both boards use the IMX6
     
    Last edited: Jun 3, 2016
  2. Andrea Rovai

    Andrea Rovai Well-Known Member

    Joined:
    Oct 27, 2014
    Messages:
    1,703
    Likes Received:
    240
    Dear @sgm,
    that page refers to Linux. /gpio folders are created to simplify the user experience according to the Arduino pinout name. If you go on reading you'll find the standard info for sysfs in the section named "Advanced Usage". The /gpio folders are not present in Android.
    Regarding your question about UDOO, please explain me if I understood it correctly. You say that on UDOO you cannot set the value of pins in input. You have to set them in output and then reading them after setting them back in input. You are saying this, aren't you?
    Finally, which version of Android are you using?
     
  3. sgm

    sgm New Member

    Joined:
    Jun 2, 2016
    Messages:
    6
    Likes Received:
    0
    I'm saying that the gpio sysfs interface is broken. Normally I should be able to set an external voltage on a pin (set as "in") and read it as it changes. On my udoo neo, this does not work. Applying an external voltage on the pin does nothing to change the value. The only way I found to change the value of the pin was from the udoo itself. I did this by changing the pin to "out" and giving the command "echo 1 > value". Reading value at this point registered no change (you should be able to read a change in value even if the pin is set to out). In order to read this change, I then had to switch the pin back to "in" and give the command "cat value" at which point it returned 1.
    I'm running the version of android provided by udoo.

    Because of this, I won't be developing on any udoo products in the future.
     
  4. Andrea Rovai

    Andrea Rovai Well-Known Member

    Joined:
    Oct 27, 2014
    Messages:
    1,703
    Likes Received:
    240
    Hi there,
    I'm sorry you're so disappointed.
    First of all, could you please clearly specify what command are you using on which pin? Otherwise it's difficult to help you.
    If you are getting these problems you could use a library to handle GPIOs, like SGWEB - Web framework using PHP/JQuery for UDOO NEO pinout management. There are others on https://udoo.hackster.io/
    Finally, have you read our Documentation about GPIOs?
     
  5. sgm

    sgm New Member

    Joined:
    Jun 2, 2016
    Messages:
    6
    Likes Received:
    0
    Yes, I have read the documentation, although the link you provided is not for the Neo.
    The commands I am giving are for pin number XX. I have tried a number of pins specified here: http://www.udoo.org/docs-neo/Hardware_&_Accessories/GPIO.html and here: http://www.udoo.org/tutorial/linux-gpio-manipulation/
    The commands (in sequence) are:
    • "echo XX > /sys/class/gpio/export"
    • "echo in > /sys/class/gpio/gpioXX/direction"
    • ***change voltage here***
    • ***read value w command below***
    • "cat /sys/class/gpio/gpioXX/value"
    • ***it hasnt changed***
    • "echo out > /sys/class/gpio/gpioXX/direction"
    • "echo 1 > /sys/class/gpio/gpioXX/value"
    • "cat /sys/class/gpio/gpioXX/value"
    • ***it STILL hasn't changed***
    • "echo in > /sys/class/gpio/gpioXX/direction"
    • "cat /sys/class/gpio/gpioXX/value"
    • *** it has changed to 1***
    RPi doesn't have this problem and neither do other dev boards I have worked with so I doubt using a library will help.
     
    Last edited: Jun 29, 2016
  6. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    @Andrea Rovai Sgm is using Android, perhaps that has other GPIO behaviour as Udoobuntu 2 RC2?
     
  7. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    I did just test it with Udoobuntu 2 RC2 and it works for me. 2 remarks:
    1. To read the value you really have to put 0 (GND) or 3.3V on it. If the pin connection is empty the state is unkown. For example if you put 3.3V on it and pull the wire out but not put GND back on it, it will remain high (1).
    2. Please note that GPIO_NUMBER is not the number written on the PCB. Instead, it is the number written in the round label close to the PCB number in the previous two images. For example, if you want to control the pin 24 (PCB name) you should read GPIO_25. The /gpio/pinXX examples use the udoo-gpio-export package wich connects to the PCB numbered pins.
     
  8. sgm

    sgm New Member

    Joined:
    Jun 2, 2016
    Messages:
    6
    Likes Received:
    0
    Last edited: Jun 30, 2016
  9. sgm

    sgm New Member

    Joined:
    Jun 2, 2016
    Messages:
    6
    Likes Received:
    0
  10. Andrea Rovai

    Andrea Rovai Well-Known Member

    Joined:
    Oct 27, 2014
    Messages:
    1,703
    Likes Received:
    240
    Dear @sgm,
    sorry that I confused UDOO NEO and QUAD with the link.
    You're doing right using /sys/class/gpio/
    The other files /gpio/pinXX are a semplification adopted just in UDOObuntu. On Android you have to use /sys/class/gpio/
    Anyway, which pin are you using?
    In the meanwhile I'd like to announce that we are working on Android 6 for UDOO NEO, which should be far better, and hopefully solve this problems.
     
    Last edited: Jul 19, 2016
  11. frudman

    frudman Member

    Joined:
    Apr 15, 2014
    Messages:
    64
    Likes Received:
    14
    Is there an example/link for this for Android (6) for Neo? Reading and writing pins (i.e. change from input to output)? Also, would there be a simple way to read pins only when they change (in an "interrupt" type or blocking read, rather than having to poll every so many milliseconds)?

    this way, it may be possible to avoid dealing with the Arduino altogether (since I can't seem to find out how to program the arduino on the neo when working with android).
     

Share This Page