#::::::::::textpak=>ADS1115Runner_wComments.txt smartyPies.com welcome projects misc imprint - legal - GDPR ADS1115Runner.py Mark©&paste the code into a file named "ADS1115Runner.py". Thanks to the guys from GeSHi and Curt, who made me revise the code. Created with GeSHi http://qbnz.com/highlighter/ #!/usr/bin/env python3 # -*- coding: utf-8 -*- ''' @author: guido lutterbach @contact: guido@smartypies.com @version: 1.1 @licence: Public Domain This program implements 4 cases for ADS1115 on raspberry pi with default libraries. 1) single-shot - open drain - timed 2) single-shot - open drain - GPIO alert 3) continuous mode - differential - GPIO alert 4) continuous mode - differential - GPIO alert when value leaves high/low threshold range Please check the electric circuit that goes with it at www.smartypies.com (ADS1115 project) For testing 1) + 2) use potentiometer 1 For testing 3) + 4) use potentiometer 2 Enjoy! ''' import cmd, time, logging, smbus, RPi.GPIO as GPIO # ADS1115 + hardware constants I2C_BUS = 1 DEVICE_ADDRESS = 0x4B POINTER_CONVERSION = 0x0 POINTER_CONFIGURATION = 0x1 POINTER_LOW_THRESHOLD = 0x2 POINTER_HIGH_THRESHOLD = 0x3 RESET_ADDRESS = 0b0000000 RESET_COMMAND = 0b00000110 # Open I2C device BUS = smbus.SMBus(I2C_BUS) BUS.open(I2C_BUS) ALERTPIN = 27 def swap2Bytes(c): '''Revert Byte order for Words (2 Bytes, 16 Bit).''' return (c>>8 |c<<8)&0xFFFF def prepareLEconf(BEconf): '''Prepare LittleEndian Byte pattern from BigEndian configuration string, with separators.''' c = int(BEconf.replace('-',''), base=2) return swap2Bytes(c) def LEtoBE(c): '''Little Endian to BigEndian conversion for signed 2Byte integers (2 complement).''' c = swap2Bytes(c) if(c >= 2**15): c= c-2**16 return c def BEtoLE(c): '''BigEndian to LittleEndian conversion for signed 2 Byte integers (2 complement).''' if(c < 0): c= 2**16 + c return swap2Bytes(c) def resetChip(): BUS.write_byte(RESET_ADDRESS, RESET_COMMAND) return # Use BCM GPIO references GPIO.setmode(GPIO.BCM) GPIO.setup(ALERTPIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) ## read mode, pull up resistor class ADS1115Runner(cmd.Cmd): intro = '''usage: type following commands 1 - one-shot measurement mode, timed 2 - one-shot measurement mode, alerted through GPIO 3 - continuous measurment mode, alerted through GPIO 4 low high - continuous mode, alerted when value out of range [low, high] q (quit) just hitting enter quits any mode 1-4. Enter 'y' to continue in modes 1 and 2.''' prompt = 'Enter 1,2,3,4 or q >>' file = None # __logfile = None def alerted(self, arg): data_raw = BUS.read_word_data(DEVICE_ADDRESS, POINTER_CONVERSION) print('alerted:' + str(LEtoBE(data_raw))) return def do_1(self, arg): '''One-shot, Read value from channel 0 with wait time''' resetChip() # compare with configuration settings from ADS115 datasheet # start single conversion - AIN2/GND - 4.096V - single shot - 8SPS - X # - X - X - disable comparator conf = prepareLEconf('1-110-001-1-000-0-0-0-11') go = 'y' while True and go in ['y','Y']: BUS.write_word_data(DEVICE_ADDRESS, POINTER_CONFIGURATION, conf) # long enough to be safe that data acquisition (conversion) has completed # may be calculated from data rate + some extra time for safety. # check accuracy in any case. time.sleep(0.2) value_raw = BUS.read_word_data(DEVICE_ADDRESS, POINTER_CONVERSION) value = LEtoBE(value_raw) print(value) #enter to break, repeat with 'y' go= input('continue: n/y') if (len(go)==0): go='n' return def do_2(self, arg): '''One-shot with GPIO alert''' # register callback for alerts GPIO.add_event_detect(ALERTPIN, GPIO.RISING, callback=self.alerted) # reset call resetChip() # compare with configuration settings from ADS115 datasheet: # start single conversion - AIN2/GND - 4.096V - single shot - 8SPS - # trad. comparator - active high - latching - assert after one conversion conf = prepareLEconf('1-110-001-1-000-0-1-1-00') BUS.write_byte(0b0000000,0b00000110) # reset call # set High and Low threshold for ALERT pin mode BUS.write_word_data(DEVICE_ADDRESS, POINTER_LOW_THRESHOLD, 0xFF7F) # 0x7FFF in BigEndian BUS.write_word_data(DEVICE_ADDRESS, POINTER_HIGH_THRESHOLD, 0x0080) # 0x8000 in BigEndian go = 'y' while True and go in ['y','Y']: BUS.write_word_data(DEVICE_ADDRESS, POINTER_CONFIGURATION, conf) #enter to break, repeat with 'y' go= input('continue: n/y\n') # remove event listener GPIO.remove_event_detect(ALERTPIN) return def do_3(self, arg): '''Continuous mode with GPIO alert''' # register callback for alerts GPIO.add_event_detect(ALERTPIN, GPIO.RISING, callback=self.alerted) # reset call resetChip() # compare with configuration settings from ADS115 datasheet # X - AIN0/AIN1 - 2.048V - continuous mode - 64SPS - # window comparator - active high - nonlatching - assert after one conversion conf = prepareLEconf('0-000-010-0-011-1-1-0-00') # set High and Low threshold for ALERT pin mode BUS.write_word_data(DEVICE_ADDRESS, POINTER_LOW_THRESHOLD, 0xFF7F) # 0x7FFF in BigEndian BUS.write_word_data(DEVICE_ADDRESS, POINTER_HIGH_THRESHOLD, 0x0080) # 0x8000 in BigEndian # write configuration ONCE BUS.write_word_data(DEVICE_ADDRESS, POINTER_CONFIGURATION, conf) # wait for input(), enter to break input('enter to stop\n' ) # remove event listener to stop execution GPIO.remove_event_detect(ALERTPIN) return def do_4(self, arg): ''' Continuous measurements with latch and allowable data range''' largs = tuple(map(int, arg.split())) if len(largs) != 2: print('please call with exactly 2 integer arguments') return # reset call resetChip() # compare with configuration settings from ADS115 datasheet # X - AIN0/AIN1 - 2.048V - continuous mode - 8SPS - # window comparator - active high - latching - assert after one conversion conf = prepareLEconf('0-000-010-0-000-1-1-1-00') # register callback for alerts GPIO.add_event_detect(ALERTPIN, GPIO.RISING, callback=self.alerted) # prepare for ALERT pin mode - define window low = min(largs) # Python BigEndian - RaspberryPi LittleEndian high = max(largs) low_val = BEtoLE(low) high_val = BEtoLE(high) logger.debug( "{:04X} {:04x} {:04x} {:04x} ".format(low, low_val, high, high_val)) BUS.write_word_data(DEVICE_ADDRESS, POINTER_LOW_THRESHOLD, low_val) BUS.write_word_data(DEVICE_ADDRESS, POINTER_HIGH_THRESHOLD, high_val) # write configuration ONCE BUS.write_word_data(DEVICE_ADDRESS, POINTER_CONFIGURATION, conf) # wait for input(), enter to break input('enter to stop\n' ) # remove event listener to stop execution GPIO.remove_event_detect(ALERTPIN) return def do_q(self, arg): '''Quit.''' return True def default(self, line): print('undefined key') def shutdown(self): GPIO.cleanup() BUS.close() pass if __name__ == "__main__": try: logging.basicConfig( level=logging.DEBUG, #format='%(name)-12s: %(levelname)-8s %(message)s') format='%(message)s') logger = logging.getLogger('ADS1115Runner') Runner = ADS1115Runner() Runner.cmdloop() finally: Runner.shutdown() # © Copyright 2017-20 by Guido Lutterbach # guido@smartypies.com # / ADS1115Runner.p #::::::::::textpak=>ADS1115Runner_pgmOnly.py import cmd, time, logging, smbus, RPi.GPIO as GPIO # ADS1115 + hardware constants I2C_BUS = 1 #DEVICE_ADDRESS = 0x4B #DC DEVICE_ADDRESS = 0x48 #DC POINTER_CONVERSION = 0x0 POINTER_CONFIGURATION = 0x1 POINTER_LOW_THRESHOLD = 0x2 POINTER_HIGH_THRESHOLD = 0x3 RESET_ADDRESS = 0b0000000 RESET_COMMAND = 0b00000110 # Open I2C device BUS = smbus.SMBus(I2C_BUS) BUS.open(I2C_BUS) ALERTPIN = 27 #GPIO27 #DC def swap2Bytes(c): '''Revert Byte order for Words (2 Bytes, 16 Bit).''' return (c>>8 |c<<8)&0xFFFF def prepareLEconf(BEconf): '''Prepare LittleEndian Byte pattern from BigEndian configuration string, with separators.''' c = int(BEconf.replace('-',''), base=2) return swap2Bytes(c) def LEtoBE(c): '''Little Endian to BigEndian conversion for signed 2Byte integers (2 complement).''' c = swap2Bytes(c) if(c >= 2**15): c= c-2**16 return c def BEtoLE(c): '''BigEndian to LittleEndian conversion for signed 2 Byte integers (2 complement).''' if(c < 0): c= 2**16 + c return swap2Bytes(c) def resetChip(): BUS.write_byte(RESET_ADDRESS, RESET_COMMAND) return # Use BCM GPIO references GPIO.setmode(GPIO.BCM) GPIO.setup(ALERTPIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) ## read mode, pull up resistor class ADS1115Runner(cmd.Cmd): intro = '''usage: type following commands 1 - one-shot measurement mode, timed 2 - one-shot measurement mode, alerted through GPIO 3 - continuous measurment mode, alerted through GPIO 4 low high - continuous mode, alerted when value out of range [low, high] q (quit) just hitting enter quits any mode 1-4. Enter 'y' to continue in modes 1 and 2.''' prompt = 'Enter 1,2,3,4 or q >>' file = None # __logfile = None def alerted(self, arg): data_raw = BUS.read_word_data(DEVICE_ADDRESS, POINTER_CONVERSION) print('alerted:' + str(LEtoBE(data_raw))) return def do_1(self, arg): '''One-shot, Read value from channel 0 with wait time''' resetChip() # compare with configuration settings from ADS115 datasheet # start single conversion - AIN2/GND - 4.096V - single shot - 8SPS - X # - X - X - disable comparator conf = prepareLEconf('1-110-001-1-000-0-0-0-11') go = 'y' while True and go in ['y','Y']: BUS.write_word_data(DEVICE_ADDRESS, POINTER_CONFIGURATION, conf) # long enough to be safe that data acquisition (conversion) has completed # may be calculated from data rate + some extra time for safety. # check accuracy in any case. time.sleep(0.2) value_raw = BUS.read_word_data(DEVICE_ADDRESS, POINTER_CONVERSION) value = LEtoBE(value_raw) print(value) #enter to break, repeat with 'y' go= input('continue: n/y') if (len(go)==0): go='n' return def do_2(self, arg): '''One-shot with GPIO alert''' # register callback for alerts GPIO.add_event_detect(ALERTPIN, GPIO.RISING, callback=self.alerted) # reset call resetChip() # compare with configuration settings from ADS115 datasheet: # start single conversion - AIN2/GND - 4.096V - single shot - 8SPS - # trad. comparator - active high - latching - assert after one conversion conf = prepareLEconf('1-110-001-1-000-0-1-1-00') BUS.write_byte(0b0000000,0b00000110) # reset call # set High and Low threshold for ALERT pin mode BUS.write_word_data(DEVICE_ADDRESS, POINTER_LOW_THRESHOLD, 0xFF7F) # 0x7FFF in BigEndian BUS.write_word_data(DEVICE_ADDRESS, POINTER_HIGH_THRESHOLD, 0x0080) # 0x8000 in BigEndian go = 'y' while True and go in ['y','Y']: BUS.write_word_data(DEVICE_ADDRESS, POINTER_CONFIGURATION, conf) #enter to break, repeat with 'y' go= input('continue: n/y\n') # remove event listener GPIO.remove_event_detect(ALERTPIN) return def do_3(self, arg): '''Continuous mode with GPIO alert''' # register callback for alerts GPIO.add_event_detect(ALERTPIN, GPIO.RISING, callback=self.alerted) # reset call resetChip() # compare with configuration settings from ADS115 datasheet # X - AIN0/AIN1 - 2.048V - continuous mode - 64SPS - # window comparator - active high - nonlatching - assert after one conversion conf = prepareLEconf('0-000-010-0-011-1-1-0-00') # set High and Low threshold for ALERT pin mode BUS.write_word_data(DEVICE_ADDRESS, POINTER_LOW_THRESHOLD, 0xFF7F) # 0x7FFF in BigEndian BUS.write_word_data(DEVICE_ADDRESS, POINTER_HIGH_THRESHOLD, 0x0080) # 0x8000 in BigEndian # write configuration ONCE BUS.write_word_data(DEVICE_ADDRESS, POINTER_CONFIGURATION, conf) # wait for input(), enter to break input('enter to stop\n' ) # remove event listener to stop execution GPIO.remove_event_detect(ALERTPIN) return def do_4(self, arg): ''' Continuous measurements with latch and allowable data range''' largs = tuple(map(int, arg.split())) if len(largs) != 2: print('please call with exactly 2 integer arguments') return # reset call resetChip() # compare with configuration settings from ADS115 datasheet # X - AIN0/AIN1 - 2.048V - continuous mode - 8SPS - # window comparator - active high - latching - assert after one conversion conf = prepareLEconf('0-000-010-0-000-1-1-1-00') # register callback for alerts GPIO.add_event_detect(ALERTPIN, GPIO.RISING, callback=self.alerted) # prepare for ALERT pin mode - define window low = min(largs) # Python BigEndian - RaspberryPi LittleEndian high = max(largs) low_val = BEtoLE(low) high_val = BEtoLE(high) logger.debug( "{:04X} {:04x} {:04x} {:04x} ".format(low, low_val, high, high_val)) BUS.write_word_data(DEVICE_ADDRESS, POINTER_LOW_THRESHOLD, low_val) BUS.write_word_data(DEVICE_ADDRESS, POINTER_HIGH_THRESHOLD, high_val) # write configuration ONCE BUS.write_word_data(DEVICE_ADDRESS, POINTER_CONFIGURATION, conf) # wait for input(), enter to break input('enter to stop\n' ) # remove event listener to stop execution GPIO.remove_event_detect(ALERTPIN) return def do_q(self, arg): '''Quit.''' return True def default(self, line): print('undefined key') def shutdown(self): GPIO.cleanup() BUS.close() pass if __name__ == "__main__": try: logging.basicConfig( level=logging.DEBUG, #format='%(name)-12s: %(levelname)-8s %(message)s') format='%(message)s') logger = logging.getLogger('ADS1115Runner') Runner = ADS1115Runner() Runner.cmdloop() finally: Runner.shutdown() # © Copyright 2017-20 by Guido Lutterbach # guido@smartypies.com # / ADS1115Runner_pgmOnly.p #::::::::::textpak=>adcRead_Pkg.py # function Package adcRead_Pkg.py import cmd, time, logging, smbus, RPi.GPIO as GPIO #Source: https://smartypies.com/projects/ads1115-with-raspberrypi-and-python/ads1115runner/ #DC #ADS1115 Datasheet: https://www.ti.com/lit/ds/symlink/ads1115.pdf?ts=1647366695082&ref_url=https%253A%252F%252Fwww.digchip.com%252F # Usage once: # define adcRead constants # see the main program test_adcRead.py # BUS = adcReadInit(I2C_BUS,icNumber) # create BUS class object # BUS.open(I2C_BUS) # . . . then repeatedly # value = adcRead(nChannel) # read nChannel of the ADS1115 once # # no other functions need to be called # # the only externally callable functions are # adcReadInit() # adcRead() # # stop this program using ctrl+c # how to stop the test def MUX(n): if n==0: m="00" if n==1: m="01" if n==2: m="10" if n==3: m="11" return m #def end def swap2Bytes(c): '''Revert Byte order for Words (2 Bytes, 16 Bit).''' return (c>>8 |c<<8)&0xFFFF #def end def prepareLEconf(BEconf): '''Prepare LittleEndian Byte pattern from BigEndian configuration string, with separators.''' c = int(BEconf.replace('-',''), base=2) return swap2Bytes(c) #def end def LEtoBE(c): '''Little Endian to BigEndian conversion for signed 2Byte integers (2 complement).''' c = swap2Bytes(c) if(c >= 2**15): c= c-2**16 return c #def end def BEtoLE(c): '''BigEndian to LittleEndian conversion for signed 2 Byte integers (2 complement).''' if(c < 0): c= 2**16 + c return swap2Bytes(c) #def end def resetChip(RESET_ADDRESS, RESET_COMMAND): #BUS.write_byte(RESET_ADDRESS, RESET_COMMAND) return #def end class ADS1115Runner(cmd.Cmd): # this is the entry-point for Runner.cmdloop() # NB cmd.Cmd has been deprecated # cmd.Cmd will cause the self.cmdLoop() to return to the object's main method. # the ''' permits the definition of a string variable containing LFs #intro = '''usage: type following commands # 1 - one-shot measurement mode, timed # 2 - one-shot measurement mode, alerted through GPIO # 3 - continuous measurment mode, alerted through GPIO # 4 low high - continuous mode, alerted when value out of range [low, high] # q (quit) # just hitting enter quits any mode 1-4. Enter 'y' to continue in modes 1 and 2.''' #prompt = 'Enter 1,2,3,4 or q >>' # if you enter 1 it will run do_1(), 2 . . . do_2() etc file = None __logfile = None def alerted(self, arg): # deprecated data_raw = BUS.read_word_data(DEVICE_ADDRESS, POINTER_CONVERSION) print('alerted:' + str(LEtoBE(data_raw))) return #def end alerted() def do_q(self, arg): exit #def end do_q() def mydo_1(self,BUS,AINn): RESET_ADDRESS = 0b0000000 RESET_COMMAND = 0b00000110 POINTER_CONVERSION = 0x0 POINTER_CONFIGURATION = 0x1 POINTER_LOW_THRESHOLD = 0x2 POINTER_HIGH_THRESHOLD = 0x3 DEVICE_ADDRESS = 0x48 # device address selected on the IC chip # replaces do_1 routine #print("into do_1 arg:",arg) #print("into do_1") '''One-shot, Read value from channel AINn with wait time''' #resetChip(RESET_ADDRESS, RESET_COMMAND) #deprecated BUS.write_byte(RESET_ADDRESS, RESET_COMMAND) #replace # compare with configuration settings from ADS1115 datasheet #DC # start single conversion - AIN2/GND - 4.096V - single shot - 8SPS - X # - X - X - disable comparator # conf = prepareLEconf('1-110-001-1-000-0-0-0-11') #DC # AINn = 2 arg1 is AINn the nChannel to read ADSn = MUX(AINn) #e.g. AINn=2 read AIN2 ( AIN2 to GND*) #DC conf = prepareLEconf('1-1'+ADSn+'-001-1-000-0-0-0-11') #DC go = 'y' #while True and go in ['y','Y']: if True : #only do this once BUS.write_word_data(DEVICE_ADDRESS, POINTER_CONFIGURATION, conf) # long enough to be safe that data acquisition (conversion) has completed # may be calculated from data rate + some extra time for safety. # check accuracy in any case. time.sleep(0.2) value_raw = BUS.read_word_data(DEVICE_ADDRESS, POINTER_CONVERSION) value = LEtoBE(value_raw) #print("mid do_1") global g_adcValue g_adcValue = value # so adcRead() can see it #print(value) # test_adcRead() will print it #enter to break, repeat with 'y' if False : # deprecated go= input('continue: n/y') if (len(go)==0): go='n' #time.sleep(sleepTime) #if end return value #def end mydo_1() def shutdown(self): #GPIO.cleanup() #BUS.close() pass #def end shutdown() #class end ADS1115Runner() def adcRead(BUS,nChannel=0) : # nChannel is the number of the analog input to read i.e. 0 = AIN0 # adcRead returns value 0 to ~11000 as the actual reading #by D@CC on 202CMar16 DC #must be preceded by # BUS.adcReadInit(I2C_BUS,icNumber) # BUS.open(I2C_BUS) #Source: https://smartypies.com/projects/ads1115-with-raspberrypi-and-python/ads1115runner/ #DC #ADS1115 Datasheet: https://www.ti.com/lit/ds/symlink/ads1115.pdf?ts=1647366695082&ref_url=https%253A%252F%252Fwww.digchip.com%252F #Jumper S of KY-18 photo-cell to AIN2 # invert the KY-18 3v3 and GND to measure the opposite [ light (not dark) ] # terminal strip is L-R on the ADS1115 for RPi from SeeedStudios # 3V3,AIN3,AIN2,AIN1,AIN0,GND # Uses 3 objects:BUS.write_byte(RESET_ADDRESS, RESET_COMMAND) #replace # Runner. for ADS1115 ADC # BUS. for ADS11#Jumper S of KY-18 photo-cell to AIN2 #DC # GPIO. for ALERTPIN class is not used #DC try: # I (D@CC) do not know anything about the logging logging.basicConfig( level=logging.DEBUG, #format='%(name)-12s: %(levelname)-8s %(message)s') format='%(message)s') logger = logging.getLogger('ADS1115Runner') #print("logger:",logger) #AINn=2 # AINn=2 to read AIN2 Runner = ADS1115Runner() # create object Runner #print("before .cmdloop") Runner.mydo_1(BUS,nChannel) # nChannel is 2 to read AIN2 #Runner.cmdloop() # will run the main Runner.method (cmd.Cmd) # which prompts for a response & invokes do_r(arg) # for a response of "r arg" #print("after .cmdloop") global g_adcValue returnValue = g_adcValue # from mydo_1 return returnValue finally: Runner.shutdown() #release this object #BUS.close() #release this object #if end adcRead() def adcReadInit(I2C_BUS=1,icNumber="ADS1115") : # arg1 is the BUS number used by the IC chip # arg2 is the number of the IC chip used on the Seeed ADS1115 4 channel RPi board # usage of global variables # global g_adcValue if icNumber=="ADS1115" : BUS=smbus.SMBus(I2C_BUS) #returns the BUS object , (usually BUS=smbus.SMBus(I2C_BUS) ) # Open I2C device # I2C_BUS = 1 # DEVICE_ADDRESS = 0x48 return BUS else: print('ERROR025: ic supported is "ADS1115"') exit #def end adcReadInit() # 9 constants included in adcRead_Pkg.py RESET_ADDRESS = 0b0000000 RESET_COMMAND = 0b00000110 POINTER_CONVERSION = 0x0 POINTER_CONFIGURATION = 0x1 POINTER_LOW_THRESHOLD = 0x2 POINTER_HIGH_THRESHOLD = 0x3 DEVICE_ADDRESS = 0x48 # device address selected on the IC chip icNumber = "ADS1115" # IC chip used I2C_BUS = 1 # BUS number used by the IC chip # end of adcRead_pkg.p #::::::::::textpak=>test_adcRead.py # test_adcRead.py # program to test adcRead() to read nChannel on the ADS1115 ADC RPi module from SeeedStuios # by D@CC on 2022CMar16 # needs to have adcRead_Pkg.py in the same folder as test_adcRead.py # needs import time import time # needs from adcRead_Pkg import adcRead,adcReadInit from adcRead_Pkg import adcRead,adcReadInit #needs to be run as >$ python3 test_adcRead.py if __name__ == "__main__": # import adcRead_pkg.py # is needed progName="test_adcRead.py" #this is the main program to test adcRead() print("starting:"+progName) # These 9 parameters are also defined in # adcRead_pkg.py: # mydo_1() RESET_ADDRESS = 0b0000000 RESET_COMMAND = 0b00000110 POINTER_CONVERSION = 0x0 POINTER_CONFIGURATION = 0x1 POINTER_LOW_THRESHOLD = 0x2 POINTER_HIGH_THRESHOLD = 0x3 DEVICE_ADDRESS = 0x48 # device address selected on the IC chip icNumber = "ADS1115" # IC chip used I2C_BUS = 1 # BUS number used by the IC chip # above constants are used with the ADS1115 IC chip: # [they could be defined as global variables in adcRead_init() instead] # These 2 constants must be defined in the test_adcRead.py program dT = 1 # sleep time between readings (set by the user of this program) nChannel = 2 # AINn is the analog pin # to read on the ADS1115 IC chip # # more than 1 channel can be read by the program # # simply use adcRead(nChannel) where nChannel is the channel to read # usage of global variables # global g_adcValue # this variable can be referenced (seen) by any program using adcRead() # it always contains the most-recent-value read by adcRead() #create the BUS object BUS = adcReadInit(I2C_BUS,icNumber) BUS.open(I2C_BUS) while True : # loop value = adcRead(BUS,nChannel) # reading nChannel of the ADS1115 once AINn="AIN"+str(nChannel) AINn=AINn.strip(" ") print ("value of "+AINn+" reading:", value) if dT==0 : break #out of while loop # dT=0 will only read it once else: time.sleep(dT) # dT>0 will read it continuously #if end #while end #end test_adcRead.p