Reading values from a TX/RX with arduino mega

Hello guys, I am running a project here and i need to read the throttle from my receiver.

as you can see at the image the values that are returned are not steady. My stick at the Tx is steady though. I dont touch anything and it returns something that changes a bit.

So…I need another way to read values i guess. Anyone? :confused:

thanks guys i have stuck on this 2 months now :frowning:

I have tried to read from
Digital pin - not working (returns 0)
Digital pin PWM
Analog Pin - not working (returns something like 665 all the time)

#define THROTTLE_PIN  9
#define AILERON_PIN  10
#define ELEVATOR_PIN  11
#define RUDDER_PIN  12

unsigned long thrDuration;
unsigned long ailDuration;
unsigned long eleDuration;
unsigned long rudDuration;
unsigned long switchDuration;

const byte thrInPin = THROTTLE_PIN;
const byte thrOutPin = 6;

const byte ailInPin = AILERON_PIN;
const byte ailOutPin = 6;

const byte eleInPin = ELEVATOR_PIN;
const byte eleOutPin = 6;

const byte rudInPin = RUDDER_PIN;
const byte rudOutPin = 6;

const byte switchInPin = 8;
const byte switchOutPin = 2;

//int autolandPin = 8;
//int val = 0;

void setup() {
	Serial.begin(9600);

        pinMode(thrInPin, INPUT);
        pinMode(ailInPin, INPUT);
        pinMode(eleInPin, INPUT);
        pinMode(rudInPin, INPUT);
        pinMode(switchInPin, INPUT);
        
        
        pinMode(thrOutPin, OUTPUT);
        pinMode(ailOutPin, OUTPUT);
        pinMode(eleOutPin, OUTPUT);
        pinMode(rudOutPin, OUTPUT);
}

void printStatus() {
  thrDuration = pulseIn(thrInPin, HIGH);
  thrDuration = map(thrDuration, 1000, 2000, 980, 2020);
  Serial.print("Throttle: \t");
  Serial.print(thrDuration);
  
  ailDuration = pulseIn(ailInPin, HIGH);
  ailDuration = map(ailDuration, 1000, 2000, 980, 2020);
  Serial.print("\tAileron: \t");
  Serial.print(ailDuration);
  
  eleDuration = pulseIn(eleInPin, HIGH);
  eleDuration = map(eleDuration, 1000, 2000, 980, 2020);
  Serial.print("\tElevator: \t");
  Serial.print(eleDuration);
  
  rudDuration = pulseIn(rudInPin, HIGH);
  rudDuration = map(rudDuration, 1000, 2000, 980, 2020);
  Serial.print("\tRudder: \t");
  Serial.print(rudDuration);
  
  printSwitchState();
  
  Serial.print("\n");    
}

void printSwitchState() {
  switchDuration = pulseIn(switchInPin, HIGH);
  Serial.print("\tSwitch: \t");
  
  if( switchDuration < 2000 ) {
    Serial.print("ON");
    // code when switch is activated (top)
  }else {
    Serial.print("OFF");
    // code when switch is deactivated (bot)
  }
  //Serial.print(switchDuration);
}

/*
 * Main function
*/void loop() {
  printStatus();
}

The signal looks quite good to me. 1066 to 1073 isn't much of a range and it's mostly 1069.

I am mapping this signal to 0-180 so i can use it via the servo library and i have problems there caz i got vales 55 56 54 55 56...so the motor is not spinning with steady angular velocity.

Um, i saw something about hardware interupts... but i didnt figure out what i must do. I have also problem with the above code caz there is too much delay.

PulseIn() is bad because it locks up the processor while it's waiting for the pulse. If you're lucky, your RC receiver will produce the pulses sequentially and you just have to find out what that order is, then write your program to read in the same order.

I would try to read them all at the same time by making a small loop that does nothing else except record the micros() when each pin goes up or down, then quits once it's seen a complete cycle from every pin. That way you will read all the inputs mostly simultaneously. You may find that your receiver will start all of the pulses together, so you only need to record the start time of one.

Thank you for your answer. Um, I actually didnt get that. I know that my processor is locked and waits for pulse. But i did not understand your solution. Could you please explain me further when you have some free time?

thanks

take a look here. this is the trottle with some noise.

Where is the noise in that image? I don't know what you were putting in the input. Is this with the throttle held steady or were you trying to push it up and down?

What did you expect to see between 0 and 300?

What did you expect to see between 300 and 700?

What did you expect to see between 700 and 800?

What did you expect to see between 800 and 1000?

What did you expect to see between 1000 and the end?

take a look here. at first i increase throttle and then i take it back to zero. i was waiting the same but without spikes… someitmes i keep it steady but its not.

What has this got to do with Tx/Rx on a Mega ?
I assumed you were enquiring about Serial.read().

I think a more appropriate title would be "How to read RC signals on a Mega". Then someone who knows the answer might offer to help ?

...R

There are several ways to read singal (values) from an TX-RX. I am trying to do that for my throttle stick. The problem is that i am reading something that is not steady. Something that for some reason has some kind of noise. For some reason when i have steady the throttle the returning value is something like 1667 1667 1668 1669 1667 1668 1669 and this is not good. Why? I am writting this as microseconds to my motor. And the motor spins a bit faster and it lows its angular velocity, then a bit more...etc when you build a quadcopter as i do you can live with that. speed must be steady. I hope I am clear now...

and thank you all that you are trying to help me. I just have no idea what to do... :confused: