Arduino Asked on October 25, 2020
I started one project where i need 4 servos to control 4 grabbers jaws. i use STM32F103C8T6 with arduino IDE for programming it. The motor TZT Micro Servo 9g SG 90. First, I was playing with stepper motors to make them rotate how I want, then I added one servo on the same protoboard where are steppers and drivers for each. I used servo sweep example, and it randomly started twitching and sometimes to spin until power is off. the STM is powered with usb cable from PC. Then i tried other 3 motors and got same result.
Then i put STM on separate protoboard and there connected servo and it was not perfect but it was much stable than on onther protoboard. Then i used old PC power supply which i modified long time ago to have jacks for 12V, 5V and 3,3V, and connected servo to it and it worked normally.
So I started connecting motors 1 by one back to protoboard with other elements and tested them while adding them, first the first one , then added second and tested both, then added 3rd and tested all 3…
First two worked fine, but when i added third, all of them started twitching again, but then it stopped. So i added fourth and now all of them are twitching even if I write in code to rotate only one or two of them, which I don’t understand how they can move if I do not give them signal from code.
Here is code for controlling both servo and stepper motors:
#include<Servo.h>
const int stepPin1 = PA4;
const int dirPin1 = PA0;
const int stepPin2 = PA5;
const int dirPin2 = PA1;
const int stepPin3 = PA6;
const int dirPin3 = PA2;
const int stepPin4 = PA7;
const int dirPin4 = PA3;
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
void setup() {
pinMode(stepPin1,OUTPUT);
pinMode(stepPin2,OUTPUT);
pinMode(stepPin3,OUTPUT);
pinMode(stepPin4,OUTPUT);
pinMode(dirPin1,OUTPUT);
pinMode(dirPin2,OUTPUT);
pinMode(dirPin3,OUTPUT);
pinMode(dirPin4,OUTPUT);
servo1.attach(PB12);
servo2.attach(PB14);
servo3.attach(PA8);
servo4.attach(PA10);
//servo1.write(0);
//servo2.write(0);
//servo3.write(0);
//servo4.write(0);
}
void loop() {
digitalWrite(dirPin1,HIGH);
digitalWrite(dirPin2,HIGH);
digitalWrite(dirPin3,HIGH);
digitalWrite(dirPin4,HIGH);
//servo1.write(100);
servo2.write(100);
//servo3.write(100);
//servo4.write(100);
for(int x = 0; x < 200; x++) {
digitalWrite(stepPin1,HIGH);
digitalWrite(stepPin2,HIGH);
digitalWrite(stepPin3,HIGH);
digitalWrite(stepPin4,HIGH);
delayMicroseconds(750);
digitalWrite(stepPin1,LOW);
digitalWrite(stepPin2,LOW);
digitalWrite(stepPin3,LOW);
digitalWrite(stepPin4,LOW);
delayMicroseconds(750);
}
delay(1000); // One second delay
digitalWrite(dirPin1,LOW);
digitalWrite(dirPin2,LOW);
digitalWrite(dirPin3,LOW);
digitalWrite(dirPin4,LOW);
//servo1.write(-100);
servo2.write(-100);
//servo3.write(-100);
//servo4.write(100);
for(int x = 0; x < 200; x++) {
digitalWrite(stepPin1,HIGH);
digitalWrite(stepPin2,HIGH);
digitalWrite(stepPin3,HIGH);
digitalWrite(stepPin4,HIGH);
delayMicroseconds(750);
digitalWrite(stepPin1,LOW);
digitalWrite(stepPin2,LOW);
digitalWrite(stepPin3,LOW);
digitalWrite(stepPin4,LOW);
delayMicroseconds(750);
}
delay(1000);
}
Here is also link to a short video of how the servos are behaving:
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP