Arduino Forum

Using Arduino => General Electronics => Topic started by: Henradrie on Apr 15, 2019, 06:28 pm

Title: Arduino Due potentiometer circuit not working
Post by: Henradrie on Apr 15, 2019, 06:28 pm
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.

Code: [Select]

//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?
Title: Re: Arduino Due potentiometer circuit not working
Post by: ReverseEMF on Apr 15, 2019, 07:46 pm
It would help if we had a schematic to look at -- something you would have known, had you read:

How To Use This Forum (http://forum.arduino.cc/index.php/topic,148850.0.html#msg_1118324)

But, here are some troubleshooting pointers [assuming you haven't tried any of these already]:

The above is what is known as a Divide-And-Conquer method.  By, your system into different segments, and then testing those segments, you stand to isolate the issue.

Here's an example of the kind of code you might use to test that Servo:

Code: [Select]
uint debug_counter = 0;
void loop()
{
//  BicepPotVal = analogRead(BicepPotPin);
  BicepPotVal = debug_counter++;
  if (BicepPotVal > 1023)
  {
    BicepPotVal  = 0;
  }
  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);
  delayMicroseconds(20000);  // 20 mS delay -- adjust as needed.
}
Title: Re: Arduino Due potentiometer circuit not working
Post by: Henradrie on Apr 15, 2019, 10:26 pm
Quote
It would help if we had a schematic to look at -- something you would have known, had you read:
I just uploaded the schematic, but honestly, the circuit is about as simple as it gets. If it was more complicated I would have posted the schematic in the first post.

The servo portion works fine. The output scales to the input every time, problem is that the input doesn't track the potentiometer output. I tested the potentiometer and it works. The whole system was working as it should at one point until it stopped, the only portions I haven't changed since then have been the pin assignments.

I'm almost certain that the problem has to do with the Due. Potentiometer works, code was working before, and the system was working before.
Title: Re: Arduino Due potentiometer circuit not working
Post by: ReverseEMF on Apr 20, 2019, 07:23 pm
I just uploaded the schematic,...
Please read How To Insert Uploaded Images Into A Post (http://"https://forum.arduino.cc/index.php?topic=364156.msg3749026#msg3749026")
Title: Re: Arduino Due potentiometer circuit not working
Post by: ReverseEMF on Apr 20, 2019, 07:29 pm
...but honestly, the circuit is about as simple as it gets...
And yet you speak of Servos, and a Due...yet your "schematic" includes none of this.  Also, no mention of the Potentiometer's resistance.  All things that would help to know.

Have you read: How To Use This Forum (http://forum.arduino.cc/index.php/topic,148850.0.html#msg_1118324)?
Title: Re: Arduino Due potentiometer circuit not working
Post by: WattsThat on Apr 21, 2019, 02:55 am
Quote
Should I modify my circuit, code, or is the Due defective?
1) The posted circuit should work. Did you verify the voltage changes at the analog pin? Round wires plugged into header connectors designed for square pins can be problematic.

2) Posted code does not compile but when the obvious mistakes are fixed, it should work. When in doubt, you can always test an analog input pin with the "AnalogInOutSerial" in the Examples->Analog selection in the IDE.

3) That leaves a board hardware issue. Unlikely but anything is possible. Check the open circuit voltage on the analog pins, it should be less than 50mv which is just noise floating around. If it is stuck at 3.3 volts, the pin protection anti-static diodes have shorted, perhaps from being connected to 5V rather than 3.3?
Title: Re: Arduino Due potentiometer circuit not working
Post by: JCA79B on Apr 21, 2019, 06:04 am
Code: [Select]
Bicep.write(BicepPotVal);
Don't you need:
Code: [Select]
Bicep.writeMicroseconds(BicepPotVal);
?
Title: Re: Arduino Due potentiometer circuit not working
Post by: ard_newbie on Apr 21, 2019, 06:58 am

Do you measure, with a multimeter, 3.3V on a 3.3V pin and 5V on a 5V pin ?

To check if you have an issue with the board itself, see this thread:

https://forum.arduino.cc/index.php?topic=551534.msg4123919#msg4123919 (https://forum.arduino.cc/index.php?topic=551534.msg4123919#msg4123919)
Title: Re: Arduino Due potentiometer circuit not working
Post by: MarkT on Apr 21, 2019, 02:28 pm
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.

Should I modify my circuit, code, or is the Due defective?
Clearly from that information the analog side is fried.  There should be no difference in behaviour from one analog pin to the next (assuming connected to the same test circuit).

Note the Due is more sensitive to overvoltage and static than the Uno due to the CMOS process
used.  5V can be immediately fatal to a Due pin (except the 5V pin!).  Failing to follow precautions for static sensitive devices is foolhardy with the Due.