iot: Error 121 performing I2C data transfer

Hi everybody,

I am using a Mlx90614 sensor and sporadically receive an exception running on RaspPi. This issue seems to be similar to #163

My code looks like this:


var settings = new I2cConnectionSettings(busId, i2CAddress);
using (I2cDevice i2c = I2cDevice.Create(settings))
{
   using Mlx90614 sensor = new Mlx90614(i2c);
   logger.Debug(" Got Mlx90614 sensor object");
   Iot.Units.Temperature irtemperature = sensor.ReadObjectTemperature();
   Iot.Units.Temperature ambientTemperature = sensor.ReadAmbientTemperature();
            
   logger.Debug($"Reading Mlx90614 temperatures done");
}

I am creating the I2C device object every 5 seconds, because I have to create antoher I2c device object with different settings (for BME280) and I don’t know if it is ok to have multiple at the same time.

Expected behavior no error ;

Actual behavior sporadically I receive the following exception: 2019-10-30 22:33:14.869 +01:00 [INF] Error while using Mlx90614Reader: Error 121 performing I2C data transfer. System.IO.IOException: Error 121 performing I2C data transfer. at System.Device.I2c.UnixI2cDevice.ReadWriteInterfaceTransfer(Byte* writeBuffer, Byte* readBuffer, Int32 writeBufferLength, Int32 readBufferLength) at System.Device.I2c.UnixI2cDevice.Transfer(Byte* writeBuffer, Byte* readBuffer, Int32 writeBufferLength, Int32 readBufferLength) at System.Device.I2c.UnixI2cDevice.WriteRead(ReadOnlySpan1 writeBuffer, Span1 readBuffer) at Iot.Device.Mlx90614.Mlx90614.ReadTemperature(Byte register) at Iot.Device.Mlx90614.Mlx90614.ReadAmbientTemperature() at Herzonaut.ObservingConditions.Raspi.Sensor.Mlx90614Reader.GetSensorDataInternal(I2cDevice i2cDevice) in C:\d\dn\Herzonaut\git\master\Herzonaut.ObservingConditions.Raspi.Sensor\Mlx90614Reader.cs:line 30 at Herzonaut.ObservingConditions.Raspi.Sensor.AbstractI2CSensorReader`1.GetSensorData() in C:\d\dn\Herzonaut\git\master\Herzonaut.ObservingConditions.Raspi.Sensor\AbstractI2CSensorReader.cs:line 39

Versions used System.Device.Giop 1.0.0 Iot.Device.Bindings 1.0.0

Add following information:

  • dotnet --info on the machine being used to build .NET Core SDK (reflecting any global.json): Version: 3.0.100 Commit: 04339c3a26

Runtime Environment: OS Name: Windows OS Version: 10.0.17763 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.0.100\

Host (useful for support): Version: 3.0.0 Commit: 7d57652f33

.NET Core SDKs installed: 2.1.701 [C:\Program Files\dotnet\sdk] 2.1.801 [C:\Program Files\dotnet\sdk] 2.1.802 [C:\Program Files\dotnet\sdk] 2.2.301 [C:\Program Files\dotnet\sdk] 2.2.401 [C:\Program Files\dotnet\sdk] 2.2.402 [C:\Program Files\dotnet\sdk] 3.0.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

  • dotnet --info on the machine where app is being run (not applicable for self-contained apps) .NET Core SDK (reflecting any global.json): Version: 3.0.100 Commit: 04339c3a26

Runtime Environment: OS Name: raspbian OS Version: 10 OS Platform: Linux RID: linux-arm Base Path: /home/pi/astro/dotnet3/sdk/3.0.100/

Host (useful for support): Version: 3.0.0 Commit: 7d57652f33

.NET Core SDKs installed: 3.0.100 [/home/pi/astro/dotnet3/sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.App 3.0.0 [/home/pi/astro/dotnet3/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.0.0 [/home/pi/astro/dotnet3/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download

  • Version of System.Device.Gpio: 1.0.0
  • Version of Iot.Device.Bindings package 1.0.0

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 36 (26 by maintainers)

Most upvoted comments

I’d like to preface my comment with the fact that I am very new to i2c, raspbian and the MLX90614.

I have seen this issue as well, exactly as described above. When querying very fast to the sensor, the 121 exception is thrown occasionally. I would like to add, however, that I can repro this in Python using the smbus library. I don’t know how similar this is to System.Device.I2c.

This python script can repro the error. With a quick test it failed 43 out of 50 times, 7 times it worked and returned expected data:

import smbus
BUS = smbus.SMBus(1)
DEVICE_ADDRESS = 0x5a
temp = BUS.read_word_data(DEVICE_ADDRESS, 0x07) * 0.02 - 273.15
emis = BUS.read_word_data(DEVICE_ADDRESS, 0x24) / 65535
print(temp)
print(emis)

The error only ever occurs on the second read, and testing with a longer script over 20000 iterations the failure rate was 70 %.

>>> %Run mlx.py
Traceback (most recent call last):
  File "/home/pi/Documents/mlx.py", line 5, in <module>
    emis = BUS.read_word_data(DEVICE_ADDRESS, 0x24) / 65535
OSError: [Errno 121] Remote I/O error

With only a print statement in between the reads I didn’t see a failure over many thousands of iterations:

import smbus	
BUS = smbus.SMBus(1)
DEVICE_ADDRESS = 0x5a
i=0

while True:
	temp = BUS.read_word_data(DEVICE_ADDRESS, 0x07) * 0.02 - 273.15
	print(i)
	emis = BUS.read_word_data(DEVICE_ADDRESS, 0x24) / 65535
	i += 1

My setup is:

  • Raspberry Pi 4, Raspbian 10
  • MLX90614-DCI by DFRobot via Core-Electronics.
    • NB: I am using a relay shield and my i2c connections are going through it’s header, but I don’t imagine it is affecting the performance.
  • Dotnet Core 3.0.0

I am leaning towards the issue being with the sensor not being able to keep up, but my knowledge here is very limited.