Go Down

Topic: serialEvent Arduino UNO (Read 299 times) previous topic - next topic

cozonac96

Mar 14, 2017, 01:26 am Last Edit: Mar 14, 2017, 01:41 am by cozonac96
Hi everybody,

I am kind of new to Arduino and I want to work with the serialEvent function. Unfortunatly I can get it to work (or maybe I dont know how to make it work). This is the code I am using. I am only testing the function to see if the serialEvent function is trigerred when I do a serialprint but I never see the word "test" appear in the serial.

Can you help ?

Code: [Select]

int number  = 1;

void setup() {
 // initialize serial:
 Serial.begin(9600);
}

void loop() {
   Serial.println(number);
}
void serialEvent() {
 Serial.println("test");
}

-dev

First, the serialEvent routines are for reading characters, not printing.  They are only called if received characters are available.

Second, the serialEvent routines are equivalent to just performing the test in loop:

Code: [Select]
void loop()
{
  if (Serial.available())
    mySerialReadRoutine();
}

void mySerialReadRoutine()
{
  char c = Serial.read();

  // Do something with the received char...
}

There is absolutely no advantage to using serialEvent.

I would suggest starting with Serial Input Basics, on the Useful Links page.

Cheers,
/dev

cozonac96

Thank you very much !

First time on the forum and I am very impressed by how fast and nice the response is !


Go Up