Go Down

Topic: RC reciever to analog 0-5 voltage (Read 5121 times)previous topic - next topic

shahar

Oct 10, 2012, 11:23 pm
Hi people

I really need your help.

I need to convert from RC reciever input to analog 0-5V output using the arduino

can someone tell me how write a code?

p.s
I know I have to connect lowpass filter to the analog output for steady Vout

johnwasser

#1
Oct 10, 2012, 11:47 pm
Code: [Select]
`const int receivePin = 2;  // The pin connected to the RC receiver's servo outputconst int outputPin = 3;  // Output PWM pinunsigned long pulseLength = constrain(pulseIn(receivePin, HIGH), 1000, 2000);analogWrite(outputPin, map(pulseLength, 1000, 2000, 0, 255));`
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

DuaneB

#2
Oct 11, 2012, 08:32 am
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

johnwasser

#3
Oct 12, 2012, 12:00 am
And for two channels (with RC output pulses of 1000 to 3000 uS instead of 1000 to 2000):

Code: [Select]
`const int inputPinA = 2;  // The pin connected to the RC receiver's servo output Aconst int outputPinA = 3;  // Output PWM pin Aconst int inputPinB = 4;  // The pin connected to the RC receiver's servo output Bconst int outputPinB = 5;  // Output PWM pin Bvoid setup() {    pinMode(inputPinA, INPUT);    pinMode(inputPinB, INPUT);}void loop() {    unsigned long pulseLength;    pulseLength = constrain(pulseIn(inputPinA, HIGH), 1000, 3000);    analogWrite(outputPinA, map(pulseLength, 1000, 3000, 0, 255));    pulseLength = constrain(pulseIn(inputPinB, HIGH), 1000, 3000);    analogWrite(outputPinB, map(pulseLength, 1000, 3000, 0, 255));}`
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

DuaneB

#4
Oct 12, 2012, 06:25 am
If you want to miss more than half of the information in the RC Signal this is fine.

If your interested in why you miss half this information, here is why, its also the reason why I prefer using interrupts, the situation gets worse for each channel that you add because pulse in can only look at a single channel at a time meaning that you are forced to ignore any other information in the signal.

Code: [Select]
`// wait for channel  0pulseLength = constrain(pulseIn(inputPinA, HIGH), 1000, 3000);// do something time consuming guaranteeing that we miss channel 1analogWrite(outputPinA, map(pulseLength, 1000, 3000, 0, 255));// now wait for channel1, channel 0 will come and go without us seeing it because now we aren't even looking for it pulseLength = constrain(pulseIn(inputPinB, HIGH), 1000, 3000);// do something time consuming to guarantee that we miss channel 0analogWrite(outputPinB, map(pulseLength, 1000, 3000, 0, 255));// and repeat`

Duane B

rcarduino.blogspot.com
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

shahar

#5
Oct 15, 2012, 12:51 am
Hi people.

OK. John's code works good
the only problem is that if I move the RC transmitter stick from full right to full left I get about two seconds respond time.
anyone knows how to improve that?

the code:

const int inputPinA = 2;  // The pin connected to the RC receiver's servo output A
const int outputPinA = 3;  // Output PWM pin A
const int inputPinB = 4;  // The pin connected to the RC receiver's servo output B
const int outputPinB = 5;  // Output PWM pin B

void setup() {
pinMode(inputPinA, INPUT);
pinMode(inputPinB, INPUT);
}

void loop() {
unsigned long pulseLength;

pulseLength = constrain(pulseIn(inputPinA, HIGH), 1000, 2000);
analogWrite(outputPinA, map(pulseLength, 1000, 2000, 0, 255));

pulseLength = constrain(pulseIn(inputPinB, HIGH), 1000, 2000);
analogWrite(outputPinB, map(pulseLength, 1000, 2000, 0, 255));
}

johnwasser

#6
Oct 15, 2012, 03:42 am

the only problem is that if I move the RC transmitter stick from full right to full left I get about two seconds respond time.
anyone knows how to improve that?

Perhaps the low-pass filter you use for converting PWM to a voltage has too large a capacitor or too large a resistor.  Sounds like the frequency cut-off is closer to 0.5 HZ than, say, 100 Hz.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

Go Up