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.
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.
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.
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.
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
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
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 .