Cluster Hat

Out of habit I add a Pi Zero to every Adafruit order I make (or anywhere else that sells the Pi Zero for $5) and have built up quite a collection, I had been looking at some Pi cluster projects but the wiring for network and power always seemed anoying and fragile.

You may wonder why someone would want a slow pi cluster, I have been looking at using Ansible as a way to manage software for all my pi based projects and for some cloud automation and thought a cluster might be a fun way to build an Ansible test bed and learn how to manage multiple Pi’s. Then I discovered the ClusterHAT which attachs to a Raspberry Pi 2/3 “Controller” and uses USB Gadget mode to connect and power 4 Pi Zero “Nodes” into a small cluster with a hat that connects via USB and the GPIO with no other networking or wiring required.

Since putting together a hub and all the cabling to make my own cluster still seemed anoying and was also more expensive I immediately ordered a ClusterHAT and another Pi Zero from Pimoroni. Using the pre-built images provided in the simple section of the ClusterHAT software setup page I prepared SD cards for each Pi before the hat arrived, I used a 10X 32GB card for the controller and 4 10X 16GB cards for each of the nodes. Using my trusty label printer I labeled each Pi Zero and SD Card. After about a week they arrived from the UK and I installed the SD cards I had prepared for each Pi and set about attaching the hat to a Pi 2 and an acrylic plate I had laying around.

Cluster Hat

I connected the Pi 2 to ethernet and powered it up, using Angry IP Scanner I angrily scanned my network and found the IP address for my new cluster controller and used SSH to connect to it:

After logging in I just typed clusterhat to see what would happen:

Cluster Hat Terminal

Seems legit, let’s turn them all on and then back off again:

Cluster Hat Terminal

A nice indicator light on the ClusterHAT lights up when each Pi Zero is turned on. After turning them back on again I angrily scanned my network again and saw 4 new IP addresses for P1, P2, P3 and P4. It really was that easy to get the ClusterHAT up and running I used SSH to connect to each pi and expand the file system, I didn’t make any other raspi-config changes as I want to try and use Ansible for that later.

Ansible Time

First I set up a public/private keypair on the controller so I don’t have to do any login stuff:

// Generate the key
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa
// Spit it Out
cat ~/.ssh/

I copied the key output and used SSH to connect to each Pi Zero from the controller:

sudo ssh [email protected], P2, P2, P4
sudo mkdir ~/.ssh
sudo nano ~/.ssh/authorized_keys

Paste the key value into nano and use CTRL X to save and exit nano and then SSH on each Pi Zero. From the controller SSH to each Pi Zero and accept the certificate and verify you don’t have to enter a password to connect.

Then on the controller install ansible:

sudo apt-get install python-pip git python-dev sshpass
sudo pip install markupsafe
sudo pip install ansible

Next I created an ansible directory and setup a hosts file:

sudo mkdir ~/ansible
sudo nano ~/ansible/hosts

And pasted the following text into nano and used CTRL X to save the hosts file and and exit:


If everything has gone perfectly you should be able to issue some ansible commands, first lets check that our ansible hosts file is set up correctly:

ansible -i ~/ansible/hosts clusternodes --list-hosts

Ansible Hosts Terminal

That worked, now lets see if we can ping all the nodes:

ansible -i ~/ansible/hosts clusternodes -m ping

Cluster Hat Terminal

That’s it, ansible on a pi zero Clustercluster using SSH keys for login, now I have to dig into making playbooks and additional ansible configuration options. The The ClusterHAT really is a nice way to build a little cluster without fighting with a ton of wiring and USB and ethernet hubs.

I have used OctoPrint to manage prints in the past with my Printrbot. As time went on I found myself using the SD card more often because it was more reliable. When I got my new MAKEiT Pro-M printer I continued to use the SD card because it has a fantastic tune feature that lets me adjust a number of settings on the fly if you are printing from the SD card.

Since most of the adjustments I make after a print does not start right or fails is just one or two settings being able to change settings on the fly has really saved me a lot of time. The timelapse and status features of OctoPrint are cool but I found I did not really miss them, I did really miss being able to upload gcode to the printer from my PC.

I knew that WiFi sd cards existed and were used by a couple of photographers I know, but when I had last looked they were pretty expensive a quick search of amazon and I found the Toshiba FlashAir 16GB. The card came with some windows software, but since I was on Linux I it was all pretty uselesss. I did find a config file in SD_WLAN folder at the root of the SD card.

With a little googling I discovered that I wanted to put the card in client mode (APPMODE=5) and allow uploads with UPLOAD=1. Then you set the APPSSID and APPNETWORKKEY for your WiFi network.


I put the SD card back in my printer and turned the printer on. Using the connected clients section of the administration tool for my home router I figured out the IP address of the card and set it to have a sticky IP so I could easily find it again.

You can browse the files on the sd card by typing the ip address into the url bar of your web browser. The upload page is located at /upload.cgi.

I have been using the card for over a week now, it it has made the process of loading gcode to the printer much nicer.

I have wanted to build a motion activated and time lapse capable raspberry pi camera for a while now but never really found a case I like. I found this nice case for a raspberry pi and camera on thingiverse. It was designed for a specific fisheye camera but looking at the model it appeared that one of the cheap Chinese fish eye cell phone lenses I have would fit nicely in the hole.

Pi Cam Assembly

I fired up tinkercad and used my calipers to measure the space inside the camera case and the thickness of the RaspiCam board and created a model to mount the official RaspiCam. I used two small pieces of gaffers tape to attach the camera to the support piece, snapped the lens into the hole in the case and slid the camera into the case. You can find my camera part here

This is really a nice simple project, any raspberry pi and camera case will work, you will also need:

  • Raspberry Pi Model B or B+, 2 or 3
  • Raspberry Pi Camera Board
  • Raspberry Pi Camera Cable
  • Button - I used on of these
  • 2 Female Jumper wires
  • Cell Phone Fisheye lens
  • SD Card

Halt Button

I soldered a couple of female jumper wires to a small momentary switch to use to halt the pi for both the surveillance and timelapse setups. For the timelapse software I am using the code from this Adafruit project which includes code for a halt button.

I have stripped this script of the time lapse features for use on the surveillance camera. Because I wanted both of these camera projects to automatically start on boot I have chosen to have two SD cards set up with raspbian lite that automatically boot into either the surveillance or timelapse camera mode. The button is connected to gpio 21 and ground on the pi, the last two pins next to the usb ports.

Motion Camera Software Setup

Since I didn't need a desktop OS for this project I downloaded the Raspbian Jessie Lite image and installed it on a SD card using Disk Image Writer in Ubuntu.

Once I booted up the raspberry pi I used raspi-config to expand the file system, set internationalization options for keyboard, time and wifi, enabled the camera, overclocked the CPU and enabled SSH.

The next thing I did was to disable the camera LED since I didn't want the camera to indicate that it was on.

// Edit the config.txt file
sudo nano /boot/config.txt

// Add the following line

The standard version of motion from apt does not work with the RaspiCam module, but there is a community supported version that has been compiled for use with the RaspiCam. There is more information on a wiki here.

Below are the commands I used to install the custom motion binary for the RaspiCam with the latest version of Raspbian Jessie Lite.

Pi Cam Assembly

// Install the motion prerequisites
sudo apt-get install -y libjpeg-dev libavformat56 libavformat-dev libavcodec56 libavcodec-dev libavutil54 libavutil-dev libc6-dev zlib1g-dev libmysqlclient18 libmysqlclient-dev libpq5 libpq-dev 

// Download and unzip the raspberry pi specific motion binary
tar -zxvf motion-mmal-lowflyerUK-20151114.tar.gz

// Test out the results
$ ./motion -c motion-mmalcam-both.conf

If you see success messages logged in the terminal after running motion, point your web browser to the ip of the raspberry pi port 8081 and you should see your camera streaming.

Timelapse Camera Software Setup

I downloaded the pre-build SD card image from Adafruit I used raspi-config to expand the file system, set internationalization options for keyboard, time and wifi, overclock the CPU and enabled SSH.

The pre-built card just works, boot up the pi and it starts taking timelapse images, hold down the switch and it shuts down the pi. I want to build the pi zero wearable version of this project but don’t yet have all the parts.

Once I had a bunch of images I made a video using FFMPEG

ffmpeg -f image2 -i img%06d.jpg time-lapse.mp4

These are both a couple of nice raspberry pi camera projects that don’t require many parts..