Sunday, 17 June 2018

Pi Camera stop motion animation



You can find the source code at

1. Connect a camera module
sudo pip3 install guizero
sudo pip3 install imageio
wget -O
4. Run the program:

A couple of "interesting" things about this project



# create the camera
camera = PiCamera(resolution="640x480")
camera_output = PiRGBArray(camera)
# capture the image
camera.capture(camera_output, "rgb")
# append the camera image to the list as a numpy array
gif_output = BytesIO()
imageio.mimsave(gif_output, animation.images, format="gif")
animation.image =

Saturday, 9 June 2018

Get the weather using Python

I recently spent a hour or so hacking a lucky cat so that it would only wave when it was sunny.
It did this by pulling the weather data from Open Weather Map using the Python module pyowm.

1. Sign up for a free API key in Open Weather Map.

2. Install the pyown Python module, open a Terminal or Command Prompt and run:

pip install pyown

Raspberry Pi / Linux
sudo pip3 install pyown

pip3 install pyown

3. Create a Python program using the following code, inserting your API key:
import pyowm

owm = pyowm.OWM('put api key here')

observation = owm.weather_at_place('Cambridge,GB')
w = observation.get_weather()

clouds = w.get_clouds()
wind = w.get_wind()
humidity = w.get_humidity()
temp = w.get_temperature('celsius')

print("{}, {}, {}, {}".format(clouds, wind, humidity, temp)

Note - it can take up to 60 minutes for your API key to be activated.

There is a lot more information which can be pulled back - have a look at the weather module documentation for more details.

Sunday, 4 March 2018

Python - Creating shortcuts

I was recently working on the mu project (a Python IDE for beginners), which is super easy to install using pip, but there is no way to automate the creation of desktop and menu shortcuts.

This seemed like a really big miss, shortcuts are the usual way for people (and certainly beginners to launch applications).

So I set to creating a really simple way of creating shortcuts for Python applications.

Enter shortcut, a X platform (Windows, MacOS, Linux, Raspberry Pi) Python module for automatically creating shortcuts.

Its really simple to install and use:
pip3 install shortcut
shortcut name_of_app
It will find the location of the app and create desktop and menu shortcuts for it.

There is also a Python API which can be used to do the same:
from shortcut import ShortCutter
s = ShortCutter()
You will find documentation at and code at

Friday, 29 December 2017

Setup Raspberry Pi Samba share

I almost always setup a samba share on every Raspberry Pi I install, it allows me to easily share files and work on my projects - so I thought I had better write down how I do it.
Install samba:
sudo apt-get install samba
Modify the Samba config file to add a share called pihome which points to the /home/pi directory:
sudo nano /etc/samba/smb.conf
Scroll to the bottom and add the following:

protocol = SMB2

   comment= Pi Home
   only guest=no
   create mask=0644
   directory mask=0755

Setup a samba password for the Pi user:
sudo smbpasswd -a pi
Restart the samba service:
sudo service smbd restart
You should now be able to connect to your Pi using the address:

Wednesday, 15 November 2017

Slack command line stream






Edit /etc/profile adding the export to the bottom:
sudo nano /etc/profile
export SLACK_API_TOKEN=[my super long token]
3. Install slackclient and colorama using pip:
sudo pip3 install colorama
sudo pip3 install slackclient
4. Download the from gist:
5. Run it:

Friday, 7 July 2017

Python Bluetooth RFCOMM Client Server



Install the library
sudo apt-get install python3-dbus
sudo pip3 install bluedot



Simple Client / Server Example

Create a new Python program and save it as

from bluedot.btcomm import BluetoothServer
from signal import pause

def data_received(data):

s = BluetoothServer(data_received)

Create a 2nd program and save it as
from bluedot.btcomm import BluetoothClient
from signal import pause

def data_received(data):

c = BluetoothClient("nameofyourserver", data_received)




from bluedot.btcomm import BluetoothAdapter

a = BluetoothAdapter()




Tuesday, 4 July 2017

Mac OS - Check Java version before running script

I needed to check what version of Java was installed on a Mac before running my program, so with the help of stackoverflow and a few other resources I pulled together the following bash script which checks to see if the version of Java is greater than 1.8 before continuing.
# Work out the JAVA version we are working with:

# Based on:
for token in $(java -version 2>&1 | grep -i version)
    if [[ $token =~ \"([[:digit:]])\.([[:digit:]])\.(.*)\" ]]

#check version is greater than 1.7 (i.e. at least 1.8)
if [ "$JAVA_VER_MAJOR" -gt "1" ]; then
    echo start your program
elif [ "$JAVA_VER_MINOR" -gt "7" ]; then
    echo start your program
    echo ERROR - Java needs to be updated.
    echo Currently installed version is $JAVA_VER_MAJOR.$JAVA_VER_MINOR - 1.8 is required