Exporting arduino analog pins possible ?

Discussion in 'UDOO NEO' started by ddewaele, Dec 28, 2015.

  1. ddewaele

    ddewaele Member

    Joined:
    Dec 2, 2014
    Messages:
    48
    Likes Received:
    11
    I noticed that some "arduino compatible pins" coming from the M4 can be exported on the Linux OS.

    For example pin 13 can be exported via /sys/class/gpio/102

    Can the same be done for the analog pins (A0,A1,A3,A4,A5) ? I didn't see a GPIO mapping for those in the docs.
     
  2. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Argh, I was typing an answer and just checked the docs and you are right. No gpio references to the analog part of the Arduino pins.
     
    Last edited: Dec 28, 2015
  3. jas-mx

    jas-mx Active Member

    Joined:
    Dec 31, 2013
    Messages:
    407
    Likes Received:
    118
    If you review the schematics, the analog pins are multiplexed with GPIO pins and selectable via a 2-Channel Analog Multiplexer (74VHC4053AFT). So it should be possible to use these pins as input pins for GPIO as long as the Multiplexer can be configured via it own gpio pins.
     
  4. ddewaele

    ddewaele Member

    Joined:
    Dec 2, 2014
    Messages:
    48
    Likes Received:
    11
    Any pointers on how to do that configuration ? I would like to export them like regular GPIOs, change directions, and read/write values to them.
     
  5. jas-mx

    jas-mx Active Member

    Joined:
    Dec 31, 2013
    Messages:
    407
    Likes Received:
    118
    Example - The gpios to control multiplexing for A0 and A1 (analog or gpio) which need to be made high for gpio support are:
    A0 - GPIO4_IO22
    A1 - GPIO4_IO18


    and the gpio pins are:
    A0 - GPIO pin is GPIO4_IO24
    A1 - GPIO pin is GPIO4_IO25


    To make A0 as gpio output and high:

    # Set multiplexer to GPIO support
    echo 118 > /sys/class/gpio/export
    echo out > /sys/class/gpio/gpio118/direction
    echo 1 > /sys/class/gpio/gpio118/value

    # Set GPIO line to output
    echo 120 > /sys/class/gpio/export
    echo out > /sys/class/gpio/gpio120/direction
    echo 1 > /sys/class/gpio/gpio120/value


    For A1:

    echo 114 > /sys/class/gpio/export
    echo out > /sys/class/gpio/gpio114/direction
    echo 1 > /sys/class/gpio/gpio114/value

    echo 121 > /sys/class/gpio/export
    echo out > /sys/class/gpio/gpio121/direction
    echo 1 > /sys/class/gpio/gpio121/value
     
    Last edited: Dec 29, 2015
    ddewaele likes this.
  6. ddewaele

    ddewaele Member

    Joined:
    Dec 2, 2014
    Messages:
    48
    Likes Received:
    11
    Thx a lot ! ... did you find this in the spec or in the kernel sources ?
     
  7. Francesco

    Francesco Active Member

    Joined:
    Jun 23, 2015
    Messages:
    220
    Likes Received:
    110
    Analog pins are used by MQX (running on the M4 core). One possibility is to disable the M4 core so ADCs are assigned to Linux.
    You can do this with `m4_enabled=false` in /boot/uEnv.txt. Then you can read analog voltages accessing /sys entries, eg:
    Code:
    /sys/devices/soc0/soc.0/2200000.aips-bus/2280000.adc/iio:device0/in_voltage0_raw
     
    Andrea Rovai likes this.
  8. jas-mx

    jas-mx Active Member

    Joined:
    Dec 31, 2013
    Messages:
    407
    Likes Received:
    118
    Multiplexer pins are in this dts file and GPIO lines are below:

    A0 - GPIO4_IO24
    A1 - GPIO4_IO25
    A2 - GPIO5_IO22
    A3 - GPIO5_IO17
    A4 - GPIO4_IO29
    A5 - GPIO4_IO30

    As mentioned you need to disable the M4 from using ADC .
     
    Last edited: Dec 30, 2015
    Andrea Rovai likes this.

Share This Page