autorope / donkeycar

Open source hardware and software platform to build a small scale self driving car.
http://www.donkeycar.com
MIT License
3.05k stars 1.28k forks source link

I2C messages are sent too close to each other #1176

Closed Prototyx closed 1 month ago

Prototyx commented 2 months ago

Hello,

I made a donkey car with a RPi 4 (CM4) connected to an Arduino UNO via I2C.

IMG_4056

Basically my Arduino UNO is replacing the PCA9685. I have my ESC and my servo attached to some PWM pins on my arduino.

It seems that there is one thread for the steering, and another one for the throttle. And each thread send their command via I2C too close to each other.

Issue : I2C messages too close to each other image

Is there a way to not have both thread sending I2C commands at the same time ? I think PCA9685 can manage 2 I2C messages very close to each other but on for my Uno it seems very difficult. I have a lot of I/O Errors. When I do the calibration for only the steering or throttle it works well.

Solution : image

Thanks for your help.

Ezward commented 1 month ago

@Prototyx Are those signals the pwm outputs? It looks like those signals are on the same pin. If those are the PWM outputs then you need to send the steering and throttle pwm on two different pins.

I would be surprised if it was an I2c issue; it's a serial protocol that can handle bus contention. What error are you seeing? Are you seeing it in the donkeycar console or the arduino serial console? Can you copy the output here?

PS: the car looks really cool; very compact. Nice.

Ezward commented 1 month ago

@Prototyx what type of Arduino are you using? Is it 5v or 3.3v? How are you handling the logic-level conversion between the RPi and the Arduino if the Arduino is 5v? The reason I ask is that it is my understanding that some logic-level conversions can 'round' the edges of a logic level change and so could possibly affect I2c communication.

Prototyx commented 1 month ago

Hello, The arduino is 5V (it's Atmega328p, same as uno board). I am using a logic level converter between the Arduino and RPi designed for I2C communications (PCA9306). I made some investigations today :

When I put the scope on I2C lines, in fast mode the frequency is not stable at all, I think the RPi has to deal with others tasks with higher priority and decreases the frequency, maybe it is for this reason that it causes a lot of errors, because the arduino is not able to manage this frequency variation.

Anyway, after decreasing the I2C speed, I was able to drive the car without problem, and I did my first autonomous session. I was very impressed !

Ezward commented 1 month ago

@Prototyx Thank you for detailing the resolution. I'm closing this issue.