From bb65ecbcab7d49601a3868c8aa0d010e85de6014 Mon Sep 17 00:00:00 2001 From: Electronica y Ciencia Date: Wed, 17 Jul 2024 16:33:20 +0200 Subject: [PATCH] ADS1115 example --- .../ADS1115/{ADS_continuous.py => ADS_read.py} | 17 +++++++++++------ examples/ADS1115/README.md | 18 ++++++------------ 2 files changed, 17 insertions(+), 18 deletions(-) rename examples/ADS1115/{ADS_continuous.py => ADS_read.py} (57%) diff --git a/examples/ADS1115/ADS_continuous.py b/examples/ADS1115/ADS_read.py similarity index 57% rename from examples/ADS1115/ADS_continuous.py rename to examples/ADS1115/ADS_read.py index caeb9e3..aac640d 100644 --- a/examples/ADS1115/ADS_continuous.py +++ b/examples/ADS1115/ADS_read.py @@ -1,5 +1,5 @@ """ -FILE : ADS_continuous.py +FILE : ADS_read.py AUTHOR : Chandra.Wijaya VERSION : 1.2.0 PURPOSE : read analog input @@ -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) diff --git a/examples/ADS1115/README.md b/examples/ADS1115/README.md index 2ea290d..85ed134 100644 --- a/examples/ADS1115/README.md +++ b/examples/ADS1115/README.md @@ -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 ```