Skip to content

Commit 1a8e5f6

Browse files
authored
Merge pull request #13 from asas1asas200/zeng-feat-listen_func
Add support for multiple rdm6300s + example!
2 parents 0c56df2 + 8053570 commit 1a8e5f6

File tree

4 files changed

+100
-5
lines changed

4 files changed

+100
-5
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+
}

keywords.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ Rdm6300 KEYWORD1
1111
#######################################
1212
# Methods and Functions (KEYWORD2)
1313
#######################################
14-
begin KEYWORD2
15-
end KEYWORD2
16-
update KEYWORD2
17-
get_tag_id KEYWORD2
18-
is_tag_near KEYWORD2
14+
begin KEYWORD2
15+
end KEYWORD2
16+
update KEYWORD2
17+
get_tag_id KEYWORD2
18+
is_tag_near KEYWORD2
19+
listen KEYWORD2
20+
is_listening KEYWORD2
1921

2022
#######################################
2123
# Constants (LITERAL1)

src/rdm6300.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,15 @@ uint32_t Rdm6300::get_tag_id(void)
117117
_tag_id = 0;
118118
return tag_id;
119119
}
120+
121+
#ifdef RDM6300_SOFTWARE_SERIAL
122+
void Rdm6300::listen(void)
123+
{
124+
_software_serial->listen();
125+
}
126+
127+
bool Rdm6300::is_listening(void)
128+
{
129+
return _software_serial->isListening();
130+
}
131+
#endif

src/rdm6300.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class Rdm6300
4040
bool update(void);
4141
uint32_t get_tag_id(void);
4242
bool is_tag_near(void);
43+
#ifdef RDM6300_SOFTWARE_SERIAL
44+
void listen(void);
45+
bool is_listening(void);
46+
#endif
4347
private:
4448
#ifdef RDM6300_HARDWARE_SERIAL
4549
HardwareSerial *_hardware_serial = NULL;

0 commit comments

Comments
 (0)