Close

Getting Started with Onion Omega2

The Onion Omega2 is a low-cost, small form-factor Linux computer with onboard wifi and storage. It has been successfully funded on both IndieGoGo and Kickstarter, and rewards have recently started landing on backers’ doorsteps.

In this post, I’ll show you how to get started with python and the GPIO pins.

Onion Omega2

Install

Setting up the Omega2 only takes a couple of minutes. When started, an access point is available to guide you through the process of connecting the Omega2 to your own wifi network. The procedure can be found here: First Time Setup.

It is worth noting though, that the use of the “Expansion Dock” is recommended to power the board, as it accepts a microUSB power supply an regulates it to the required 3.3V input. The dock also facilitates access to the GPIO pins.

Once the Omega2 is connected to the local network, it’s possible to connect via ssh.

Connect

Using a terminal, it is possible to connect to the Omega2 using the same “omega-ABCD.local” address. The ssh username is “root”, the password “onioneer”.

Fredericks-Mac-mini:~ frederickvandenbosch$ ssh root@omega-2771.local

The authenticity of host 'omega-2771.local (fe80::40a3:6bff:fe00:2771%en0)' can't be established.
RSA key fingerprint is SHA256:yS9TX3GGq1FQGfd0WBd5UWdwqjKZoGdWt0GyJIt3mL0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'omega-2771.local,fe80::40a3:6bff:fe00:2771%en0' (RSA) to the list of known hosts.
root@omega-2771.local's password:


BusyBox v1.25.1 () built-in shell (ash)

   ____       _             ____
  / __ \___  (_)__  ___    / __ \__ _  ___ ___ ____ _
 / /_/ / _ \/ / _ \/ _ \  / /_/ /  ' \/ -_) _ `/ _ `/
 \____/_//_/_/\___/_//_/  \____/_/_/_/\__/\_, /\_,_/
 W H A T  W I L L  Y O U  I N V E N T ? /___/
 -----------------------------------------------------
   Ω-ware: 0.1.6 b137
 -----------------------------------------------------
root@Omega-2771:~#

That’s it! We’re now connected to the Omega2 via ssh. Time for some maintenance …

Upgrade

Chances are high that your Omega2’s firmware is no longer the latest version available. Upgrading the firmware of the Omega2 in order to benefit from the latest features, can be done with a single command. The Omega2 will connect to the internet, compare the installed version to the latest one and upgrade if necessary.

root@Omega-2771:~# oupgrade

> Device Firmware Version: 0.1.6 b137
> Checking latest version online...
> Repo Firmware Version: 0.1.9 b149
> Comparing version numbers
> New firmware version available, need to upgrade device firmware
> Downloading new firmware ...
/usr/bin/oupgrade: local: line 377: not in a function
--2017-01-20 13:00:01-- http://repo.onion.io/omega2/images/omega2p-v0.1.9-b149.bin
Resolving repo.onion.io... 52.89.44.24, 54.149.140.66
Connecting to repo.onion.io|52.89.44.24|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7078055 (6.8M) [application/octet-stream]
Saving to: '/tmp/omega2p-v0.1.9-b149.bin'

/tmp/omega2p-v0.1.9-b149.bin 100%[===============================================================================>] 6.75M 1.23MB/s in 6.8s

2017-01-20 13:00:08 (1010 KB/s) - '/tmp/omega2p-v0.1.9-b149.bin' saved [7078055/7078055]

> Starting firmware upgrade....
Saving config files...
killall: watchdog: no process killed
Sending TERM to remaining processes ... onion-helper udhcpc udhcpc

After the upgrade, the Omega2 will reboot and the banner will display the new version. In this particular case, I received the Omega2 with firmware “0.1.6 b136” and upgraded to version “0.1.9 b149”.

Fredericks-Mac-mini:Desktop frederickvandenbosch$ ssh root@192.168.0.230
root@192.168.0.230's password:
BusyBox v1.25.1 () built-in shell (ash)

  ____       _             ____
 / __ \___  (_)__  ___    / __ \__ _  ___ ___ ____ _
/ /_/ / _ \/ / _ \/ _ \  / /_/ /  ' \/ -_) _ `/ _ `/
\____/_//_/_/\___/_//_/  \____/_/_/_/\__/\_, /\_,_/
W H A T  W I L L  Y O U  I N V E N T ? /___/
-----------------------------------------------------
Ω-ware: 0.1.9 b149
-----------------------------------------------------

Downgrade

Now, upgrading isn’t always great either. Especially when the product is new and a lot of active development is still happening. Bugs can be introduced or previously working features can become broken.

This is the case for the multiplexing capabilities of the Omega2’s GPIO pins in version “0.1.9 b149”. Trying to list the current configuration of the pins returns an error:

root@Omega-2771:~# omega2-ctrl gpiomux set uart1 gpio
unable to open mmap file

I quickly found an open ticket, stating this was broken in the latest release. By downgrading, the functionality can be restored.

Downgrading requires you to download the desired firmware file and execute the “upgrade” using that specific file.

root@Omega-2771:/tmp# wget http://repo.onion.io/omega2/images/omega2p-v0.1.6-b137.bin

--2017-01-26 19:09:57-- http://repo.onion.io/omega2/images/omega2p-v0.1.6-b137.bin
Resolving repo.onion.io... 54.149.140.66, 52.89.44.24
Connecting to repo.onion.io|54.149.140.66|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7078055 (6.8M) [application/octet-stream]
Saving to: 'omega2p-v0.1.6-b137.bin'

omega2p-v0.1.6-b137.bin 100%[==============================================================================================>] 6.75M 706KB/s in 11s

2017-01-26 19:10:08 (653 KB/s) - 'omega2p-v0.1.6-b137.bin' saved [7078055/7078055]
root@Omega-2771:/tmp# sysupgrade omega2p-v0.1.6-b137.bin

Saving config files...
killall: watchdog: no process killed
Sending TERM to remaining processes ... avahi-daemon onion-helper udhcpc udhcpc

After a reboot of the Omega2, the banner has been updated and shows the downgraded version: “0.1.6 b137”.

Fredericks-Mac-mini:Desktop frederickvandenbosch$ ssh root@192.168.0.230
root@192.168.0.230's password:

BusyBox v1.25.1 () built-in shell (ash)

  ____       _             ____
 / __ \___  (_)__  ___    / __ \__ _  ___ ___ ____ _
/ /_/ / _ \/ / _ \/ _ \  / /_/ /  ' \/ -_) _ `/ _ `/
\____/_//_/_/\___/_//_/  \____/_/_/_/\__/\_, /\_,_/
W H A T  W I L L  Y O U  I N V E N T ? /___/
-----------------------------------------------------
Ω-ware: 0.1.6 b137
-----------------------------------------------------

Update

Upgrading the firmware covers the core functionality of the Omega2, but the applications need to be updated separately.

root@Omega-2771:~# opkg update

Downloading http://repo.onion.io/omega2/packages/core/Packages.gz.
Updated list of available packages in /var/opkg-lists/omega2_core.
Downloading http://repo.onion.io/omega2/packages/core/Packages.sig.
Signature check passed.
Downloading http://repo.onion.io/omega2/packages/base/Packages.gz.
Updated list of available packages in /var/opkg-lists/omega2_base.
Downloading http://repo.onion.io/omega2/packages/base/Packages.sig.
Signature check passed.
Downloading http://repo.onion.io/omega2/packages/packages/Packages.gz.
Updated list of available packages in /var/opkg-lists/omega2_packages.
Downloading http://repo.onion.io/omega2/packages/packages/Packages.sig.
Signature check passed.
Downloading http://repo.onion.io/omega2/packages/onion/Packages.gz.
Updated list of available packages in /var/opkg-lists/omega2_onion.
Downloading http://repo.onion.io/omega2/packages/onion/Packages.sig.
Signature check passed.

GPIO

The Omega2 has a bunch of GPIO pins which can be used to control things or serve as inputs for data. There is a tool called “gpioctl” installed by default, which can be used to do just that.

Output

In its simplest form, an output can be used to control an LED, once you can do that, the LED can be replaced by more complex components.

Take an LED and resistor. Connect one end of the resistor to GPIO 0, the other end to the LED’s anode. Finally, connect the LED’s cathode to ground.

The syntax of the command is simple: gpioctl

root@Omega-2771:~# gpioctl dirout-high 0
Using gpio pin 0.

root@Omega-2771:~# gpioctl dirout-low 0
Using gpio pin 0.

The LED should turn ON and OFF respectively.

Input

Connect one end of the button to 3.3V and the other end to GPIO 1.

Set the direction of GPIO 1 to input, press the button and read the state. It should toggle between HIGH (pressed) and LOW (released).

root@Omega-2771:~# gpioctl dirin 1
Using gpio pin 1.

root@Omega-2771:~# gpioctl get 1
Using gpio pin 1.
Pin 1 is LOW

root@Omega-2771:~# gpioctl get 1
Using gpio pin 1.
Pin 1 is HIGH

root@Omega-2771:~# gpioctl get 1
Using gpio pin 1.
Pin 1 is LOW

Multiplexing

Some GPIO pins on the Omega2 can have multiple functions. That’s a feature called multiplexing. It is possible to reconfigure these pins on the fly with a simple application, depending on your project’s I/O needs.

Get the current GPIO configuration:

root@Omega-2771:~# omega2-ctrl gpiomux get

Group i2c - [i2c] gpio
Group uart0 - [uart] gpio
Group uart1 - [uart] gpio
Group uart2 - [uart] gpio pwm
Group pwm0 - pwm [gpio]
Group pwm1 - pwm [gpio]
Group refclk - refclk [gpio]
Group spi_s - spi_s [gpio]
Group spi_cs1 - [spi_cs1] gpio refclk
Group i2s - i2s [gpio] pcm
Group ephy - [ephy] gpio
Group wled - wled [gpio]

If you require more GPIO pins, the function of some pins can be switched using the “gpiomux” function.

root@Omega-2771:~# omega2-ctrl gpiomux set uart1 gpio
set gpiomux uart1 -> gpio

root@Omega-2771:~# omega2-ctrl gpiomux set uart2 gpio
set gpiomux uart2 -> gpio

root@Omega-2771:~# omega2-ctrl gpiomux set i2c gpio
set gpiomux i2c -> gpio

The changes are reflected when listing the new configuration.

root@Omega-2771:~# omega2-ctrl gpiomux get
Group i2c - i2c [gpio]
Group uart0 - [uart] gpio
Group uart1 - uart [gpio]
Group uart2 - uart [gpio] pwm
Group pwm0 - pwm [gpio]
Group pwm1 - pwm [gpio]
Group refclk - refclk [gpio]
Group spi_s - spi_s [gpio]
Group spi_cs1 - [spi_cs1] gpio refclk
Group i2s - i2s [gpio] pcm
Group ephy - [ephy] gpio
Group wled - wled [gpio]

You now have a lot more “normal” GPIO pins to use.

Python

Now that the basic GPIO functions work, let’s explore python and control these GPIO pins from code.

First step: install python.

python-light

As the name suggests, “python-light” is a lighter version of python, requiring less disk space. Ideal, since the Omega2 has limited onboard storage.

root@Omega-2771:~# opkg install python-light

Installing python-light (2.7.13-3) to root...
Downloading http://repo.onion.io/omega2/packages/packages/python-light_2.7.13-3_mipsel_24kc.ipk.
Installing python-base (2.7.13-3) to root...
Downloading http://repo.onion.io/omega2/packages/packages/python-base_2.7.13-3_mipsel_24kc.ipk.
Installing libffi (3.2.1-2) to root...
Downloading http://repo.onion.io/omega2/packages/packages/libffi_3.2.1-2_mipsel_24kc.ipk.
Installing libbz2 (1.0.6-2) to root...
Downloading http://repo.onion.io/omega2/packages/base/libbz2_1.0.6-2_mipsel_24kc.ipk.
Configuring python-base.
Configuring libffi.
Configuring libbz2.
Configuring python-light.

Once done, verify the installation is successful by querying the python version.

root@Omega-2771:~# python --version

Python 2.7.13

Python installed: check!

pyOnionGpio

The folks at Onion have created a python module to make interfacing with the GPIO from code easier. It can be installed using the package manager.

root@Omega-2771:~# opkg install pyOnionGpio

Installing pyOnionGpio (0.1-1) to root...
Downloading http://repo.onion.io/omega2/packages/onion/pyOnionGpio_0.1-1_mipsel_24kc.ipk.
Configuring pyOnionGpio.

Demo

To test python and the GPIO module, I created a simple script to light up an LED when a button is pressed.

Create a file and paste the code below.

root@Omega-2771:~# vi led-button.py

Once the file is saved, make it executable.

root@Omega-2771:~# sudo chmod +x led-button.py

Wire up the button and LED, run the script and start pressing the button!

Et voila, your are now controlling the Omega2’s GPIO from code, using python!

© Frederick Vandenbosch, 2014-2021. Unauthorised use and/or duplication of this material without express and written permission from this blog’s author and owner is strictly prohibited. Excerpts and links may be used, provided that full and clear credit is given to Frederick Vandenbosch with appropriate and specific direction to the original content.