SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By biglazyb
#199622
Hi,

I posted this in the comments at the Sparkfun site as well, anyone have any insight?

Question about this shield - I am attempting to get an analog signal from a flex sensor (SEN-08606) to the arduino through the analog inputs on the shield following the wiring guide at https://learn.sparkfun.com/tutorials/fl ... okup-guide. The circuit works fine on the arduino without the shield, but with it my range is extemely limited:

Resistor / range arduino /range shield + arduino

0.1 K / 15-70 / 536-545

4.7 K / 50-264 / 844-853

10 K / 140-430 / no range

47 K / 400-800 / 1001-1004

100 K / 590-903 / 1012-1014

I am trying to position servos using the range, so I am severely limited by the readings that come across with the shield. It appears there is something about the analog inputs on the shield that impact circuit resistance significantly - is there a way to overcome this?
By Valen
#199635
The hookup guide suggests to connect the flex sensor to pin A0. This is also used as software serial receive pin on the shield for the Xbee. So there is a conflict depending the setting of the switch. Pins A2,A3,A4 might work better. Also make sure it is not defined as an output with internal pull-up resistor enabled. Since you don't show what code you used it is hard to say if that is the case.

As for driving the servo's, investigate the map function to scale the output of the sensor to the servo input range.
By biglazyb
#199668
Hi Valen - thanks for your quick response - and you were right. A0/A1 inputs have some kind of limitation on resistive inputs whereas A2-A5 do not.

Here is the code I am running, have not hooked up the servos as I had hoped to get the input issue sorted out first -
Code: Select all
//Define sensors and servos

#include <Servo.h> //Includes servo library

Servo move1, move2, move3, move4, move5;

int servoPin1 = 5;
int servoPin2 = 6;
int servoPin3 = 9;
int servoPin4 = 10;
int servoPin5 = 3;

int flexPin1 = A0;
int flexPin2 = A1;
int flexPin3 = A2;
int flexPin4 = A3;
int flexPin5 = A4;

void setup()
{
  //Attach the servo objects to their respective pins
  move1.attach(servoPin1);
  move2.attach(servoPin2);
  move3.attach(servoPin3);
  move4.attach(servoPin4);
  move5.attach(servoPin5);
  Serial.begin(9600);
  /* set each servo pin to output; I'm not acutally sure if this is
  even necessary, but I did just in case it is */
  pinMode(servoPin1, OUTPUT);
  pinMode(servoPin2, OUTPUT);
  pinMode(servoPin3, OUTPUT);
  pinMode(servoPin4, OUTPUT);
  pinMode(servoPin5, OUTPUT);
  
  //Set each flex sensor pin to input: this is necessary
  pinMode(flexPin1, INPUT);
  pinMode(flexPin2, INPUT);
  pinMode(flexPin3, INPUT);
  pinMode(flexPin4, INPUT);
  pinMode(flexPin5, INPUT);
  
  
}

void loop()
{
  //Defines analog input variables
  int flex1 = analogRead(flexPin1);
  int flex2 = analogRead(flexPin2);
  int flex3 = analogRead(flexPin3);
  int flex4 = analogRead(flexPin4);
  int flex5 = analogRead(flexPin5);
  
  /* Defines "pos" variables as being proportional to the flex inputs.
  The 400 to 700 value range seemed adequate for my sensors, but you can change
  yours accordingly. */
  int pos1 = map(flex1, 400, 700, 0, 180);
  pos1 = constrain(pos1, 0, 180);
  int pos2 = map(flex2, 400, 700, 0, 180);
  pos2 = constrain(pos2, 0, 180);
  int pos3 = map(flex3, 400, 700, 0, 180);
  pos3 = constrain(pos3, 0, 180);
  int pos4 = map(flex4, 480, 640, 0, 180);
  pos4 = constrain(pos4, 0, 180);
  int pos5 = map(flex5, 400, 700, 0, 180);
  pos5 = constrain(pos5, 0, 180);
  
  //Tells servos to move by the amount specified in the "pos" variables
  move1.write(pos1);
  move2.write(pos2);
  move3.write(pos3);
  move4.write(pos4);
  move5.write(pos5);

  Serial.print("sensor: ");
  Serial.print(flex4);
  Serial.print("  servo: "); 
  Serial.println(pos4);
  delay(20);
}
I'll be using the XBee to send serial commands to the motor shield from a separate Arduino. I hadn't messed with XBee yet so I was hoping to test my circuits and select my resistors based on the analog input of the Uno -- from your comment and further testing I've figured that whatever is going on, the A0 and A1 inputs are different from the other 4 when using the shield. Looks like I need to read up on XBee to get this working with more than 4 analog inputs. Thanks again.