Maltese Online Radio – Raspberry Pi

So here’s the story:

  1. I woke up to Mum complaining that she can’t listen any longer to the radio from our kitchen due to noise interferance
  2. My brother suggested of buying an online radio
  3. I said “No..I can build one using the Raspberry Pi 2 and Music Player Daemon”
  4. I expected some excitement from their end but they just replied “ok”. Sad.
  5. Using the terminal I installed the player:
sudo apt-get install mpd mpc
  1. Changed the audio output to the headphone jack:
  2. In the terminal I added some local radio stations using the command mpc add. I used Chrome’s Developer Tools(f12) to get these links:
Classic FM  mpc add
Radio Malta 1 mpc add
One Radio mpc add
Radio Malta 2 mpc add
Magic Malta mpc add
Radio 101 mpc add
Radju Marija mpc add
bay radio mpc add
bay easy mpc add
bay retro mpc add
Campus FM mpc add mms://
RTK FM mpc add
Vibe FM mpc add 
Bkara FM mpc add 
  1. From Ebay, I bought: 16 x 2 LCD Keypad Kit + DIY Transparent Acrylic Case For Raspberry Pi. I selected this product because it comes with 5 buttons and a case.
  1. When the product arrived, I attached the LCD on the Pi. No soldering is required. It’s very easy. Just place the LCD board in the respective GPIOs.
  2. Followed this tutorial to enable I2C (with Raspi Config) –
  3. Continued the setup :×2-character-lcd-plus-keypad-for-raspberry-pi/usage
  4. Installed the following library (can be done in step 10):
  5. Programmed the following code (Buttons Up&Down = Volume Control; Buttons Left/Right = Skip radio; Button Select – Turn off Pi) :
# Example using a character LCD plate.
import time
import Adafruit_CharLCD as LCD
import traceback
import subprocess
import os.path
import os

# Initialize the LCD using the pins
lcd = LCD.Adafruit_CharLCDPlate()
# create some custom characters
lcd.create_char(1, [2, 3, 2, 2, 14, 30, 12, 0])
lcd.create_char(2, [0, 1, 3, 22, 28, 8, 0, 0])
lcd.create_char(3, [0, 14, 21, 23, 17, 14, 0, 0])
lcd.create_char(4, [31, 17, 10, 4, 10, 17, 31, 0])
lcd.create_char(5, [8, 12, 10, 9, 10, 12, 8, 0])
lcd.create_char(6, [2, 6, 10, 18, 10, 6, 2, 0])
lcd.create_char(7, [31, 17, 21, 21, 21, 21, 17, 31])

#turn on green light
lcd.set_color(0.0, 0.0, 1.0)
lcd.message("connecting: \n")

message = ""

def isConnected():
    global lcd
    while True: #keep repeating until internet connection is found
            ip = subprocess.check_output("hostname -I",shell=True)
            ip = ip[:3]
            if ip != "192":
                counter = 0
                while True:
                    print 'trying to connect to internet'
                    lcd.message("connecting to\n internet")
                    remote_server = ""
                    status =['ping','-c','1',remote_server])#test connection with google
                    if(status == 0):
                        counter +=1

                    if(counter > 3):

def startPlaying():
    global lcd
    lcd.clear()"mpc stop ",shell=True)"mpc play ",shell=True) #start player

def updateCurrentStation():
    global message
    message = subprocess.check_output('mpc current',shell=True)
    message = updateStationName(message.strip())
    if(len(message) > 15):
        message = message[:16] + '\n' + message[16:30]

def updateStationName(message): #this function updates those station name that are not returning a proper name
    if(message == ""):
        message = "101"
    elif(message == ""):
        message = "One Radio"
    elif(message == ""):
        message = "Bkara FM"
    elif(message == ""):
        message = "RTK"
    elif(message == ""):
        message = "Classic FM"
    return message

def checkStatus():
    status = subprocess.check_output('mpc status',shell=True)
    if(status[0:6] == 'volume'): #empty status starts with text volume

def Main():

    global lcd
    global message
    cache_oldmessage = ""


        # Make list of button value, text, and backlight color.
        buttons = ( (LCD.SELECT, 'Select', (1,1,1)),
                    (LCD.LEFT,   'Left'  , (1,0,0)),
                    (LCD.UP,     'Up'    , (0,0,1)),
                    (LCD.DOWN,   'Down'  , (0,1,0)),
                    (LCD.RIGHT,  'Right' , (1,0,1)) )

        while True:

            # Loop through each button and check if it is pressed.
            for button in buttons:
                if lcd.is_pressed(button[0]):

                    if(button[0] == LCD.LEFT):
                        print("left button")                       

                        lcd.message("connecting:\n ")
              "mpc next ",shell=True)

                    elif(button[0] == LCD.RIGHT):
                        print("right button")

                        lcd.message("connecting: \n")
              "mpc prev ",shell=True)

                    elif(button[0] == LCD.UP):
              "mpc volume +5" ,shell=True)
                        print("volume increased")

                    elif(button[0] == LCD.DOWN):
              "mpc volume -5" ,shell=True)
                        print("volume decreased")

                    elif(button[0] == LCD.SELECT):
                        lcd.set_color(0.0, 1.0, 1.0)
                        lcd.set_color(0.0, 0.0, 0.0)

              ['poweroff -f'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                        os.system('shutdown now -h')

                    time.sleep(0.75) #button click delay

            if(cache_oldmessage != message):
                cache_oldmessage = message

    except Exception as ex:
        lcd.set_color(1.0, 0.0, 0.0)


  1. Followed the following tutorial to launch the python script automatically on start-up:
  2. If you are having mpc connection timeouts with newest raspbian versions, just follow the fix by user csrlima in the following forum:
  3. Tested the radio. Like a boss 🙂



Raspberry Pi GPIO Emulator

This Raspberry Pi emulator simulates some of the functions used in the RPi.GPIO library (using python). The intention of this library is educational.



The easiest way is to download the zip file and extract the files in the same working environment of your script. To use the emulator just type the following at the beginning of your script.

from EmulatorGUI import GPIO


This library simulates the following functions which are used in the RPi.GPIO library.

  • GPIO.setmode()
  • GPIO.setwarnings()
  • GPIO.setup()
  • GPIO.input()
  • GPIO.output()

Test Example

from EmulatorGUI import GPIO
#import RPi.GPIO as GPIO
import time
import traceback

def Main():


        GPIO.setup(4, GPIO.OUT)
        GPIO.setup(17, GPIO.OUT, initial = GPIO.LOW)
        GPIO.setup(18, GPIO.OUT, initial = GPIO.LOW)
        GPIO.setup(21, GPIO.OUT, initial = GPIO.LOW)
        GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_UP)
        GPIO.setup(15, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
        GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
        GPIO.setup(26, GPIO.IN)

            if (GPIO.input(23) == False):

            if (GPIO.input(15) == True):

            if (GPIO.input(24) == True):

            if (GPIO.input(26) == True):

    except Exception as ex:
        GPIO.cleanup() #this ensures a clean exit



Click here to download

Christmas Tree Controller

This is a brief explanation how to create a Christmas tree that its LEDs are controlled by the end user from a website. The concept is pretty simple. We need to have a server, a website, a database, a relay, LEDs and of course a Netduino. Obviously this concept can be applied on a RaspberryPi.

Video Demonstration

General Setup

For this project Node.JS was chosen because it has a popular library called Socket.IO and can be easily connected with MongoDB. Socket.IO is a JavaScript library for real time web applications. It enables real-time communication between web clients and servers. MongoDB is a cross-platform document-oriented database which is classified as a NoSQL database. Socket.IO was used to display the Christmas tree’s animation state (controlled by netduino) in real time to all connected users via Node.JS. MongoDB was used to store the user’s LEDs animation.

Here is a step-by-step breakdown structure of what was done:

Step 1 – User enters animation sequence: Selected LED colours with duration in seconds.

Step 2 – Upon submission, the user’s data is stored in MongoDB and emitted via Socket.IO to all connected clients in JSON.

Step 3 – Netduino checks every two seconds with Node.JS if there’s a new animation for playing. If there is, Node.JS gets the data from the database and returns it to Netduino as JSON string. Then Netduino parses the JSON string and plays the animation. Once it finishes, it instructs Node.js to get the next animation.

Step 4 – Another challenging part was how to setup the relay with the batteries, LEDs and Netduino. The following tutorial was followed and implemented:




Digital Game Based Learning – Learn Binary & Hexadecimal Conversions



I created this game using Unity 3D for a teaching course. The game takes place in World War 2 and contains one single mission. A number of planes are inbound to destroy a town and the objective of the player is to stop the enemy. The player has to translate incoming messages by using ASCII encoding and destroy respective enemy planes.

This game supports assessment for:

  • Decimal to ASCII Encoding
  • Binary to ASCII Encoding
  • Hexadecimal to ASCII Encoding



Click here to download (Runs only on Windows)


Step 1 – First Screen

Step 1

Learn programming using Call of Duty 4

I’ve been talking with several young programming language students and many of them want to build and develop games. Some of them tried Unity 3D and Unreal Engine on their own but they found the engines very complex to use. I totally understand their situation. These types of engines are used by people that have good understanding in programming and 3D graphics. On the other hand this motivation should not be wasted! I think that at this stage, these students should try to modify high end games and at the same time learn the basics of programming rather than get into detail of how these game engines work.

Call of Duty 4 is the perfect solution for this objective. One can build mods using a programming language that is similar to C# and test the code in an online collaborative environment. I created some notes and decided to share them online. Feel free to use and enjoy 🙂




Mission 1

Learn Bubble and Merge Sort Algorithms by playing a 3D Digital Game

I created this game for my masters dissertation. The game idea is based on the famous game World of Warcraft and supports single player and multiplayer game modes. The single player supports only one student while the multiplayer supports two students working together to solve the same task. Both game modes support spectator mode which can be used by any lecturer to act as a facilitator. The game has been developed using Unity 3D and can be played freely on any PC. One must not make any profit on such content.

Click Here to Download Game.

Technical Details:

  • Runs only on Windows.
  • Open Port TCP843 (if game won’t connect with the online Server)
  • Only 20 concurrent users allowed

LED Controller – Android & Netduino

In today’s tutorial we are going to connect Netduino with Android. It is recommended to first read this tutorial to better understand how Netduino works and can be connected to the LEDs.



The first thing that you need to understand is that Netduino can act as a server that accepts web page requests. Based on the content of the web requests, one can turn on/off LEDs. Therefore we can create an Android application that sends HttpPosts and has full control on our LEDs. It sounds easy right?

In our example we hosted the Netduino server locally by connected the Ethernet cable to the router and connected the Nexus 7 via the Wi-Fi.