Turnigy 9x 8ch pulseIn oscillating

Hello guys. This is my first post.
I have the arduino mega 2560 and a turnigy 9x radio with 8ch receiver...
I get the value of receive with pulseIn function and set value to servo:

...
int val = pulseIn(rxPin, HIGH);
myServo.write(val);

the motor work, but oscillating. See Serial.println(val):

1048
1048
1047
1041
1026
1048
1047
1047
1048
1048
1049
1048
1027
1049
1048
1047
1048
1026
1047
1048
1049
1048
1047
1048
1048
1026
1047
1049
1047
1049
1047
1047
1048
1048
1048

how can I fix it ?

Thank :slight_smile:

Apply some smoothing

AWOL:
Apply some smoothing

Thank for your reply AWOL.
But how i apply smoothing ?

Rolling average,median filter, low-pass filter...

AWOL:
Rolling average,median filter, low-pass filter...

Can you give me an example ?

int val = pulseIn(rxPin, HIGH);
rolling = (val / 8) + ((rolling * 7) / 8);
myServo.write(rolling);

AWOL:

int val = pulseIn(rxPin, HIGH);

rolling = (val / 8) + ((rolling * 7) / 8);
myServo.write(rolling);

Dont work :frowning:

rolling is initializing how ?

Dont work

Works for me.

AWOL:

Dont work

Works for me.

Other idea ? :frowning:

Other idea ?

Sure. Explain what "don't work" means. You made some changes to some code you haven't posted. We can't see the changes. We can't see the new serial output. So, yeah, I have some ideas. You probably don't want to hear them, though.

PaulS:

Other idea ?

Sure. Explain what "don't work" means. You made some changes to some code you haven't posted. We can't see the changes. We can't see the new serial output. So, yeah, I have some ideas. You probably don't want to hear them, though.

only was changed values

120
120
120
120
120
120
109
120
120
120
120
120
120
109
120
120
120
120

the receiver give me value between 1044 (minimum) and 1875 (maximum).

I'm sorry for bothering...
Thank you very much.

Sorry for english.