This Python (not CircuitPython) code is intended for collecting continuous, differential Analog-to-Digital Converter (ADC) counts with a timestamp.
The Raspberry Pi will collect data and save to a csv file as long as it receives a HIGH signal. The code is cyclic; once it has been started from the terminal, it will repeat the process of waiting, collecting data, and storing data until interrupted.
-
This code was written on a Raspberry Pi 0W but can be run on any Raspberry Pi.
-
The ADS1115 is a 16-bit, general-pupose, programmble gain amplifier (PGA) ADC breakboard board from Adafruit & Texas Instruments (datasheet).
-
This code uses Adafruit's ADS1115 Python library.
The microcontroller-ADC wiring is described in Adafruit's tutorial.
This code assumes two microcontrollers. The first is controlling some process which produces analog measurements. The second is a Raspberry Pi communicating with the ADS1115 chip. Since both mirocontrollers control events on independent timelines, timestamps are created to correlate the two chronologies.
Generally, this code returns 820 samples per second. The ADS1115 datasheet sets an upper limit of 860 samples per second. While the Raspberry Pi's bus speed can be changed from the default 100000 to 400000 ((https://www.raspberrypi-spy.co.uk/2018/02/change-raspberry-pi-i2c-bus-speed/)), doing so does not positively impact the sampling rate of the afore-described setup. It results in ADC data being read by the Raspberry Pi multiple times (data duplication).
If you are willing to trade precision for speed, the ADS1015 is a 12-bit ADC with an upper limit of 3,300 samples per second.
Please see the examples in Adafruit's ADS1115 Python library for explanations on how to alter I2C addresses, ADC conversion speeds, PGA, etc.
A detailed explanation of I2C is provided in the ADS1115 datasheet, but a nice job of explaining I2C and its relevance to microcontroller-ADS1115 communication and code can also be found here.
If you are interested in using CircuitPython or Arduino, check out Adafruit's newer tutorial.