Home Blog Page 15

Can My Water Cooled Raspberry Pi Cluster Beat My MacBook?

I recently built a water-cooled Raspberry Pi cluster and a lot of people asked how the cluster would compare to a computer because Raspberry Pi’s themselves aren’t seen as being particularly powerful.

If you haven’t already, have a look at my post on building the Pi Cluster.

How the cluster compares to a traditional computer isn’t really an easy question to answer. It depends on a number of factors and what metrics you measure it against. So this got me thinking of how to fairly compare the cluster to a computer in a way that doesn’t rely too heavily on the software being run and uses my Pi Cluster in the way it was intended when I built it,.

Water Cooled Raspberry Pi Cluster Comparison

The cluster, and Raspberry Pi’s in general, aren’t designed for gaming or rendering high-end graphics, so obviously won’t perform well against a computer in this respect. But my intention behind building this cluster, apart from learning about and experimenting with cluster computing was to run mathematical models and simulations.

The Test Script

I initially thought of doing something along the lines of calculating Pi to a particular number of decimal places, but then I stumbled across a simple 4 node cluster setup mentioned in The Mag Pi which was used to find prime numbers up to a certain limit. This seemed like a good comparison as it is simple to understand and edit, it is easily adjustable and it can be run on Windows PCs, Macs and Raspberry Pi’s, so you can even join in and see how your computer compares.

Python Script For Finding Primes From The Mag Pi

The script just runs through each number, up to a limit, and checks its divisibility to figure out if it is a prime number or not. I have simplified their cluster script so that it can be run on a PC, Mac or single Raspberry Pi.

import time
import sys

#Start and end numbers
start_number = 1
end_number = 10000

#Record the test start time
start = time.time()

#Create variable to store the prime numbers and a counter
primes = []
noPrimes = 0

#Loop through each number, then through the factors to identify prime numbers
for candidate_number in range(start_number, end_number, 1):
    found_prime = True
    for div_number in range(2, candidate_number):
        if candidate_number % div_number == 0:
            found_prime = False
            break
    if found_prime:
        primes.append(candidate_number)
        noPrimes += 1

#Once all numbers have been searched, stop the timer
end = round(time.time() - start, 2)

#Display the results, uncomment the last to list the prime numbers found
print('Find all primes up to: ' + str(end_number))
print('Time elasped: ' + str(end) + ' seconds')
print('Number of primes found ' + str(noPrimes))
#print(primes)

I know that this is a very inefficient way of searching for prime numbers, but the intention is to make the script computationally expensive so that the processors have to work. There are some interesting thoughts and algorithms for finding prime numbers if you’d like to do some further reading.

For each setup, we’ll be testing the time it takes to find all prime numbers up to 10,000, 100,000 and 200,000.

I’ll be doing 5 comparisons, running the simulation on two laptops – a 2020 MacBook Air and a somewhat outdated HP Laptop running Windows 10 Pro. We’ll then compare these laptops to a single Pi 4B running at 1.5Ghz, then overclock the single Pi to 2.0Ghz, and then finally run the simulation on the Raspberry Pi Cluster with all of the Pis overclocked to 2.0Ghz.

There were a few requests on my build video to compare the cluster to a one of AMDs Ryzen CPU’s. So if any of you are running one, please try running the Python script which you can download above and share the results in the comments section. I’d also be interested to see how the Pi 400 performs if anyone has one of those.

Edit – Multi-process Test Script

Thanks to Adi Sieker for putting together a multi-process version of the script. This script makes use of all available cores and threads on the computer it’s being run on, so should give much better comparative results for multi-core processors.

I’ll add my updated test results for each system running this script at the end of this post.

import multiprocessing as mp
import time


#max number to look up to
max_number = 10000
#four processes per cpu
num_processes = mp.cpu_count() * 4

def chunks(seq, chunks):
        size = len(seq)
        start = 0
        for i in range(1, chunks + 1):
            stop = i * size // chunks
            yield seq[start:stop]
            start = stop

def calc_primes(numbers):
    num_primes = 0
    primes = []

    #Loop through each number, then through the factors to identify prime numbers
    for candidate_number in numbers:
        found_prime = True
        for div_number in range(2, candidate_number):
            if candidate_number % div_number == 0:
                found_prime = False
                break
        if found_prime:
            primes.append(candidate_number)
            num_primes += 1
    return  num_primes

def main():
    #Record the test start time
    start = time.time()

    pool = mp.Pool(num_processes)

    #0 and 1 are not primes
    parts = chunks(range(2, max_number, 1), 1)
    #run the calculation
    results = pool.map(calc_primes, parts)
    total_primes = sum(results)

    pool.close()

    #Once all numbers have been searched, stop the timer
    end = round(time.time() - start, 2)

    #Display the results, uncomment the last to list the prime numbers found
    print('Find all primes up to: ' + str(max_number) + ' using ' + str(num_processes) + ' processes.')
    print('Time elasped: ' + str(end) + ' seconds')
    print('Number of primes found ' + str(total_primes))

if __name__ == "__main__":
    main()

Testing The Laptops And Individual Pi

Now that we know what we’re going to be doing, let’s get started with testing the computers.

I’ll start off on my Windows PC. The windows PC has a 7th generation dual-core i5 processor running at 2.5GHz.

Outdated HP Laptop

Let’s start off by running the script to 10,000.

Windows 10000

So as expected, that was completed pretty quickly, 1.69 seconds to find 1230 prime numbers below 10,000.

Now let’s try 100,000. Remember that even though 100,000 is only ten times more than 10,000, it’s going to take significantly longer than 10 times the time, because there are exponentially more factors to check as the numbers get larger.

Windows 100000

So running the test to 100,000, we get a time of 73 seconds, which is a minute and 13 seconds and we found 9593 prime numbers.

Lastly, lets try 200,000.

Windows 200000

So it took 267 seconds or a little under 5 minutes to find the prime numbers to 200,00 and we found 17,985 primes.

Here’s a summary of the HP laptop’s results.

HP Laptop

Next, we’ll look at the MacBook Air. The MacBook Air has a 1.6 GHz Dual Core i5 processor, let see how that compares to the older HP laptop. We’d expect the MacBook to be a bit slower than the PC as it’s CPU is only running at 1.6GHz, while the PC is running at 2.5Ghz.

2020 MacBook Air

The MacBook Air was quicker to 10,000 but then took a little longer than the PC for the next two tests, taking just under 6 minutes to find the primes up to 200,000.

MacBook 10000
MacBook 200000
MacBook 200000

Here’s a summary of the results of the two tests so far:

Laptops

Let’s now move on to the singe Raspberry Pi running at 1.5Ghz.

Overclocked Pi 4B

The Pi 4B has a quad-core ARM Coretex-A72 processor.

Pi Running 1.5 Ghz

Even to 10,000, we can already see that the Pi is quite a bit slower than the other computers, taking 2 seconds for the first 10,000 and taking a little over 13 minutes to get to 200,000.

Next we’ll overclock the Pi to 2.0Ghz and see what sort of difference we see.

Pi Running 2.0 Ghz

Overclocking the Pi has made a bit of an improvement. It took 1.57 seconds to 10,000, and around 11 minutes to get to 200,000.

Here’s a summary of the results of our tests of the individual computers:

2 Ghz Pi

Setting Up The Raspberry Pi Cluster

Next, we need to get the Pi’s all overclocked and working together in a cluster. To do this, there are a couple of things we need to set up.

Setting Up The Raspberry Pi Cluster

I’ve installed a fresh copy of Raspberry Pi OS on the host or master node and then a copy of Raspberry Pi OS Lite on the other 7 nodes.

Prepare Each Node For SSH

Boot them up and then run the following lines to update them:

sudo apt -y update
sudo apt -y upgrade

Next, run;

sudo raspi-config

And change each Pi’s password, hostname. I used hostnames Node1, Node2 etc.. Also, make sure that SSH is turned on for each Pi so that you can access them over the network.

Changing Hostname And Password

Next, you need to assign static IP addresses to your Pi’s. Make sure that you’re working in a range which is not already assigned by your router if you’re not working on a dedicated network.

sudo nano /etc/dhcpcd.conf

Then add the following lines to the end of the file:

interface eth0
static ip_address=192.168.0.1/24

I used IP addresses 192.168.0.1, 192.168.0.2, 192.168.0.3 etc.

Then reboot your Pi’s and you should then be able to do the rest of the setup through Node 1.

We can now use the NMAP utility to see that all 8 nodes are online:

nmap 192.168.0.1-8
Using NMAP To See All Nodes Are Online

Overclock Each Node To 2.0 GHz

Next, we need to overclock each Pi to 2.0 GHz. I’ll do this from node 1 and SSH into each node to overclock it.

SSH into each Pi by entering into the terminal on Node1:

ssh pi@192.168.0.2

You’ll then be asked to enter your username and password for that node and you can then edit the config file by entering:

sudo nano /boot/config.txt

Find the line which says #uncomment to overclock the arm and then add/edit the following lines:

over_voltage=6
arm_freq=2000
OverClocking Each Pi In Cluster Through SSH

Reboot each node once you’ve edited and saved the file.

Create SSH Key Pairs So That You Don’t Need To Use Passwords

Next, we need to allow the Pis to communicate with the host without requiring a password. We do this by creating SSH keys for the host and each of the nodes and sharing the keys between them.

Let’s start by creating the key on the host by entering:

ssh-keygen -t rsa
Creating Host Node's SSH Key

Just hit ENTER or RETURN for each question, don’t change anything or create a passphrase.

Next, SSH into each node as done previously and enter the same line to create a key on each of the nodes:

ssh-keygen -t rsa
Creating Individual Node's Keys

Before you exit or disconnect from each node, copy the key which you’ve created to the master node, node 1:

ssh-copy-id 192.168.0.1

Finally, do the same on the master node, copying it’s key to each of the other nodes:

ssh-copy-id 192.168.0.2

You’ll obviously need to increment the last digit of the IP address and repeat this for each of your nodes so that the key is copied to all nodes.

This is only done in pairs between the host and each node, so the nodes aren’t able to communicate with each other, only with the host.

You should now be able to SSH into each Pi from node 1 without requiring a password.

ssh '192.168.0.2'

Install MPI (Message Passing Interface) On All Nodes In The Raspberry Pi Cluster

Next, we’re going to install MPI, which stands for Message Passing Interface, onto all of our nodes. This allows the Pis to delegate tasks amongst themselves and report the results back to the host.

Let’s start by installing MPI on the host node by entering:

sudo apt install mpich python3-mpi4py
Installing MPI On Host Node

Again use SSH to then install MPI onto each of the other nodes using the same script:

Installing MPI On Other Nodes In The Raspberry Pi Cluster

Once you’ve done this on all of your nodes, you can test that they’re all working and that MPI is running by trying the following:

mpiexec -n 8 --host 192.168.0.1,192.168.0.2,192.168.0.3,192.168.0.4,192.168.0.5,192.168.0.6,192.168.0.7,192.168.0.8 hostname

You should get a report back from each node with it’s hostname:

Check MPI Is Running On All Nodes

Copy The Prime Calculation Script To Each Node

The last thing to do is to copy the Python script to each of the Pis, so that they all know what they’re going to be doing.

Here is the script we’re going to be running on the cluster:

The easiest way to do this is with the following line:

scp ~/prime.py 192.168.0.2:

You’ll again obviously need to increment the IP address for each node, and the above assumes that the script prime.py is in the home directory.

You can check that this has worked by opening up an SSH connection on any node and trying:

mpiexec -n 1 python3 prime.py 1000

Once this is working, then we’re ready to try out our cluster test.

Testing The Raspberry Pi Cluster

We’ll start out with calculating the primes up to 10,000. So we’ll start a cluster operation with 8 nodes, list the node’s IP addresses and then tell the operation what script to run, in which application to run it and finally the limit to run the test up to:

mpiexec -n 8 --host 192.168.0.1,192.168.0.2,192.168.0.3,192.168.0.4,192.168.0.5,192.168.0.6,192.168.0.7,192.168.0.8 python3 prime.py 10000

The cluster was able to get through the first 10,000 in 0.65 seconds – faster than either of our computers. Which is quite surprising given that the system needs to manage communication to and from the nodes as well.

Here are the results for the test to 10,000, 100,000 and then to 200,000:

Pi Cluster Finding Primes Computing Test

The search to 200,000 took just 85 seconds, which is again a little over 3 times faster than the Windows PC and 4 times faster than the MacBook. It was also a just a little slower than 8 times faster than the individual Pi.

Here is a comparison of the combined results from all of the tests done:

Pi Cluster

Lastly, I just ran the simulation to 500,000 on the cluster to see how fast it would be.

Raspberry Pi Cluster Additional Test Up To 500000

That took 526 seconds, or a little under 9 minutes.

I plotted a trend and forecast the 500,000 times for the other tests so that you can see how they compare. I’ve converted all of these values to minutes to make them a bit more understandable.

Raspberry Pi Cluster Forecast

So our cluster was able to beat the PC and Mac quite significantly, which might be somewhat surprising, but that is the power of cluster computing. You can imagine that when running really large simulations, which often take a couple of days on a PC, being able to run the simulation just 2-3 times faster is a massive saving. A week-long simulation on the PC can be completed by the Pi Cluster in just two and a half days.

Now obviously we could cluster PCs as well to achieve better simulation times, but remember that each Pi node in this setup costs just $35, so you can build a pretty powerful computer for a few hundred dollars using Raspberry Pis. You’re also not limited to just 8 nodes, you could add another 8 nodes to this setup for around $400 and you’d have a cluster which performs 6 times faster than the PC.

Multi-Process Test Results

As mentioned in an earlier edit in the post, Adi Sieker put together a multi-process version of the script.

Here are the results of the tests done so far (I’ll keep adding to them as I complete them on each platform):

HP Laptop – Using 16 processes:

  • 10,000 – 0.9 s
  • 100,000 – 18.27 s
  • 200,000 – 66.99 s
  • 500,000 – 374.3 s (6 mins 15 s)

What About The Temperature Of The Loop?

I also checked the temperature of the master node, which is midway through the cooling loop (5th in the loop), to see how warm it was after the test:

Check CPU Temperature Afterwards

It was only around 8 degrees above room temperature after the test.

Next, I’m going to be doing a full thermal test on the Raspberry Pi Cluster to check how it performs under full load for a duration of time. So be sure to check back in a week or two or subscribe to my channel for updates on Youtube.

As mentioned earlier, feel free to download the script and try it out on your own computer and share your results with us in the comments section. We’d love to see how some other setups compare.

Making an Arduino Oplà IoT Weather Station with Cloud Dashboard

Today we’re going to be looking at using the Arduino Oplà IoT kit to make your own weather station which posts data to the cloud, which you can view on a dashboard on your computer, phone or tablet from anywhere in the world.

IoT Remote Trends

Towards the end of last year, Arduino launched their Oplà IoT kit. I did an unboxing and first impressions post which is linked here. I played around with programming the Arduino locally and using it to fetch information from the internet, but I didn’t get to try the Arduino IoT Cloud. So today we’re going to do just that.

Arduino Opla IoT Kit Unboxing

Here’s a video of the build, read on for the full write-up:

What You Need To Build Your IoT Weather Station

This project is primarily based on the Personal Weather Station project which is included in the kit, but we’ll also be making some improvements and enhancements to get a bit more out of it.

So we’ll just be using the components which are included in the Arduino Oplà IoT kit, you can get here:

  • Oplà IoT Kit From Arduino Store – Buy Here
  • Oplà IoT Kit From Amazon Store – Buy Here
Items Required To Build You Own IoT Weather Station

For this project, we’re going to be using the IoT Carrier board, the Arduino MKR1010 board, the plastic case and then the power cable, USB cable and three included screws.

Building The Weather Station

Arduino MKR1010 Wifi Board

The Arduino used in the IoT kit is the MKR1010 board, with onboard WiFi and Bluetooth connectivity. It plugs into the carrier board, takes readings from the sensors and then posts these to the cloud using its WiFi connection.

To get started, we’ll follow the project guide on the Oplà site.

Opla IoT Website, 8 Included Projects

As you can see, there are 8 included projects, we’re going to be running through the Personal Weather Station project.

Personal Weather Station Project

We’re going to be using the temperature and humidity sensor, the pressure sensor and the light sensor, which are all positioned at the bottom on the front of the carrier board. So we don’t need to add any external sensors or do any wiring.

Temperature & Humidity Sensors

Setting Our Arduino Up As An IoT Cloud Device

To start off, we need to set our Arduino MKR1010 board up as an IoT cloud device.

Plug MKR1010 Wifi Board Into Computer

To do this, we need to plug it into our computer and install the Arduino create plugin. This is a small plugin which runs in your system tray and allows the web interface to talk to the board. Once you’ve downloaded and installed the plugin, check that it is running in your system tray. If not, you’ll need to search for it and run it.

We then go across to devices on the IoT cloud page and set up an Arduino device.

Connect Your Arduino To The Cloud

This process is fairly well automated, it first detects your board, then uploads a generic sketch to the device which enables it to connect to the IoT cloud and be seen as an IoT device. It lastly runs through a verification process to test that it is working correctly.

Creating Our Weather Station “Thing”

Once we have our device set up, we can start creating our first “thing”, which will be our Weather Station.

Create Your First Thing

Thing’s are basically cloud-based applications which you can create using the Arduino IoT cloud platform – each project you create, which uses it’s own Arduino, is a new Thing.

Associate Your Device

When you first create a thing, you’ll need to assign a device to it, which will be our MKR1010 board which we set up previously.

Create Variables For Each Metric or Parameter

We then need to create variables for all of the metrics which we’d like to control over the cloud. This doesn’t need to be all of the variables you’re going to use in your sketch, just all of the ones which you want to be able to view or control over the cloud.

For our weather station, this is the temperature, pressure, humidity, light and a weather report string. For each variable, you’ll need to tell the system how often it should be updated and whether the cloud can just read the variable or read and write to the variable.

Configure Network Name & Password

Once all of your variables are created, the last thing to do is to put in your WiFi network name and password so that the board is able to connect to it.

Web Editor And Serial Monitor

In this same area, you’re able to edit the sketch and view the serial monitor, but we’re going to rather do this in the full online editor where we have a bit more space. Before we leave, we just need to rename the Thing so that our sketch is named appropriately in the editor, we’ll call ours “WeatherStation”.

Programming Our Weather Station

If you open up the web editor, you’ll see a basic generated sketch which looks similar to a typical Arduino sketch.

Web Editor Basic Sketch

The main difference is that the cloud connection code has been added to the setup function and the variables that we created earlier are already available to use, so you don’t need to re-add them to the code.

We’re going to remove the main portion of this code and replace it with the Personal Weather Station example code as a starting point.

Let’s have a quick look at what the code does.

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial);
 
  // Defined in thingProperties.h
  initProperties();
 
  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  //Get Cloud Info/errors , 0 (only errors) up to 4
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
 
  //Wait to get cloud connection to init the carrier
  while (ArduinoCloud.connected() != 1) {
    ArduinoCloud.update();
    delay(500);
  }
  delay(500);
  CARRIER_CASE = false;
  carrier.begin();
  carrier.display.setRotation(0);
  delay(1500);
}

In the setup function, we start the serial monitor, for debugging information, we then import our “thing” properties and establish a connection with the Cloud. Lastly, we create an object to control the carrier board.

You’ll notice that there is a property called Carrier_Case which is set to false. This sets different calibration setpoints for the capacitive buttons so that they’re able to be activated through the case when the carrier is in it. We’ll be using it out of the case for now.

void loop() {
  ArduinoCloud.update();
  carrier.Buttons.update();
 
  while(!carrier.Light.colorAvailable()) {
    delay(5);
  }
  int none;
  carrier.Light.readColor(none, none, none, light);
  
  temperature = carrier.Env.readTemperature();
  humidity = carrier.Env.readHumidity();
  pressure = carrier.Pressure.readPressure();
 
 
  if (carrier.Button0.onTouchDown()) {
    carrier.display.fillScreen(ST77XX_WHITE);
    carrier.display.setTextColor(ST77XX_RED);
    carrier.display.setTextSize(2);
 
    carrier.display.setCursor(30, 110);
    carrier.display.print("Temp: ");
    carrier.display.print(temperature);
    carrier.display.print(" C");
  }
 
  if (carrier.Button1.onTouchDown()) {
    carrier.display.fillScreen(ST77XX_WHITE);
    carrier.display.setTextColor(ST77XX_RED);
    carrier.display.setTextSize(2);
 
    carrier.display.setCursor(30, 110);
    carrier.display.print("Humi: ");
    carrier.display.print(humidity);
    carrier.display.print(" %");
  }
 
  if (carrier.Button2.onTouchDown()) {
    carrier.display.fillScreen(ST77XX_WHITE);
    carrier.display.setTextColor(ST77XX_RED);
    carrier.display.setTextSize(2);
 
    carrier.display.setCursor(30, 110);
    carrier.display.print("Light: ");
    carrier.display.print(light);
  }
 
  if (carrier.Button3.onTouchDown()) {
    carrier.display.fillScreen(ST77XX_WHITE);
    carrier.display.setTextColor(ST77XX_RED);
    carrier.display.setTextSize(2);
 
    carrier.display.setCursor(30, 110);
    carrier.display.print("Pressure: ");
    carrier.display.print(pressure);
    
  }
 
  if (humidity >= 60 && temperature >= 15) {
    weather_report = "It is very humid outside";
    
  }else if (temperature >= 15 && light >= 700) {
    weather_report = "Warm and sunny outside";
    
  }else if (temperature <= 16 && light >= 700) {
    weather_report = "A little cold, but sunny outside";
  }
 
}

In the loop function, we update the cloud variables, then get readings for the state of the buttons as well as readings from our sensors. We then check if any of the buttons have been pushed and if they have then we update the display accordingly. Lastly, we have some weather condition checks which generate a single line weather report if they’re met.

Upload Basic Sketch To Arduino

Let’s try upload this generic sketch to our board and see how it works.

Board Makes Ticking Noise When Uploading Sketch

When the board is mounted onto the carrier, it makes some ticking noise (which you can hear in the video) when the sketch is uploaded as the two relays are energised and de-energised.

Open Serial Montitor To View Data

Once the code is uploaded, we need to open the serial monitor to allow the board to run, as there was a “while loop” pause for this in the setup function.

We can then see the board connect to the WiFi and then establish a connection with the cloud.

Let’s have a look at what is displayed on the carrier’s display.

We saw from the code that we need to touch one of the first four buttons to get the display to change.

View Data On IoT Carrier Display

The first is temperature, then humidity, then light and then finally the pressure. The fifth button doesn’t do anything yet. Touching these four buttons reveals readings for each of the four variables we’ve set up.

Last Button Doesn't Do Anything

It looks like our Arduino is doing everything it should be and is connected to the cloud, so now let’s have a look at how we access the cloud data.

Creating A Cloud Dashboard For Our Weather Station

Now that we know that the board is connected to the cloud and should be posting data, we can create a dashboard to view the data over the internet.

Build A Dashboard

In the dashboard creator, we can create and arrange a number of displays, charts and buttons to view data from and interact with our Arduino.

Add Gauges and Dials For Each Metric

We’re going to start by adding a readout for each of our variables used in our IoT Weather Station. These will be a percentage readout for humidity, a gauge for temperature and then just a value readout for the pressure and the light level. We’ll also create a messenger to view our weather report information.

Add Graphs For Each Metric

Instead of just being able to see the current values of the variables, it would be nice to also be able to see the historic data. We’re going to do this by adding a chart for each variable as well. Adding a chart allows you to see data for the past hour, day, 7 days and 15 days all plotted onto a line graph.

Using The Dashboard

Once we’re done with creating the dashboard, we click on use dashboard to save the layout and start using it.

The data will continue to be logged on the cloud and you can access this dashboard through your browser from any computer.

Mobile Phone Remote App IoT Weather Station

There is also an IoT Remote app which you can load onto your phone or tablet to view your created dashboards.

IoT Remote Graph Trend

You can tap on the expand icon to open any of the charts in a landscape view to get better resolution.

It is quite interesting to play around with the sensors on your Arduino and see them respond on the cloud. Like covering up the light sensor.

Covering The Light Sensor
Covering The Light Sensor IoT Remote App

I put my finger over the light sensor and then watched the light level drop on my IoT Remote app, then removed it and watched it increase again.

Improving Our Weather Station

Now that we’ve got he basic IoT Weather Station up and running, let’s have a look at how we can improve upon it.

One limitation of the included sketch is that the data on the display is only updated each time the button is pushed. So if you leave it displaying the temperature, you just get a static readout and it doesn’t update the display until you press the temperature button again.

Keep Pressing Button To Update Display

The general layout and colours are also a bit boring, so we’re going to try to change those too.

Here is my final version of the code:

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/151ec4be-5c5f-47b2-9225-e383f05732e5 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  float humidity;
  float temperature;
  int light;
  float pressure;
  String weather_report;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/
	
#include "thingProperties.h"
#include <Arduino_MKRIoTCarrier.h>
MKRIoTCarrier carrier;

int modeSelect = 0;
int previousMode = 0;
int refreshCount = 0;
 
void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  //while (!Serial);
 
  // Defined in thingProperties.h
  initProperties();
 
  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  //Get Cloud Info/errors , 0 (only errors) up to 4
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
 
  //Wait to get cloud connection to init the carrier
  while (ArduinoCloud.connected() != 1) {
    ArduinoCloud.update();
    delay(500);
  }
  delay(500);
  CARRIER_CASE = true;
  carrier.begin();
  carrier.display.setRotation(0);
  carrier.display.fillScreen(ST77XX_BLACK);
  carrier.display.setTextColor(ST77XX_WHITE);
  carrier.display.setTextSize(3);

  carrier.display.setCursor(60, 80);
  carrier.display.print("Weather");
  carrier.display.setCursor(60, 120);
  carrier.display.print("Station");
  delay(2000);
  carrier.display.fillScreen(ST77XX_BLACK);
  carrier.display.setTextColor(ST77XX_WHITE);
  carrier.display.setTextSize(2);

  carrier.display.setCursor(70, 80);
  carrier.display.print("Connected");
  carrier.display.setCursor(50, 110);
  carrier.display.print("To IoT Cloud");
  delay(2000);
}
 
void loop() {
  ArduinoCloud.update();
  carrier.Buttons.update();
 
  while(!carrier.Light.colorAvailable()) {
    delay(5);
  }
  int none;
  carrier.Light.readColor(none, none, none, light);
  
  temperature = carrier.Env.readTemperature();
  humidity = carrier.Env.readHumidity();
  pressure = carrier.Pressure.readPressure();
  
  if(carrier.Button0.onTouchDown()) {
    modeSelect = 0;
  }
  else if(carrier.Button1.onTouchDown()) {
    modeSelect = 1;
  }
  else if(carrier.Button2.onTouchDown()) {
    modeSelect = 2;
  }
  else if(carrier.Button3.onTouchDown()) {
    modeSelect = 3;
  }
  else if(carrier.Button4.onTouchDown()) {
    modeSelect = 4;
  }
   
  if(modeSelect != previousMode) {
    updateDisplay();
    previousMode = modeSelect;
    refreshCount = 0;
  }
  else if (refreshCount >= 50) {
    updateDisplay();
    refreshCount = 0;
  }
 
  if (humidity >= 60 && temperature >= 15) {
    weather_report = "It is very humid outside";
  }
  else if (temperature >= 25 && light >= 700) {
    weather_report = "Hot and sunny outside";
  }
  else if (light <= 100) {
    weather_report = "It is dark outside";
  }
  else if (temperature >= 15 && light >= 700) {
    weather_report = "Warm and sunny outside";
  }
  else if (temperature <= 16 && light >= 700) {
    weather_report = "A little cold, but sunny outside";
  }
  else if (humidity >= 90 && temperature <= 15) {
    weather_report = "It is wet and rainy outside";
  }
  refreshCount++;
}

void updateDisplay () {
    if (modeSelect == 0) {
    carrier.display.fillScreen(ST77XX_RED);
    carrier.display.setTextColor(ST77XX_WHITE);
    carrier.display.setTextSize(4);

    carrier.display.setCursor(70, 50);
    carrier.display.print("Temp:");
    carrier.display.setCursor(40, 110);
    carrier.display.print(temperature);
    carrier.display.print(" C");
  }
  else if (modeSelect == 1) {
    carrier.display.fillScreen(ST77XX_BLUE);
    carrier.display.setTextColor(ST77XX_WHITE);
    carrier.display.setTextSize(4);

    carrier.display.setCursor(70, 50);
    carrier.display.print("Humi:");
    carrier.display.setCursor(40, 110);
    carrier.display.print(humidity);
    carrier.display.print(" %");
  }
  else if (modeSelect == 2) {
    carrier.display.fillScreen(ST77XX_GREEN);
    carrier.display.setTextColor(ST77XX_BLACK);
    carrier.display.setTextSize(4);

    carrier.display.setCursor(60, 60);
    carrier.display.print("Light:");
    carrier.display.setCursor(80, 120);
    carrier.display.print(light);
  }
  else if (modeSelect == 3) {
    carrier.display.fillScreen(ST77XX_CYAN);
    carrier.display.setTextColor(ST77XX_BLACK);
    carrier.display.setTextSize(4);

    carrier.display.setCursor(60, 60);
    carrier.display.print("Press:");
    carrier.display.setCursor(20, 110);
    carrier.display.print(pressure);
    carrier.display.print(" Pa");
  }
  else {
    carrier.display.fillScreen(ST77XX_BLACK);
  }
}

Let’s have a look at what I’ve changed.

I’ve started out by commenting out the serial monitor “while loop” as we now know that our board is connecting correctly and we don’t want to have to open up the serial monitor to get it to run, especially if it is powered by a battery.

I then added some splash screen text which is displayed on startup. This just says “Weather Station” and then “Connected To IoT Cloud” two seconds later.

In the loop function, I modified the code so that each button selects a display mode and the display is then updated in the background without having to press the button again. This means that pushing a button will change the current display, but otherwise, the display continues to be updated every 50 loop cycles. This relates to about every 3-4 seconds. If you update the display on every cycle then it slows the code down significantly and the display starts flickering.

I also added a few more weather reports based on some extra conditions.

I moved the display updates into their own function, which is called from the loop function, and then added some colour and changed the font size for each variable display. If we’ve got a colour display then we may as well use it!

Now let’s upload the new code and see how it looks.

The displays now look a bit more vibrant and they continue to refresh in the background, so you can mount the carrier onto a wall and have a function weather station display.

I also added some functionality to the last button, which now blacks out the display. This could be useful at night to make it less distracting and may use less power when running on a battery since this is an OLED display.

View IoT Weather Station With Remote App

You can now watch the display and the app update simultaneously.

Powering The Weather Station Using A Battery

The last thing I’m going to try is putting the IoT Weather Station into the case and powering it using a 18650 lithium-ion battery.

Add Power Jumper

For that, we need to add this little power lead between the board and the Arduino.

Installing Carrier Board Into Case

We can then screw the carrier into the case using the three included screws to hold it up against the front of the case.

Insert Battery Into IoT Carrier

Now let’s add the battery to power it on and close up the back cover.

One thing I would have liked on the carrier is a power switch. As soon as you put the battery into the carrier then the Arduino turns on and you can’t turn it off again without removing the back cover and removing the battery.

Complete Standalone Weather Station

We can now change the display by pressing on the cover above the buttons.

The capacitive touch buttons work really well without the case but are a little too sensitive when inside. It’s really easy to activate them by mistake when you’re handling the case or even hovering a finger near another of the buttons.

That’s it for our weather station. We now have a standalone device which is connected to our WiFi network and is continuously posting the data to the cloud, which we can then access on our computer or mobile devices.

Add Additional Sensors To Analogue Inputs Eventually

Next, I’d like to try adding a rain sensor and anemometer or wind direction indicator to the station using the analogue inputs. I’d need to also make some leads for these so that they can be placed outside.

Monitor The IoT Weather Station Remote Metrics

Let me know what you think of this IoT Weather Station in the comments section below. Have you built anything interesting with your Arduino Opla IoT Kit?

Building A Water Cooled Raspberry Pi 4 Cluster

A couple of weeks ago I built a single water cooled Raspberry Pi 4 just to see how well it would work. This was obviously crazy overkill for a single Raspberry Pi, but it isn’t actually why I bought the water cooling kit. I bought it along with 7 other Raspberry Pi 4Bs so that I could try building my own water cooled Raspberry Pi 4 Cluster.

Here’s my video of the build, read on for the write-up:

While water cooling a single Raspberry Pi doesn’t make too much sense, water cooling a whole cluster is a bit more practical. The whole system is cooled by a 120mm fan, which is significantly quieter than even a single small 40mm fan. The water cooling system, while expensive by itself, actually costs a bit less than some other cooling solutions, given that I’d have to buy 8 of them.

An Ice Tower is an effective cooling solution for an individual Pi, but they’re quite noisy, and at around $20 each, you’re looking at $160 just for cooling the cluster. The water cooling system was only around $85 for the whole kit, blocks, and additional tubing.

Ice Tower On Raspberry Pi

For those of you who don’t know what a Pi Cluster is, it’s essentially a set of two or more Raspberry Pi’s which are connected together on a local network and work together to perform computing tasks, by sharing the load.

Raspberry Pi Cluster

There is usually one Pi which is designated as the host or master node and it is in charge of breaking up the task into smaller tasks and sending these out to all of the nodes to work on. The master node then compiles all of the completed tasks back into a final result.

The Parts I Used To Build My Cluster

To build my cluster, I got together 8 Raspberry Pis, a network switch, a USB power supply, and then the water cooling kit, cooling blocks and a bunch of network cables, USB C cables, standoffs, and screws to put it all together.

I also used a 3mm MDF board and some wood sections I had lying around to make up the mounting board and frame.

Building The Raspberry Pi 4 Cluster

Making & Assembling the Cooling Block Brackets

I started off by making up the 8 acrylic brackets to hold the cooling blocks in position over each Pi’s CPU.

Liquid Cooled Raspberry Pi 4B

These are the same design as the one used previously for my single Raspberry Pi, but are now red to suit the cables and fan.

Laser Cutting Cooling Brackets
Water Cooling Block Bracket

Each bracket consists of two parts which are glued together to hold the cooling block in place.

Gluing Brackets Together
Water Cooling Blocks

I also had to include a spacer to lift the cooling block a bit higher off the CPU so that it clears the surrounding components, otherwise, I’d have to remove the display connector from all 8 Raspberry Pis. I used a bit of thermal paste between the blocks and the spacers.

Spacer Blocks Installed

The cooling blocks were then mounted onto the Raspberry Pis. I started by securing the Pi between some red aluminium standoffs, which would be used to mount the Pi onto the base, and some nylon standoffs for the cooling block to screw into.

Installing Standoffs On Each Pi

The bracket picks up on the hole on the standoffs and clamps the cooling block down onto the Pi’s CPU.

Cooling Block Mounted With Standoffs

I then repeated this 7 more times for the other Pis needed to build the 8 node Raspberry Pi 4 Cluster.

All 8 Raspberry Pi's Prepared With Cooling Blocks

Deciding on the Cluster Layout

The traditional way to build a cluster is to place standoffs onto each Pi and then mount them on top of each other to form a stack. This is the easiest and most compact way to assemble them, but doesn’t really work that well with my cooling block bracket and isn’t all that eye-catching.

Raspberry Pi Cluster

This got me thinking of a way to better layout the Raspberry Pi 4 Cluster so that the cooling water circuit was clearly visible and the cluster was both functional and eye-catching. It would be even better if it could be mounted onto a wall to form a hang-up feature.

I played around with a couple of layout options, considering the placement of the components to minimise cable and tube lengths and trying to maintain some symmetry to keep it looking neat.

Pi Cluster Layout Option 1
Pi Cluster Layout Option 2
Raspberry Pi 4 Cluster Chosen Layout Option

I settled for having four Pi’s on each side of the radiators, keeping the large fan as the focal point in the design. I’d then put the reservoir and pump underneath the radiator to circulate the water through the loop. The Ethernet switch would be positioned at the top of the cluster to feed the network cables down to each node.

Ethernet Patch Leads To Be Used

I’d be connecting the Pi’s to the switch using some red patch leads. I found some red 50cm low-profile leads which looked like they would work well for this application. The thinner leads meant that that excess cable could be coiled up a bit easier and the runs were really short, so conductivity wasn’t a big issue.

USB C Cables and Charging Hub

To power the Raspberry Pis, I bought a high power USB charging hub and some short USB C cables. The hub provides up to 60W, distributed over 6 ports. I couldn’t find a suitable 8 port one, so settled on splitting two of the ports into two.

I’d also have to keep an eye on the power consumption as the official power supply for the Pi 4B is a 3 amp, so a bit more than this hub could supply to each. But, I have also never seen one of my Pis run over 1 amp in practice, even under load. If need be then I could buy a second power supply down the line.

Positioning the Pis on the Back Board

Once I had my layout in mind, I started making the backboard. I positioned all of the major components onto a piece of 3mm MDF and then marked out where they would be placed and the holes needed to mount them.

Checking Clearances With Cables Installed

I checked the clearances required for the cables and then started planning the cooling water tube routing. It was at this point that I realised that having four Pi’s arranged in a square would result in an unnecessarily complex cooling water loop, and I switched to having the four Pi’s in a straight line on each side. With the four in a line, the tubing could just be looped from one to the next along each side.

Change Layout To Two Vertical Lines

I also had to make a decision on how best to run the cooling water loop. If I put each Pi in series then the first will be the coolest in the loop and each will get progressively warmer, with the last one running the warmest. If I put the Pi’s in parallel then they’ll all receive the same temperature water, but balancing the flow rates becomes a problem and it’s quite likely that one or two which are the furthest away would receive little to no flow through them. I decided that warm water was better than no water and I didn’t want to buy 8 valves to try and balance the flow rate between them, so I set out connecting them in series.

Add A Display To The Middle Of The Raspberry Pi 4 Cluster

I also had a gap at the top where there was a lot of spare space, so I decided to pull out an old touch panel which I had used on a previous project. Having a display for the master node meant that I would have a way to monitor the system and even display stats, graphs or diagnostics directly on the cluster.

I then marked out the positions for each of the components on the back board and their mounting holes.

Marking Out Layout On The MDF

Making the Back Board

I decided to cut the corners off of the back board to give it a bit more of an interesting shape. I used a Dremel to cut the board to size, cut the corners off and cut a section out of the middle for the airflow through the radiator.

Use Dremel To Cut The Board
MDF Cutouts Made

To mount the Raspberry Pi’s onto the board, I decided to design and laser cut a small acrylic base to add a red accent and guide the power cable through to the back.

Designed And Cutout Bases For Pi's

Each base consists of a red bottom layer and a black top layer, which were glued together with some acrylic cement.

Glued Bases Together

I also designed a couple of cable and tube management stands to help with the routing of the cables and the tubes.

Cut Out Some Cable And Tube Mounts

I then checked all of the positions of the mounting holes and drilled them out.

Drilled Holes For Mounting Components

I decided to add some wooden sections to the back of the board to stiffen it and to create an area behind the board for cable management and the power supply. I used a spare section 0f 40mm x 20mm pine which I cut into three sections.

Glue Wood Strips Onto Back Of Cluster Board

I made holes underneath the acrylic bases for the USB cables to run through. These aligned with the large hole in the acrylic bases.

Cut Holes For Cabling

To complete the back board, I sprayed the front and back of the board black.

Spraying The Back Board Black

Assembling the Raspberry Pi 4 Cluster Components onto the Back Board

I then mounted the Pis, the network switch and cooling water components onto the back board.

Mounting The Raspberry Pi 4Bs

Each Pi was secured using four M3 x 8mm button head screws, which screwed into the aluminium standoffs.

Pis Secured With Button Head Screws

The cooling water components were mounted with the fasteners which came in the kit.

Mounted Switch And Cooling Water Components

I then cut the cooling water tube to the correct lengths and pushed them onto the fittings.

Cut Water Cooling Tubing Runs
Installed Water Cooling Tubing

I could then start adding the Ethernet and power cables. I started by plugging a USB C cable into each Pi and routing these to the back of the board, where I mounted the USB hub.

Feed Cables Through To Back Of Pi

I then added an Ethernet cable to each Pi, routing these up each side and into the cutout which would be behind the display, before bringing them back out to the front of the board and up to the switch. This meant that the excess cabling could be coiled up behind the board, out of ordinary sight.

Plugging In Network Cables on the Raspberry Pi 4 Cluster

I used the acrylic stand which I had cut out to hold and guide the Ethernet cables.

Use Stands To Secure Network Cables

The last thing to add was the display, which I mounted on an acrylic face panel with some acrylic side supports to hold it in place.

Mounted Touch Screen Display

You’ll notice that I had to mount the master node a bit lower than the others so that I could get the HDMI cable in without clashing with the Pi next to it.

Cable Routing On The Back Of The Cluster

I tied up all of the cables at the back of the cluster using some cable ties and some cable holders which I cut from acrylic and glued into place. The cabling at the back isn’t particularly neat, but it would be out of sight in any case.

I also made up a connector to take the 12V supply from the switch and split it off to power the 120mm fan and cooling water pump. They only draw around 150mA together while running, so there was some extra capacity in the power supply.

RGB Strip For Back Accent Colour

As a final touch, I added an RGB LED strip to the back to create some accent lighting on the wall behind it. The strip has an RGB remote control with a number of colours and features, but I was only going to be using the red LEDs.

Radiator and Fan Components on the Raspberry Pi 4 Cluster

Filling The Cooling Water Loop Up

With all that done, I just need to fill the cooling water circuit and hope that I didn’t drown one of the Pis. I had visions of filling it up and having water pour all over one of the new Pis.

I obviously kept everything turned off while filling the reservoir, although I did flick the pump and fan on twice to circulate the water a bit so that I could re-fill the reservoir.

I turned the cluster onto its side to fill it so that the reservoir was upright.

Filling Water Reservoir on the Raspberry Pi 4 Cluster

Luckily there were no major leaks!

There was one minor slow leak on the inlet to the first cooling block, probably because of the twist and pressure on the tube to get to the radiator. I clamped the tube with a small cable tie and the leak stopped.

All the cooling water loop needed now was some colour.

Adding Some Colour To The Cooling Water

Preparing Raspberry Pi OS On The Pis

I prepared a copy of Raspberry Pi OS Lite on 7 microSD cards and a copy of Raspberry Pi OS on the 8th for the master node which has the display attached.

Burned Pi Os Images To SD Cards

I could then power on the cluster and check that they all boot up. This was done primarily to check that all of the Pis booted up correctly, were able to run on the single power supply and were all recognised and accessible over the network.

I’m not going to get into the software side of the cluster in this post as there are a number of options, depending on what you’d like to do with it and how experienced you are with network computing, but I’ll be covering that in a future post, so make sure that you sign up to my newsletter or subscribe to my Youtube channel to follow my projects.

Running The Completed Water Cooled Raspberry Pi 4 Cluster

With all of the SD cards inserted and the water cooling circuit surviving a 10 minute run with no leaks, I powered up the USB hub to supply power to the Pis.

Raspberry Pi 4 Cluster System Running And Booted Up

The system was initially quite noisy as the air bubbles worked their way out of the radiator and cooling water loop, but it eventually settled down. You can hear an audio clip of the cluster running in the video at the beginning of the post.

Raspberry Pi 4 Cluster Running

The display is also a nice way to run scripts and visualise information or performance stats for the cluster.

Running Scripts On Touch Screen

Here I’m just running the script I used previously to display the CPU temperature of the Pi.

Stats Display on Raspberry Pi 4 Cluster

Have a look at my follow-up post in which I set up the cluster to find prime numbers and compare its performance to my computers.

I hope you’ve enjoyed following this Raspberry Pi 4 Cluster build with me, please share this post with a friend if you did and leave a comment to let me know what you liked or disliked about the build.

Arduino Oplà IoT Kit – Unboxing And First Impressions

Today I’m going to be taking a look at the new Oplà IoT kit from Arduino, which they’ve kindly sent across for me to unbox and share with you.

Thank you to Arduino for making this post and video possible!

The kit was launched in early November, so just in time to find it under the tree for Christmas 2020.

Where To Get An Arduino Oplà Iot Kit?

The kit sells for $114 from the official Arduino online store. I’ve put links to the Arduino store product page and to the kit on Amazon below. It is quite expensive, but it also comes with a lot of functionality on the IoT carrier board and a lot of potential for building more complex IoT projects once you’ve worked your way through the included ones.

Purchase Links

  • Oplà IoT Kit From Arduino Store – Buy Here
  • Oplà IoT Kit From Amazon Store – Buy Here

What’s On The Box?

Let’s start by taking a look at what the box looks like and what’s on the outside.

The box is quite large and prominently features the MKR IoT Carrier board on the front. There are also a couple of graphics around the carrier depicting the included projects and a bright orange feature disc highlighting the included 12 month Create Maker Plan Subscription.

Arduino Opla IoT Kit Box

On the back of the box, we’ve got a description of the included components and details of the included projects.

Included In The Kit

From the list on the box, the kit includes a MKR IoT carrier, which is the big round board featured prominently on the front, as well as the Arduino MKR WiFi 1010 board, cables for the sensors and battery, a motion sensor, a moisture sensor, a plastic enclosure and a USB cable.

Opla IoT Kit Projects

Using the included components and their instructions, you can build 8 projects, which all make use of the Internet in some way.

Some of these projects are more common, like the Smart Garden and Personal Weather Station and there are also some unique ones like the Solar System Tracker and the Thinking About You project.

Unboxing The Arduino Oplà IoT Kit

Now that we’ve taken a look at what’s on the outside, let’s get the box open and see what is inside.

Unboxing The Opla IoT Kit

The outside of the box is a slip-on cover which is held in place with a clear, round sticker on each end.

Opla IoT Box Open

With the slip-on cover removed, you’re immediately presented with the MKR IoT carrier board, as well as an introduction to the kit and instructions on where to get started.

You also get a code to activate your 12 month Create Maker Plan.

MKR IoT Carrier

The carrier board is the heart of this kit, and although the MKR WiFi 1010 board is the brains behind the kit, this carrier is the device you connect all of the sensors and IO devices to and what you use to control and interact with the Arduino.

You then lift the side panel which the IoT carrier is mounted onto to find the rest of the components behind it.

Open Cover To Reveal Back Contents

So, in the back of the box we’ve got the Arduino, the plastic enclosure, the sensors and the cables.

Taking A Closer Look At The Oplà IoT Kit Components

Now that we’ve got the box open, lets get the components out and take a closer look at each of them. We’ll start with the MKR IoT Carrier on the front of the flip-out section.

MKR IoT Carrier Board

On the carrier we’ve got a large round OLED display in the middle surrounded by 5 RGB LEDS and 5 captive touch sensors.

RGB LEDs and Capacitive Touch Sensors

We’ve also got some smaller sensors along the bottom edge, which are each labelled with a graphic.

Sensors On Bottom

These look like a humidity sensor, light sensor, and then the IMU or motion sensor. There are also another two small LEDs below the sensors.

Plugs or Ports For Sensors

On the back, we’ve got some sockets for external sensors. These include two analogue inputs and an I2C port. The plug on the right side is for the battery cable connector.

Relay Modules

We’ve got two relay outputs, which can be used to drive things like lights and pumps or switch appliances on and off. The relays are on one side of the carrier and the ports for the connections to the relays on the other.

Back Of MKR IoT Carrier

We have also got the socket for the Arduino, and then an SD card slot, and a battery holder.

The carrier takes an 18650 lithium ion battery, which from the box sounds like it can be charged by the carrier board.

I like that they’ve included the battery holder to enable the board and enclosure to be completely standalone, without needing a power supply. I’ll probably test out the battery life at some stage as I’ve always found WiFi-connected controllers to be quite power-hungry.

Plastic Enclosure

We’ve then got the plastic enclosure.  The plastic is frosted over, but you can still see into it to see the buttons and display. It feels like it’s well built and good quality plastic, like it would hold up fine if it were dropped or bumped around.

Screw Holes On Back Of Enclosure

The back cover looks like it just snaps into place and has two screw holes to mount it onto a wall.

Arduino MKR WiFi 1010 Board

We’ve then got the Arduino MKR WiFi 1010 board, which Arduino says is the easiest point of entry to basic IoT and pico-network application design.

ATSAMD21 Chip on MKR WiFi 1010

The chip on the board is a low power Arm Cortex-MO 32-bit SAMD21 processor and it has both Bluetooth and WiFi connectivity, which is powered by the onboard Nina-W10.

Arduino MKR WiFi 1010

The board has 8 digital IO pins, 13 PWM pins, 7 analogue input pins, a 10 bit analogue output pin as well as UART, SPI and I2C interfaces, so it really is a powerful board with a lot of features.

PIR Motion Sensor

We’ve got a motion sensor.

Capacitive Moisture Sensor

A captive moisture sensor, which I prefer over the resistive moisture sensors which are often supplied.

Cables & Screws

And then also the cables and some small screws, which I assume are to mount the carrier to the case.

Getting Started With The Oplà IoT Kit

Website To Get Started

The front panel inside the box said we should head over to opla.arduino.cc to get started, so let’s have a look at what is there.

Opla IoT Kit Website

The Opla IoT homepage lists the 8 included projects.

Project Page For Each Project

Each project page includes instructions that detail which components are used, as well as how to assemble, program and use the Arduino and carrier to complete the project.

There are also two getting started guides.

Getting To Know The Carrier

The first, called Getting To Know The Carrier, shows you how to use and program the MKR IoT Carrier

Getting To Know The Cloud

The second, called Getting To Know The Cloud, details how to use the cloud functionality, including programming the Arduino and then creating and using web-based Dashboards.

There are essentially two different ways to use this kit, the first is to upload your project directly to the Arduino and use it in conjunction with the carrier, and the second is to load a generic cloud application onto the Arduino and connect to it using Arduino’s cloud server and web-application. This enables you to create dashboards to view information and control and monitor the sensors and relays remotely.

Arduino Maker Plan

Included with the kit is a 12-month maker plan, which gives you access to Arduino’s web-based toolkit, enabling you to create, store and compile sketches online as well as store data from your cloud-connected Arduino boards. They’ve also got an Android and iOS mobile app that allows you to view and control your Arduino from your mobile phone or tablet.

Plug The Arduino Onto The Carrier

Let’s put the Arduino onto the IoT carrier and try out the introductory sketch.

Plug The USB Cable In

The Arduino plugs into the back of the IoT carrier and you still program the Arduino by plugging the included USB cable directly into the Arduino’s USB port.

Uploading The Example Sketch To The Arduino

I then used the online IDE to compile and upload the OplaIoTExample code, which displays a basic temperature and humidity readout on the OLED display.

You’ll need to install the Arduino Create Plugin on your computer to allow the web application to communicate with your Arduino, but this was quick and easy to do and the application picked up my board right away.

I uploaded the code and was able to then see the temperature and humidity data being displayed on the Serial monitor.

IoT Example Project Temperature

The carrier now also displayed the temperature in red and I was able to change between the temperature and humidity displays by simply touching the two sensors buttons, 00 and 01, alongside the display.

Humidity Opla Iot Example

First Impressions of the Oplà IoT Kit

As with other genuine Arduino products, the IoT carrier board feels like it’s good quality and well built. I’ve had my original Arduino Uno for over 8 years now, I’ve built hundreds of projects on it and it’s still going strong.

The carrier and MKR WiFi 1010 board look and feel modern. The round colour OLED display at the centre looks great and gives you loads of options for creating feedback displays and menus for the surrounding touch sensors. The touch sensors are also a welcome addition and add to the modern and unique look of the carrier.

I like that they’ve included the enclosure as a way to make your projects look more complete without having to buy or 3d print a case. The case reminds me of the Nest Thermostat, and wouldn’t look out of place on a wall in your home as an IoT hub for your latest project.

Overall, I really like that Arduino has taken another step towards building a cloud-based system. There are already loads of projects and platforms out there to create IoT devices. But without a dedicated server to host the cloud services, you’re left with only having local network control or having to try and get your own static IP address and configure port forwarding on your router to access your device over the internet. This makes it significantly more complicated, and less secure than this solution.

Trying Out An Example IoT Project

Look out for my next Oplà IoT post where I’m going to try building one of the included projects.

What do you think of the Arduino Oplà IoT Kit? Do you have one already or are you going to be getting one? Let me know in the comments section.

Micro:bit Automatic Plant Watering System

In this guide, I’m going to be showing you how to build an automatic plant watering system using a Micro:bit and some other small electronic components. The Micro:bit monitors the moisture content of your plant’s soil using a sensor and then switches on a pump to water it once it gets too dry. This way, your plant is always looked after, even when you’ve forgotten about it or you’re away.

If you like this project, then you might also want to have a look at my smart indoor plant monitoring base, which is made using an Arduino.

Here’s a video of the build and the Micro:bit watering the plant, read on for the full step by step instructions:

What You Need To Build Your Micro:bit Plant Watering System

What You Need To Make A Microbit Plant Waterer

I’ve used the MicroBit version 2, but this project can be made using the first version as well.

How To Build Your Micro:bit Plant Watering System

MicroBit is a small, programmable microcontroller, which has a number of onboard sensors and buttons, making getting started with programming really easy.

It supports the use of block coding for children and less experienced programmers, and JavaScript or Python for those more experienced with programming and want to access additional functionaliy. It also has a range of IO pins available for sensors and devices along it’s bottom edge.

Capacitive Soil Moisture Sensor

The capacitive moisture sensor that I’m using runs on 3.3V, which is perfect to be used directly with the MicroBit.

Note: These capacitive sensors generally state that they operate between 3.3V and 5V, and output a maximum of 3.3V as they have an onboard voltage regulator. I’ve found that a lot of the cheaper versions of these sensors don’t actually work with an input voltage of 3.3V, but require 3.5-4V before they actually “switch on”. You’ll need to be careful with this as the Micro:bit is only designed for an input voltage of up to 3.3V.

Pump And Relay Module

The pump will need to be turned on and off using a relay module. The relay module switches power to the pump so that current isn’t flowing through the MicroBit.

Designing The Circuit & Block Code

I’ve designed the circuit and did the block coding in TinkerCAD, since they’ve recently added the MicroBit to their platform.  Block coding is a really easy way to build basic programs by just dragging and dropping function blocks.

I Designed The Circuit and Code In TinkerCAD

I represented the pump with a DC motor and simulated the input from the moisture sensor using a potentiometer as this has the same three connections as the moisture sensor.

Programming Can Also Be Done On The Micro:bit.org Website

Here is a version of the code from the MicroBit editor.

You can also use the online MicroBit editor on the official MicroBit website if you’d like. This version has a bit more functionality on the block coding side but is more limited in what you can do with circuit design.

My final version of the block code shows a smiley face when it’s turned on then starts taking moisture readings every 5 seconds and plotting them on the graph on the display. It also checks whether the level is below the set limit, and if it is, then it turns on the pump for 3 seconds.

I also added functions to the two buttons where button A turns the pump on for 3 seconds to manually water the plant and button B shows the raw moisture level reading taken from the sensor so that you can easily establish your setpoint level.

Micro:bit Plant Waterer Test Setup On Desk

Once I had designed and simulated the program, I connected the components using alligator leads to test that it all worked correctly on my desk. This was to check that the input from the moisture sensor was being read correctly and that the relay switched on and off.

Building The Components Into The Housing

Once I was happy with the test setup, I got to work on building the components into a suitable housing and doing the permanent electrical connections.

Two Food Containers For Food And Storage

I found these two containers in a local discount store. They stack together so that I could use the bottom one as a tank and the top one to house the electronics. I couldn’t find the exact ones I used on Amazon, but I’ve linked to a similarly sized set with a hinged lid which should work just as well.

Building The Water Tank

I started by building the tank.

Mount The Pump With Inlet Near Bottom

I needed to mount the pump into the tank with the water inlet as close to the bottom as possible, making sure that there was still enough space for the water to flow. I just glued the pump in place using a glue gun.

Drill Holes For The Cable & Tube

I then drilled holes for the wires to the motor and the tube for the water outlet.

Completed Water Tank

Now that the tank is complete, we can start with the electronics housing.

Assembling The Electronics Housing

I wanted the MicroBit to be mounted onto the front of the housing so that it’s easy to see as I’m using the LED display on the front as a graph of the water level.

Drill Holes For The Microbit And Electronics

So I drilled three 4mm holes through the front to hold the MicroBit and act as the connections to the IO pins which go through to the wiring on the inside of the case. I also drilled an additional hole above the Micro:bit for the power lead.

I then drilled holes for the power socket at the back and for the pump and moisture sensor wiring.

Use Screws To Mount The Microbit Onto The Tank

I used a long M3 x 20mm button head screw on each of the 3 pins I needed to connect to, Pin 0, Pin 2 and GND. I connected the wiring to the back of these screws by wrapping the exposed wire around the threads and then using some heat shrink tube to hold it in place.

Solder Electronics Together

I then added all of the wiring and connected the components together inside the housing using the same layout as I had tested on my desk.

Connect All Components Together

Using The Micro:bit Automatic Plant Watering System

Now that the plant watering system is assembled, we can fill the tank with water and try it out.

Fill Tank With Water

With the sensor out of the soil, it immediately sensed that the “soil” was dry and turned the pump on, so it looks like it’s all working correctly.

Test Micro:bit Setup With No Soil

I then pushed the sensor into the soil on one of my indoor plants and positioned the water tube over the soil before switching it back on again.

Sensor In Pot
Complete Setup With Plant
The Graph On The Front of the Micro:bit Shows The Moisture Level

The graph on the front shows the moisture level which has been measured by the sensor as the soil dries out.

When Soil Dries Out, The Pump Comes On

When it gets below the threshold set in the code, the pump comes on automatically in 3-second intervals, waiting for 5 seconds between each pumping cycle, until the moisture level goes above the threshold again.

The Pump Can Also Be Turned On By Pushing Button A

You can also press Button A on the front of the MicroBit to turn the pump on for 3 seconds and water the plant manually.

Pumping Water To Plant

You could use chain multiple MicroBits together using their radio link to view your plant’s moisture level from a different room or even water them remotely. This would be great if you had a couple of plants being cared for using Micro:bits, and you wanted a single one to act as a dashboard in a central location.

Micro:bit Looking After Plant

Have you used a MicroBit for one of your projects? Let me know what you built in the comments section.

The Magic of Tidying Up: Liberating Cleaning Methods That Really Work

Everyone loves a neat and clean home. However, a long list of daily obligations doesn’t leave you with enough time to tidy up, which can lead to stress. Here are some liberating cleaning methods to work their magic for multitasking persons and busy parents.

Use alcohol for chair stains

Many chairs are now made with microfiber upholstery, which makes them harder to clean. Rub the stain with alcohol and wipe with a clean sponge. Alcohol won’t leave a mark because it evaporates faster than water. You don’t have to worry about alcohol fading your fabric either. Make a mixture of one part dishwashing liquid and two parts hydrogen peroxide, spray it on the stain, rub it in, let stand and wash.

Baking soda is good for trash odors

Sprinkle baking soda at the bottom of a trashcan to keep the unpleasant odors away. This is particularly helpful if you have cans in a hot garage or porch. If you’re using trash bags, roll up an old newspaper and put it in the bottom of the bag. The papers will absorb the odor and prevent unwanted leakage from the discarded products in the bag.

Baking soda is good for trash odors

Keep sinks and stove clean

Dirty sinks, stovetops, or counters are signs of a messy home. Make a habit of wiping down the surface you’ve just used. It takes only a few seconds to wipe down the used area, and it will stay clean and disinfected, ready for the next use. Additionally, if you don’t clean the surfaces regularly, grease and grime will build up over time and make it harder to restore their original shine, but any quality polish will keep those kinds of surfaces neat and clean.

Don’t neglect glass surfaces

Sometimes, it’s easy to neglect your windows, mirrors, or any other glass surface, especially if you don’t have kids and pets to make it dirty with their little fingers or paws. You can use traditional window cleaning products, but if you notice that there’s no change, then you can opt for a water-based hydrophobic glass coating that can repel dirt by using water that picks up the dirt and make it easier for you to remove it. That way your windows and glassy decor will stay cleaner for much longer, which will make your home look and feel more pleasant. Also, such coating products can also be used in your car and other glass surfaces in your home.

Don’t neglect glass surfaces

Cleaning your blinds with a pair of socks

Dust can accumulate on your blinds. This may not have occurred to you, but a pair of old socks can help you clean your blinds. Mix equal amounts of water and vinegar in a bowl, put a sock over one hand, dip it into the mixture and go over the blinds. Use the other sock to wipe away the dampness.

Lemon helps in cleaning microwaves

If your children made a mess in the microwave while trying to reheat leftovers from dinner, a lemon can save the day. Slice the lemon into a bowl of water and put it in the microwave on high for 3 minutes. Keep it in the microwave for 3 more minutes and then just wipe out the inside of it. No tough cleaning required. If you want to get rid of odor quickly, place a bowl of white vinegar inside the microwave, shut the door, and keep it there for an hour.

A bathroom with essential oils

Keeping your bathroom fresh can be a real challenge, particularly during the summer months, when your house is cramped with guests and your children’s friends. A great trick you can use is to add a few drops of your favorite essential oil to the inner roll core of your toilet paper. Every time the roll is used, a pleasant smell will be released.

Get rid of old clothes

If you’re wondering which pieces of clothes to retain, simply apply the old rule: If you haven’t worn it in a year, dump it. Avoid cluttering your closet with old stuff you hardly ever wear. Instead, treat yourself with something new. If an old item goes out, a new one can take its place, but be careful not to get overwhelmed with new pieces without dismissing the old ones.

Get rid of old clothes

Keep your garage neat

Check the state of your garage every six months and get rid of anything you don’t need. You can have plenty of things, like old bookshelves and rugs, that only take up space in your garage. It’s a good idea to have labeled bins for different stuff. This will make finding things much easier.

Balancing work and home is challenging and we need all the help we can get. Use these tips to make your home fresh again, stress-free.

Thermal Test On Raspberry Pi Cooling Options – Is Water Cooling Worth It?

Last week, I put together a water-cooled Raspberry Pi 4 and overclocked it to 2.0Ghz to see how well the cooling system would work. It was really effective and only saw a couple of degrees increase in temperature when running at full CPU load for 5 minutes, even when overclocked.

This sounds good, but the PC water cooling system used on the Pi costs a couple of times more than the Pi does, and uses more power than the Pi to run too. So I wanted to have a look at whether some other options could be more cost-effective, and how well they work to keep the Pi cool in comparison.

I got together a couple of common Raspberry Pi cooling options, and I’m going to be comparing the running temperature and cost for each of them. We’ll be looking at just putting aluminium heat sinks onto the Pi, then using the heat sinks in conjunction with a fan in a compact case, then a more significant fan and heatsink combination called an Ice Tower, and finally the water cooling system.

Here’s a video of the tests and results, read on for the written guide:

Purchase Links For The Raspberry Pi Cooling Solutions

Note: Some of the above parts are affiliate links. By purchasing products through the above links, you’ll be supporting this site, with no additional cost to you.

Testing The Raspberry Pi Cooling Options

For each cooling option, I’ll start by running the CPU at full load at the default clock frequency of 1.5Ghz, and then we’ll do a second test with the Pi overclocked to 2.0Ghz. I’ll record the CPU temperature at 1-second intervals and plot these onto a graph for each.

I’ll collect the data like this:

Case 1.5Ghz

The Raspberry Pi 4 allows the CPU temperature to go up to 80°C before it starts throttling the CPU performance to lower the temperature and prevent the CPU from burning out.

From the test results, it looks like mine starts throttling the CPU around 83 or 84 degrees, but we’ll work on 80 as the documented limit.

Raspberry Pi Cooling Temperature Limit 80 Degrees

So if any of the cooling options exceed 80 degrees then you’re going to start getting limited performance from the Pi, and you’ll probably reduce its life by running it this hot for extended periods of time.

It’s also worth remembering that this test just runs the CPU at maximum load indefinitely. This represents a worst case scenario. In practice, your Pi will likely only use a fraction of the CPU capacity for most of its running time, obviously depending on your application and usage.

Testing The Aluminium Heat Sinks

Let’s start out with the plain aluminium heat sinks.

Aluminium Heatsinks Only Raspberry Pi

This is by far the cheapest option, you can usually get a set of these for around $1 – $2. They have a peel-off back and you just stick them onto the heat-generating components on the Pi.

Raspberry Pi Cooling Aluminium Heatsinks Running

The benefit of the heat sink only option is that it is completely silent, so if you’ve got a low-intensity application for your Pi then this might be a good option.

Let’s see how well they do in the thermal tests. We’ll start off at 1.5 Ghz.

Heatsink Only 1.5 Ghz

Right off the mark, before even starting the test, the Pi is already running quite warm. We’ve got a starting temperature of around 51 degrees.

Heatsink Only 1.5 Ghz With Notes

It took around a minute and forty seconds before the CPU was at 80 degrees and the performance started getting throttled.

There isn’t much point in continuing the test once we’ve hit 80 degrees as we’re then losing CPU performance and the temperature will just stay around 80 degrees as the Pi manages the CPU load.

So, I stopped the test and you can see that the temperature initially dropped off quite quickly, but flattened out after another minute or so to around 65 degrees. So it would take a long time to get back down to the 50 degree starting temperature.

Next I increased the clock frequency to 2.0Ghz.

Heatsink Only 2.0 Ghz

Running at 2.0 Ghz, we had a starting temperature of around 61 degrees at idle, which is already pretty high. It only took about 10 seconds to reach 80 degrees once the test was started.

Heatsink Only 2.0 Ghz With Notes

You can also clearly see the Pi throttling the CPU performance on this graph.

The cool down curve after the test is quite similar to the 1.5 Ghz test, flattening out at a slightly higher temperature than at the start of the test.

Heatsink Only Comparison

Here are the two heat sink only graphs plotted together. You can see how much faster the 2.0Ghz test increased the CPU temperature, it’s basically unusable without any active cooling.

Testing The Fan Case

Next let’s move on to the fan case.

I typically enjoy making my own cases for Raspberry Pi’s, but I had this one from an earlier version Pi lying around, so I just opened up the cutouts for the HDMI ports on the side to make it fit.

Raspberry Pi Cooling Fan Case

The fan and CPU are in the same place, so the fan is blowing down directly onto the CPU heat sink. These acrylic cases with fans as also quite a cheap option and usually range between $5 and $10 for a case, including the fan and heat sinks.

Raspberry Pi Cooling Acrylic Case Running

These small fans are quite noisy, so it can be distracting if you’re just using your Pi as a desktop computer or you use it as a media player on your TV. Have a listen to the sound it makes in the video at the beginning of this post.

Let’s see how effective the fan is at keeping the CPU cool.

Fan Case 1.5 Ghz

The fan has already helped reduce the starting temperature to a lower, 46 degrees. I was then able to run the test for a full three and a half minutes without the Pi overheating. The temperature seems to stabilise around 65 degrees. The temperature also drops off much faster now once the test is stopped.

So you can comfortably use your Pi at any CPU load in a fan case at 1.5 Ghz.

Now let’s try overclocking it to 2.0 Ghz and see if the temperature still stays under 80 degrees.

Fan Case 2.0 Ghz

The idle temperature at 2.0 Ghz increase a little, to 50 degrees and unfortunately we weren’t able to complete the test at 2.0 Ghz.

Fan Case 2.0 Ghz With Notes

The Pi overheated a little over a minute into the test and started throttling the CPU performance. There was still a sharp drop in temperature once the test stopped, so the case fan helps quite a bit, but is not an effective option if you’re going to be overclocking your Pi.

Here is a comparison between the two tests with the fan case.

Fan Case Comparison

Testing The Ice Tower

Now lets have a look at the Ice Tower.

Raspberry Pi Cooling Ice Tower

This has become a popular option for Raspberry Pi cooling, and they make a low profile version now too. They also quite affordable, costing around $20 to $25. The Ice Tower has a much bigger heatsink with heat pipes to a large radiator with a significantly larger fan than the case.

Ice Tower Running On Pi 4

The Ice Tower is also quite loud, its about the same sound level as the case fan, so let’s see if it does better in the thermal test.

Ice Tower 1.5 Ghz

Our starting temperature is now lower than with the case, at just 41 degrees and I was able to run the test for the full three minutes and it only went slightly over 50 degrees. This is more than a 10 degree difference over the fan case. You can also see that the temperature returns to almost the same as the idle temperature just 20 seconds after the test is stopped, which is the quickest so far.

The Ice Tower is looking promising for overclocking, so lets try taking it up to 2.0 ghz.

Ice Tower 2.0 Ghz

There wasn’t much difference between the idea temperature at 1.5 Ghz and at 2.0 Ghz, at 2.0 Ghz we again started around 41 degrees.

The Ice Tower managed the full run of 3 minutes without going much over 60 degrees, but it looked like it was still steadily increasing. So I left it running for a further 2 minutes to see how it went and it started flattening out at about 65 degrees.

Ice Tower Comparison

So an Ice Tower is a great option for Raspberry Pi cooling, even when overclocked. It is quite a lot more than the previous two options and you’ll still need to get a case or cover for your Pi, but there are a few options available with a cutout specifically for the Ice Tower.

Testing The Water Cooled Pi

Now let’s look at the final option, the water cooling system which I built for mine.

Raspberry Pi Cooling Desktop Setup

This setup is by far the largest and the most expensive. The cooling system cost around $100 for all of the parts to assemble it and this was using a cheap non-name brand kit, which is definitely not the best quality.

Raspberry Pi 4 Liquid Cooling

One benefit of this setup is that it is much quieter than the fan case or the Ice Tower, as the larger 120mm fan turns much slower.

Let’s see how the water cooled setup does in the thermal test.

Water Cooling 1.5 Ghz

Starting with the 1.5 Ghz test, the idle temperature is now just 28 degrees, which is over 10 degrees lower than the Ice Tower and 20 degrees lower than the heat sink option.

There was a noticeable spike in temperature when the test started, but it remains fairly constant at around 32 degrees for the three and a half minutes of the test. It also dropped back down to the starting temperature almost instantly when the test was stopped.

Now let’s try overclocking it to 2.0 Ghz.

Water Cooling 2.0 Ghz

At 2.0 Ghz, we have the same starting temperature of around 28 degrees. We again have a noticeable spike when starting the test, but the temperature stays around 38 degrees for the rest of the test. I ran this test for four minutes before stopping it, and the temperature dropped off almost instantly again when it stopped.

Water Cooling Comparison

So the water cooling system definitely works the best at keeping the Pi cool and providing a much quieter cooling solution. But it is way more expensive than the other options and is much more difficult to assemble. It’s also not exactly compact, this system is a couple of times larger than the Ice Tower and that’s already considered to be a large heatsink for a Pi.

Summary Of The Raspberry Pi Cooling Tests

Here’s an overlay of all of the Raspberry Pi cooling options which I’ve tested today:

Overall Comparison

It’s quite noticeable just how much better the ice tower and the water cooling circuits are for high CPU loads, especially when overclocked. Heat sinks only and fan cases are great if you’re going to be using your Pi for light loads, such as a Pi-hole, network storage, or WiFi camera. If you’re going to be doing any CPU intensive tasks, like video editing, light gaming, or simulations then you’ll need to get a more substantial cooling solution, like the Ice Tower. And if you’re a fan of overkill like me, then you definitely need a water-cooled Pi.

Let me know in the comments section what your Raspberry Pi cooling solution is.

Water Cooled Raspberry Pi 4 – Totally Unnecessary, But Pretty Awesome

Today I’m going to see if I can use a PC water cooling kit to make a water cooled Raspberry Pi 4. I’ve seen a couple of people try this on older model Pi’s, using reducers and adapters to get to a small cooling block onto the CPU, but I’m going to try and make an adapter to fit a larger 30mm cooling block onto a Pi 4.

Just to be clear, this is totally unnecessary and is more of a let’s do it because we can, not because we should type of project. But we’ll have fun building it anyway, and hopefully it works well in the end!

Here’s a video of the build and the test, read on for the write-up:

What You Need For A Water Cooled Raspberry Pi

  • Raspberry Pi 4 – Buy Here
  • Pi Power Supply – Buy Here
  • 120mm Water Cooling Kit (Not From Amazon) – Buy Here
  • 240mm Water Cooling Kit (Larger, But From Amazon) – Buy Here
  • Water Cooling Block Kit For Raspberry Pi 4 – Buy Here
    • Alternate to Above – CPU Cooling Block (Not From Amazon) – Buy Here
  • Adjustable 12V Power Supply – Buy Here

Note: Some of the above parts are affiliate links. By purchasing products through the above links, you’ll be supporting this site, at no additional cost to you.

PC Water Cooling Kit

I bought a kit that included a 120mm fan and a radiator, a 12V pump, a reservoir and some tubing. These kits are commonly available online for significantly less than the name brand components sold for high-end PCs, but it’s still quite expensive just to mess around with.

Full Sized CPU Cooling Water Block

The kit also included a full size CPU cooling block. It looks quite cool (excuse the pun) but is way too big to try and fit onto the Pi, so I’m going to be using one of these smaller 30 x 30mm blocks which can accommodate a half-inch or 12mm tubing.

CPU Cooling Water Block

Building The Water Cooled Raspberry Pi 4

Mounting The Cooling Block To The Pi

I’m going to start out by making a bracket to hold the cooling block in place on the Pi over the CPU.

Designing A Bracket To Hold The CPU Block

We’ll need a square section to locate the block and hold it down onto the CPU and then some legs off to the four mounting holes to hold it in place. I’ve tried to avoid covering the GPIO pins and the major components, the bracket will be quite high up, so won’t interfere with any of the surface mount components.

Laser Cutting The CPU Mounting Bracket

I cut the two parts for the bracket out on my laser cutter from 3mm fluorescent green acrylic.

Gluing The Retaining Ring In Place

 Then glued the pieces together using some acrylic cement.

Cooling Water Block & Bracket

Now that we’ve got a bracket to hold the heat sink in place, lets fit it to the Pi.

Can't Mount The Block Directly

The cooling block can’t be mounted straight onto the CPU as the display connector is too high. We’ll need to put a spacer in between the CPU and cooling block to lift it above the display connector, with enough room for the tubes.

Cut A Sqaure Of Aluminium Spacer Block

I’ve cut a section of 4mm aluminium to fit on top of the CPU to space the cooling block away so that it clears the display connector.

Add Standoffs For The Cooling Block

Next, I’m going to use some nylon standoff mounts for the screws which hold the cooling block bracket to screw into. I’ll hold these in place with some shorter nylon standoffs underneath the Pi.

Put Thermal Paste Onto CPU

I’ll use some thermal paste between the CPU and the spacer and then again between the spacer and the cooling block.

Secure With M3 Screws

The acrylic bracket is then clamped down onto the CPU using some M3 x 12mm button head screws.

Cooling Block Mounted on Water Cooled Raspberry Pi

Making The Cooling Circuit Stand

Now that we’ve got our cooling block mounted onto our Pi, we can start working on mounting the rest of the cooling circuit.

Water Cooling Stand

Rather than just connecting all of the components together on a desk, I decided to design a stand to mount the water cooling components and Raspberry Pi, so that it looks more complete.

I’m going to use clear acrylic for the stand with some fluorescent green legs to match the cooling block bracket. The water cooling components should just bolt straight onto this sheet once it’s been cut out.

Laser Cutting The Water Cooling Stand

Again, I cut this stand out on my laser cutter from 3mm acrylic, this time clear.

Now that we’ve got our stand components made, lets start putting them together.

Mount Water Cooling Components To Test Stand

I’ll start by mounting the reservoir, pump and radiator onto the stand.

Glue Raspberry Pi Stand Together

Next, I need to glue the Raspberry Pi stand components onto the main cooling water stand. I clamped the components in place and allowed the cement to cure for a couple of hours before trying to mount the Pi.

Mount Pi To Stand

Once the glued had properly cured, I put two lengths of tubing onto the heat sink so that I didn’t have to try push them on in the tight space between the Pi and the pump, and then mounted the Pi onto the stand using four nylon M3 nuts on the bottom of the standoffs.

Connect Remaining Tubing on Water Cooled Raspberry Pi 4

I then added the fittings and finished off the tubing.

One side of the cooling block goes to the pump and the other to the radiator. We also need a section of tube from the radiator to the top of the reservoir.

The last thing to do is to add a small acrylic block to the base of the pump to hold the weight of the pump and reservoir. The legs on the stand are not strong enough to support all of the cooling components and I didn’t want to make them bigger as I like the look of the thinner sections. You’ll also hardly notice the block under the pump if it’s clear.

Fill Up Circuit With Cooling Water

Our water cooled Pi is now complete, we just need to fill it up with water or cooling liquid and try it out. The system took around 300ml of cooling liquid to fill.

Testing The Water Cooled Raspberry Pi 4

The fan and pump are actually quite quiet when running, the system is a lot quieter than some of the small case fans I’ve used on a Raspberry Pi.

Fan Running On Radiator on Water Cooled Raspberry Pi

Now let’s try and do a stress test on the water cooled Raspberry Pi to see how well this cooling system works.

CPU Test At 1.5GHz

With the CPU clock frequency set to the default 1.5Ghz, we start out with a temperature of around 28°C. This was in a room of around 25°C, so it was done with quite a warm ambient temperature.

Start of run 1.5Ghz

I then did a 5-minute stress test at full CPU load.

End of Run 1.5Ghz

There was a small spike initially where the temperature went up to 31°C but it stayed between 31°C and 33°C for the rest of the test and dropped off quickly when the test was stopped.

Full Run 1.5GHz

Here’s a graph of the CPU temperature for the duration of the test.

CPU Test At 2.0GHz

Now I’m going to try overclocking the Pi to test it at a higher CPU frequency.

Overclocking to 2.0Ghz

I set the CPU frequency to 2.0Ghz for this test.

Let’s try doing a stress test and see what we get.

Start Run 2Ghz

For this test we started out with a temperature of around 29°C, which then quickly spiked to 39°C when the test was started.

Almost Complete 2Ghz

The temperature the stayed around 36°C to 37°C for the rest of the test.

End 2Ghz

Here’s a graph of the CPU temperature for the duration of the 2Ghz test.

Conclusion

The water cooling system on this Pi works really well at keeping the CPU cool. Even when overclocked to 2.0Ghz, the Raspberry Pi 4’s CPU temperature never went above 40°C. I wasn’t able to test the Pi at the maximum 2.147Ghz as my Pi wouldn’t boot up at this frequency, probably due to under-voltage. I’ll try and get this fixed and do a test at the maximum frequency as well at some stage.

To get an idea of whether this is worthwhile, I’m going to be comparing this water cooling system to an Ice Tower, a standard acrylic case and fan and then just a Pi with a static heat sink on it in the next week or two. So make sure that you check back here, or subscribe to my Youtube channel and turn on notifications so that you don’t miss out on that.

Let me know what you think of this water cooled Raspberry Pi 4 in the comments section below!

Setting Up A Pi-hole Network Ad Blocker On A Raspberry Pi Zero W

Pi-hole is a clever piece of software which acts as a network-wide ad blocker. It enables you to block ads on websites, ads in apps on your mobile devices and even on your smart TV, regardless of the software they’re running and without the need for any other local software on the device. Pi-hole also improves your network speed, because the ads are blocked before they are downloaded. This also saves data if you’re on a limited data plan.

Open Pi Hole From Any Device

A web interface lets you interact with your Pi-hole and view stats on your network traffic.

Now that you know what Pi-hole is, let’s have a look at how to to set one up on your home network, step by step.

If you’re running a large network with lots of users and traffic then the best device to use would be one of the Raspberry Pi 3 or 4 models with an ethernet connection to your router. But for a smaller home network with less than 50 devices and only a couple of users online at a time, a Pi Zero W works perfectly.

Raspberry Pi Zero W Pi-hole

I’ve been using one for a month now.

Here’s a step by step video guide to setting up your Pi-hole, read on for the written guide:

What You Need To Make Your Own Pi-hole Ad Blocker

  • Raspberry Pi Zero W Complete Kit – Buy Here

Alternately, buy the individual components:

What You Need For Your Pi-hole Ad Blocker

You’re going to need a Raspberry Pi Zero W, a micro SD card of at least 16GB, and something to put the Pi into to protect it, I just used the official case. You can usually buy these kits online for around $30-$50 dollars which includes everything you need, even a power supply, although you can buy the Pi alone for as little as $10 if you do some searching.

You won’t need a mouse, keyboard or monitor for this as we’ll be using another computer on the network to set up the Pi-hole.

Preparing Raspberry Pi OS Lite On The SD Card

We’ll start by preparing the Raspberry Pi’s operating system on the SD card, Pi-hole will then be installed to run on this operating system later.

Insert Your SD Card For Image Flashing

Plug your microSD card into your computer. Don’t worry about formatting it just yet, we’ll get to that in a minute.

Raspberry Pi Image Flasher Utility

Start by downloading the Raspberry Pi Imager on your computer. This is a fairly new tool and it’s one of the easiest to use. They have a version for Windows, Mac and Linux.

Writing The Image To The SD Card

You just select the Raspberry Pi operating system you need, which in our case is Raspberry Pi OS Lite, and then select the SD card you want to write the image to. Click write and let the tool do the rest, it’ll write the image, check it and then eject the SD card.

There is a bit more to do on the SD card before we’re done on the computer, so you’ll need to plug it in again to access it. You might get a couple of windows pop up and one which says you need to format the card in order to use it, just ignore these and close them. Don’t format the card again.

PiOS Lite Boot Folder

The will be one readable partition on the card called boot, you should be able to open this partition and you’ll see a number of files. We need to add two files to this directory, one to tell the Pi how to connect to your network and another to enable SSH so that you can access it over the network.

wpa supplicant txt file

Download the network settings template wpa_supplicant and open it using a basic text editor like Wordpad.

WPA Supplicant

In the network settings section, you need to add your local WiFi network name next to ssid and your network password next to psk, leaving all of the punctuation marks in place. You can also change your country code at the top if you’d like, this can be set up later though.

Save and close the file.

Changing file to conf

Now change the extension of the file from .txt to .conf. Click yes if you are given a warning.

Paste supplicant file

Now copy this file into your boot directory.

Thats the first done, now we need to add an SSH file.

Add SSH file

Create a new text file and change its name to ssh and remove the extension. So the file should just be a blank file called ssh with no extension.

Completed Files Required

Once you’ve got both of these files then you can eject and remove your SD card.

Insert The SD Card Into The Pi Zero W

Plug the SD card into your Pi, then put it into it’s case and plug the power cable in. It’ll take a few seconds to boot up.

Power It Up

First Boot & Connecting To Your Pi Zero W

Finding Your Pi’s IP Address

Now that you’ve got your Pi booted up and (hopefully) running, you need to be able to access it in order to install Pi-hole onto it and make any settings changes or updates.

To do this, you first need to figure out your Pi’s IP address, which has been assigned by your router. There are many ways to do this, one of the easiest is by logging into your routers admin page. You’ll need to do this later anyway to make a few changes to your router’s settings. There are often details on how to login to the admin page, along with the default username and password, on the label on the router.

Finding The Pi's IP Address

Depending on how complex your router’s software is, you may need to do some exploring until you find a page which lists all of the devices currently connected to the network along with their IP address, this is usually called a DHCP table. Take note the IP address assigned to your Pi.

While you’re logged in, you need to set this IP address (or another one if you’d like) up as a static IP address, so that your router always assigns this same address to your Pi-hole, this is an important step, you’ll see why in a bit. Again, all routers are a bit different, so you’ll need to do some digging if you don’t know how to set up a static IP on yours. If you can’t find the option, try googling your Router’s model and the words “static IP” and you should find some information.

You’ll typically need your Pi’s MAC address, which should also be listed in the DHCP table, and the IP address which you want to use. Enter these to assign your chosen IP address to your Pi each time it joins the network. If you choose a different one to the one currently assigned then you might have to reboot the Pi after this step.

Now that you’ve got your Pi’s IP address, you can access it over the network.

Connecting To Your Pi Over The Network

You’ll need to install a terminal emulator / SSH client like Putty to access your Pi’s terminal.

Using Putty To Access Pi

Enter your Pi’s IP address and then click open to attempt to connect to the Pi.

You’ll get to a black terminal display that asks you for a login. The default username is “pi” and the password is “raspberry”.

Raspberry Pi Config

You’ll want to change these as soon as possible. So it’s a good idea to run the configuration tool first by entering:

sudo raspi-config
Raspberry Pi Config Utility

This tool lets you change a number of settings on your Pi.

As a start, you should change:

  • The default username
  • The password
  • Make sure that you’ve got the correct regional settings selected.

Installing Pi-hole On Your Raspberry Pi Zero W

Now you should have your Raspberry Pi Zero set up properly with a new username and password and connected to your network, with access to it over SSH.

Install Pi-hole

Now you can install Pi-hole by entering the following command:

curl -sSL https://install.pi-hole.net | bash
Running Through Pi-hole Installer

The Pi will start downloading and installing the software. It takes a couple of minutes to run through and you’ll then get to the following page to guide you through the Pi-hole setup.

Installation Settings

For the most part, you can just run through the default selected options and hit OK for each. You shouldn’t make any changes to these settings unless you know what you’re doing or you’ll likely just land up with a Pi-hole that doesn’t work.

Upstream DNS Provider

You might want to change your Upstream DNS provider if you’d like. This is just the provider which your Pi-hole is going to use as the name server for your domain requests.

Also, make sure that the IP address listed is the one which you set as the static IP for your Pi.

Installation Complete

It’ll then run through another setup process and you’ll finally get to an “installation complete” display. Take note of the Admin Webpage password as you’ll need this to log in to the Pi at a later stage to view the detailed statistics and to change any settings. You’ll be able to change this password from the web interface – but you need this password in order to do so.

You can change your Pi-hole password at a later stage over SSH using the command:

sudo pihole -a -p (new password)

You can now close the terminal connection.

Fresh Install Of Pi-hole

Test if Pi-hole is running by going to your browser and typing in the IP address that you’ve configured for your Pi along with forward slash and admin.

192.168.20.14/admin

You should see a page like this show up. You’ll notice that no queries have been received or blocked yet because the router isn’t directing traffic through the Pi-hole, there is still one last thing to set up.

Setting Up Your Router To Direct DNS Requests Through Your Pi-hole

You’ll need to log back into your router and find your DNS settings page.

Set Up Pi-hole As DNS Server

Here you’ll need to set your Pi-hole’s IP address as the primary DNS server, if your router has to have a secondary DNS server, then type the same address into that field as well. Click save or apply to make the changes. You may then need to reboot your network devices to take effect.

Open Pi-hole From Any Device

If you go back to your Pi-hole dashboard, you should now see requests coming through and ads queries being blocked.

Log Into Pi-hole

If you log in to your Pi-hole using the admin password that was created during setup, you should have more access to the network statistics and see detailed logs.

Settings To Shut Down Pi-hole

You’ll also be able to change settings, add or remove domains on the block list, and reboot or turn off your Pi.

Remember that if you turn off your Pi and your router’s primary and secondary DNS server are set to your Pi’s address, you will no longer have access to the internet until your Pi is back online. So make sure that your Pi-hole is on a reliable power source, preferably the same one as your router.

Raspberry Pi Zero W Pi-hole

Some routers have a USB port on them which has enough power to supply an external drive. This port usually supplies enough power to drive a Raspberry Pi Zero W running as a Pi-hole, so you can ensure that they’re always on together.

This guide is just a starting point to get your Pi-hole up and running, there is a lot more than can be done using Pi-hole once you’re comfortable with it.

You can also set the Pi up to run the DHCP service, which allows the Pi-hole to identify devices by their name rather than IP address and even integrate powerful third-party anti-malware and anti-phishing DNS services.

That’s it, you’ll now be able to enjoy an ad free browsing experience on your home network!

Its worth noting that there are some limitations to the ad blocking ability of the Pi-hole. The Pi-hole is simply blocking requests being made to domains which are known to serve ad content, if the website you are accessing serves its own ad content, from their same domain, then the Pi-hole won’t block these ads. Typical examples are ads running on Youtube videos or Facebook ads in your Facebook news feed.

Let me know if you’ve used a Pi-hole in the comments section.

DIY Raspberry Pi 4 Desktop Case With OLED Stats Display

Today I’m going to be showing you how to make your own desktop case for a Raspberry Pi 4, which looks like a mini desktop pc.

Raspberry Pi 4 Desktop Case Computer
Raspberry Pi 4 Desktop Case Computer

The body of the case is 3D printed and it has clear acrylic sides so that you’re able to see into it. I’ve used an Ice Tower to cool the CPU, but have mounted the fan onto the side of the case rather than on the heatsink.

OLED Stats Display For Raspberry Pi 4

I’ve also included an OLED display on the front of the case which displays the Pi’s IP address and some stats like the CPU, storage and memory usage, and the CPU temperature.

You can now buy a pre-made kit for this Raspberry Pi 4 Desktop Case – Buy Here.

Here’s a video of the build and the case and display in operation:

What You Need To Make Your Own Raspberry Pi 4 Desktop Case

Raspberry Pi 4 Desktop Case Oled Display Ice Tower

In addition to the above, you’ll also need to have access to a 3D printer to print the plastic portion of the case.

I use the Creality Ender 3 Pro which I’ve found to produce great quality prints and is quite affordable.

3D Printer – Creality Ender 3 Pro – Buy Here

You don’t need a laser cutter for this build, although it does help significantly with making the sides. You can also use an online laser cutting service or simply cut your own sides using hand tools. I’ve used a Desktop K40 laser cutter/engraver.

Laser Cutter – K40 – Buy Here

Note: The above parts are affiliate links. By purchasing products through the above links, you’ll be supporting this channel, with no additional cost to you.

Making The Raspberry Pi 4 Desktop Case

3D Printing The Body

I started out by designing the 3D printed body of the case in Tinkercad.

Designing The Case In Tinkercad

Note: This design is copyrighted and is available for your personal, non-commercial use only. It may not be reproduced for commercial gain or republished in any form.

I’ve also put together a pack with some additional case variations which is available through this link – Additional 3D Print Files. This pack includes:

  • Case With SD Card Cutout
  • Case With OLED Display On The Other Side (USB & Ethernet Ports On Back)
  • Case With No OLED Display Cutout
  • Additional Side Panel Design With Larger HDMI Cutout

I drew a rough outline of the case and then positioned the Raspberry Pi within the case so that the USB and Ethernet ports are available through the front and the Power, HDMI, and audio ports are accessed through the side panel.

The OLED display is positioned on the front of the case above the ports. The OLED display will be held in place with two small clips on the top edge and a screw with a plastic clip at the bottom, a design which I’ve used before on my Arduino based reaction timer.

Designing The Case Mounting Footprint

The Pi is going to be mounted onto the brass standoffs which came with the Ice Tower, so I added some holes to accommodate the M2.5 threads.

I don’t remove the SD card on the back of the Pi very often, so I didn’t add a cut-out for it. If you do, then just add a circular cut-out to the case at the back so that you can still access it. It is going to be a bit of a chore to swap the SD card if you don’t have this cut-out as you’ll need to remove the Pi from the case to access it, I’m happy with doing this if I ever need to change the card.

3D Printing The Case Housing

I 3D printed the Raspberry Pi 4 Desktop Case using Black PLA with a 0.2mm layer height and 15% infill. I also added print supports for the cutouts for the display and ports on the front. You’ll probably need to add these as well, which is easy to do in your slicing software. You’ll also need to print the small plastic display clamp.

3D Printed Components

Install The Raspberry Pi & Ice Tower

Now that the main body of the case is complete, let’s mount the Raspberry Pi into it. Start by screwing the brass standoffs into the holes in the base.

The holes for the brass standoffs are intentionally quite tight the first time you screw them in. You’ll likely need to use a small wrench or spanner to get them screwed in, you can also use some needle nose pliers if you don’t have a suitable size wrench.

Standoffs Mounted Into The Case

I’ve just changed the orientation of the screws and standoff mounts supplied with the Ice Tower so that they screw straight into the bottom of the case and don’t require and through holes. If you follow the Ice Tower installation manual, you’ll notice that the standoffs and screws are installed the opposite way around.

Remove The Fan From The Ice Tower

Next, we need to remove the fan from the Ice Tower so that we can attach it to the acrylic side panel. By moving the fan onto the side panel, we make sure that cool air is being drawn in from the outside of the case and then has to leave from the exhaust air vents on the opposite side.

Mount The Ice Tower Legs

Add the support brackets to the bottom of the Ice Tower heatsink as per the instructions. Make sure that you follow the correct orientation of these.

Secure The Pi With The Second Set Of Brass Standoffs

Update – As a few people have pointed out, it’s easier to install the OLED display and the screw to hold it in place before putting the Ice Tower in.

Place the Raspberry Pi into position and then use the second set of brass standoffs, screwed into the bottom set, to secure it.

Install The Ice Tower

Stick the heat sink pad onto the Pi’s CPU and peel off the top layer of protective film. Position the Ice Tower heat sink onto the heat pad on the CPU and then secure it with the four screws into the brass standoffs.

Install The OLED Display

Now we need to install the OLED display onto the front panel. If your display came without the pins soldered into place, solder them onto the back of the display.

Install The OLED Display

Slide the top edge of the display in under the plastic clips and then gently push it down into position in the cut-out.

Secure The OLED Display Clip

Use the 3d printed clamp to hold it in place with a small screw. You might need a flexible shaft or 90-degree screwdriver to tighten the screw.

Update – I’ve put together a detailed guide to connect and program the OLED display.

Don’t over-tighten the screw, the clamp just needs to gently hold the display in place. If you clamp it too tightly you might crack the glass on the display.

Make Up The OLED Display Ribbon Cable Connector

Now we need to prepare the wiring to the OLED display. You’ll need to make 4 connections to your GPIO pins, two for power and two for communication. I made up this short connector cable using some DuPont connectors and some ribbon cable. You can also use some female pin header strips or female breadboard jumpers to connect the display to the Pi.

Plug In The Ribbon Cable Connector

Once your cable is made up, connect it to the back side of the display and then plug the leads into the GPIO pins as follows:

  • GND to Pin14 Ground
  • VCC to Pin1 3.3V Power
  • SCL to Pin5 SCL (GPIO 3)
  • SDA to Pin3 SDA (GPIO 2)
GPIO-Pinout-Diagram-2

I’ve noticed that there are two versions of these OLED displays available and they have the power pins the opposite way around, one version has VCC and then GND and one GND and then VCC, so just make sure that you’re connecting power the correct way around for your display.

Make The Acrylic Sides

The internal parts of the case are now mostly done, so let’s make up the acrylic sides to close it up.

Export Side Profile Of Case To Make Acrylic Sides

I started in Tinkercad again and positioned a block in the case roughly where the Ice Tower heat sink is going to be so that the holes for the fan are in the correct place on the side panels. I then exported the side profile of the case and heat sink to open up in Inkscape to draw the laser cutting profile.

We need two sides, one with the fan for the inlet and one with some holes in it for the exhaust air.

Drawing The Acrylic Sides In Inkscape

We can remove the inside edge profile as we only need the outline of the case and the screw holes. We need to add a hole for the fan and the four surrounding holes for the fan screws. We’ll also need to add cut-outs for the ports along the side of the Raspberry Pi.

Making The Hexagon Pattern For The Exhaust Air

Next, I created a mirror of the fan side to the exhaust side and drew a hexagon pattern for the exhaust airflow.

Completed Side Panels

If you’re not going to be laser cutting the sides and you’re cutting them out by hand, then replace these hexagon holes with circular drilled holes (Ø8mm) in the same area.

Laser Cutting The Side Profiles

Now let’s get the sides cut out. I used 2mm clear acrylic for the side panels.

Side Sheets Ready To Be Installed

You can use a colour tinted or opaque acrylic as well if you’d like. A lot of the coloured sheets are only available in 3mm. This won’t really matter, you’ll just have thicker edges.

Screw Fan Onto Side Panel

To mount the fan onto the side panel, you’ll need to press some M3 nuts into the pockets by the screw holes. It’s easiest to place the nut on a flat surface and then press the fan hole over the nut to push it into place. These are tight so that you don’t need to use a spanner to hold them when you tighten the screws.

If you want to re-use the fan screws, they’ll be too short to fit through the acrylic and fan and then into the nuts, you’ll need to press the nuts into the front (acrylic side) of the fan. You’re relying on the friction between the nut and the fan to hold it in place, but it works fine in this case as there isn’t much load on them.

Screw Fan Side Panel Onto Case

Screw the fan side panel onto the 3D printed case using four M3 x 8mm hex head machine screws.

Pi 4 Desktop Case - Fan Side Panel In Place

The screws should be a bit tight as the inside of the holes aren’t threaded, most 3D printers can’t print such a fine thread.

Attach Fan Power

Now plug the fan into the 5V supply on the Pi and then install the other side panel. The red wire to Pin 4 (5V) and the black wire to Pin 6 (Ground).

Pi 4 Desktop Case - Screw On Exhaust Air Side

That’s it for the assembly, the Raspberry Pi 4 Desktop Case is now complete. We just need to get the OLED display working.

Programming The OLED Display

Update – I’ve put together a detailed guide to connect and program the OLED display.

To get the display working, we need to run a Python script. You’ll need to boot your Pi up to do this.

The Raspberry Pi communicates with the display using I2C communication, so you’ll also need to make sure that this is enabled in your preferences or do it through the command line by running:

sudo raspi-config

Then select Interfacing Options, then I2C, then select Yes and then reboot the Pi with the following command:

sudo reboot

You’ll also need to ensure that the python-smbus and i2c-tools libraries are both installed. They should be by default, but it’s worth checking, by running the following commands:

sudo apt-get install python-smbus
sudo apt-get install i2c-tools
sudo pip3 install Adafruit_BBIO

While you’re at this stage, it’s also worth checking that your Pi is able to see your display. You can display a list of devices connected to the I2C bus by entering the following command:

sudo i2cdetect -y 1

This should display an output similar to the below:

0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

This indicates that a device has been detected and it’s address is 0x3c. If you don’t get anything showing up here then check your connections to your display and make sure that you’ve got I2C communication enabled on your Pi.

Don’t proceed with trying to program the display if you aren’t getting an address in this step. This means that the Pi isn’t able to see the display, and it won’t be able to display anything until it is.

Next, let’s have a look at the script and how to install it. This script is mostly based on one of the example scripts in the Adafruit Python Library for OLED display modules, with a few changes by Shakhizat Nurgaliyev to add the CPU temperature and change the format of the display.

# Copyright (c) 2017 Adafruit Industries
# Author: Tony DiCola & James DeVito
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import time

import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1306

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont

import subprocess

# Raspberry Pi pin configuration:
RST = None     # on the PiOLED this pin isnt used
# Note the following are only used with SPI:
DC = 23
SPI_PORT = 0
SPI_DEVICE = 0

# Beaglebone Black pin configuration:
# RST = 'P9_12'
# Note the following are only used with SPI:
# DC = 'P9_15'
# SPI_PORT = 1
# SPI_DEVICE = 0

# 128x32 display with hardware I2C:
disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)

# 128x64 display with hardware I2C:
# disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)

# Note you can change the I2C address by passing an i2c_address parameter like:
# disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, i2c_address=0x3C)

# Alternatively you can specify an explicit I2C bus number, for example
# with the 128x32 display you would use:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, i2c_bus=2)

# 128x32 display with hardware SPI:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))

# 128x64 display with hardware SPI:
# disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))

# Alternatively you can specify a software SPI implementation by providing
# digital GPIO pin numbers for all the required display pins.  For example
# on a Raspberry Pi with the 128x32 display you might use:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, dc=DC, sclk=18, din=25, cs=22)

# Initialize library.
disp.begin()

# Clear display.
disp.clear()
disp.display()

# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
width = disp.width
height = disp.height
image = Image.new('1', (width, height))

# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)

# Draw a black filled box to clear the image.
draw.rectangle((0,0,width,height), outline=0, fill=0)

# Draw some shapes.
# First define some constants to allow easy resizing of shapes.
padding = -2
top = padding
bottom = height-padding
# Move left to right keeping track of the current x position for drawing shapes.
x = 0


# Load default font.
font = ImageFont.load_default()

# Alternatively load a TTF font.  Make sure the .ttf font file is in the same directory as the python script!
# Some other nice fonts to try: http://www.dafont.com/bitmap.php
# font = ImageFont.truetype('Minecraftia.ttf', 8)

while True:

    # Draw a black filled box to clear the image.
    draw.rectangle((0,0,width,height), outline=0, fill=0)

    # Shell scripts for system monitoring from here : https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and-cpu-load
    cmd = "hostname -I |cut -f 2 -d ' '"
    IP = subprocess.check_output(cmd, shell = True )
    cmd = "top -bn1 | grep load | awk '{printf \"CPU Load: %.2f\", $(NF-2)}'"
    CPU = subprocess.check_output(cmd, shell = True )
    cmd = "free -m | awk 'NR==2{printf \"Mem: %s/%sMB %.2f%%\", $3,$2,$3*100/$2 }'"
    MemUsage = subprocess.check_output(cmd, shell = True )
    cmd = "df -h | awk '$NF==\"/\"{printf \"Disk: %d/%dGB %s\", $3,$2,$5}'"
    Disk = subprocess.check_output(cmd, shell = True )
    cmd = "vcgencmd measure_temp |cut -f 2 -d '='"
    temp = subprocess.check_output(cmd, shell = True )

    # Write two lines of text.

    draw.text((x, top), "IP: " + str(IP,'utf-8'), font=font, fill=255)
    draw.text((x, top+8), str(CPU,'utf-8') + " " + str(temp,'utf-8') , font=font, fill=255)
    draw.text((x, top+16), str(MemUsage,'utf-8'), font=font, fill=255)
    draw.text((x, top+25), str(Disk,'utf-8'), font=font, fill=255)

    # Display image.
    disp.image(image)
    disp.display()
    time.sleep(.1)

You’ll need to download the original Adafruit example library from Github to get the setup complete by using these commands in your terminal:

sudo python -m pip install --upgrade pip setuptools wheel
git clone https://github.com/adafruit/Adafruit_Python_SSD1306.git

Open a new terminal window, then navigate to the library’s directory:

cd Adafruit_Python_SSD1306

Install the library for Python 3:

sudo python3 setup.py install

You can then run the above stats.py file or the example stats.py file in the Adafruit directory, you’ll just get a slightly different display layout with the Adafruit example.

Change to the directory containing the stats.py script:

cd examples

Execute the script:

python3 stats.py

You can test run the script to check that your display is working correctly and you don’t get any errors before setting it to run automatically.

To set the script to run automatically, you’ll need to find the script’s directory, then open crontab and add a line to run the script:

@reboot python3 /home/pi/stats.py &

You’ll obviously need to change the directory /home/pi/ to reflect the directory where you have your script saved.

Don’t forget to add the & at the end, this tells the Pi to continue starting up and run the script in the background.

Raspberry Pi 4 Desktop Case Display Showing stats

Reboot the Pi to automatically run the script and you should then see the stats shown on the OLED display when it starts up.

Raspberry Pi 4 Desktop Case Lights
Raspberry Pi 4 Desktop Case With LED Lighting
Pi 4 Desktop Case With LEDs

I’ve also made an Ice Edition of this case using white PLA for the case and a blue-tinted acrylic for the side panels. This Ice Edition Kit is available through my Etsy store.

Ice Edition Raspberry Pi Case 2
Ice Edition Raspberry Pi Case

Let me know if you like this Raspberry Pi 4 Desktop Case or what you’d do differently in the comments section.

Edit – Alternate Font Option for the OLED Display

Thanks for Richard Jelbert for finding an alternate font which looks much clearer than the default one.

Pi Desktop Case Alternate Font

To get this font to work, you’ll need to:

  • Change the display size setting from 128 x 32 to 128 x 64. To do this you just need to comment out the 128 x 32 line and uncomment the 128 x 64 line a little below it:
# 128x32 display with hardware I2C:
disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)

# 128x64 display with hardware I2C:
# disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)
  • Download the font PixelOperator.ttf from https://www.dafont.com/pixel-operator.font and then place it into the script directory. You’ll then need to edit the below code by commenting out the initial font = Image… line and uncommenting the last line, changing ‘Minecraftia.ttf’ to your font and selecting a suitable font size. Richard has used font size 16.
# Load default font.
font = ImageFont.load_default()

# Alternatively load a TTF font.  Make sure the .ttf font file is in the same directory as the python script!
# Some other nice fonts to try: http://www.dafont.com/bitmap.php
# font = ImageFont.truetype('Minecraftia.ttf', 8)

Re-load the script and you should then get a much clearer text readout on your display.

Share This Guide

3D Printed Raspberry Pi 4 Desktop Case Pinterest