예제 #1
0
  @url https://github.com/DFRobot/DFRobot_PH
'''
import sys
sys.path.append('../')
import time
ADS1115_REG_CONFIG_PGA_6_144V = 0x00  # 6.144V range = Gain 2/3
ADS1115_REG_CONFIG_PGA_4_096V = 0x02  # 4.096V range = Gain 1
ADS1115_REG_CONFIG_PGA_2_048V = 0x04  # 2.048V range = Gain 2 (default)
ADS1115_REG_CONFIG_PGA_1_024V = 0x06  # 1.024V range = Gain 4
ADS1115_REG_CONFIG_PGA_0_512V = 0x08  # 0.512V range = Gain 8
ADS1115_REG_CONFIG_PGA_0_256V = 0x0A  # 0.256V range = Gain 16

from DFRobot_ADS1115 import ADS1115
from DFRobot_PH import DFRobot_PH

ads1115 = ADS1115()
ph = DFRobot_PH()

ph.begin()
while True:
    #Read your temperature sensor to execute temperature compensation
    temperature = 25
    #Set the IIC address
    ads1115.setAddr_ADS1115(0x48)
    #Sets the gain and input voltage range.
    ads1115.setGain(ADS1115_REG_CONFIG_PGA_6_144V)
    #Get the Digital Value of Analog of selected channel
    adc0 = ads1115.readVoltage(0)
    #Convert voltage to PH with temperature compensation
    PH = ph.read_PH(adc0['r'], temperature)
    print "Temperature:%.1f ^C PH:%.2f" % (temperature, PH)
        log_cursor = log_conn.cursor()
        logdb = LogDBHandler(log_conn, log_cursor, db_tbl_log)

    except Error as e:
        print(e)
    else:
        print('MySQL Logger Connection Successful')
    logging.getLogger('').addHandler(logdb)

# Register MY_LOGGER
log = logging.getLogger('HydroMonitorApp Logger')
log.setLevel(log_error_level)
logging.basicConfig(filename=log_file_path)

# initialize all objects.
ads1115_l = ADS1115()
ads1115_r = ADS1115()

ph = DFRobot_PH()
ec = DFRobot_EC()
# Set GPIO pin to input and activate pull_down walter level sensor to reference pin to ground
gpio_pin = 15
GPIO.setup(gpio_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

# Load Raspberry Pi Drivers for AdaFruit 1-Wire Temperature Sensor
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')

# Setup objects for ADS1115 board
i2c = busio.I2C(board.SCL, board.SDA)