Writing Your Odroid Project in Bash

I’ve purchased my Odroid-N2+ and installed the Ubuntu MATE operating system on an SD card. It works great!

One part of the SBC (Single Board Computer) is the GPIO (General Purpose Input & Output) pins, that can be used for sending and receiving signals to the devices the user develop.

An easy project for begginers can be found in Odroid Wiki wehn you select from the tree on the left side of your browser’s screen:

odroid-## -> application note -> gpio -> wiringpi

(replace ‘##’ by your Odroid model)

Or click here to go to the page.

Start by installing the ‘odroid-wiringpi’ as described at the beggining of the page.

Once you got to the example relevant to your device, you’ll see an image that will help you to locate the relevant pins on your device.

Note: the physical pin number differs from the WiringPi number.

The program you will find for turning the LED on and on is in C. With some changes I’ve made it looks as follows:

    #include <stdio.h>
    #include <stdlib.h>
    #include <wiringPi.h>
    #include <signal.h>
    #include <unistd.h>
    void sig_handler(int signo)
        if (signo==SIGINT)
    int main(void)
        /* Connect to signal-handler, so the LED will not stay on
         * when the user presses <Ctrl>+C */
        if(signal(SIGINT, sig_handler)==SIG_ERR)
            printf("Cannot catch SIGINT\n");
        pinMode(0, OUTPUT);
        for (;;)
            digitalWrite(0, HIGH); 
            digitalWrite(0, LOW); 
        return 0;

You can use the same pin handling functions for other devices such as Raspberry Pi and Arduino.

Now, the hint for translating your program into Bash (GNU Bourne Again SHell) is the command found on the Odroid Wiki page:

gpio readall

The output of that bash commands looks as follows:

In the output you can see the mapping of each physical pin to the corresponding WiringPi(wPi) number to be used in a program, and its mode (for example Input or output). The table can help you decide what WiringPi pin number to choose if you translate a program written for another device into yours. For example, Raspberry PI uses BCM numbering, that does not appear in the table.

While trying to find how to access the pins from a Bash script, I found many examples with files under the ‘/sys’ folder. We don’t need them here. If the command ‘gpio’ takes parameters, then check if you can use others to set the pin mode adn to write to it using the command:

gpio -h

From the output, you can learn that you can set the pin mode, read from the pin or write to the pin using the ‘gpio’ command.

Following is the full script to blink the LED, and turn it off when the user presses



function brexit () {
  gpio write 0 0
  exit 0

echo "Hello, world"
trap brexit SIGINT

gpio mode 0 out
  gpio write 0 1
  sleep 1
  gpio write 0 0
  sleep 1

The ‘brexit’ function turns the LED off, and the ‘trap’ command associates it with the signal SIGINT (user break).

Command ‘gpio write <pin-number> <value>‘ sets the pin value to

  • 1 – HIGH to turn the LED on.
  • 0 – LOW to turn the LED 0


Hearing Sound from Firefox Using Bluetooth Headphones in FreeBSD

I’ve gotten myself Bluetooth Headphones and a USB Bluetooth dongles, and I want to hear sounds through my new headphones.

Since the headphones are a Bluetooth device, they should be discovered and paired. In the famous manual, FreeBSD Handbook , there are two sections in which to find instructions on Bluetooth and sound:

  • 33.5 Bluetooth – in chapter 33 – Advanced Networking.
    There is also a useful utility named bluetooth-config you can use to create or modify the files ‘/etc/bluetooth/hcsecd.conf.; and ‘/etc/bluetooth/hosts
  • 8.2.3. Setting up Bluetooth Sound Devices – in chapter 8 – Multimedia

Having configured Bluetooth and installed virtual_oss. All you have to do each time you want to listen through your Bluetooth headphones is to run the following commands replacing BT_ADDR by your device name:

  1. hccontrol -n ubt0hci create_onnection BT_ADDR
  2. virtual_oss -C 2 -c 2 -r 48000 -b 16 -s 768 -R /dev/null -P /dev/bluetooth/BT_ADDR -d dsp

Now, if you use VLC to listen to audio, all you have to do is select the ‘dsp’ output device. But, if you want to hear the sounds plyed by Firefox, you should have to add a module to PulseAudio. I haven’t found any Bluetooth modules I can install on my FreeBSD, but have found that module-sndio can do the job for me,, to add it, run the command:

pkg install pulseaudio-module-sndio

And add the following line to ‘/usr/local/etc/pulse/default.pa

load-module module-sndio device=snd/0

To start the service sndio at boot time, add the following line to ‘/etc/rc.conf‘:


To hear sounds from the Firefox browser, make sure PulseAudio stream it to ‘/snd/0‘ My display manager is XFCE4, and I use the plugin ‘xfce4-pulseaudio-plugin’ to view my output devices. In the following image, you can see that firefox sounds are streamed to that device:

Now, if everythiing is set correctly, but you cannot hear the sound, type the follwing shell command as a regular user:

pulseaudio --kill