Esempio n. 1
0
def main():
    """This is the main function. It takes 1 argument:
    Ex: python readADC.py 1\t Writes to dataTable in database
    Ex: python readADC.py 2\t Writes to tempTable in database"""
    i2cMux.readI2CMux(1)
    channel = "1"
    # channel min
    # channel max
    # channel units
    # channel interval
    # channel upload ftp link
    #configureI2CMux()
    args = sys.argv
    table = 2
    if len(args) > 2:
        if args[1] == "1" or args[1] == "2":
            #print(args[1])
            table = args[1]
        channel = args[2]
    dictionaryData = uploadCSV.getAllDictionaries()
    temperature = readADC(channel, dictionaryData)
    tempFormatted = "{0:.2f}".format(temperature)
    print("ADC Reading, Channel #" + str(channel) + ": " + "\n" +
          tempFormatted)
    # Insert data into database
    #print("Inserting into database: " + tempFormatted + "for channel " + channel)
    if (tempFormatted > 0):
        insertIntoDatabase(channel, tempFormatted, table)
    else:
        print("Invalid temperature reading.")
        if (retrycounter < 5):
            retrycounter = retrycounter + 1
            main()
Esempio n. 2
0
def initLCD():
    i2cMux.readI2CMux(4)
    time.sleep(0.3)
    pi = pigpio.pi()
    try:
        handle = pi.i2c_open(1, LCD_Address)
        time.sleep(.55)
        pi.i2c_write_device(handle, [0x00,0x38,0x39,0x14,0x78,0x5E,0x6D,0x0c,0x01,0x06])
        time.sleep(0.75)
        pi.i2c_close(handle)
        time.sleep(.2)
    except:
        print("Error Initializing LCD")
Esempio n. 3
0
def main():
    print("Main")
    i2cMux.readI2CMux(4)
    setupGPIO()
    initLCD()
    toggle = 0
    while True:
        repeatThis()
        if toggle == 0:
            setLCDBacklight(1)
            toggle = 1
        else:
            setLCDBacklight(3)
            toggle = 0
        time.sleep(4)
Esempio n. 4
0
def writeText(text):
    i2cMux.readI2CMux(4)
    time.sleep(0.3)
    pi = pigpio.pi()
    try:
        handle = pi.i2c_open(1, LCD_Address)
        time.sleep(.25)
        pi.i2c_write_device(handle, [0x00,0x02])
        time.sleep(.15)
        while len(text) < 20:
            text = text + " "
        pi.i2c_write_device(handle, "A" + text)
        time.sleep(.15)
        pi.i2c_close(handle)
        time.sleep(.1)
    except:
        print("Error Writing LCD Text")
Esempio n. 5
0
def enableDisableHeater(onOff):
    i2cMux.readI2CMux(3)
    time.sleep(0.2)
    pi = pigpio.pi()
    try:
        handle = pi.i2c_open(1, Hum_Address)
        time.sleep(.55)
        if onOff == 1:
            pi.i2c_write_device(handle, [0x30, 0x6D])
        else:
            pi.i2c_write_device(handle, [0x30, 0x66])
        time.sleep(0.2)
        pi.i2c_close(handle)
        time.sleep(0.1)
        pi.stop()
    except Exception as e:
        print(
            "readHumidifier.py:enableDisableHeater(), Error Reading Humidifer")
        print(e)
Esempio n. 6
0
def initLCD():
    print("Initializing LCD")
    i2cMux.readI2CMux(4)
    time.sleep(0.1)
    try:
        if pi.connected:
            print("Pigpio initLCD already connected.")
    except:
        pi = pigpio.pi()
    try:
        handle = pi.i2c_open(1, LCD_Address)
        time.sleep(.5)
        pi.i2c_write_device(
            handle,
            [0x00, 0x38, 0x39, 0x14, 0x78, 0x5E, 0x6D, 0x0c, 0x01, 0x06])
        time.sleep(0.5)
        pi.i2c_close(handle)
        time.sleep(.2)
    except:
        logging.debug("lcdTest.py:initLCD, Error Initializing LCD")
        print("Error Initializing LCD")
    if pi.connected:
        pi.stop()
Esempio n. 7
0
def main():
    """This is the main function. It takes 1 argument:
    Ex: python readHumidifier.py 1\t Writes to dataTable in database
    Ex: python readHumidifier.py 2\t Writes to tempTable in database"""
    #but there is only one table?
    dictionaryData = uploadCSV.getAllDictionaries()
    print(dictionaryData['enabled5'])
    select = 1
    if dictionaryData['enabled5'] == "Yes":
        select = 0
    i2cMux.readI2CMux(3)
    args = sys.argv
    table = 2
    if len(args) > 1:
        if args[1] == "1" or args[1] == "2":
            #print(args[1])
            table = args[1]
    if select == 1:
        tempHum = readHum("6", dictionaryData)
    if select == 0:
        tempHum = readHum_i2c("5", dictionaryData)
    print(tempHum)
    if select == 1:
        insertIntoDatabase("6",
                           tempHum.split(":")[0] + ":" + tempHum.split(":")[2],
                           dictionaryData, table)
        insertIntoDatabase("1",
                           tempHum.split(":")[0], dictionaryData,
                           table)  #happens in readADC
        insertIntoDatabase("2",
                           tempHum.split(":")[1], dictionaryData,
                           table)  #happens in readADC
    if select == 0:
        insertIntoDatabase("5",
                           tempHum.split(":")[0] + ":" + tempHum.split(":")[2],
                           dictionaryData, table)
Esempio n. 8
0
def writeText(text):
    i2cMux.readI2CMux(4)
    time.sleep(0.1)
    try:
        if pi.connected:
            print("Pigpio LCDtext1 already connected.")
    except:
        pi = pigpio.pi()
    try:
        handle = pi.i2c_open(1, LCD_Address)
        time.sleep(.1)
        pi.i2c_write_device(handle, [0x00, 0x02])
        time.sleep(.1)
        while len(text) < 20:
            text = text + " "
        pi.i2c_write_device(handle, "A" + text)
        time.sleep(.1)
        pi.i2c_close(handle)
        time.sleep(.1)
    except Exception as e:
        logging.debug("lcdTest.py:writeText, Error Writing LCD Text")
        print("lcdTest.py:writeText, Error Writing LCD Text")
    if pi.connected:
        pi.stop()