Skip to content

Commit

Permalink
ADS1115 example
Browse files Browse the repository at this point in the history
  • Loading branch information
electronicayciencia committed Jul 17, 2024
1 parent f7faffa commit bb65ecb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
FILE : ADS_continuous.py
FILE : ADS_read.py
AUTHOR : Chandra.Wijaya
VERSION : 1.2.0
PURPOSE : read analog input
Expand Down Expand Up @@ -29,12 +29,17 @@
print(os.path.basename(__file__))
print("ADS1X15_LIB_VERSION: {}".format(ADS1x15.__version__))

# set gain to 4.096V max
ADS.setGain(ADS.PGA_4_096V)
ADS.setDataRate(ADS.DR_ADS111X_128)
ADS.setMode(ADS.MODE_CONTINUOUS)
ADS.requestADC(0) # First read to trigger
f = ADS.toVoltage()

while True :
raw = ADS.getValue()
print("{0:.3f} V".format(ADS.toVoltage(raw)))
val_0 = ADS.readADC(0)
val_1 = ADS.readADC(1)
val_2 = ADS.readADC(2)
val_3 = ADS.readADC(3)
print("Analog0: {0:d}\t{1:.3f} V".format(val_0, val_0 * f))
print("Analog1: {0:d}\t{1:.3f} V".format(val_1, val_1 * f))
print("Analog2: {0:d}\t{1:.3f} V".format(val_2, val_2 * f))
print("Analog3: {0:d}\t{1:.3f} V".format(val_3, val_3 * f))
time.sleep(1)
18 changes: 6 additions & 12 deletions examples/ADS1115/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,11 @@ from EasyMCP2221 import SMBus
Run the examples in [chandrawi/ADS1x15-ADC](https://github.com/chandrawi/ADS1x15-ADC) repository with no further modifications.

```console
$ python ADS_continuous.py
ADS_continuous.py
$ python ADS_read.py
ADS_read.py
ADS1X15_LIB_VERSION: 1.2.2
0.000 V
0.104 V
1.954 V
2.359 V
3.285 V
3.085 V
2.922 V
2.463 V
2.085 V
1.622 V
Analog0: 12991 1.624 V
Analog1: 4647 0.581 V
Analog2: 4622 0.578 V
Analog3: 4646 0.581 V
```

0 comments on commit bb65ecb

Please sign in to comment.