Go Down

Topic: Simple timed serial event (Read 866 times) previous topic - next topic


Hi all :)

I'm trying to come up with a snipet that looks for an incoming string on the serial port. If the code does not show up every second, the do something. It would be a failsafe for a serial port controlled R/C car. The controller would send out "something" every second to verify that there is radio connection.(Xbee)  Arduino on the other side would look for this signal and if it didn't show for a sec, center the servo (throttle).



May 20, 2011, 06:25 am Last Edit: May 20, 2011, 06:26 am by Graynomad Reason: 1
Something like this.

Code: [Select]
loop () {

   static long LastDataRx;

  if (Serial.available() > 0) {
      Serial.flush(); // assuming you don't care what the data is, just that there was some
      LastDataRx = millis();

   if (millis() - LastDataRx >= 1000) {


Rather than flush the data it would be better to at least test for a valid character if you have control of the transmitted data and/or know what to expect.

Rob Gray aka the GRAYnomad www.robgray.com


thanx I'll try this.
I know exactly what the string is as it would be sent from the transmitter and it would be just the text "failsafe" coming every 500ms. If it doesn't come, just stop. (Center servos)

Go Up