Blinking LED with Linux or Hello World with iMX233-OLINUXINO


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
sleep 1
echo 0 > /sys/class/gpio/gpio0/value
sleep 1

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:

20 Comments (+add yours?)

  1. Morgaine
    Apr 23, 2012 @ 17:15:25

    Very cool, good progress!

    By the way, you don’t need “[ 1 -eq 1]” as the conditional expression for infinite loops, just use “true”. 🙂


  2. Kiril Zyapkov
    Apr 23, 2012 @ 18:03:33


    Although the LED is blinking at 0.5 Hz 🙂


  3. Greg
    Apr 23, 2012 @ 22:19:47

    Are you sure it should read
    echo cat /sys/class/gpio/gpio2/value

    I would think the correct line would be
    cat /sys/class/gpio/gpio2/value


  4. Greg
    Apr 23, 2012 @ 22:22:05

    And I /really/ have to get me one of these little beauties 🙂


  5. sagt3k
    Apr 24, 2012 @ 09:03:09

    I am very interested in communication via I2C, you could show me some examples? What distribution of Linux you are using?


    • OLIMEX Ltd
      Apr 24, 2012 @ 09:39:31

      please go to Freescale web and download the L2.6.31_10.05.02_ER_docs.tar.gz documents there is described LTIB and the Linux support package, all iMX233 peripherials have implemented drivers: SPI, I2C, UARTs, Video effects, etc etc.


  6. Jason
    Apr 27, 2012 @ 07:08:14

    FYI there is a unix command “true” that is more typically used for infinite loops in shell scripts. It’s just a program (or shell intrinsic) that always returns 0. So a more idiomatic infinite loop would start “while true”


  7. Per Cramer
    Aug 02, 2012 @ 14:11:31

    Nice little sample. I installed the arch linux distribution and it is running nicely. But any hints on how to work with the i2c?


  8. Trackback: iMX233-OLinuXino working with GPIOs « olimex
  9. flavigny
    Oct 08, 2012 @ 17:44:42

    I am interrested in connecting some Leds to the gpio pins. I read your post, you do’nt wrote where is the other leg of te led ? watching your photo, it appears to be 5V or Ground. For dummies; may be you will update to indicate pin 40.
    I Also note that you do’nt talk about an in line resistor (as for LED1 integarted) ?


  10. Lukas
    Jan 30, 2013 @ 23:36:15

    Thanks, very helpful post. I am having this problem, though:
    I attached an LED to pin18 on the board, which corresponds to gpio17 in Linux. It’s value is currently 1, so the LED is on.
    When I try to set it to 0, with:

    echo 0 > /sys/class/gpio/gpio17/value

    the board immediately crashes (shuts down). Do you have any idea what could be the problem? Thanks!


  11. Carlos
    Feb 08, 2013 @ 20:22:26

    Hi everyone,
    I am interested in connecting more LED in another GPIOs and I am having a hard time to figure the LINUX GPIO numbers.

    I know that:


    What about the others GPIOs, does anyone knows what is the correspondence between LINUX GPIO number and iMX233 pin number?



Leave a Reply

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

You are commenting using your 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 )

Connecting to %s

%d bloggers like this: