1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| import time import board import busio import adafruit_ads1x15.ads1115 as ADS from adafruit_ads1x15.analog_in import AnalogIn
i2c = busio.I2C(board.SCL, board.SDA)
ads0 = ADS.ADS1115(i2c) ads1 = ADS.ADS1115(i2c, address = 73)
chan0 = AnalogIn(ads0, ADS.P0) chan1 = AnalogIn(ads0, ADS.P1) chan2 = AnalogIn(ads0, ADS.P2) chan3 = AnalogIn(ads0, ADS.P3)
chan4 = AnalogIn(ads1, ADS.P0) chan5 = AnalogIn(ads1, ADS.P1) chan6 = AnalogIn(ads1, ADS.P2) chan7 = AnalogIn(ads1, ADS.P3)
print("{:>5}\t{:>5}".format('raw', 'v'))
while True: print("{:>5} | {:>5} |{:>5} |{:>5} |{:>5} |{:>5} |{:>5} |{:>5}".format(chan0.value, chan1.value,chan2.value,chan3.value,chan4.value,chan5.value,chan6.value,chan7.value)) print("{:>5.3f} | {:>5.3f} | {:>5.3f} |{:>5.3f} |{:>5.3f} |{:>5.3f} |{:>5.3f} |{:>5.3f} |".format(chan0.voltage,chan1.voltage,chan2.voltage,chan3.voltage,chan4.voltage,chan5.voltage,chan6.voltage,chan7.voltage)) time.sleep(0.5)
|