Raspberry Pi IoT Project: Temperature Part 2 – Testing Hardware (Raspberry Pi / Python)

In part 1 I looked at the planning of my new Raspberry Pi / IoT project (temperature readings) and decided on the hardware to use. I already had the Raspberry Pi 3 (and appropriate microSD, power etc…) so the only thing missing was the temperature sensors.

I ordered the sensor highlighted in part 1 (BMP280 and a breakout garden pHAT) late on Thursday evening and they arrived first thing Saturday morning, which meant that I could make a start on testing the hardware.

Pimoroni delivered the goods really quick
Pimoroni delivered the goods really quick

As the Breakout Garden pHAT requires no soldering it is very easy to fit, just a small push on the the Pi’s GPIO pins whist the Pi is powered off.


Pimoroni maintain an installation script (a .sh file) on their GitHub for the Breakout Garden, the script detects which sensors are plugged into the garden and activates the relevant components.

Pimoroni GitHub
Pimoroni GitHub

The software installation of the Breakout pHAT and sensor is again easy, using the wget command to pull down the zip of the above mentioned script and then unzipping it, and running it.


Once the script has run the Breakout Garden pHat and sensor are installed. Then it just takes a little bit of Python to get a reading from the sensor so that it can be tested:

import time

from bmp280 import BMP280
from smbus2 import SMBus
except ImportError:
from smbus import SMBus

bmp280 = BMP280(i2c_dev=bus)

seconds_to_run = 100

for i in range(seconds_to_run):
temperature = bmp280.get_temperature()
print(‘The temperature is {:04.1f} degrees celesuis’.format(temperature))

Getting a temperature reading
Getting a temperature reading

The Python script above is available on my GitHub (https://github.com/geektechdude/temperature_project)