ADC121C021 pyserial Interfacing

I am attempting to connect and interact with an ADC121C021(connected to a pressure transducer) through a PR33-17 USB-I2C interface. I have wired everything and tested the product with the AnyI2C application, and receive ADC values that correctly change when the pressure differs. The next step is automating this data query/collection, which I am attempting to do with the pyserial library since I am on windows and cannot use smbus libraries. I have tried working through this page (Serial to I2C Conversion - NCD USART to I2C Converter Protocol) and developing byte strings to send, and ended up with these byte strings:

configure read
\xaa\x06\xbc\x32\x50\x01\x80\x00\xee
request data back
\xaa\x07\xbc\x32\x50\x01\x00\x02\xb6

However, I have not received any response back(no data, error messages, or even bytes) to ~20 variations of these calls. I have also tried using the API Encoded strings from AnyI2C and did not have any success sending those either. All I need to do is request the ADC values and read them back over serial periodically. Any advice on how to do this?

You don’t need the smbus lib. it should be a simple serial read write. i have never used python with this device.

After sending the command byte strings over serial I get no bytes in reply. Are there any setup or configuration calls I am missing? I am using the same baud rate as AnyI2C so thats the issue.

When using any I2C , you can view the entire Tx and Rx payload. Ensure that you send the same payload using a serial terminal first, and check that your serial port settings are correct.

I appreciate the assistance. Here is the working output on anyi2c(logging in API Encoded mode)

and here is my python attempt to replicate the exact output from anyi2c with which I get no bytes at all in reply without modifying my hardware setup:

import time

import serial

COM_PORT = “COM101”
BAUDRATE = 115200

VREF = 5.0
ser = serial.Serial(
port=COM_PORT,
baudrate=115200,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
timeout=2.0,
)

def read_adc_raw():
time.sleep(1.5)

ser.reset_input_buffer()

ser.write(b"\xbe\x50\x80")
time.sleep(0.5)
ser.write(b"\xbe\x50\x80")
time.sleep(0.5)
bytes_waiting = ser.in_waiting
print(f"\nBytes waiting in buffer: {bytes_waiting}")

data = ser.read(2)
print(f"data = {data}")
if len(data) != 2:
print(“No data”)

ser.reset_input_buffer()

ser.write(b"\xbe\x50\x02\x00\x00")
time.sleep(0.5)
ser.write(b"\xbe\x50\x02\x00\x00")

time.sleep(0.5)

bytes_waiting = ser.in_waiting
print(f"\nBytes waiting in buffer: {bytes_waiting}")

data = ser.read(2)

print(f"data = {data}")
if len(data) != 2:
return None

raw = ((data[0] << 8) | data[1]) >> 4
return raw

def adc_to_voltage(raw):
return (raw / 4095.0) * VREF

def voltage_to_psi(v):
return v * 20.0 # 0–100 PSI

while True:
raw = read_adc_raw()

if raw is None:
print(“No data”)
continue

voltage = adc_to_voltage(raw)
psi = voltage_to_psi(voltage)

print(f"Raw: {raw} | Voltage: {voltage:.4f} V | PSI: {psi:.2f}")

time.sleep(0.2)

Working with the bare bones example on Serial to I2C Conversion - NCD USART to I2C Converter Protocol, I got data back, I will work in the anyi2c payload

I was calculating my checksums incorrectly, I can read the ACD now. Thanks!

1 Like