Raspberry Pi – Screen Stream


Very easy to run. All PIs should be on the same network.

1) Extract Zip on Desktop

2) Open terminal (you can easily press Tools -> Open Current Folder in terminal)

3) type: python server.py

4)In the extracted folder there’s a text file called ‘url.txt’. Open it and share the hyperlink with your audience

Download Link



Mac OS – Stream your screen


My Screen

  • Stream your screen with others that are on the same local network. Users can’t control your MAC.
  • Developed using Python
  • Open source
  • Very easy to run
  • Tested with 20 concurrent students in a lab with cable connection

Step 1

  • Download zip and extract on your Desktop (very important)
  • Install python and flask server on Mac (if not already installed)

Step 2

  • Run the following two scripts separately in terminal. (Open two terminals – scripts found in MyScreenMac folder)
  • python screen_capture.py and python server.py

Step 3

  • In the MyScreenMac folder you should find a text file named ‘url.txt’. Open it and distribute the link with your audience. They should write the link in Safari/Chrome or other web browser.


  • Lower the resolution of your MAC for faster streaming or else edit the ‘screen_capture.py’ script. In my testing environment, I have a projector connected with the iMac. Automatically Mac OS reduces the resolution when it detects the projector.
  • Press ctrl+c in the terminal to stop the scripts

Flask Server with GPIOs

Let’s say that you have a running Flask server and you want your user to control the state (on/off) of an LED via the GPIO. The following technique shows how to connect Flask server with a separate GPIO script using PID.

Download the whole project

Run the following two scripts at the same time using the terminal:

from flask import *
import os
import signal

app = Flask(__name__)

#create a route path for index page
def index():
    return render_template("index.html")

#create a route path for about page
def about():

    if 'name' in session: #if session 'name' exists
        print(session['name']) #print what's inside session[name]

        session.pop('name',None) #after printing, delete session name

    return render_template("aboutus.html") #render the html template aboutus

#/students accepts a get and post requests
def student():
    if(request.method == 'POST'): #if user fills a form
        studentName = request.form['studentname']
        if(studentName == "jimmy"):
            session["name"] = studentName #create session, name it 'name' and fill with studentName
            return redirect(url_for("about")) #redirect to about page
            return render_template("student.html") #render student template

        return render_template("student.html")#render student template

#routes with paramaters
def led(param=None):
    if(param == "on"): #if paramater is /led/on
        #read process id from text file generated by ledscript.py
        processId = int(fh.read()) #load the process id

        fh.write("1") #save 1 in text file. 1 means LED ON. 0 means LED Off

        #send signal to process id
        os.kill(processId, signal.SIGUSR1)
        return "LED ON"
    elif(param =="off"): # if paramater is /led/off
        #read process id from text file
        processId = int(fh.read())


        #send signal to process id (ledscript)
        os.kill(processId, signal.SIGUSR1)
        return "LED OFF"
        return "LED MAIN PAGE"

if __name__ == "__main__":
    app.secret_key = 'asdfd!45sdf' #create secret key to secure sessions
    app.run(debug=True, host = "")

import RPi.GPIO as GPIO
import time
import traceback
import os
import signal

def Main():
        #when scripts runs create processid.txt
        fh.write(str(os.getpid())) #get current process id and store in file



        GPIO.setup(4, GPIO.OUT, initial = GPIO.LOW) #setup GPIO4 to low

        def handUSR1(signum,frame): #this function is automatically triggered from flask
            led = int(fh.read())

            if(led == 0): #if 0 is found in text file
                print("LED OFF") #turn off led
                print("LED ON") #if not 0 (1) is found in text file
                GPIO.output(4,GPIO.HIGH) #turn on led

        signal.signal(signal.SIGUSR1,handUSR1) #callback function for SIGUSR1 signal (from flask when kill command is given)


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


Control a separate running script from a Web Server (python)- RPi

Let’s say that you have a running Flask server and you want your user to control the state (on/off) of a motion sensor via the GPIO. The most complex way is to create a multi-threading script which handles the server and GPIO code.

Another approach is to separate the server script from the GPIO script. Thus having two layers of scripts. This has the advantage to debug in isolation. For this technique one has to use Unix Signals which can be used to send signals from one process to another.

When you execute a script on your UNIX system, the system creates a process id (pid) which is different every time. A signal is a software interrupt which notifies a process with a significant event or request.

The following table gives a list of the most common signals:

SIGHUP 1 Linux sends a process this signal when it becomes disconnected from a terminal.
SIGINT 2 Linux sends a process this signal when the user tries to end it by

pressing CTRL+C.

SIGILL 4 Linux sends a process this signal when it attempts to execute an illegal instruction.
SIGABRT 6 Linux sends a process this signal to the process when the process calls the ‘abort ()’ function
SIGFPE 8 Linux sends a process this signal when it has executed an invalid floating-point math instruction
SIGKILL 9 Linux sends a process this signal to end it immediately
SIGUSR1 10 User programs can send this signal to other process
SIGUSR2 12 User programs can send this signal to other process
SIGSEGV 11 Linux sends a process this signal when the program has attempted an invalid memory access
SIGPIPE 13 Linux sends a process this signal when the program has attempted to access a broken data stream, such as a socket connection that has been already closed
SIGALRM 14 A process can receive this signal from the Linux using the function alarm (), after a time period mentioned in its argument.
SIGTERM 15 Linux sends a process this signal requesting it to terminate
SIGCHLD 17 Linux sends a process this signal when a child process exits
SIGXCPU 24 Linux sends a process this signal when it exceeds the limit of

CPU time that it can consume.

SIGVTALRM 26 A process can receive this signal from the Linux using the function setitimer (), after a time period mentioned in its argument.

We are interested in SIGUSR1 and SIGUSR2 which can be used to send user signals.

Step 1:

First create the server layer (app.py). Documentation about Flask server can be found here.

from flask import *
import os
import signal

app = Flask(__name__)

def index():
    return render_template('index.html')

def process1():
    #read process id from text file
    processId = int(fh.read())

    #send signal to process id
    os.kill(processId, signal.SIGUSR1)

    return render_template('trigger1.html')

def process2():
    #read process id from text file
    processId = int(fh.read())

    #send signal to process id
    os.kill(processId, signal.SIGUSR2)

    return render_template('trigger2.html')

if __name__ == '__main__':

Step 2:

Create the SignalReceiver.py script (you can modify this to control the GPIOs)

import os
import signal
import time

fh.write(str(os.getpid())) #get current process id and store in file

def handUSR1(signum,frame):

def handUSR2(signum,frame):

signal.signal(signal.SIGUSR1,handUSR1) #callback function for SIGUSR1 signal
signal.signal(signal.SIGUSR2,handUSR2) #callback function for SIGUSR2 signal

    print("Waiting for signal")

Step 3: Run Server


Step 4: Run SignalReceiver.py


Step 5: 

In the browser, click Trigger 1 and Trigger 2 hyperlink buttons. Notice that SignalReceiver.py outputs ‘triggered 10′ and ‘triggered 12′. This means that both signals were sent and received correctly.


Link to project: https://sourceforge.net/projects/pi-send-signals-to-scripts/

PIXEL(Raspbian)-Virtual Box-Persistence Drive

Please note that this is not officially approved by the PI team but the MagPi magazine offers a similar tutorial using a pendrive.

Step 1

Download the Pixel (Jessie Raspbian) image file: http://downloads.raspberrypi.org/pixel_x86/images/pixel_x86-2016-12-13/2016-12-13-pixel-x86-jessie.iso

Step 2:

Open Virtual Box, press new and create the following settings:


Press Create and enter the following settings


Press Start



Step 3:

Browse to the downloaded ISO file and press Start


Pixel is loaded


Step 4:

To test persistence, create a new folder on your desktop and restart your OS.



Once your OS is restarted, you will notice that the folder you created is lost. This is because there is no persistence drive present.


Step 5 (to create persistence drive):

Open terminal window and enter sudo apt install gparted


When installation is finished, enter sudo gparted


Click on Device > Create Partition Table and press Apply


Right Click on the unallocated partition and press New


Enter label name persistence with the following default settings and press Add


Press the green very good sign and press Apply to any warning messages


Press Close and close everything


Now we are going to copy  the whole operating system from the virtual optical drive to
the hard drive.

Open the terminal window and enter sudo dd if=/dev/sr0 of=/dev/sda bs=1M


Close the virtual machine (shutdown the OS)

Step 6:

Create a new Virtual Machine with the following settings. It is very important that you use your previously created virtual hard disk file. Do no create a new virtual hard disk.


Step 7:

Start your new machine and create a new python script to test persistence. I saved my file in the desktop. Restart your OS.


Step 8:

Test file is still there. Persistence worked 🙂



Screen Sky – Android App

Download my new Android App – Screen Sky



– This app changes your wallpaper automatically every 60 minutes according to the weather. Weather data is collected from openweathermap.org by using your GPS location.

– You can also upload your pictures or take photos and tag them with weather and time conditions.

– Default app pictures and uploaded photos can be deleted by a long click on the respective image.

– Notifications are pushed when no wallpapers are found under respective weather and time status.

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: https://www.raspberrypi.org/documentation/configuration/audio-config.md
  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 http://media-ice.musicradio.com/ClassicFMMP3
Radio Malta 1 mpc add http://s38.myradiostream.com:6982
One Radio mpc add
Radio Malta 2 mpc add http://s11.myradiostream.com:4954
Magic Malta mpc add http://s46.myradiostream.com:6076
Radio 101 mpc add http://stream.vanilla.net.mt:8000/Title1=Radio%20101Length1=-1Version=2
Radju Marija mpc add http://dreamsiteradiocp2.com:8096
bay radio mpc add http://s1.voscast.com:8132
bay easy mpc add http://s1.voscast.com:8154
bay retro mpc add http://s1.voscast.com:8156
Campus FM mpc add mms://stream.um.edu.mt/CampusFM
RTK FM mpc add http://stardust.wavestreamer.com:3328/Live
Vibe FM mpc add http://s9.voscast.com:7824/ 
Bkara FM mpc add http://majestic.wavestreamer.com:8209/Live 
  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. http://www.ebay.co.uk/itm/New-16-x-2-LCD-Keypad-Kit-DIY-Transparent-Acrylic-Case-For-Raspberry-Pi-/112058244362?_trksid=p2047675.l2557&ssPageName=STRK%3AMEBIDX%3AIT&nma=true&si=D01jYFjgSMSs6rfWdX2eA1IH%252F%252Bo%253D&orig_cvip=true&rt=nc
  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) – https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c
  3. Continued the setup : https://learn.adafruit.com/adafruit-16×2-character-lcd-plus-keypad-for-raspberry-pi/usage
  4. Installed the following library (can be done in step 10): https://github.com/adafruit/Adafruit_Python_CharLCD
  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 = subprocess.call(['ping','-c','1',remote_server])#test connection with google
                    if(status == 0):
                        counter +=1

                    if(counter > 3):

def startPlaying():
    global lcd
    subprocess.call("mpc stop ",shell=True)
    subprocess.call("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 == "http://stream.vanilla.net.mt:8000/Title1=Radio%20101Length1=-1Version=2"):
        message = "101"
    elif(message == ""):
        message = "One Radio"
    elif(message == "http://majestic.wavestreamer.com:8209/Live"):
        message = "Bkara FM"
    elif(message == "http://stardust.wavestreamer.com:3328/Live"):
        message = "RTK"
    elif(message == "http://media-ice.musicradio.com/ClassicFMMP3"):
        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 ")
                        subprocess.call("mpc next ",shell=True)

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

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

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

                    elif(button[0] == LCD.DOWN):
                        subprocess.call("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)

                        #subprocess.call(['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: https://www.dexterindustries.com/howto/auto-run-python-programs-on-the-raspberry-pi/
  2. If you are having mpc connection timeouts with newest raspbian versions, just follow the fix by user csrlima in the following forum: https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=159485
  3. Tested the radio. Like a boss 🙂