1

I am trying to get an ADC and external oscillator (ADS131M02-q1 and SG531p respectively) to read a 1Vpp@60Hz signal from a function generator to print to a Raspberry Pi my issue is that the ADC value and voltage value always read as 0

import spidev
import time

# create a new SPI object
spi = spidev.SpiDev()
spi.open(0, 0)

# set the SPI mode and clock frequency
spi.mode = 0b01
spi.max_speed_hz = 1000000

# read the ADC values and print them to the console
while True:
    # send the reset command to the ADC
    spi.xfer([0x06])

    # read the ADC values
    adc_values = spi.readbytes(4)
    value = (adc_values[0] << 24) | (adc_values[1] << 16) | (adc_values[2] << 8) | adc_values[3]
    voltage = value / (2 ** 31 - 1) * 2.5
    print("ADC Value: ", value)
    print("Voltage: ", voltage)

    # wait for some time before reading again
    time.sleep(0.1)

above is the code, so far I have confirmed the wiring to the spi pins on the RPi, checked the functionality of the oscillator and function generator on a oscilloscope and checked to make sure that default register values on the ADC are necessary, I am extremely new at python so i am wondering if i have made a clear error in the code

  • I am not familiar with this particular ADC or SPI in Python, but perhaps this [repo][1] can give you some hints. It has C code for interfacing with a click board that includes the ADS131M02-q1. [1]: https://github.com/MikroElektronika/mikrosdk_click_v2/tree/master/clicks/adc15 – cj.burrow Mar 14 '23 at 18:44
  • There is a driver in the Linux kernel (https://elixir.bootlin.com/linux/latest/source/drivers/iio/adc/ti-ads131e08.c), you can modify, if needed, and use it instead of slow python code. – 0andriy Mar 17 '23 at 22:15

0 Answers0