Hello to everyone. To briefly explain my problem, the multi-turn potentiometer I used to make my own car steering which wants 6 to 7 turns wiper servo.
I use FlySky I6B Remot control and reciever
I copy code from @James_Bruton youtube channel he used normarl pot for his project and it is only 180 degree turn.
Here his project link How to Make an R/C Servo from a Wiper Motor | James Bruton - YouTube
The potentiometer I used is 10k 3590s. I want to please change in this code for multiturn pot I would be very happy if he shared his opinion with me. Thanks in advance.
Here is the code he used
#include <PID_v1.h> //PID loop from http://playground.arduino.cc/Code/PIDLibrary
double Pk1 = 1; //speed it gets there
double Ik1 = 0;
double Dk1 = 0;
double Setpoint1, Input1, Output1, Output1a; // PID variables
PID PID1(&Input1, &Output1, &Setpoint1, Pk1, Ik1 , Dk1, DIRECT); // PID Setup
volatile unsigned long pwm;
volatile boolean done;
unsigned long start;
int pot;
unsigned long currentMillis;
long previousMillis = 0; // set up timers
long interval = 20; // time constant for timers
void setup() {
pinMode(2, INPUT);
pinMode(A0, INPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
attachInterrupt(0, timeit, CHANGE);
Serial.begin(115200);
PID1.SetMode(AUTOMATIC); // PID Setup - trousers SERVO
PID1.SetOutputLimits(-255, 255);
PID1.SetSampleTime(20);
}
void timeit() {
if (digitalRead(2) == HIGH) {
start = micros();
}
else {
pwm = micros() - start;
done = true;
}
}
void loop() {
currentMillis = millis();
if (currentMillis - previousMillis >= interval) { //start timed event
previousMillis = currentMillis;
pot = analogRead(A0);
Serial.print(pot);
Serial.print(" , ");
Serial.print (pwm);
Serial.print(" , ");
Setpoint1 = map(pwm, 1000, 2000, -255, 255);
Input1 = map(pot, 0, 1023, -255, 255);
PID1.Compute();
Serial.println(Output1);
if (Output1 > 0) {
analogWrite(5, Output1);
analogWrite(6, 0);
}
else if (Output1 < 0) {
Output1a = abs(Output1);
analogWrite(5, 0);
analogWrite(6, Output1a);
}
if (!done)
return;
done = false;
} // end of timed event
}
Hello, do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation of your ask).
That’s not the issue, it’s how your post looks like. Please read how to use the forum and how to post code,
➜ please edit your post, select the code part and press the </> icon in the tool bar to mark it as cod (also make sure you indented the code in the IDE before copying, that’s done by pressing ctrlT on a PC or cmdT on a Mac).
@paulpaulson
This the difference.
Rotary potentiometer (the most common type) vary their resistive value as a result of an angular movement. Rotating a knob or dial attached to the shaft causes the internal wiper to sweep around a curved resistive element. The most common use of a rotary potentiometer is the volume-control pot.
Multi-turn potentiometers allow for a shaft rotation of more than 360 degrees of mechanical travel from one end of the resistive track to the other.
I think the biggest problem is that you are not calling timeit() to get the pulse length from the radio. I recommend you replace 'timeit()' with 'pulseIn()':
pot = analogRead(A0);
pwm = pulseIn(2, HIGH, 30000);
Note: Input and Setpoint just have to be in the same units. They don't have to be related to Output. I would use the analog input range:
I believe Mr. @paulpaulson was asking this rhetorical manner, that is to say there is no electrical difference, therefor it seems like the code woukd not need to change.
Except for some constants and the assumptions that they imply.