Hi im doing a arduino project based on robotic arm(5dof) using pca9685.
But the servos movement are too fast so that it cannot stand steadily.
Can you please help me to control the speed of servos using pca9685.
Your topic was MOVED to its current forum category which is more appropriate than the original as it has nothing to do with Installation and Troubleshooting of the IDE
The solution is to move the servos in steps rather than in a single move to the final target angle
ie, move a little, wait a while, move a little, wait a while and so on
Please post a full sketch that illustrates what you are trying to do. It is almost inevitable that you will need to restructure your sketch considerably in order to do what you want
I will post my code shortly
You might try a library that allows control of the servo speed.
Im using PCA9685 module for my project.
Will this module help me to reduce the speed of the servos when i use them along with PCA9685?
'
#include "HCPCA9685.h"
int arr[20];
int img;
int realpos1,realpos2;
int i;
unsigned int realpos;
#define I2CAdd 0x40
int shoulder;
int elbow;
int wrist;
int gripper_1;
int gripper_2;
int base;
HCPCA9685 hc(I2CAdd);
void setup() {
// put your setup code here, to run once:
hc.Init(SERVO_MODE);
hc.Sleep(false);
Serial.begin(9600);
i=0;
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available()>=2)
{
//String nam=Serial.readString();
unsigned int servopos=Serial.read();
unsigned int servopos1=Serial.read();
realpos=((servopos1*256)+servopos);
if(realpos>=1000)
{
realpos1=realpos;
Serial.println(realpos1);
}
else if(realpos<=3)
{
realpos2=realpos;
if (realpos2==1)
{
// Serial.println(realpos1+1000);
arr[i]=realpos1;
i=i+1;
}
else if(realpos2==2)
{
Serial.println(realpos1+2000);
}
else if(realpos2==3)
{
//Serial.println(realpos1+3000);
runservo();
}
}
}
if (realpos>=1000 && realpos<=1180)
{
base=map(realpos,1000,1180,420,10);
hc.Servo(0,base);
}
if (realpos>=2000 && realpos<=2180)
{
shoulder=map(realpos,2000,2180,420,10);
hc.Servo(3,shoulder);
}
if (realpos>=3000 && realpos<=3180)
{
elbow=map(realpos,3000,3180,420,10);
hc.Servo(7,elbow);
}
if (realpos>=4000 && realpos<=4180)
{
wrist=map(realpos,4000,4180,420,10);
hc.Servo(8,wrist);
}
if (realpos>=5000 && realpos<=5180)
{
gripper_1=map(realpos,5000,5180,10,420);
hc.Servo(12,gripper_1);
}
if (realpos>=6000 && realpos<=6180)
{
gripper_2=map(realpos,6000,6180,10,420);
hc.Servo(15,gripper_2);
}
}
void runservo()
{
for(int j=0;j<sizeof(arr)/2;j++)
{
if(arr[j]>=1000 and arr[j]<=1180)
{
base=map(arr[j],1000,1180,420,10);
hc.Servo(0,base);
Serial.println("Base");
//delay(150);
}
else if(arr[j]>=2000 and arr[j]<=2180)
{
shoulder=map(arr[j],2000,2180,420,10);
hc.Servo(3,shoulder);
//delay(150);
}
else if(arr[j]>=3000 and arr[j]<=3180)
{
elbow=map(arr[j],3000,3180,420,10);
hc.Servo(7,elbow);
//delay(150);
}
else if(arr[j]>=4000 and arr[j]<=4180)
{
wrist=map(arr[j],4000,4180,420,10);
hc.Servo(8,wrist);
// delay(150);
}
else if(arr[j]>=5000 and arr[j]<=5180)
{
gripper_1=map(arr[j],5000,5180,10,420);
hc.Servo(12,gripper_1);
//delay(150);
}
else if(arr[j]>=6000 and arr[j]<=6180)
{
gripper_2=map(arr[j],6000,6180,10,420);
hc.Servo(15,gripper_2);
//delay(150);
}
else
{
continue;
}
Serial.println(arr[j]);
delay(1000);
}
}
'
This is the code that i have written for controlling my robotic arm using bluetooth and also to save the positions so that it can repeat the motions automatically.
Can you please help me to reduce the speed of the servos?
I have controlled using delay().
It did not worked.
I have created a bluetooth app using MIT app inventer.
Thank you
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
You cannot use a normal servo library with the PCA9685. It generates the PWM signals itself
#include "HCPCA9685.h"
int arr[20];
int img;
int realpos1,realpos2;
int i;
unsigned int realpos;
#define I2CAdd 0x40
int shoulder;
int elbow;
int wrist;
int gripper_1;
int gripper_2;
int base;
HCPCA9685 hc(I2CAdd);
void setup() {
// put your setup code here, to run once:
hc.Init(SERVO_MODE);
hc.Sleep(false);
Serial.begin(9600);
i=0;
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available()>=2)
{
//String nam=Serial.readString();
unsigned int servopos=Serial.read();
unsigned int servopos1=Serial.read();
realpos=((servopos1*256)+servopos);
if(realpos>=1000)
{
realpos1=realpos;
Serial.println(realpos1);
}
else if(realpos<=3)
{
realpos2=realpos;
if (realpos2==1)
{
// Serial.println(realpos1+1000);
arr[i]=realpos1;
i=i+1;
}
else if(realpos2==2)
{
reseting();
}
else if(realpos2==3)
{
//Serial.println(realpos1+3000);
runservo();
}
}
}
if (realpos>=1000 && realpos<=1180)
{
base=map(realpos,1000,1180,420,10);
hc.Servo(0,base);
}
if (realpos>=2000 && realpos<=2180)
{
shoulder=map(realpos,2000,2180,420,10);
hc.Servo(3,shoulder);
}
if (realpos>=3000 && realpos<=3180)
{
elbow=map(realpos,3000,3180,420,10);
hc.Servo(7,elbow);
}
if (realpos>=4000 && realpos<=4180)
{
wrist=map(realpos,4000,4180,420,10);
hc.Servo(8,wrist);
}
if (realpos>=5000 && realpos<=5180)
{
gripper_1=map(realpos,5000,5180,10,420);
hc.Servo(12,gripper_1);
}
if (realpos>=6000 && realpos<=6180)
{
gripper_2=map(realpos,6000,6180,10,420);
hc.Servo(15,gripper_2);
}
}
void runservo()
{
for(int j=0;j<sizeof(arr)/2;j++)
{
if(arr[j]>=1000 and arr[j]<=1180)
{
base=map(arr[j],1000,1180,420,10);
hc.Servo(0,base);
Serial.println("Base");
//delay(150);
}
else if(arr[j]>=2000 and arr[j]<=2180)
{
shoulder=map(arr[j],2000,2180,420,10);
hc.Servo(3,shoulder);
//delay(150);
}
else if(arr[j]>=3000 and arr[j]<=3180)
{
elbow=map(arr[j],3000,3180,420,10);
hc.Servo(7,elbow);
//delay(150);
}
else if(arr[j]>=4000 and arr[j]<=4180)
{
wrist=map(arr[j],4000,4180,420,10);
hc.Servo(8,wrist);
// delay(150);
}
else if(arr[j]>=5000 and arr[j]<=5180)
{
gripper_1=map(arr[j],5000,5180,10,420);
hc.Servo(12,gripper_1);
//delay(150);
}
else if(arr[j]>=6000 and arr[j]<=6180)
{
gripper_2=map(arr[j],6000,6180,10,420);
hc.Servo(15,gripper_2);
//delay(150);
}
else
{
continue;
}
delay(1000);
}
}
void reseting()
{
for (int j=0;j<(sizeof(arr))/2;j++)
{
arr[j]=0;
}
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.