Hi folks im new to arduino and im working on my first project in college to control a robotic hand with an arduino. ive managed to write the code to allow me to move the motors and pick up an object and hold it tightly using pressure sensors. but now my supervisor wants me to do the same thing but using serial to do it.
problem is i havent been able to get the motors to do anything through serial. ive looked all over and the example with the arduino library seems to do nothing at all. in fact none of of the programmes ive found do anything for me. if anyone has any experience with this kind of thing i could use your help.
this is a old programme i found through you tube. it works in the video but when i tried it nothing happened. its exactly what i need though. if someone could point out the flaws in the code id appreciate it.
or if you could show me how to get the motors to move on command i can take it from there.
p.s. the search engine is rubbish " i typed in "controlling servos through serial" and it gave me 34 pages of stuff that had nothing to do with it
#include <Servo.h>
Servo servo1;
Servo servo2;
int inByte=0;
char buf[256];
void setup (){
delay(500);
Serial.begin(9600);
servo1.attach (10);
servo2.attach (9);
Serial.println("I am ready");
}
void loop() {
int i=0;
while(true) {
if (Serial.available() > 0) {
inByte = Serial.read();
if (inByte==stopByte) {
buf(i) = "/0";
break;
}
buf(i) = inByte;
i++;
Serial.print("I recieved:");
Serial.println(inByte);
}
}
Serial.print("I recieved strings; ");
Serialprintlin(buf);
char motor = buf(0);
int k = 2;
while ( buf[k] != "/0" ){
buf [k-2] = buf [k];
k++;
}
buf[k-2] = "/0" ;
int angle = atoi [buf];
if{motor=="1") {
Serial.print ("Motor is 1, and angle is:");
Serial.println(angle);
servo1.write(angle);
}
else if (motor =="2"){
Serial.print("motor is 2, and angle is;");
Serial.printl,(angle);
servo2.write(angle);
}
}/code]