Pimoroni Enviro pHAT

Enviro pHAT by Pimonori is a small and handy addition to Raspberry Pi versions 2, 3 and 4 as well as compact Raspberry Pi Zero. It features several sensors to measure various "environmental" variables such as temperature, pressure, light level and colour, 3-axis motion, compass heading, and input voltage. Currently, this version is discontinued and Enviro (which is a pHat too, technically) is suggested as more advanced replacement.

Overview
Enviro pHAT is a HAT/pHAT board, which is connected to Raspberry Pi board via 40-pin GPIO header mount. Note that only difference between Hat and pHAT is that the latter has is designed especially to work Raspberry Pi Zero and fits its form factor. However, due to certain compatibility between the Raspberry Pi versions and revisions as well as other similar products (e.g. Orange, Banana Pi) it will work with them too. The pHat comes as a single board with separate pinout headers, which should be soldered prior to installation on Raspberry Pi board. It uses 3 GPIO pins (#2,3,4) and 5V power and communicates over i2c interface. To be mounted properly, the board should be oriented in a way so it is mounted "atop" the Raspberry Pi. To read the pHAT sensors one can use dedicated python library or and  packages for a direct access to the GPIO pins. The following instructions are tested on Raspberry Pi 2 Model B and Enviro pHAT. Modern Enviro (not tested due to the lack of equipment) will require different python library, however, general approach would be the same.

Installation consists of the following steps:


 * 1) enabling hardware configuration in ,
 * 2) checking kernel configuration and modules,
 * 3) UDEV configuration,
 * 4) software installation.

Hardware and config.txt
The pHat communicates with Raspberry Pi via I2C interface, so it should be enabled in the file, used to configure interfaces and Pi itself on the boot. Add those lines in addition to the ones present:

Last line sets the i2c speed with 100KHz ( default frequency) which can be changed if needed.

Configuring the kernel
One needs essentially  and   (and   on RPi 4) modules for I2C communication. Raspberry Pi kernel distribution already has necessary modules pre-compiled. Alternatively, using default kernel configuration,  ,   for the appropriate target will select necessary modules. Otherwise check if you have these modules selected.

While the  (and   on RPi 4) is normally loaded automatically during the boot,   is not. Create a and add the module there:

During the boot the modules the service will load it.

UDEV configuration
When the service runs it populates /dev with existing devices, including  and  (normally, ), which are the GPIO pins and i2c bus, which the Enviro pHat is connected to. Currently on Gentoo these devices are created with ownership, however, it is more handy to change this policy so the devices are created with  and  groups, respectively, so the users can have access to them, given added to those groups.

If the Enviro pHat is already installed on the Raspberry Pi board at this point, one can either simply reboot, or modprobe the modules and restart the udev.

Check if the devices are present and have correct permissions.

Software installation
Install the to check whether pHat is detected via i2c.

There is an official python package used to interact with the Enviro pHat, however it is not currently present in the main tree, so one may use to install them.

Then, from the user added to the and  groups in the previous section, install the required packages.

If the  works in  then, everything is configured correctly and works. E.g. create small python script file:

and check if the sensor reads the temperature outside the pHAT.

If it worked, then everything is set up for non-root user usage.