Skip to content

Serial.begin() - enhance documentation and add example for changing the baud rate #711

@roboter-basteln

Description

@roboter-basteln

The documentation of Serial.begin() does not limit the use to one time - which is correct. However, it's not described how to use Serial.begin() multiple times.

I have asked a Stack Exchange question about it. From the answer I got there, I would like the documentation to be enhanced like this:

Description
[...]
`Serial.begin()` can be used multiple times within a program. 
Be aware that data that was already written might still be buffered. 
Therefore, you might want to use `Serial.flush()` before changing the baud rate.

and add an example

Example Code
[...]
Changing the baud rate:
void loop() {
      Serial.begin(1200);
      Serial.println("Hello");
      Serial.flush();
      Serial.begin(9600);
      Serial.println("world");
      Serial.flush();
 }

This could be useful e.g. if the two communication ends want to negotiate the baud rate. Forgetting to flush will likely cause effects that prevent successful negotiation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions