how we can use the PC a 9 6 8 5 16 channel 12 bit Pulse Width Modulation servo controller . We are going to control 16 servo individually I’m gonna show you how to control individually few of them and then I’m going to show how to control all 16 of them with the same or different angle. you can get the code for this by clicking at the link below the video in the description which will take you to www.robojax.com/learn/arduino let’s get started with this.
I will reply to all comments and questions of my channel subscriber make sure to subscribe and leave the notification on Hardware Explained and this is the module we have 16 ports here . these three pins belong to one servo this belongs to other servo where we can connect this servo motor with three wires and here as you can see that even the color matches the darker color if the ground all of these are ground which are connected to this ground and to the ground pin and the middle pin is for the power of servo which will be connected to this middle and that is five volts it all of these are connected to this pin.
So you can connect the external power of 5 volts to this and this pin. the reason to connect the external power and not Arduino is that you cannot power up all the servo motors maybe one servo small servo is possible to be powered but for proper practice you should always connect external power so you will have external power and for this chip to operate we will connect separate voltage to this VCC then this V+ is the same thing as this so they are connected so if for some reason you cannot connect here you can connect your external power here on this side we have ground so this ground on this ground is the same they are connected and then we have OE this is a pin that you can leave it (not connected) but for better practice connected to ground or zero and these are the two pen SCL that clock pin and SDA the data pin.
SDA and SCL are for I squared C (I2C) communication to control and self multiple while we just use two wires to control 16 servo here we have terminals and in case if we want to cascade and connect to or move on this side we can control up to 64 servo motors connected cascading here so all of the servos will be connected on these ports.
the length of this module is 62.1mm for 4.44 inches the width is 0.99 inch or one inch or 25.2mm millimeters the depth is determined by the capacitor which is the biggest component here 14.
1mm or 0.55 inch and if you’re come if you’re concerned with weight it weighs 10.6g and briefly to explain this micro servo small G90 and this is the metal version of this a little expensive and this is a high torque servo with metal gear and both cases these can rotate up to 180 degrees if you pay attention here it can go only half of a cycle half of a circle so this is 180 degrees and this also can go and 180 degrees and it’ll stop we will use this module to control these using Pulse Width Modulation (PWM) signals to control them between zero and hundred and eighty degrees with different pulse width.
I’ll have the datasheet for PCA 9 6 8 5 this is from NXP Semiconductors originally it has been designed to control LED using Pulse Width modulation with pulse width modulation so we can control servos as well. I will provide you the link in case if you need further information and the operating voltage is 2.
3 to 5.5V point 5 volts and because we’re using servo motors we will connect it to 5 volts and it can tolerate up to 5 point 5 volts. the chip is offered in two package type here TSS o P 28 and also VHQFN28 with square shape.
Here is a schematic diagram this is from Adafruit with the exception of this section where we have a mosfet that is for reverse voltage protection this does not exist in the module that we have everything else is exactly the same on our module this is a chip we have four ports of four connectors which are connected to sixteen servo motors we have signal five volts and ground the five volts is connected to the main terminal that we have and here are the pins where you can solder and select different I2C address. and can control multiple of these modules and here are the inputs including SDA and SCL and an LED with a 470 ohm resistor Wiring Explained let me explain the wiring the first thing that we do is we connect external power source of 5 volts to this because all the servo motors majority of them are 5 volts so you will connect your servo motor here and the power will go directly to the servo.
now when you connect the power here on this module this chip will not receive power because this VCC on this side and ground aside this VCC is directly connected to the middle pin and not to this chip.
But it is connected to this ping which also you can connect your positive here if you wish but I’m going to show you how we can use that so these two is connected to my battery (5V) and you will click your servo motor and these terminals as you can see the color matches here the darker color will be on this side the red is at the middle and then orange is on this side if the wire is white the white will be on this side which is the signal so you will connect your first servo like this and then connect the second third fourth and so forth up to 16 and by number this is servo 0 this is 3 and the last one is 15. some of the server wires you might see might be like this in this case the black is the ground this is VCC or 5 volts and white is a signal. ground is connected to the ground this purple pen and then blue is connected to the ground using this blue because manufacturer is suggesting that not used connected to the ground then here we have SCL and SDA SDA is yellow it is connected to A5 and SCL is connected using green wire to A5.
so these are I2C pins.
you can also connect SDA and SCL in here directly. the last pin here is orange, orange is VCC which supplies 5 volts I’ve connected here to 5 volt . so this will get five volts. now if you want to use external power then then disconnect this five volts here and connect this from here to this pin so we are supplying five volts from this sending back to this chip and then we can also supply five volts from here to Arduino once once we remove the orange pin now this is useless I’m just disconnecting it from five volts and I have to supply 5 volts to this pin. this is this will work actually you can connect it to VIN here but because we are connecting five volts in both cases this is better because this VIN goes through the regulator and will reduce it but if you connect it directly here (to 5V) this will go to the five volts of the board and then you can connect it to your battery like this so at this point we have 5 volts to Arduino when there is no USB and then five volt is also connected to the module Code explained :Control servos one by one let me explain the basic code.
I’ve taken the library from Adafruit from Github and the link will be provided included with this. and I have made some modification you need to install the library. (see video V1) the first line wire dot H that is required for I2C communication which is used with this board and then this line includes AdafruitPWMServoDriver.h that is their library , this line means grab that library and use it once I will give you a zip file that you click and download and save it in your computer let’s say my document or download after that click on a sketch-> include library-> add dot zip library and then point it to where you saved it. for example if this was inside the download go to download and select the files the zip file that I’ve already and click open after that you have to make sure to close all the instances of this library otherwise you will not be able to see it in the example.
From this class we are creating here the instance of the class we call it PWM or pulse width modulation and this is the main class that is being initialized. several minimum servo maximum or the values that have determined what experiment have separate video explaining that I will provide you the link watch that. inside the setup we initially the serial monitor to print some information for us and here if I open it the program is already running running so then we use PWM.begin that begins is starting the library and settings and setPWMFreq frequency this is a sixty Hertz or 60 times the update frequency and here inside the loop this is a code where it runs continuously and I have two for loop one for loop goes from 0 to 15 this means one less than 16 which means 15 and starts from here and here you the square I chose the closing of this so it goes the I equal 0 1 2 3 up to 15 and then I have another for-loop which starts from here and closes here the job of this one is to start from 0 to 180 degrees you see it 181 and every time it goes from zero and then it becomes 10 the splash 10 means add 10 to the previous value of angle which was for example if it starts with 0 it will be 10 and then 20 30 40 and so forth up to 180 so and then we wait 50 millisecond give it a little time so that servo can move.
So how it moves is that we say pwm.
setPWM(i) this “i” this is 0 1 2 this is a number of our servo and leave this at 0 and here angles to pulse and then angle so if we put the angle that’s our value but this module needs pulse so this is a function that I have written that takes the angle that angle which is 0 10 20 40 up to 180 and returns a pulse which I will explain next at the bottom. so this receives a pulse for this servo and that servo if it is one servo one will move to that angle and then it becomes 2 or 3 it goes to several 2 servo 3 servo 4 and so forth of servo 1 and then I will become 2 it goes to server to server 3 up to 16 servo and after that we wait one second and the loop will continue from service 0 up to servo 15.
Here is the angle to pulse the value that you pass here will receive that angle from 0 to 180 we will receive it and we have to map it meaning the angle that you receive is from 0 to 180 and we have to put maximum and maximum of the servo so when it is 0 it goes to the minimum which is 121 and we have defined it here through experiment(in V1 Video. Link below) hundred 25 and for maximum is 575 so this max so the job of this map is to convert that value to the minimum and maximum and the result will be here as a pulse integer and the suggest printing the text on the screen for us. and then the pulse will be returned here it says return false so every time you call this this line will get a pulse value like between 125 to 575 some number according to the angle and it will move the servo to that location to that angle.
Demonstration moving servos one by one now let me demonstrate it I’ve connected all the service and this is now connected to Arduino the main power is not connected to this module this is 5 volts and I’m connecting it now as you can see each servo 13 14 15 will run there is 1 second delay and then servo number 0 1 2 up up to 15 will run this is the basic code that shows you how each server can be controlled at any angle and if you want to change and control different server you can use this line just put here your servo for example 5 solve of 5 or 6 the 6 means that were number 7 will be controlled and here put your angle if you wanted to for example go to 130 degrees just type here hundred and 30 and it will convert it to pulse because here we need to type the path so this function will take care of that so use this line to control it each servo at any angle right now it’s running the code is running and sending signal because there is no power so you don’t see the action of servos when I turn it on it just continues from wherever it is Code 2 explained: Individual servo control this is the code where only servo 5 8 and 15 is being controlled to go a different angle so the angles go bit 1 from 0 to 280 so these three will move the rest of the code is exactly the same and I did not put I I put 5 8 and 15 it’s just random for demonstration the point is that you can use this line for your own purpose discard this for loop because if you want to control only one servo or two or three just make multiple copy and change this accordingly and the angle that you want just put it here Demonstration #2:Controlling each servo and here is the demonstration for that I am powering it up as you can see 5 8 and 15 is only working that is far often they are working simultaneously if I open the serial monitor and he’ll the serial monitor shows that what angle is corresponding to what pulse value Code #3 explained: Controlling all servo motors and this is the code where the for-loop goes from zero to 180 and inside loop goes from 0 to 16 and is changing with the angle so it controls all of the servos together so this loop goes with let’s say zero degree and it goes to all service immediately without the delay I did not put any delay so it goes 0 1 2 3 up to 15 all of them will move to the same location and immediately it goes the angle changes they go to the next one let’s say 10 and then they go to 20 30 40 up 280 and the loop with for one second and comes back and does the same thing Demonstration of controlling all servo motors at once and here is a demonstration I’m uploading the code right now Arduino is plugged in.
I can unplug the Arduino from USB you see not working but if I power it up and power it up using external power now it’s running with the external power without Arduino connected to USB Subtitle typed and corrected by Ahmad Shamshiri on May 16, 2020 in Ajax, ON, Canada I would liek to thank my Patrons from Patreon.com I did my part to help you learn. Now you can help me by Thumb up 👍 the video. Subscribing to my channel and typing simple “Thank you” in the comment section.
you I have PayPal Account if you want to donate money. The link is below the video. Thank you. thank you for watching this was how to control 16 channel servo motors using Arduino if you learn something and found this useful please thumb up 👍 as this will help my video in the search algorithm of YouTube if you have comment or question make sure to subscribe as I will respond only to subscribers