Arduino Mega, RC pulses, garbage and missing chars on serial.print()

I'm trying to read pulses from a RC receiver, the model is FlySky FS-16X, FS-IA6B.

I'm having problems since sometimes I get weird values on the RC channels.
They range from 947 to 2000 ms but sometimes I read 0 or 500 or any other value which is outer the standard range.

Moreover, I get truncated strings when I try to read from serial.

This is the code:

#define CH1 A3 // INPUT 18
#define CH2 A4 // INPUT 19
#define CH3 A6 // INPUT 15
int throttle, steering;
int emergency;

void setup() {
  Serial.begin(57600);
  pinMode(CH1, INPUT);
  pinMode(CH2, INPUT);
  pinMode(CH3, INPUT);
}

void loop() {
  throttle = pulseIn(CH1, HIGH, 30000);
  steering = pulseIn(CH2, HIGH, 30000);
  emergency = pulseIn(CH3, HIGH, 30000);

  Serial.print("throttle: ");
  Serial.print(throttle);
  Serial.print(" steering: ");
  Serial.print(steering);
  Serial.print(" emergency: ");
  Serial.print(emergency);
  Serial.println();

  delay(100);
  
}

and this is what I get:

throttle:steering: 1487 emergency: 1988
throttl steering: 1487 ergency: 1988
thrott8 steering: 1493 emergency: 1988
throttle: 1488 steering: 149ergency: 1988
trtle: 1491 steering: 1493 emergency: 1988
throttle: 1494 steering: 487 emergency: 1988
t494 steering: 1487 emergency: 1988
throttle: 1488 steerin: 1493 emergency: 1988
throttle: 1488 steering: 1493 emergency: 1988
throttle: 1494 stee87 emergency: 19ttle: 1494 stee487 emergency: 1tle: 1488 steering: 1493 emergency:88
throttle: 1488 steering: 1493 emergency: 1988
hrottle: 1494 steering: 1487 emergency: 1988
throttle: 1494 steering: 1487 emergency: 1988
le: 14 steering: 1493 emergency: 1988
throttle 1488 steering: 1493 emegency: 1988
hrottle: 1488 steering: 1493 emergency: 1994
throtsteering: 1487 rgency: 1988
ttle: 1494 steering: 1487 emergency: 1988
thottle: 1488 steering: 193 emergency: 1988
throttle: 1488 steering:  emergency: 1988
tle: 1494 steering7 emergency: 1988
steeringhrottle: 1488 steeri3 emergency: 1988

as you can see I get lots of garbage and missing chars.

How can I solve this problem?

what Arduino/Microcontroller are you using?
could you increase the serial baudrate and see what happens?

1 Like

I'm using arduino MEGA2560 and I tried different baud rates with no success.

At the moment, I tried to print on Serial1 and I receive all the chars correctly.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.