Skip to content
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

Serial and SoftwareSerial port comments #203

Merged
merged 2 commits into from
May 3, 2017
Merged

Conversation

jpmeijers
Copy link
Collaborator

Added a description of the Stream parameters passed to TheThingsNetwork library. Elaborate about Software Serial and serial on other devices.


# Comments
## Serial ports (Stream objects)
The Stream objects (Serial ports) need to be initialized at the correct baud rates at the start of your `setup()` function. See [our examples](https://github.com/TheThingsNetwork/arduino-device-lib/blob/asian-frequency-plans/examples) for more details. For example:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong branch

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we really start with the definition of the serials, so explain a bit about the hardware serial(s) and potential software serials?

}
```

### SodaqOne
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SODAQ One

```

### TheThingsUno
At the top of your sketch use
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or any Leonardo with RX/TX connected to the RN module

}
```

SoftwareSerial does not operate correctly at high baud rates. We normally use it at 9600 baud. Because the RN2483 and RN2903 normally operates at 57600 baud, we need to switch it to 9600 baud so that we can communicate with it using 9600 baud. Luckily this is done automatically inside TheThingsNetwork Arduino library, so you as user do not have to worry about this.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the autobaud feature really strong enough to handle this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another tip is to use AltSoftSerial; which determines for you which RX/TX pins you can use, but it's reliable

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to stick to standard libraries, and therefore the SoftwareSerial library that comes with Arduino. AltSoftSerial has the side effect that it can cause interference with your own program when you use timers and interrupts. On a normal Arduino you should be able to use SoftwareSerial on all pins.

The autobaud() function is based on the version in my library. That one is quite stable. We can however test this one a bit better. I'll see if I can find an Arduino and RN2483 to test with.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to stick to standard libraries, but better not use them when you know they're not reliable in certain cases. AltSoftSerial is required when you want to use other (software) serial on The Things Uno, that's definitely not stable with standard libraries.

The autobaud is stable but I'm not sure if it really sets the RN module to any baud rate you want, or it merely syncs the serial interface timing so that it doesn't get corrupted on first transmissions.

@johanstokking johanstokking merged commit 34bd655 into master May 3, 2017
@johanstokking johanstokking deleted the software-serial-docs branch May 3, 2017 12:39
@jpmeijers
Copy link
Collaborator Author

Maybe the description of the Serial ports belongs better in https://github.com/TheThingsNetwork/docs/edit/master/_content/devices/arduino/usage.md than in the API reference. Should I move it?

I should also add a comment about a level shifter and/or voltage levels (3.3V vs 5V) for when someone builds their own device.

@johanstokking
Copy link
Member

Yes indeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants