#!/usr/bin/env python # read_ec_ph.py # 2018-08-29 # # Uses spiroboard.py to read EC and pH from the SpiroBoard import pigpio import time import spiroboard as sb if __name__ == "__main__": # Open the pigpio I/O library pi = pigpio.pi() if not pi.connected: exit(0) # Open bit banging I2C on standard I2C pins error = pi.bb_i2c_open(2, 3, 100000) if error: exit(error) # Set the static state of the square wave and gain measurement pi.write(sb.SQW,0) # Square Wave off pi.write(sb.ENINL,1) # Active Low input sample disable pi.write(sb.ENOUTH,0) # Active High output sample disable pi.write(sb.ECSEL,0) # Select the calibration resistor pi.write(sb.TEMPSEL,0) # Select the EC Thermistor # Enable the output registers to drive the GPIO pins pi.set_mode(sb.SQW, pigpio.OUTPUT) pi.set_mode(sb.ENINL, pigpio.OUTPUT) pi.set_mode(sb.ENOUTH, pigpio.OUTPUT) pi.set_mode(sb.ECSEL, pigpio.OUTPUT) pi.set_mode(sb.TEMPSEL, pigpio.OUTPUT) # Read the EC and pH (ppm, ph) = sb.read_ec_ph(pi) print ppm, ph # Reset initial state for controls pi.write(sb.SQW,0) # Square Wave state pi.write(sb.ENINL,1) # Active Low input sample disable pi.write(sb.ENOUTH,0) # Active High output sample disable pi.write(sb.ECSEL,0) # Select the calibration resistor pi.write(sb.TEMPSEL,0) # Select the EC Thermistor pi.bb_i2c_close(2) pi.stop()