Olimex A20 initalising GPIO automatically on boot up

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.

Advertisements
Tagged with:
Posted in Olimex

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

In Archive
%d bloggers like this: