Enviro pHAT review

By Russell Barnes. Posted

This Zero-size add-on features four built-in sensors plus analogue inputs

While not an official Raspberry Pi standard, Pimoroni’s pHAT class of half-size add-on boards are great fun and match the Pi Zero’s form factor perfectly, although they’ll work with any 40-pin Pi model. The latest addition to the line is the Enviro pHAT, which is all about taking environmental and motion measurements. Along with several built-in sensors, it features four analogue input channels to connect your own external sensors. In effect, the Enviro pHAT is Pimoroni’s Flotilla weather, colour, and motion modules rolled into one, with the addition of an analogue-to-digital (ADC) converter.

The full article can be found in The MagPi 49 and was written by Phil King

First things first: the Enviro pHAT comes in kit form, so you’ll need to get your soldering iron out to attach the 2×20‑pin female header and six male pins for the analogue inputs. Alternatively, you could even solder the pHAT straight onto the GPIO pins of a Pi Zero, if you wanted to use them together as a permanent room-monitoring or motion-measuring device.

Once the pHAT is assembled and mounted on the Pi’s GPIO header, installing the software requires just a single command in the terminal. Assuming your Pi already has I2C enabled, you’re then able to start coding to obtain readings from the sensors, using the pHAT’s own Python library. The latter is partitioned into five separate modules: light, weather, motion, analog (inputs), and leds.

Modular sensors

The light module offers two main methods for reading the built-in TCS3472 sensor, which monitors four different values: clear, red, green, and blue. As well as an ambient light level reading using light.light(), you can obtain RGB colour values with light.rgb(), for a tuple which can easily be split into separate values. As you can see, the function naming structure used by the library couldn’t be simpler, so it’s all very easy to code. To aid accuracy of colour readings, the board has two small white LEDs located on either side of the light sensor, which can be switched on and off using the leds Python library module. Even so, the colour values produced are for a duller shade than the real item analysed, so may require some calibration.

The library’s weather module enables you to obtain temperature and barometric pressure (in hPa) readings from the Enviro pHAt’s BMP280 sensor, but it doesn’t measure humidity. Since the sensor is mounted on the PCB rather than remotely, its temperature reading is greatly affected by the heat of the Raspberry Pi CPU beneath it. Therefore, you’ll need to calibrate it by comparing the real ambient temperature, using a standard thermometer, to discover the difference; for us it was around 7°C, but it may vary depending on the setup. For a more accurate reading, you could always use a remotely placed temperature sensor connected to the pHAT’s analogue input section: more on that later.

 The HAT is well labelled even though it's so small

Detecting motion

The Enviro pHAT includes an LSM303D accelerometer/magnetometer for detecting the board’s motion through three axes (pitch, roll, and vertical) and its compass bearing. The latter can easily be calibrated to north, so long as you already know where that is; it’s done by setting a variable to its value and subtracting it from the reading (with modulo 360) to get the correct compass heading in degrees. Meanwhile, the motion.accelerometer() tuple can be split into three variables, one for each axis. You can also obtain the raw magnetometer data if you prefer. Since the combination of Enviro pHAT and Pi Zero has such a small form factor, it’s ideal for measuring the motion of people carrying it or objects attached to it, although it’ll require a portable power source such as a phone charger.

Last but not least, the Enviro pHAT features an ADS1015 ADC for reading external analogue sensors. Located on a short edge of the board are six pins: 5V power output and ground, plus four input channels to take readings from sensors. Note that the input pins are designed to measure signals between 0 and 3.3V, so if your sensor’s output is 5V you’ll need to create a voltage divider, using three identical resistors on a breadboard, to lower it to 3.3V. While Pimoroni says that in its tests, running 5V into the ADC inputs didn’t cause any adverse effects, the readings won’t be reliable unless you use a voltage divider. It’s not much of a hurdle, though, and the inclusion of an analogue input section for connecting extra sensors is a major bonus.

Overall, with its similar functionality, the Enviro pHAT is a cheaper, more portable alternative to a Sense HAT, although without the LED matrix and a few other features, but with the addition of analogue inputs for extra sensors. The Python library is very intuitive and easy to use, aided by an online tutorial (magpi.cc/29maHZT) to get you started and a few helpful code examples in the GitHub repository. With its small form factor, we can see the Enviro pHAT being used with a Pi Zero to create IoT devices for monitoring room temperature, light levels (to possibly trigger electric lighting), and various other remote uses. By using a stacking header, it could also be combined with another Pimoroni pHAT, such as the Scroll pHAT with its LED matrix, to display its readings in situ.

Last word


For portable projects requiring sensor data, the Enviro pHAT could prove particularly useful. You could just mount it on a Pi Zero and leave it on a shelf to monitor room conditions, for instance, logging its readings into a file or database. The inclusion of an ADC and analogue inputs for external sensors is a bonus for what is a fun, easy-to-use add-on with plenty of possibilities.

From The MagPi store