0

Getting I/O errors when using Python 3 smbus module under Raspbian to retrieve (read) data back from a laptop Smart Battery. A similar program coded in C for Arduino works perfectly with this battery. The errors appear to be random; sometimes the 1st read gives an I/O error and sometimes the 10th read produces the error. Anyone have any idea why the errors are so random?

I have now attached the Python program I am using to obtain data from the laptop Smart Battery as well as some examples of what output the program produces. The first run shows the output when all 4 SMbus transactions work without error. The 2nd and 3rd runs show the output when the I/O error occurs. Note that the I/O Error occurs on different bus transactions which is why I am calling this a "random" error.

# Read Smart Battery Info Using Python smbus module

import smbus
#import time

I2C_BUS = 1
BAT_ADDR = 0x0b

pad = 35 # amount to pad parameter descriptions

# ****** Smart Battery Commands & Returned Data Type ******
cmdRemTimeAlmThresh = 0x02  # uint (r/w)
cmdTemperature      = 0x08  # uint, Temperature in 0.1degK
cmdDesignVoltage    = 0x19  # uint, voltage of new pack in mV
cmdSerNum           = 0x1c  # uint, serial number

#------------------------------------------------------------------------------

print("Smart Battery Info\n")

bus = smbus.SMBus(I2C_BUS)
bus.pec = True
#time.sleep(1)

# Get serial number
serial_number = bus.read_word_data(BAT_ADDR, cmdSerNum)
print("{0:{2}}{1}".format("Serial number:", serial_number, pad))

# Get remaining time alarm threshold
rem_time_alarm_thres = bus.read_word_data(BAT_ADDR, cmdRemTimeAlmThresh)
print("{0:{2}}{1} minutes".format("Remaining time alarm threshold:",
                                  rem_time_alarm_thres, pad))

# Get design voltage
design_voltage = bus.read_word_data(BAT_ADDR, cmdDesignVoltage) / 1000.0
print("{0:{2}}{1} V".format("Design voltage:", design_voltage, pad))

# Get battery temperature
data_word = bus.read_word_data(BAT_ADDR, cmdTemperature)
temperature = 9/5 * ((data_word/10.0) - 273.15) +32
print("{0:{2}}{1:0.1f} \xb0F".format("Battery temperature:", temperature, pad))

bus.close()

Here is what the program output looks like when it completes with no errors:

>>> 
 RESTART: /home/pi/Documents/Python Programs/HW-related/SmartBatInfo_mini.py 
Smart Battery Info

Serial number:                     1201
Remaining time alarm threshold:    10 minutes
Design voltage:                    10.8 V
Battery temperature:               65.6 °F

Here is what the program output looks like when the 4th SMbus transaction fails:

>>> 
 RESTART: /home/pi/Documents/Python Programs/HW-related/SmartBatInfo_mini.py 
Smart Battery Info

Serial number:                     1201
Remaining time alarm threshold:    10 minutes
Design voltage:                    10.8 V
Traceback (most recent call last):
  File "/home/pi/Documents/Python Programs/HW-related/SmartBatInfo_mini.py", line 39, in <module>
    data_word = bus.read_word_data(BAT_ADDR, cmdTemperature)
OSError: [Errno 121] Remote I/O error

Here is what the program output looks like when the 1st SMbus transaction fails:

>>> 
 RESTART: /home/pi/Documents/Python Programs/HW-related/SmartBatInfo_mini.py 
Smart Battery Info

Traceback (most recent call last):
  File "/home/pi/Documents/Python Programs/HW-related/SmartBatInfo_mini.py", line 26, in <module>
    serial_number = bus.read_word_data(BAT_ADDR, cmdSerNum)
OSError: [Errno 121] Remote I/O error
>>> 

So my question is what can I do to eliminate the apparently random I/O errors I am getting from SMbus transactions?

  • 4
    the problem could be with the code, or it could be with the RPi, or it could be the connections between the battery and the RPi, or it could be the moon being in the wrong phase .... it is not possible to guess with the near zero information that you provided – jsotola Dec 11 '18 at 23:01

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.