DFRobot / DFRobot_HX711_I2C

MIT License
5 stars 2 forks source link

Python scripts crashing on Raspberry Pi #3

Open tlp19 opened 1 year ago

tlp19 commented 1 year ago

Hi, I am trying to use the "Gravity: I2C 1Kg Weight Sensor Kit - HX711" with a Raspberry Pi 4 Model B with Python 3.9 and I can't get the Python scripts provided in this repository to work.

My Setup

My Problem

When running the get_calibration.py example on my device, the orange light turns on but then I get the following error in my terminal after a few seconds:

OSError: [Errno 121] Remote I/O error

The orange light then turns off about 7 or 8 seconds later (no blinking, so the calibration failed).

The traceback is as follows:

File ".../my_file.py", line 20, in <module>
    while hx711.get_cal_flag() != 1:
File ".../DFRobot_HX711_I2C.py", line 176, in get_cal_flag
    ppFlag = self.peel_flag()
File ".../DFRobot_HX711_I2C.py", line 103, in peel_flag
    data = self.read_reg(self.REG_DATA_GET_PEEL_FLAG,1);
File ".../DFRobot_HX711_I2C.py", line 209, in read_reg
    self.ic2bus.write_byte(self.addr,reg)
File ".../smbus2.py", line 414, in write_byte
    ioctl(self.fd, I2C_SMBUS, msg)
OSError: [Errno 121] Remote I/O error

Similarly, when I run the readWeight.py, I receive 2 or 3 weight readings of 0g before getting the same error.

I am not sure if this is an error due to the DFRobot_HX711_I2C.py Python library, or from the hardware, or from both.

Can you please help me to fix this issue?

Thank you.

Timo614 commented 1 year ago

Can try using my circuit python library: https://github.com/Timo614/dfrobot_hx711_i2c_circuit_python/blob/main/dfrobot_hx711.py

The python logic in this repo didn't work for me as well. One thing I noticed was the python logic has the wrong i2c address hardcoded in the library file (0x60) albeit the example file you're using has the correct one of 0x64. https://github.com/DFRobot/DFRobot_HX711_I2C/blob/master/DFRobot_HX711_I2C.h#L26

I didn't dig into why the current library didn't work as I was happy with it working with circuit python for my needs but one thing I did notice was the python library, unlike the arduino library, does not write the following during initialization:

REG_DATA_INIT_SENSOR is 0x70 The arduino library calls this as its first action https://github.com/DFRobot/DFRobot_HX711_I2C/blob/master/DFRobot_HX711_I2C.cpp#L23