Exemplo n.º 1
0
import time
from machine import I2C
import PCF8591
import binascii

i2c = I2C(0, I2C.MASTER, baudrate=100000)
adcModule = PCF8591.PCF8591(
    i2c, addr=i2c.scan()[0])  # Initializate module with library
sample = 0

while True:
    dataread = adcModule.read(PCF8591.ACHNNL0)  # read from A0
    time.sleep(1)  # sample time
    print("Sample " + str(sample))  #
    print(dataread)  # print read data
    sample += 1
''' TEST WITH NO LIBRARY
while True:
    dataread = i2c.readfrom(0x48, 1)                    # receive 1 bytes from slave
    time.sleep(1)                                       # sample time
    print("Sample "+str(sample))
    test = int(binascii.hexlify(dataread),16)           #
    print(str(test))                                    # print read data
    sample+=1
'''
Exemplo n.º 2
0
            return T
        elif R == float("inf"):
            T = 0. - C2K
            return T
        else:
            T = 1. / self.B * np.log(R / self.R0) + 1. / self.T0
            return 1 / T - C2K


#Test/example code. Read in 3 different thermistors and display their temperatures

if __name__ == "__main__":
    import PCF8591
    #import DHT
    try:
        adc = PCF8591.PCF8591()
        adc.set_input_mode(0)
        thermistor = Thermistor(adc)
        #DHT22=DHT.DHT(21,sensortype=22)
        print("")

        adc.set_input_channel(0)
        T = thermistor.read()
        print("Temperature= %f 'C" % T)

        print("")
        adc.set_input_channel(1)
        T = thermistor.read()
        print("Temperature= %f 'C" % T)

        print("")