Welcome

This documentation will guide you through the methods available in the Enviro pHAT python library.

Enviro pHAT is an environmental sensor add-on, packing 4 different sensors, letting you measure temperature, pressure, light level, colour, 3-axis motion, compass heading, and analog inputs.

At A Glance

light.rgb()
light.light()
light.raw()
leds.on()[source]
leds.off()[source]
weather.temperature()
weather.pressure()
weather.altitude(qnh=1020)
weather.update()
analog.read(channel=0, programmable_gain=None, samples_per_second=1600)
analog.read_all()
analog.available()
motion.magnetometer()
motion.accelerometer()
motion.heading()
motion.raw_heading()
motion.update()

Light

Light sensing is provided by a TCS3472 colour sensor, with filtered channels for Red, Green and Blue. plus an unfiltered “Light” channel.

light.rgb()

Return a tuple containing the red, green and blue colour values ranging 0 to 255 scaled against the clear value.

light.light()

Return the clear/unfiltered light level as an integer.

light.raw()

Return the raw red, green, blue and clear channels

For colour sensing, two LEDs are placed either side of the TCS3472 to illuminate the subject.

leds.on()[source]

Turn LEDs on.

leds.off()[source]

Turn LEDs off.

Weather

Weather sensing is provided by a BMP280. The altitude is approximated from atmospheric pressure.

weather.temperature()

Return the current temperature.

Note: This value may be affected by nearby sources of heat, including the Pi itself.

weather.pressure()

Return the current air pressure.

weather.altitude(qnh=1020)

Return the current approximate altitude.

Parameters:qnh – Your local value for atmospheric pressure adjusted to sea level.
weather.update()

Update stored temperature and pressure values.

This function is called automatically when calling temperature() or pressure().

Analog

The four channels of Analog input are provided by an ADS1015.

analog.read(channel=0, programmable_gain=None, samples_per_second=1600)

Read a specific ADC channel.

Parameters:
  • channel – ADC channel, from 0 to 3
  • programmable_gain – Gain amount to use, one of 6144, 4096, 2048, 1024, 512 or 256 (default 4096 or 6144 depending on revision)
  • samples_per_second – Samples per second, one of 128, 250, 498, 920, 1600, 2400, 3300 (default 1600)
analog.read_all()

Read all analog channels and return their values in a tuple.

analog.available()

Check if the ADC is available.

Motion

Motion sensing is provided by an LSM303D accelerometer and magnetometer. The compass heading is approximated.

motion.magnetometer()

Read the magnetomter and return the raw x, y and z magnetic readings as a vector.

The returned vector will have properties x, y and z.

motion.accelerometer()

Read the accelerometer and return the x, y and z acceleration as a vector in Gs.

The returned vector will have properties x, y and z.

motion.heading()

Return a tilt compensated heading calculated from the magnetometer data.

Returns None in the case of a calculation error.

motion.raw_heading()

Return a raw compas heading calculated from the magnetometer data.

motion.update()

Update both the accelerometer and magnetometer data.