Please excuse me, I'm very new to all of this (programming, arduino, etc.)
I want to convert a signal from an rc remote to a pwm signal. I connected the receiver of the remote to a multimeter to make sure that I'm getting a varying voltage, and I am. 0V when not touching the joystick and 5V when I pull the joystick completely (with nice steady values in between). In reading through the forum and google a bit it seems that people are doing stuff with PPM with RC remotes, but I'm hoping I don't have to go that route, since I seem to be getting good voltage values. (I've tried copying and pasting a few of those codes with zero luck...it's a bit over my head at the moment).
In any case, I AM having problems with the analogRead and analogWrite functions, mostly the analogWrite. As soon as I try taking in the signal using analogRead, I notice I'm getting a serious lag; when I pull on the joystick, it takes a couple seconds or so for the reading to change on the serial monitor. I'm also losing resolution on my voltage. Both the input and output seem to be just high or low.
It feels like I might have to explore the PPM more, but I'm hoping there's an easier solution. If I have to do PPM, is there something simpler than these? I just haven't gotten them to work.
(RCArduino: How To Read RC Receiver PPM Stream)
(Arduino Playground - ReadReceiver)
(Read PPM signals from RC receiver or Control - Exhibition - Arduino Forum)
(Arduino ppm signal reader and generator - RC Groups)
here's my current simple code:
const int input1Pin = 1; //designate input and output pins from remote to motors
const int input2Pin = 0;
const int output1Pin = 9;
const int output2Pin = 6;
int ch1; // channel values
int ch2;
void setup()
{
// pinMode(output1Pin, OUTPUT); //unnessecesary for analogWrite function
// pinMode(output2Pin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
displayinputsoutputs();
ch1 = analogRead(input1Pin);
ch2 = analogRead(input2Pin);
analogWrite(output1Pin, map(ch1, 0, 1023, 0, 256));
analogWrite(output2Pin, map(ch2, 0, 1023, 0, 256));
}
void displayinputsoutputs()
{
Serial.print("Channel 1:");
Serial.println(ch1); //print the value of each channel
Serial.print("Channel 2:");
Serial.println(ch2);
Serial.print("Channel 1 Output:");
Serial.println(map(ch1, 0, 1023, 0, 256));
Serial.print("Channel 2 Output:");
Serial.println(map(ch2, 0, 1023, 0, 256));
Serial.println(" ");
delay(500);
}