Skip to main content

Driver for the Anyleaf pH sensor

Project description



For use with the AnyLeaf pH and RTD sensors in Python



To get started as quickly as possible, run these commands from a terminal:

  • sudo apt install python3-scipy
  • pip3 install anyleaf
  • git clone
  • cd ph-python/examples
  • python3

pH readings will display in your terminal.

To install the anyleaf Python package, run pip3 install anyleaf, or pip install anyleaf, depending on how pip is set up on your operating system.

Example use, for Raspberry Pi, and CircuitPython boards:

import time

import board
import busio
from anyleaf import PhSensor, CalPt, CalSlot, OnBoard, OffBoard

def main():
    i2c = busio.I2C(board.SCL, board.SDA)
    delay = 1  # Time between measurements, in seconds
    ph_sensor = PhSensor(i2c, delay)

    # 2 or 3 pt calibration both give acceptable results.
    # Calibrate with known values. (voltage, pH, temp in °C).
    # You can find voltage and temperature with `ph_sensor.read_voltage()` and 
    # `ph_sensor.read_temp()` respectively.
    # For 3 pt calibration, pass a third argument to `calibrate_all`.
        CalPt(0., 7., 25.), CalPt(0.17, 4., 25.)

    # Or, call these with the sensor in the appropriate buffer solution.
    # This will automatically use voltage and temperature.
    # Voltage and Temp are returned, but calibration occurs
    # without using the return values.
    # V, T = ph_sensor.calibrate(CalSlot.ONE, 7., Offboard(40.))
    # ph_sensor.calibrate(CalSlot.TWO, 4., OnBoard())

    # Store the calibration parameters somewhere, so they persist
    # between program runs.

    while True:
        pH =
        # To use an offboard temperature measurement: ``
        print(f"pH: {pH}")


if __name__ == "__main__":

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for anyleaf, version
Filename, size File type Python version Upload date Hashes
Filename, size anyleaf- (6.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size anyleaf- (6.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page