Problem with Serial control of multiple servos


hey,

so year 12 student using 2 arduino unos create wirelessly controlled robotic hand via 5 flex sensors , 5 servo motors. able 2 servos working @ same time 2 flex sensors, moment try 3, incorrect data gets sent servos , spaz out.

for serial communication using apc 220's.
as mentioned, both arduinos uno's.

attached tx arduino code (used flex sensors data , send rx arduino via serial), quite long due calibration code make motors less jittery, ive attached it.

and here rx arduino code:
code: [select]
#include <servo.h>

servo thumb, index, middle, ring, pinky;
int thumbpin = 9, indexpin = 10, middlepin = 11, ringpin = 12, pinkypin = 13;

int ledpin = 2;

void setup()
{
  serial.begin(19200);
 
  pinmode(ledpin, output);
  thumb.attach(thumbpin);
  index.attach(indexpin);
  middle.attach(middlepin);
  ring.attach(ringpin);
  pinky.attach(pinkypin);
}

void loop()
{
  if (serial.available() >= 5){
    digitalwrite(ledpin, high);
   
    delay(1);
   
    byte thumbpos = serial.read();
    byte indexpos = serial.read();
    byte middlepos = serial.read();
    byte ringpos = serial.read();
    byte pinkypos = serial.read();
   
    thumb.write(thumbpos);
    index.write(indexpos);
    middle.write(middlepos);
    ring.write(ringpos);
    pinky.write(pinkypos);
   
  }
  else
  {
    digitalwrite(ledpin, low);
  }
}


so should happen 5 flex sensor values sent tx arduino rx arduino , rx arduino write corresponding finger value servo. whats happening @ moment after little while sensor values 'mixed up' , continuously change servo.

any appreciated. code may not optimised be, working first.
thanks,
aiid0z.

code: [select]
  // send data
 
//  serial.print("thumb ");
  serial.write(thumbpos);
//  serial.print("index ");
  serial.write(indexpos);
//  serial.print("middle ");
  serial.write(middlepos);
//  serial.println("ring ");
//  serial.print(ringpos);
//  serial.println("pinky ");
//  serial.print(pinkypos);

send 3 bytes.

code: [select]
  if (serial.available() >= 5){
wait 5.

why?


Arduino Forum > Using Arduino > Programming Questions > Problem with Serial control of multiple servos


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support