Code: Select all
Serial.begin(9600); //
Moderators: adafruit_support_bill, adafruit
Code: Select all
Serial.begin(9600); //
Code: Select all
Serial.begin(9600); //
Code: Select all
Serial.begin(9600); //
Code: Select all
int flexpin=A0;
int flexpin1=A1;
int flexpin2=A2;
int flexpin3=A3;
int flexpin4=A4;
byte pos=0; // changed int to byte
byte pos1=0;
byte pos2=0;
byte pos3=0;
byte pos4=0;
int flexsum=0;
int flexsum1=0;
int flexsum2=0;
int flexsum3=0;
int flexsum4=0;
#define sampleSize 20
//
// Read "sampleSize" samples and report the average
//
int ReadAnalog(int Pin)
{
long reading = 0;
analogRead(Pin); // read the analog in value:
delay(1); // waits 1ms for the between each analog pin reads
for (int i = 0; i < sampleSize; i++)
{
reading += analogRead(Pin);
}
return reading/sampleSize;
}
void setup()
{
Serial.begin(9600);
}
void loop()
{
flexsum = ReadAnalog(flexpin);
flexsum1 = ReadAnalog(flexpin1);
flexsum2 = ReadAnalog(flexpin2);
flexsum3 = ReadAnalog(flexpin3);
flexsum4 = ReadAnalog(flexpin4);
{
Serial.print(flexsum);
Serial.print("\t");
Serial.print(flexsum1);
Serial.print("\t");
Serial.print(flexsum2);
Serial.print("\t");
Serial.print(flexsum3);
Serial.print("\t");
Serial.print(flexsum4);
Serial.print("\t");
}
byte pos=map(flexsum,870,800,0,180); //Added Byte in front of pos
byte pos1=map(flexsum1,870,800,0,180);
byte pos2=map(flexsum2,870,800,0,180);
byte pos3=map(flexsum3,870,800,0,180);
byte pos4=map(flexsum4,870,800,0,180);
delay(50); //Would I change the delay of the glove here?
}
Code: Select all
#include <Servo.h>
Servo myservo; // create servo object to control a servo
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
int pos=0; // variable to store the servo position
int pos1=0;
int pos2=0;
int pos3=0;
int pos4=0;
void setup()
{
Serial.begin(9600); // initialize serial communications at 9600 bps:
myservo.attach(2); // attaches the servo on pin 2 to the servo object
myservo1.attach(3);
myservo2.attach(4);
myservo3.attach(5);
myservo4.attach(7);
}
void loop()
{
if(Serial.available() >=5)
{
byte servodig = Serial.read();
byte servodig1 = Serial.read();
byte servodig2 = Serial.read();
byte servodig3 = Serial.read();
byte servodig4 = Serial.read();
myservo.write(servodig); // tells servo to go to position based on finger position
myservo1.write(servodig1);
myservo2.write(servodig2);
myservo3.write(servodig3);
myservo4.write(servodig4);
Serial.println(pos);
Serial.println(pos1);
Serial.println(pos2);
Serial.println(pos3);
Serial.println(pos4);
}
}
You will have to test yourself to verify if it works, but I can see a few problems in the code still:Now do I have the communication piece for the xbee to work?
Code: Select all
#include <Servo.h>
int flexpin=A0; // Analog input pin that the flex sensor is attached to
int flexpin1=A1;
int flexpin2=A2;
int flexpin3=A3;
int flexpin4=A4;
int pos=0; // variable to store the servo position
int pos1=0;
int pos2=0;
int pos3=0;
int pos4=0;
Servo myservo;
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
int flexsum=0;
int flexsum1=0;
int flexsum2=0;
int flexsum3=0;
int flexsum4=0;
#define sampleSize 20
//
// Read "sampleSize" samples and report the average
//
int ReadAnalog(int Pin)
{
long reading = 0;
analogRead(Pin); // read the analog in value:
delay(1); // waits 1ms for the between each analog pin reads
for (int i = 0; i < sampleSize; i++)
{
reading += analogRead(Pin);
}
return reading/sampleSize;
}
void setup()
{
myservo.attach(2); // attaches the servo on pin 2 to the servo object
myservo1.attach(3);
myservo2.attach(4);
myservo3.attach(5);
myservo4.attach(7);
Serial.begin(9600); // initialize serial communications at 9600 bps:
}
void loop()
{
flexsum = ReadAnalog(flexpin);
flexsum1 = ReadAnalog(flexpin1);
flexsum2 = ReadAnalog(flexpin2);
flexsum3 = ReadAnalog(flexpin3);
flexsum4 = ReadAnalog(flexpin4);
if(Serial.available())
{
Serial.println(flexsum);
Serial.println(flexsum1);
Serial.println(flexsum2);
Serial.println(flexsum3);
Serial.println(flexsum4);
delay(100);
}
pos=map(flexsum,870,800,0,180);
pos1=map(flexsum1,870,800,0,180);
pos2=map(flexsum2,870,800,0,180);
pos3=map(flexsum3,870,800,0,180);
pos4=map(flexsum4,870,800,0,180);
myservo.write(pos); // tell servo to go to position in variable 'pos
myservo1.write(pos1);
myservo2.write(pos2);
myservo3.write(pos3);
myservo4.write(pos4);
delay(200); // stop the program for some time
}
Code: Select all
int flexpin=A0; // Analog input pin that the flex sensor is attached to
int flexpin1=A1;
int flexpin2=A2;
int flexpin3=A3;
int flexpin4=A4;
int pos; // variable to store the servo position
int pos1;
int pos2;
int pos3;
int pos4;
int flexsum=0;
int flexsum1=0;
int flexsum2=0;
int flexsum3=0;
int flexsum4=0;
#define sampleSize 20
//
// Read "sampleSize" samples and report the average
//
int ReadAnalog(int Pin)
{
long reading = 0;
analogRead(Pin); // read the analog in value:
delay(1); // waits 1ms for the between each analog pin reads
for (int i = 0; i < sampleSize; i++)
{
reading += analogRead(Pin);
}
return reading/sampleSize;
}
void setup()
{
Serial.begin(9600); // initialize serial communications at 9600 bps:
}
void loop()
{
flexsum = ReadAnalog(flexpin);
flexsum1 = ReadAnalog(flexpin1);
flexsum2 = ReadAnalog(flexpin2);
flexsum3 = ReadAnalog(flexpin3);
flexsum4 = ReadAnalog(flexpin4);
{
pos=map(flexsum,870,800,0,180);
pos1=map(flexsum1,870,800,0,180);
pos2=map(flexsum2,870,800,0,180);
pos3=map(flexsum3,870,800,0,180);
pos4=map(flexsum4,870,800,0,180);
Serial.write(pos);
Serial.write(pos1);
Serial.write(pos2);
Serial.write(pos3);
Serial.write(pos4);
delay(50);
}
}
Code: Select all
#include <Servo.h>
int pos; // variable to store the servo position
int pos1;
int pos2;
int pos3;
int pos4;
int data1=0;
int data2=0;
int data3=0;
int data4=0;
int data5=0;
Servo myservo; // create servo object to control a servo
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
void setup()
{
myservo.attach(2); // attaches the servo on pin 2 to the servo object
myservo1.attach(3);
myservo2.attach(4);
myservo3.attach(5);
myservo4.attach(7);
Serial.begin(9600); // initialize serial communications at 9600 bps:
}
void loop()
{
if(Serial.available() >=5)
data1 = Serial.read();
data2 = Serial.read();
data3 = Serial.read();
data4= Serial.read();
data5 = Serial.read();
pos=map(data1,870,800,0,180);
pos1=map(data2,870,800,0,180);
pos2=map(data3,870,800,0,180);
pos3=map(data4,870,800,0,180);
pos4=map(data5,870,800,0,180);
myservo.write(pos); // tell servo to go to position in variable 'pos
myservo1.write(pos1);
myservo2.write(pos2);
myservo3.write(pos3);
myservo4.write(pos4);
}
Have you tested it? What does it do?How does the communication coding look?
Code: Select all
Serial.write(0); // synchronization bytes
Serial.write(0);
Serial.write(0);
Serial.write(pos);
Serial.write(pos1);
Serial.write(pos2);
Serial.write(pos3);
Serial.write(pos4);
Code: Select all
int sync = 0;
while ( sync < 3)
{
if (Serial.read() == 0)
{
sync++;
}
else
{
sync = 0;
}
}
Code: Select all
Serial.write(0); // synchronization bytes
Serial.write(0);
Serial.write(0);
Code: Select all
int flexpin=A0; // Analog input pin that the flex sensor is attached to
int flexpin1=A1;
int flexpin2=A2;
int flexpin3=A3;
int flexpin4=A4;
int pos; // variable to store the servo position
int pos1;
int pos2;
int pos3;
int pos4;
int flexsum=0;
int flexsum1=0;
int flexsum2=0;
int flexsum3=0;
int flexsum4=0;
#define sampleSize 20
//
// Read "sampleSize" samples and report the average
//
int ReadAnalog(int Pin)
{
long reading = 0;
analogRead(Pin); // read the analog in value:
delay(1); // waits 1ms for the between each analog pin reads
for (int i = 0; i < sampleSize; i++)
{
reading += analogRead(Pin);
}
return reading/sampleSize;
}
void setup()
{
Serial.begin(9600); // initialize serial communications at 9600 bps:
}
void loop()
{
flexsum = ReadAnalog(flexpin);
flexsum1 = ReadAnalog(flexpin1);
flexsum2 = ReadAnalog(flexpin2);
flexsum3 = ReadAnalog(flexpin3);
flexsum4 = ReadAnalog(flexpin4);
{
pos=map(flexsum,870,800,0,180);
pos1=map(flexsum1,870,800,0,180);
pos2=map(flexsum2,870,800,0,180);
pos3=map(flexsum3,870,800,0,180);
pos4=map(flexsum4,870,800,0,180);
Serial.write((byte)0);
Serial.write((byte)0);
Serial.write((byte)0);
Serial.write(pos);
Serial.write(pos1);
Serial.write(pos2);
Serial.write(pos3);
Serial.write(pos4);
delay(50);
}
}
Code: Select all
#include <Servo.h>
int pos; // variable to store the servo position
int pos1;
int pos2;
int pos3;
int pos4;
int data1=0;
int data2=0;
int data3=0;
int data4=0;
int data5=0;
int sync = 0;
Servo myservo; // create servo object to control a servo
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
void setup()
{
myservo.attach(2); // attaches the servo on pin 2 to the servo object
myservo1.attach(3);
myservo2.attach(4);
myservo3.attach(5);
myservo4.attach(7);
Serial.begin(9600); // initialize serial communications at 9600 bps:
}
void loop()
{
while ( sync < 3)
{
if (Serial.read() == 0)
{
sync++;
}
else
{
sync = 0;
}
}
data1 = Serial.read();
data2 = Serial.read();
data3 = Serial.read();
data4= Serial.read();
data5 = Serial.read();
pos=map(data1,870,800,0,180);
pos1=map(data2,870,800,0,180);
pos2=map(data3,870,800,0,180);
pos3=map(data4,870,800,0,180);
pos4=map(data5,870,800,0,180);
myservo.write(pos); // tell servo to go to position in variable 'pos
myservo1.write(pos1);
myservo2.write(pos2);
myservo3.write(pos3);
myservo4.write(pos4);
}
That looks right. How does it work? Looking at code is no substitute for testing.Did I make the right corrections?
Code: Select all
#include <Servo.h>
int flexpin=A0; // Analog input pin that the flex sensor is attached to
int flexpin1=A1;
int flexpin2=A2;
int flexpin3=A3;
int flexpin4=A4;
int pos=0; // variable to store the servo position
int pos1=0;
int pos2=0;
int pos3=0;
int pos4=0;
Servo myservo;
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
int flexsum=0;
int flexsum1=0;
int flexsum2=0;
int flexsum3=0;
int flexsum4=0;
#define sampleSize 20
//
// Read "sampleSize" samples and report the average
//
int ReadAnalog(int Pin)
{
long reading = 0;
analogRead(Pin); // read the analog in value:
delay(1); // waits 1ms for the between each analog pin reads
for (int i = 0; i < sampleSize; i++)
{
reading += analogRead(Pin);
}
return reading/sampleSize;
}
void setup()
{
myservo.attach(2); // attaches the servo on pin 2 to the servo object
myservo1.attach(3);
myservo2.attach(4);
myservo3.attach(5);
myservo4.attach(7);
Serial.begin(9600); // initialize serial communications at 9600 bps:
}
void loop()
{
flexsum = ReadAnalog(flexpin);
flexsum1 = ReadAnalog(flexpin1);
flexsum2 = ReadAnalog(flexpin2);
flexsum3 = ReadAnalog(flexpin3);
flexsum4 = ReadAnalog(flexpin4);
if(Serial.available())
{
Serial.println(flexsum);
Serial.println(flexsum1);
Serial.println(flexsum2);
Serial.println(flexsum3);
Serial.println(flexsum4);
delay(100);
}
pos=map(flexsum,870,800,0,180);
pos1=map(flexsum1,870,800,0,180);
pos2=map(flexsum2,870,800,0,180);
pos3=map(flexsum3,870,800,0,180);
pos4=map(flexsum4,870,800,0,180);
myservo.write(pos); // tell servo to go to position in variable 'pos
myservo1.write(pos1);
myservo2.write(pos2);
myservo3.write(pos3);
myservo4.write(pos4);
delay(200); // stop the program for some time
}
What is the current rating of your servo power supply? Do you measure a drop in voltage associated with jittering behavior?The servos for the hand will work for about a minute some times less before all five servos begin to make small jitters and will not respond to the glove control
What does the serial output say? Are you getting reasonable readings from the flex sensors?The fingers connected to pin A1 and A3 will not respond but no issues with the other fingers. We have swapped out servos and flex sensors with same results