|
4 | 4 | import time |
5 | 5 |
|
6 | 6 | import board |
7 | | -import busio |
8 | 7 | import countio |
9 | 8 |
|
10 | | -import adafruit_ads1x15.ads1015 as ADS |
11 | | - |
12 | | -# import adafruit_ads1x15.ads1115 as ADS |
13 | | -from adafruit_ads1x15.ads1x15 import Comp_Latch, Comp_Mode, Comp_Polarity, Mode |
14 | | -from adafruit_ads1x15.analog_in import AnalogIn |
| 9 | +from adafruit_ads1x15 import ADS1015, AnalogIn, ads1x15 |
15 | 10 |
|
16 | 11 | # Create the I2C bus |
17 | | -i2c = busio.I2C(board.SCL, board.SDA) |
| 12 | +i2c = board.I2C() |
18 | 13 |
|
19 | 14 | # Create the ADS object |
20 | | -ads = ADS.ADS1015(i2c) |
| 15 | +ads = ADS1015(i2c) |
21 | 16 | # ads = ADS.ADS1115(i2c) |
22 | 17 |
|
23 | | -# Create a single-ended channel on Pin 0 |
| 18 | +# Create a single-ended channel on Pin A0 |
24 | 19 | # Max counts for ADS1015 = 2047 |
25 | 20 | # ADS1115 = 32767 |
26 | | -chan = AnalogIn(ads, ADS.P0) |
| 21 | +chan = AnalogIn(ads, ads1x15.Pin.A0) |
27 | 22 |
|
28 | 23 | # Create Interrupt-driven input to track comparator changes |
29 | 24 | int_pin = countio.Counter(board.GP9, edge=countio.Edge.RISE) |
30 | 25 |
|
31 | 26 | # Set ADC to continuously read new data |
32 | | -ads.mode = Mode.CONTINUOUS |
| 27 | +ads.mode = ads1x15.Mode.CONTINUOUS |
33 | 28 | # Set comparator to assert after 1 ADC conversion |
34 | 29 | ads.comparator_queue_length = 1 |
35 | 30 | # Set comparator to use traditional threshold instead of window |
36 | | -ads.comparator_mode = Comp_Mode.TRADITIONAL |
| 31 | +ads.comparator_mode = ads1x15.Comp_Mode.TRADITIONAL |
37 | 32 | # Set comparator output to de-assert if readings no longer above threshold |
38 | | -ads.comparator_latch = Comp_Latch.NONLATCHING |
| 33 | +ads.comparator_latch = ads1x15.Comp_Latch.NONLATCHING |
39 | 34 | # Set comparator output to logic LOW when asserted |
40 | | -ads.comparator_polarity = Comp_Polarity.ACTIVE_LOW |
| 35 | +ads.comparator_polarity = ads1x15.Comp_Polarity.ACTIVE_LOW |
41 | 36 | # Gain should be explicitly set to ensure threshold values are calculated correctly |
42 | 37 | ads.gain = 1 |
43 | 38 | # Set comparator low threshold to 2V |
|
0 commit comments