You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- `Stream& modemStream`: Stream for the LoRa modem (see comments at the end of this document).
16
-
- `Stream& debugStream`: Stream to write debug logs to (see comments at the end of this document).
15
+
- `Stream& modemStream`: Stream for the LoRa modem ([see notes](https://www.thethingsnetwork.org/docs/devices/arduino/usage.html)).
16
+
- `Stream& debugStream`: Stream to write debug logs to ([see notes](https://www.thethingsnetwork.org/docs/devices/arduino/usage.html)).
17
17
- `fp_ttn_fp fp`: The frequency plan: `TTN_FP_EU868` or `TTN_FP_US915` depending on the region you deploy in.
18
18
- `uint8_t sf = 7`: Optional custom spreading factor. Can be `7` to `12` for `TTN_FP_EU868` and `7` to `10` for `TTN_FP_US915`. Defaults to `7`.
19
19
- `uint8_t fsb = 2`: Optional custom frequency sub-band. Can be `1` to `8`. Defaults to `2` (for US915).
@@ -174,79 +174,3 @@ void sleep(unsigned long mseconds);
174
174
```
175
175
176
176
- `unsigned long mseconds`: number of milliseconds to sleep.
177
-
178
-
# Comments
179
-
## Serial ports
180
-
The RN2483 and RN2903 make use of a serial interface to communicate with your device's main processor. Serial interfaces are similar to the RS232 serial port on older computers. The most microcontrollers have hardware Universal Asynchronous Receiver/Transmitters (UARTs) or also called HardwareSerial ports. Serial communication is offloaded to these UARTs so that the main processor does not have to waste time on this slow task. A UART can only support one serial interface at a time, and most processors only have one or two UARTs. Therefore if you already used the available UARTs to communicate with, for example, your computer and a GPS, you do not have any left for the RN2483/RN2903.
181
-
182
-
When you run out of UARTs, you can still use serial communication handled in software. In this case it is not offloaded to dedicated hardware, and the main processor needs to handle the communication. This is called Software Serial. Depending on how the software serial is implemented, you can have as many as you want, as long as you have free GPIO pins on your device. Note that not all GPIO pins support all types of software serial. Examples of software serial is the default Arduino [SoftwareSerial](https://www.arduino.cc/en/Reference/SoftwareSerial) library, and the [AltSoftSerial](https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html) library.
183
-
184
-
### Stream objects
185
-
In the Arduino world serial ports are abstracted as stream objects. All stream objects have the same functions, even if lower down they use different physical connections (UART, SoftwareSerial, AltSoftSerial). This library does not care what you use, as long as it extends the Stream object.
186
-
187
-
The Stream objects 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/master/examples) for more details. For example:
188
-
```
189
-
loraSerial.begin(57600);
190
-
debugSerial.begin(9600);
191
-
```
192
-
193
-
### TheThingsUno
194
-
TheThingsUno is basically the same as an Arduino Leonardo with Serial1 connected to the RN2483/RN2903. Therefore if you use an Arduino Leonardo, and connect your RN2483/RN2903 to the Serial1 pins, you can use the same configuration than for TheThingsUno.
195
-
196
-
At the top of your sketch use
197
-
```
198
-
#define loraSerial Serial1
199
-
#define debugSerial Serial
200
-
```
201
-
And in your `setup()` function use
202
-
```
203
-
void setup()
204
-
{
205
-
loraSerial.begin(57600);
206
-
debugSerial.begin(9600);
207
-
...
208
-
}
209
-
```
210
-
211
-
### SODAQ One
212
-
At the top of your sketch use
213
-
```
214
-
#define loraSerial Serial1
215
-
#define debugSerial SerialUSB
216
-
```
217
-
And in your `setup()` function use
218
-
```
219
-
void setup()
220
-
{
221
-
loraSerial.begin(57600);
222
-
debugSerial.begin(9600);
223
-
...
224
-
}
225
-
```
226
-
227
-
### Arduino Uno, Arduino Nano or other devices using SoftwareSerial
228
-
The Arduino Uno only has one hardware serial port which is used to communicate over USB to the computer. When connecting an RN2483/RN2903 to the Arduino Uno, one has to make use of SoftwareSerial. If you connected the RN2483/RN2903 to the Arduino using the same pinout as [described on the forum](https://www.thethingsnetwork.org/forum/t/how-to-build-your-first-ttn-node-arduino-rn2483/1574), you can make use of the following code.
229
-
230
-
At the top of your sketch use
231
-
```
232
-
#include <SoftwareSerial.h>
233
-
234
-
#define debugSerial Serial
235
-
236
-
SoftwareSerial loraSerial(10, 11); // RX, TX
237
-
```
238
-
And in your `setup()` function use
239
-
```
240
-
void setup()
241
-
{
242
-
loraSerial.begin(9600);
243
-
debugSerial.begin(9600);
244
-
...
245
-
}
246
-
```
247
-
248
-
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. This is done automatically inside TheThingsNetwork Arduino library. Changing of the baud rate of the RN2483/RN2903 is not always very reliable. Power cycling the device, or a reset, might be necessary.
249
-
250
-
If you connected the RN2483/RN2903 to different pins on the Arduino, you can change the line `SoftwareSerial loraSerial(10, 11); // RX, TX` to specify the correct RX and TX pins (from the Arduino's perspective).
251
-
252
-
When using the [AltSoftSerial](https://github.com/PaulStoffregen/AltSoftSerial) library the pins you can use for software serial is fixed according to which device you use. You therefore do not have a choice which pins to use, and you may lose some other functionality, but this library seems to be more stable than the default SoftwareSerial library.
0 commit comments