Hi all,
I have a potentiometer controlling a servo circuit on a Due that isn't working. The output doesn't scale linear to the input.
Circuit is the classic 3 wire potentiometer circuit. One pole to ground, the other to 3.3v, and the wiper to analog in. Output is an RC signal on a digital pin using the servo library.
//General parameters setup
const int ServoMin = 600; //pulse width in microseconds
const int ServoMax = 2100; //pulse width in microseconds
// Bicep setup
Servo Bicep;
int BicepPos = 0;
const uint BicepPin = 22;
const uint BicepPotPin = 2;
int BicepPotVal = 0;
// The setup() function runs once each time the micro-controller starts
void setup()
{
Serial.begin(9600);
//Motor and Servo initialization
Bicep.attach(BicepPin, ServoMin,ServoMax);
}
// Add the main program code into the continuous loop() function
void loop()
{
BicepPotVal = analogRead(BicepPotPin);
Serial.print("Bicep, Read value:"); Serial.print(BicepPotVal);
BicepPotVal = map(BicepPotVal,0,1023,ServoMin,ServoMax);
Bicep.write(BicepPotVal);
Serial.print(" Sent value:"); Serial.println(BicepPotVal);
When I run this code on analog 0 the output stays at the same value regardless of how I adjust the potentiometer. When I switched to analog 1 the input would jump from 200 to 800 with a 10 degree turn. Same with analog 2.
I checked the potentiometer with a multimeter and it is working properly. The voltage output varies linearly with amount of rotation.
I believe the problem lies in the Due hardware itself. I must have fried it somehow but don't know how. I would switch over to another Due but I want to make sure that my setup is good so I don't risk frying the other one.
Should I modify my circuit, code, or is the Due defective?