/ examples / ads1x15_simpletest.py
ads1x15_simpletest.py
 1  import time
 2  import board
 3  import busio
 4  import adafruit_ads1x15.ads1015 as ADS
 5  from adafruit_ads1x15.analog_in import AnalogIn
 6  
 7  # Create the I2C bus
 8  i2c = busio.I2C(board.SCL, board.SDA)
 9  
10  # Create the ADC object using the I2C bus
11  ads = ADS.ADS1015(i2c)
12  
13  # Create single-ended input on channel 0
14  chan = AnalogIn(ads, ADS.P0)
15  
16  # Create differential input between channel 0 and 1
17  # chan = AnalogIn(ads, ADS.P0, ADS.P1)
18  
19  print("{:>5}\t{:>5}".format("raw", "v"))
20  
21  while True:
22      print("{:>5}\t{:>5.3f}".format(chan.value, chan.voltage))
23      time.sleep(0.5)