AMS812 Pressure sensor IO error with Python

I have been trying to get my python code to work with my sensor to add graphs and excel functions, but I keep getting an IO error 121 for line data = bus.read_i2c_block_data(0x78,4). My java code works, which means that the sensor is communicating with the pi.

I have pasted both the python and java code for reference.

import smbus
import time

Get I²C bus

bus = smbus.SMBus(1)


data = bus.read_i2c_block_data(0x78,4)

Convert the data

pres = ((data[0] & 0xFF) * 256) + data[1]
temp = ((data[2] * 256) + (data[3] & 0xFF)) / 32
pressure = (pres - 1638.0) / (13107.0 / 10.0)
cTemp = ((temp * 200.0) / 2048) - 50.0
fTemp = (cTemp * 1.8 ) + 32

Output data to screen

print ("Pressure : %.2f mbar ") %pressure



public class AMS5812
public static void main(String args[]) throws Exception
// Create I²C bus
I²C Bus Bus = I²C Factory.getInstance(I2CBus.BUS_1);
// Get I²C device, AMS5812 I²C address is 0x78(120)
I²C Device device = Bus.getDevice(0x78);

        // Read 4 bytes of data
        // pressure msb, pressure lsb, temp msb, temp lsb
        byte[] data = new byte[4];, 0, 4);
        // Convert the data
        double pressure = ((data[0] & 0xFF)* 256 + (data[1] & 0xFF));
        double temp = ((data[2] & 0xFF)* 256 + (data[3] & 0xFF));
        pressure = ((pressure - 3277.0) / ((26214.0) / .0725));
        double cTemp = ((temp - 3277.0) / ((26214.0) / 110.0)) - 25.0;
        double fTemp = (cTemp * 1.8 ) + 32;
        double pressurewc = 0.703070 * pressure;
        // Output data to screen
        System.out.printf("Pressure is : %.2f wc%n", pressurewc);
        System.out.printf("Pressure is : %.2f PSI%n", pressure);
        System.out.printf("Temperature in Celsius : %.2f C%n", cTemp);
        System.out.printf("Temperature in Fahrenheit : %.2f F%n", fTemp);

The sensor does not show up when I run I²C detect -y 1, nothing shows up since the sensor’s address is higher than 0x77. When I run the Java code, I get the temp and pressure from the sensor. I’ve compared the readings with an actual pressure sensor and the readings match. Could I be missing something in my python code?

data = bus.read_i2c_block_data(0x78,4)
replace with
data = bus.read_i2c_block_data(0x78,0x00,4)
and see if it responds.

Unfortunately I still get the same [errno 121] Remote I/O error :frowning:

the other way to read without defining the reg location is
data = bus.read_i2c_block_data(0x78,0x55,4)
generally the remote I/O error comes when the i2c device and pi has connection issue. can you check your cables.


Same error :frowning: I have attached a picture of both the java code running and giving me a value through the terminal. Did the board go bad? It’s been a while since I tested the Java values to a prebuilt pressure sensor.

Here is a picture of the set up.

The sensor should be fine, i have seen this kind of issue in past. there are a few i2c devices which does not work sambus(python) lib.
I will see if i can find something,
you can also share this on pi fourm. its possible someone over there might have faced the same issue.

Thank you so much for the help :slight_smile:

Is this more of a code issue or because of the address. I was wondering if it would be easier if I buy a sensor with a lower address? but I would also love to get the current sensor working in order to further increase my knowledge about these devices.