gobot icon indicating copy to clipboard operation
gobot copied to clipboard

write /dev/i2c-1: remote I/O error on Raspberry 4 and Adafruit Motorhat

Open gandaldf opened this issue 4 years ago • 2 comments

Hi, I'm trying to run this example: https://github.com/hybridgroup/gobot/blob/release/examples/raspi_adafruit_dcmotor.go on my Raspberry Pi 4B 4GB to work with two simple DC motors connected to a single Adafruit Motorhat. The wiring seems right (I tried the default Python example from Adafruit website and it run smoothly) but when I try go run main.go I get this error:

2021/02/05 15:07:16 Initializing connections...
2021/02/05 15:07:16 Initializing connection RaspberryPi-5F8E62B9 ...
2021/02/05 15:07:16 Initializing devices...
2021/02/05 15:07:16 Initializing device AdafruitMotorHat-F82D156 ...
2021/02/05 15:07:16 Robot adaFruitBot initialized.
2021/02/05 15:07:16 Starting Robot adaFruitBot ...
2021/02/05 15:07:16 Starting connections...
2021/02/05 15:07:16 Starting connection RaspberryPi-5F8E62B9...
2021/02/05 15:07:16 Starting devices...
2021/02/05 15:07:16 Starting device AdafruitMotorHat-F82D156...
2021/02/05 15:07:16 1 error occurred:
	* write /dev/i2c-1: remote I/O error

I tried to build the example and then run it under sudo but I get the same problem.

I checked to have enabled the I2C interface from raspi-config and when I run sudo i2cdetect -y 1 I get this:

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: 60 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: 70 -- -- -- -- -- -- --

So I can't really understand what is wrong, because with Python I have no problem. Can someone please help me?

@deadprogram @erkkah @maruel

gandaldf avatar Feb 05 '21 14:02 gandaldf

After a bit research I found @crazyquark was right in #759 issue: if you are just using the "DC part" of Adafruit Motorhat the driver can't get the DC connection because it get stuck here: https://github.com/hybridgroup/gobot/blob/master/drivers/i2c/adafruit_driver.go#L152

gandaldf avatar Feb 05 '21 18:02 gandaldf

I just proposed a solution here: #783

gandaldf avatar Feb 05 '21 19:02 gandaldf