Thank you for all the replies.
The error was that I was unaware of the fact that Pi uses little endian format and adc used big endian format. I figured it out by using a constant dc voltage supply to pi and modified the code accordingly.
The current problem I face is:
When the sampling rate is 860sps and I read 860 samples, sometimes the values are repeated and sometimes I see 860 discrete values. This behaviour is random. My loop has this code:
while len(buffer) < sampling_rate:
start_time = time.perf_counter()
b = bus.read_word_data(0x48, 0)
value = ((b & 0xFF00) >> 8 | (b & 0x00FF) << 8)
buffer.append(value)
stop_time = time.perf_counter()
difference = stop_time - start_time
if difference < sampling_interval:
time.sleep(sampling_interval - difference)
else:
print("oversleep")
where the timing mismatch is being taken care of using if else condition.
I use ADS1115 and the data sheet says that there is an alert/ready pin for precise measurements.
I am using gpiozero library to access this pin and have this basic code to test the condition of gpio pin connected to alert/ready pin of ADS1115:
from gpiozero import DigitalInputDevice
import adafruit_ads1x15.ads1115 as ADS
from adafruit_extended_bus import ExtendedI2C as I2C
import time
from smbus2 import SMBus
with SMBus(1) as bus:
i2c = I2C(1)
ads = ADS.ADS1115(i2c, gain=1)
ads._write_register(2, 0b0000000000000000)
ads._write_register(3, 0b0000000010000000)
ALERT_PIN = 17
alert = DigitalInputDevice(ALERT_PIN)
try:
while True:
# Read the alert pin
if alert.is_active:
print("Alert Triggered!")
else:
print("No Alert")
time.sleep(1) # Delay for 1 second
except KeyboardInterrupt:
print("Program terminated")
when executing this code I face "RuntimeError: Cannot determine SOC peripheral base address " this error. I tried working with gpiod library as well and found no luck. Also RPi.GPIO library and found in many discussions forum that this library is not supported in Pi 5.
Is there any other way where I can access the gpio pin and read the status of the alert/ready pin from ADS1115?
Or is there any other way where I can verify that the timing is matched between the adc sampling and pi receiving the data?
My thoughts so far: The adc does not have a mind of it's own, so it samples at the sampling rate mentioned in the configuration register. The pi has to fetch data continuously at an interval mentioned in the code. The fact that the data is repeated sometimes and not always is because the processor of pi being distracted by other background tasks?
The error was that I was unaware of the fact that Pi uses little endian format and adc used big endian format. I figured it out by using a constant dc voltage supply to pi and modified the code accordingly.
The current problem I face is:
When the sampling rate is 860sps and I read 860 samples, sometimes the values are repeated and sometimes I see 860 discrete values. This behaviour is random. My loop has this code:
while len(buffer) < sampling_rate:
start_time = time.perf_counter()
b = bus.read_word_data(0x48, 0)
value = ((b & 0xFF00) >> 8 | (b & 0x00FF) << 8)
buffer.append(value)
stop_time = time.perf_counter()
difference = stop_time - start_time
if difference < sampling_interval:
time.sleep(sampling_interval - difference)
else:
print("oversleep")
where the timing mismatch is being taken care of using if else condition.
I use ADS1115 and the data sheet says that there is an alert/ready pin for precise measurements.
I am using gpiozero library to access this pin and have this basic code to test the condition of gpio pin connected to alert/ready pin of ADS1115:
from gpiozero import DigitalInputDevice
import adafruit_ads1x15.ads1115 as ADS
from adafruit_extended_bus import ExtendedI2C as I2C
import time
from smbus2 import SMBus
with SMBus(1) as bus:
i2c = I2C(1)
ads = ADS.ADS1115(i2c, gain=1)
ads._write_register(2, 0b0000000000000000)
ads._write_register(3, 0b0000000010000000)
ALERT_PIN = 17
alert = DigitalInputDevice(ALERT_PIN)
try:
while True:
# Read the alert pin
if alert.is_active:
print("Alert Triggered!")
else:
print("No Alert")
time.sleep(1) # Delay for 1 second
except KeyboardInterrupt:
print("Program terminated")
when executing this code I face "RuntimeError: Cannot determine SOC peripheral base address " this error. I tried working with gpiod library as well and found no luck. Also RPi.GPIO library and found in many discussions forum that this library is not supported in Pi 5.
Is there any other way where I can access the gpio pin and read the status of the alert/ready pin from ADS1115?
Or is there any other way where I can verify that the timing is matched between the adc sampling and pi receiving the data?
My thoughts so far: The adc does not have a mind of it's own, so it samples at the sampling rate mentioned in the configuration register. The pi has to fetch data continuously at an interval mentioned in the code. The fact that the data is repeated sometimes and not always is because the processor of pi being distracted by other background tasks?
Statistics: Posted by Ananya — Mon Jul 29, 2024 2:39 pm