Today I did my first Linux shell script with iMX233-OLinuXino. I used to use Windows for many years, then recently moved to Ubuntu but never had to deal with shell scripting till now.
We should make GPIO testing bench to do functional test of the iMX233-OLinuXino GPIO ports, so I had to learn some new stuff.
Raivis installed so called SYSFS package in the OLinuXino Linux kernel which allow you to access the GPIOs from the linux shell so I had to read some more about Linux shell scripting to may make the board GPIO tester.
After reading about SYSFS it seems pretty easy to manipulate the GPIOs from the shell.
To make GPIO1 output and set in “1″ for instance this should be executed:
echo out > /sys/class/gpio/gpio1/direction
echo 1 > /sys/class/gpio/gpio1/value
and to make GPIO2 as input and read it could be done with this script:
echo in > /sys/class/gpio/gpio2/direction
echo cat /sys/class/gpio/gpio2/value
echo will return 0 or 1 depend on GPIO2 state
All gpios can be seen with
$ ls /sys/class/gpio
So my first thing was to attach LED to PIN9 (CONNECTOR.PIN19) which correspondents to gpio0 in Linux (yes I know it’s confusing, there is one cross table and Linux kernel assign the numbers not exactly as per our schematic )
Then run VI and created my first linux script:
echo out > /sys/class/gpio/gpio0/direction
while [ 1 -eq 1 ]
echo 1 > /sys/class/gpio/gpio0/value
echo 0 > /sys/class/gpio/gpio0/value
saved it as “gpio” and made it executable with
$chmod +x gpio
then executed the script with:
as expected the LED start blinking with 1Hz which you can see on the video: http://youtu.be/4FvNwmmj_X8