Go Down

Topic: Arduino Due potentiometer circuit not working (Read 310 times) previous topic - next topic

Henradrie

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?

ReverseEMF

#1
Apr 15, 2019, 07:46 pm Last Edit: Apr 15, 2019, 07:52 pm by ReverseEMF
It would help if we had a schematic to look at -- something you would have known, had you read:

How To Use This Forum

But, here are some troubleshooting pointers [assuming you haven't tried any of these already]:
  • Use the Serial print functions to directly output the ADC conversions values, and see if they behave as expected as you turn the Pot -- which, I see, you've already done.
  • Implement a counter, in code, that will feed expected values to the Servo function, and see if the Servo turns as expected.  Be sure to include, the counting loop, enough delay for the Servo to run properly.

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.
}
"It's a big galaxy, Mr. Scott"

Please DON'T Private Message to me, what should be part of the Public Conversation -- especially if it's to correct a mistake, or contradict a statement!  Let it ALL hang out!!

Henradrie

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.

ReverseEMF

"It's a big galaxy, Mr. Scott"

Please DON'T Private Message to me, what should be part of the Public Conversation -- especially if it's to correct a mistake, or contradict a statement!  Let it ALL hang out!!

ReverseEMF

#4
Apr 20, 2019, 07:29 pm Last Edit: Apr 20, 2019, 07:29 pm by ReverseEMF
...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?
"It's a big galaxy, Mr. Scott"

Please DON'T Private Message to me, what should be part of the Public Conversation -- especially if it's to correct a mistake, or contradict a statement!  Let it ALL hang out!!

WattsThat

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?
Vacuum tube guy in a solid state world

JCA79B

#6
Apr 21, 2019, 06:04 am Last Edit: Apr 21, 2019, 06:05 am by JCA79B
Code: [Select]
Bicep.write(BicepPotVal);
Don't you need:
Code: [Select]
Bicep.writeMicroseconds(BicepPotVal);
?

ard_newbie


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

MarkT

#8
Apr 21, 2019, 02:28 pm Last Edit: Apr 21, 2019, 02:36 pm by MarkT
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.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up