GPIO using Linux

Started by kgolding, February 14, 2014, 07:27:13 PM

Previous topic - Next topic

kgolding

Hello,

Having got my first A20 up and working today I found that the GPIO files (/sys/class/gpio/*) were missing. As per https://www.olimex.com/wiki/A20-OLinuXino-MICRO#GPIO_under_Linux you have to initialise them. So I decided to make this initialisation happen automatically, and below is how I did in case it can help anyone else!

1. Create a file and put the following text in it using
nano /etc/init.d/initgpio.sh

#!/bin/sh
### BEGIN INIT INFO
# Provides:          gpioinit
# Required-Start:    $remote_fs
# Required-Stop:
# Should-Start:      udev
# Default-Start:     S
# Default-Stop:
# Short-Description: Initialises the GPIO exports
# Description:       Initialises the GPIO exports
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin

do_start () {
        for i in `seq 1 1 230`; do echo $i > /sys/class/gpio/export; done
}

case "$1" in
  start|"")
        do_start
        ;;
  restart|reload|force-reload)
        echo "Error: argument '$1' not supported" >&2
        exit 3
        ;;
  stop)
        # No-op
        ;;
  *)
        echo "Usage: initgpio.sh [start]" >&2
        exit 3
        ;;
esac

:


2. Make the file executable using
chmod 755 /etc/init.d/initgpio.sh

3. Add the file to the startup process by running the command below, and you can safely ignore the two warnings about the levels not matching.
update-rc.d initgpio.sh defaults

Job done, reboot and your gpio files will be there for you.

dannym

Number 33 is the SATA power pin. It's a bad idea to export it and not set it to output.

On second thought, it's a bad idea to export it at all.

Otherwise nice :-)