Go Down

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

shahar

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

Code: [Select]

const int receivePin = 2;  // The pin connected to the RC receiver's servo output
const int outputPin = 3;  // Output PWM pin
unsigned long pulseLength = constrain(pulseIn(receivePin, HIGH), 1000, 2000);
analogWrite(outputPin, map(pulseLength, 1000, 2000, 0, 255));
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

DuaneB

Read this
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

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 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, 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: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

DuaneB

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  0
pulseLength = constrain(pulseIn(inputPinA, HIGH), 1000, 3000);
// do something time consuming guaranteeing that we miss channel 1
analogWrite(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 0
analogWrite(outputPinB, map(pulseLength, 1000, 3000, 0, 255));

// and repeat


Duane B

rcarduino.blogspot.com
Read this
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

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


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: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Go Up