Skip to content

Commit 8053570

Browse files
committed
feat(examples): add an example for switching between multiple software serial devices
1 parent 42973f1 commit 8053570

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* A simple example to interface with multiple software serials.
3+
* Use multiple software serials on some boards can only listen one UART at a time like Uno.
4+
*
5+
* Note:
6+
* You can use it for connect other software serials devices not only rdm6300.
7+
* In these case, we use two rdm6300 readers for example.
8+
*
9+
* The LED pin of rdm6300 is set at 5V (HIGH) at initial,
10+
* and if an RFID was read, the LED pin goes to 0V (LOW) for some moments.
11+
* We can use this property to switch between two devices,
12+
* but it still can only read from a device at a time.
13+
*
14+
* And be aware about usage of listening switch between devices.
15+
*
16+
* Connections:
17+
* | Uno | rdm6300-1 | rdm6300-2 | notes |
18+
* |-----+-----------+-----------+-------------------------------------|
19+
* | D5 | TX | | |
20+
* | D6 | LED | | |
21+
* | D7 | | TX | |
22+
* | D8 | | LED | |
23+
* | GND | GND | GND | |
24+
* | VCC | VCC | VCC | The rdm6300 must be powered with 5V |
25+
*
26+
* Zeng (https://github.com/asas1asas200)
27+
*/
28+
29+
#include <rdm6300.h>
30+
31+
#define RDM6300_1_RX_PIN 5
32+
#define RDM6300_1_LED_PIN 6
33+
#define RDM6300_2_RX_PIN 7
34+
#define RDM6300_2_LED_PIN 8
35+
36+
Rdm6300 rdm6300_1;
37+
Rdm6300 rdm6300_2;
38+
39+
Rdm6300 *current_rdm6300;
40+
41+
void setup()
42+
{
43+
Serial.begin(115200);
44+
pinMode(RDM6300_1_LED_PIN, INPUT);
45+
pinMode(RDM6300_2_LED_PIN, INPUT);
46+
47+
rdm6300_1.begin(RDM6300_1_RX_PIN);
48+
rdm6300_2.begin(RDM6300_2_RX_PIN);
49+
50+
rdm6300_1.listen();
51+
current_rdm6300 = &rdm6300_1;
52+
53+
Serial.println("Place RFID tag near any rdm6300...");
54+
}
55+
56+
void loop()
57+
{
58+
// checkout listening if needed
59+
if (digitalRead(RDM6300_1_LED_PIN) == LOW
60+
&& !rdm6300_1.is_listening()) {
61+
Serial.println("Switch to listening RDM6300_1");
62+
rdm6300_1.listen();
63+
current_rdm6300 = &rdm6300_1;
64+
} else if (digitalRead(RDM6300_2_LED_PIN) == LOW
65+
&& !rdm6300_2.is_listening()) {
66+
Serial.println("Switch to listening RDM6300_2");
67+
rdm6300_2.listen();
68+
current_rdm6300 = &rdm6300_2;
69+
}
70+
71+
/* If you use rdm6300 with other devices, you had better set a TIMEOUT and run a while-loop to
72+
make sure the tag can be read correctely. */
73+
if (current_rdm6300->update())
74+
Serial.println(current_rdm6300->get_tag_id(), HEX);
75+
76+
delay(10);
77+
}

0 commit comments

Comments
 (0)