Skip to content

SerialEvent tutorial omission #7669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
EffC00k opened this issue Jun 5, 2018 · 2 comments
Closed

SerialEvent tutorial omission #7669

EffC00k opened this issue Jun 5, 2018 · 2 comments
Labels
Component: Documentation Related to Arduino's documentation content Type: Bug

Comments

@EffC00k
Copy link

EffC00k commented Jun 5, 2018

This tutorial:
https://www.arduino.cc/en/Tutorial/SerialEvent
for SerialEvent()
is missing a call to SerialEvent()
in the loop() function. The code is never called.

@per1234 per1234 added the Component: Documentation Related to Arduino's documentation content label Jun 5, 2018
@per1234
Copy link
Collaborator

per1234 commented Jun 5, 2018

The tutorial's code is correct. SerialEvent is called from the main() function (which is hidden in the core library):

So even though there is no call in loop(), SerialEvent() will indeed be called when there is data available.

What is not correct is this statement on that page:

This function is called inside the loop().

I believe that is the cause of the confusion, and should be fixed.


My suggested edit to the page:

Change:

This example demonstrates use of the SerialEvent() function. This function is called inside the loop(). If there is serial data in the buffer each character found is added to a string until a newline is found.

To:

This example demonstrates use of the SerialEvent() function. This function is called when there is Serial data available. Each received character is added to a string until a newline is found.

@tofrnr
Copy link

tofrnr commented Jun 12, 2018

my suggestion:
Change:... To:

This example demonstrates use of the SerialEvent() function.
Once having been initialized by an arbitrary function
void serialEvent() { ... }
this function is called then automatically in the background when there is Serial data available. Notice that there is no need to call this function then repeatedly in the loop() function.
Each received character is added to a string until a newline is found.

PS,
IMO that is a bad practice though, one would expect to initialize a function or class in setup(), additionally specifying the arbitrary Serial port, like e.g.,

void setup() { 
   // *snip*
   SerialEvent (myeventhandler0, Serial);
   SerialEvent (myeventhandler1, Serial1);
   // *snip*
}

void myeventhandler0() {...}
void myeventhandler1() {...}

and then to get the expected behaviour in the background.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Documentation Related to Arduino's documentation content Type: Bug
Projects
None yet
Development

No branches or pull requests

3 participants