Notifications
Clear all

I2C woes  


Mattack65
(@mattack65)
Active Member
Joined: 3 months ago
Posts: 6
Topic starter  

Bill said in one of his YouTube videos, that I2C is not practical for longer connections. I want to share with you my experience, which proves his point. I had intended to control 512 micro servos over 32 PCA9685 servo controllers, all stringed together with an I2C bus with a total length of about 1 to 2 meters.

The servos are split into "modules" of 32 each, each module having 2 controllers.

So I built the first servo module, containing 32 servos and two PCA9685 boards and connected it to a breadboard and the breadboard to a Raspberry Pi which runs the Python code to control the servos.
It worked fine with an I2C bus of 10 cm length. However, when I grew the bus to 30 cm length, it already stopped working. I made two videos to show the result:

10 cm bus:

30 cm bus:

As you can see, at 30 cms, the signals are basically random.

I added two 1k pull up termination resistors to the bus lines as recommended, but that made no noticeable difference. I am also not sure, if the PCA9685 boards don't already contain the pull up resistors.
It looks like I will have to find another way, to control the 512 servos.

The option that I am currently considering is to have an ESP32 control 32 or possibly 64 servos close by (via the PCA9685 and I2C bus as in the test) and then send the steering commandos from the Raspberry Pi to those 16 or 32 ESP32's by WiFi. The software will generate up to about 10000 servo commands per second, and most simple bus systems (UART e.g. seem to be too slow for that.)

Feedback and suggestions welcome.


Quote
Topic Tags
DroneBot Workshop
(@dronebot-workshop)
Workshop Guru Admin
Joined: 2 years ago
Posts: 939
 

@mattack65

Those are great videos, thanks for sharing them!

Posted by: @mattack65

It looks like I will have to find another way, to control the 512 servos.

I just have to ask - what are you building that requires 512 servo motors?

😎

Bill

"Never trust a computer you can’t throw out a window." — Steve Wozniak


ReplyQuote
Mattack65
(@mattack65)
Active Member
Joined: 3 months ago
Posts: 6
Topic starter  

🙂

I want to make an installation with 256 mirrors (16 x 16 grid), that can move on two axis each.

Here are two short videos of the 4 x 2 prototype.

Almost everything is 3D printed, plus some spring wire.

I was inspired by this man:

except I want my mirrors to move in two directions.

 

kinetic 5 v45

ReplyQuote
DroneBot Workshop
(@dronebot-workshop)
Workshop Guru Admin
Joined: 2 years ago
Posts: 939
 

@mattack65

They say if you break a mirror you get "7 years of bad luck". So be very careful that you don't drop your whole project, or the next 1792 years will be pretty miserable for you!

😲

That is one amazing project, please be sure to keep us updated with more video.

And on the I2C side, have you considered using an I2C multiplexer to divide your output into several independent I2C busses? Might be a way around the situation with long wires.

😎

Bill

"Never trust a computer you can’t throw out a window." — Steve Wozniak


Centari liked
ReplyQuote
Mattack65
(@mattack65)
Active Member
Joined: 3 months ago
Posts: 6
Topic starter  

@dronebot-workshop

And on the I2C side, have you considered using an I2C multiplexer to divide your output into several independent I2C busses? Might be a way around the situation with long wires.

I could try that, even though I don't have address conflict issues, just to improve the bus signal.

Have you or anybody else by chance any experience with I2C extenders like this one: Adafruit LTC4311 I2C Extender ?


ReplyQuote
Mattack65
(@mattack65)
Active Member
Joined: 3 months ago
Posts: 6
Topic starter  

@dronebot-workshop
I have now tested the Adafruit LTC4311 I2C Extender and it worked like a charm.
https://www.adafruit.com/product/4756
Whereas before I ran into trouble with just 30 cm of bus cable, after I inserted this board after 10 cm I could add another 80 cm of bus cable without any problems. I have not yet tested the maximum length.

image

Centari and noweare liked
ReplyQuote
Mattack65
(@mattack65)
Active Member
Joined: 3 months ago
Posts: 6
Topic starter  

OK, I have an update and a confession to make.
It turned out, that the LTC4311 signal enhancer was not really necessary and the I2C bus would work quite well, if I had not made an embarrassing rookie mistake:
Apparently the ground cable that I used to power the pwm-controller-modules was too thin (it was just a jumper cable in my test build). So whenever I made large servo movements with many servos at the same time, the cable was too thin for the power and it messed with the ground of the bus (which is the same ground) and that messed up the signals. Duh!

Once I made the power cables both massively larger, all the problems went away.
In today's test I daisy-chained 16 pwm-servos-modules together (see picture below). The total bus-length, including the 16 servo-modules, was about 3 meters. I attached a total of 64 servos, 32 on the first 2 modules and another 32 servos on the last 2 modules. I tried it both with the LTC4311 in the chain and without.

The bus was attached to a Raspberry Pi 4 and I had cranked up the I2C bus speed to max. The test program was written in python.

Differences:

1) Without the LTC4311 the max. throughput was about 5000 commands per sec., but I saw fluctuations in bus speed and every now and then a command would fail if running at max. speed. With the LTC4311 it was about 3200 commands per sec. at most, but no fluctuations in bus speed and no visible failing commands.

2) At a more "normal" rate of just a few 100 commands per second the bus worked fine with or without the LTC4311 over the full 3 meters and all 64 servos.

As a side note: I had also run the bus on an ESP32 at max speed (in C++) and I could crank out 10'200 servo commands per second with no problems on the bus and no lost commands. (I had to tune the Adafruit library a bit for that.)

Lessons learned:

1) Make sure you use thick enough cables on your pwm-control-modules or you mess up the I2C bus signals.

2) The I2C bus is faster than expected and can be longer than expected if you override the default speed and if you avoid power surges.

I have not tested the longest possible I2C bus before it fails and if the LTC4311 would extend that length.

i2c bus

And if anyone is interested in the 4 x 4 prototype:

This post was modified 2 weeks ago by Mattack65

ReplyQuote