Notifications
Clear all

Using the PCA9685 with 6 servos

6 Posts
3 Users
1 Likes
2,610 Views
(@garyp)
Member
Joined: 4 years ago
Posts: 2
Topic starter  

Hi all. I'm a new subscriber and I'm using the sketch which was on the DoneBot Workshop.
https://dronebotworkshop.com/servo-motors-with-arduino/

My servos all work, I have tested them, and the 5 Analog ports work, I have also tested them.

But they do not seem to work together.  Bill's example using 4 servos, when uploaded and wired works perfectly with my 3D printed robot arm, but only uses 4 of the servos. 

So I modified the code as below:

// Define Potentiometer Inputs
int controlA = A0;
int controlB = A1;
int controlC = A2;
int controlD = A3;
int controlE = A4;
int controlF = A5;

// Define Motor Outputs on PCA9685 board
int motorA = 0;
int motorB = 1;
int motorC = 2;
int motorD = 3;
int motorE = 4;
int motorF = 5;

When I added 2 more pots, that's when the issues started. The servos went crazy and chattered.
I removed all of the wiring and retested each servo with A0 and it reacted as expected.
My problem seems to start when I use the A4 and A5 ports, so I googled it and found this thread:
https://forum.arduino.cc/index.php?topic=577620.0

The guy says "No worries, you're not the only one that encountered a situation like this. It's a common beginner's mistake to forget that an 328P processor shares A4 and A5 with the I2C bus."
Is this true and what are my options?

Another guy says to "Use an eight channel analogue muxer for the five analogue sensors.
Then you have six analogue inputs left, and the two I2C pins still free.
The three free analogue inputs can be used to control the muxer (still three analogue inputs left). "

I'm thinking that is why when I connect all of the servos and pots up w/o the PCA board it works as expected.

That was an old thread, what are my other options?


   
Quote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1018
 

@garyp

First let me apologize for being one of the reasons your post hasn't been seen until now.  I'm one of the moderators and just now approved your post, so until now no one else was seeing it.  When you are new to the forum and there is a link in your first post, as you had the link to the mux/demux from SparkFun, the message is held for moderation so that the link can be 'checked out' so to speak.  It seems none of the other moderators saw you post either and I didn't see it until this morning.  And I missed it because I was playing around with some PCA9685 modules of my own yesterday!

Using the PCA9685 with just four servos as Bill did, along with the the four pots everything is fine.  And with out the PCA9685 you can add two more servos and pots and everything still works as expected.  But now you are out of analog ports an digital PWM ports.  So if you ever wanted more servos you wouldn't have any PWM ports to drive them.  The PCA9685 to the rescue for up to 16 servos.  But the PCA9685 is an I2C device, and on the UNO the A4 and A5 pins are used to do I2C communications, so you now effectively have just four analog input pins.  I have never used the mux/demux that the link to SparkFun covers, but I'm going to have to look into it.

I think your best bet is to look into it as well.  Or look into getting an Arduino Mega 2560.  It has 16 analog input pins as well as 15 digital pins capable of PWM.

I know that is many more words than you may have expected, but I wanted to make up for what may have been perceived by you as being ignored.  ? 

SteveG


   
ReplyQuote
(@garyp)
Member
Joined: 4 years ago
Posts: 2
Topic starter  

Hi @codecage. I understand about the link.  I've seen this kind of abuse on other websites, so I'm good with it.
I signed up here because none of my local friends speak Arduino, PC or electronics for that matter.

Thanks for the pointer to the Arduino Mega 2560. I'm going to go look into that. It might be a better solution all the way around.
Edit: wow, it's cheap on Amazon. Only 38.50 for the real version, and 18.99 for the Sunfounder open source version.

Currently I'm learning serial communications so I can use Processing. I had this idea to plug in my Logitech F310 game pad into the PC and drive it with Processing, then pass the data to the Arduino by way of the serial bus.
It should work in theory. ? 

I also have one that's Bluetooth so I could connect it to the Arduino that way but I think the Bluetooth module is a slave device like a headphone and not a master like a PC. I'm not sure.

Regarding links please, how long will I be new so I can leave links?

This post was modified 4 years ago 3 times by GaryP

   
ReplyQuote
Jbell
(@jbell)
Member
Joined: 4 years ago
Posts: 2
 

It is possible to handle 6 servos with the NANO board.  It has A0 through A7 which has 8 ports and that will support 6 pots and still have 2 for I2c.  I have used it for this exact purpose.   Just be sure to use A4 & A5 for I2C communication.  Hope that gives you another option to try.


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1018
 

@garyp

To be honest with you Gary, I don't exactly know.  I help Bill out by saving him the time it takes to keep an eye on things and don't know everything about the behind the scenes of the forum.  But it isn't to long since I don't remember more than a couple of posts having to be moderated for any one member.  If it's only two, than you might be in the clear now, as the post I'm replying to right now was awaiting moderation as well.

You'll find a lot of help for things you are looking into on this forum.

In addition to the Mega, lay in a supply of the Nano version of the Arduino as well.  It actually has two additional analog ports than the Uno, and it is much cheaper to boot.

SteveG


   
zaknick reacted
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1018
 

@jbell

You must have been giving your advice to @garyp while I was composing my last post to him.

Great minds! 0 ? 

SteveG


   
ReplyQuote