Introduction: Blinking a LED With Onion Omega

Yesterday, I received the Onion Omega, which I backed on Kickstarter a couple of months ago. Onion Omega is a single board Linux computer, running Open WRT and can be easily connected to the internet (it actually has two WiFi antennas). I believe I paid something around 25$, which I consider a fair price, especially after they have deployed their web interface, called Onion Console. This, will enable the Omega to interact easily via the cloud, making it a IoT development platform, full of potential.

Unfortunately, the guys over at Onion, are currently busy with trying to set up the web Console, so not many tutorials can be found, apart of their FAQ page.

Luckily, they have provided us with an easy interface to control the Omega's GPIO pins, so using a very simple bash script, I was able to create beginner friendly "Hello World" example, by blinking a LED lamp.

The materials you will need are:

  • Onion Omega
  • Onion Omega's Dock
  • LED lamp
  • Small resistance for the LED
  • Jumper cables
  • Breadboard

Step 1: Prepare the Circuit

Connect one of Onion Omega's IO pins to a small resistance (~300Ω) and that to a LED lamp's anode (the "long" leg). Connect the LED's cathode ("short" leg) to the Onion Omega's Ground.

Use the pictures above for reference. Note that the first sketch is not pin-accurate, but merely for illustration purposes.

Step 2: Setup the Environment

  1. Follow the official Get Started guide to connect the Onion Omega to your local WiFi and the internet. Linux users should not need to download any drivers.
  2. Connect to the Omega via shell (instructions on how to do that are included in the Get Started link above).
  3. Make sure you are running the latest firmware by running in the shell the following command: oupgrade -force
  4. (Optional) Update the package manager opkg, by typing: opkg update
  5. (Optional) Install a text editor of your choice, I used nano: opkg install nano

Then you are good to go!

Step 3: Blink the LED

Unfortunately, at the moment the Onion Console is not up and running yet, nor it is clear how to program the GPIOs with a common programming language, such as C or Python, even though, it is promised that this will be possible in the future.

Instead, we will use a common bash script and the fast-gpio interface, that enables the users to easily read and write to the IO pins (read more about it here). Our script shall do the following simple tasks, indefinitely, until we stop its execution:

  1. Declare a pin as an output.
  2. Set that specific pin to HIGH
  3. Wait for one second
  4. Set the pin to LOW
  5. Wait for one second
  6. Go to step 2

First, we need to create a file and start writing into it. We will name it: Blink.sh

If you downloaded nano previously, you can achieve this by typing: nano Blink.sh

Paste the following code into it:

#!/bin/ash
## Simple script to blink a LED on the Onion Omega using fast-gpio

## the variable that will hold the pin number, where the LED lamp is connected
LED_PIN=6

## declare the LED_PIN as output
fast-gpio set-output $LED_PIN

while true
do
## set LED_PIN to HIGH (turn LED on)
fast-gpio set $LED_PIN 1

## sleep for 1 second (equivalent to Arduino's delay(1000)
sleep 1

## set LED_PIN to LOW (turn LED off)
fast-gpio set $LED_PIN 0

## sleep for 1 second (equivalent to Arduino's delay(1000)
sleep 1
done

The code should be self explanatory, but let me know if you have questions. It will blink a LED connected to pin number 6.

After you have written the code, press control+o to save the file and control+x to exit nano.

Make the script executable by running the command: chmod +x Blink.sh

Finally, execute the script by typing: ./Blink.sh

If everything went as it should, you should see your LED blinking, every one second! You can stop the script by pressing control+c. That's all! :)

Comments

author
GabrielC55 made it! (author)2017-02-04

I'm getting the segmentation fault error. how can i fix this?

author
pjobson made it! (author)pjobson2017-02-15

The new version of the firmware nuked fast-gpio, there are a bunch of messages about it on the community hub.

https://community.onion.io/search/fast-gpio%20segmentation%20fault?in=titlesposts

author
Dimitris Platis made it! (author)Dimitris Platis2017-02-05

Are you trying to run exactly the same code?

author
masteruan made it! (author)2017-02-07

When I try the code...

Segmentation fault

Segmentation fault

Segmentation fault

Segmentation fault

author
pjobson made it! (author)pjobson2017-02-15

The newest firmware nuked fast-gpio, it segfaults constantly.

author
buminda1 made it! (author)buminda12017-02-11

I'm using omega2+, and following is working for me,

LED_PIN=1

gpioctl dirout-low $LED_PIN

while true

do

gpioctl dirout-high $LED_PIN

sleep 1

gpioctl dirout-low $LED_PIN

sleep 1

etc..

author
Dimitris Platis made it! (author)Dimitris Platis2017-02-07

Maybe something has changed in the API for the GPIOs since then. Try just turning the light on however they do this nowadays and then it will be a piece of cake modifying the script. :)

author
sanushinp made it! (author)2017-01-21

Finally got all the equipment for this and was able to blink the LED :D

Thanks so much for the tutorial!

author
nunibyes made it! (author)2016-08-22

where can i buy the onion omega 2?

author
Dimitris Platis made it! (author)Dimitris Platis2016-08-22

You can pledge for it on Kickstarter!

author
nunibyes made it! (author)nunibyes2016-08-24

so its not avalible yet?

author
RooX1 made it! (author)RooX12016-08-22

You better hurry > https://www.kickstarter.com/projects/onion/omega2-5-iot-computer-with-wi-fi-powered-by-linux

author
ProfCTurner made it! (author)2015-11-22

A nice tutorial thanks. Now that the console is up and running one can make the file at the prompt with something like:

touch blink.sh
chmod a+rwx blink.sh

Then from the console, go to editor, and look in "root" to find the file blink.sh where you can edit it from an easier GUI environment, or indeed even just paste in your code. The permissions could be tightened up later if desired.

author
tim_smith84 made it! (author)2015-11-13

Awesome! Thanks

author
nlapo058 made it! (author)2015-11-10

Great simple tutorial, thank you!

How would you make the omega run the sketch as soon as it is powered on, and without having to plug it to the computer?

Thanks!

author
Dimitris Platis made it! (author)Dimitris Platis2015-11-10

After you have successfully completed the above tutorial, edit the file: /etc/rc.local (for example if you have installed nano you can type nano /etc/rc.local)

And add the full path to your script (mine is /usr/blink.sh) BEFORE the "exit 0" which should be the last line in that file. For example my /etc/rc.local file looks like this now:

# Put your custom commands here that should be executed once

# the system init finished. By default this file does nothing.

/usr/blink.sh || exit 1 #blinking script

exit 0

author
chrispix made it! (author)2015-10-16

Thanks! Just got my Omega and was trying to figure out how to use it to blink the eyes on a giant spider I'm building for Halloween.