Pages: [1]   Go Down
Author Topic: Connecting two rfid readers (ID-12 innovations) at the same time to the arduino  (Read 1057 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear forum,

Currently I am working on a (for me) complex project to create a physical calendar which can read rfid tags.

One of the interactions I want to have is for me to first Identify a tag on a central interface, I can speak a message, then I can put the rfid tag on the calendar, then when the second reader comes by the tag it will read the message back to me. I use the ID-12 innovations rfid reader.

The problem I have is with the two rfid readers, this is the way I initialize it:

....
NewSoftSerial rfidSerial =  NewSoftSerial(RFID_RX, RFID_TX);
....
setup(){
rfidSerial.begin(9600);
...
}

This works when I use a single rfid reader.

Then when I want to do the same again for a second rfid-reader in the same code it only takes the reader that is inititalized last (rfidSerial.begin(9600)smiley-wink.

Is is possible to create 2 newSoftSerials?

This is how I connected the reader (I connected them to 3,4,5,6 instead of 13,0 in the image):
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 651
Posts: 50841
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is is possible to create 2 newSoftSerials?
It is possible to make two instance of NewSoftSerial, but only one instance can listen at a time. You really need an Arduino that has more than one hardware serial port, or you need to connect one of your RFID readers to the hardware serial port.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is is possible to create 2 newSoftSerials?
It is possible to make two instance of NewSoftSerial, but only one instance can listen at a time. You really need an Arduino that has more than one hardware serial port, or you need to connect one of your RFID readers to the hardware serial port.

Is it possible to solve this in the software, by letting the rfid-readers listen in turns? (and how would this be done?)

I am currently using the Arduino Uno, which uses the 0 and the 1 port for serial communication, is it possible to use these ports?

I also need to send data to processing which occupies the usb port, I once read the usb port can't be used at the same time as the 0 and 1 port is this correct?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 651
Posts: 50841
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is it possible to solve this in the software, by letting the rfid-readers listen in turns?
Yes, as long as you don't mind missing what the other device sent to the serial port while not listening to it.

Quote
and how would this be done?
Using any method of an instance of NewSoftSerial (or SoftwareSerial::listen() when you move up to 1.0).

Quote
I am currently using the Arduino Uno, which uses the 0 and the 1 port for serial communication, is it possible to use these ports?
The hardware serial port (pins 0 and 1) is how the Arduino IDE loads a new program, so the reader would need to be unplugged/powered off while uploading a sketch. Other than that, the serial port is available for debugging OR connecting an external device (such as a RFID reader) to.

Quote
I also need to send data to processing which occupies the usb port, I once read the usb port can't be used at the same time as the 0 and 1 port is this correct?
It would be better if you had mentioned ALL your requirements up front.

Seriously, it's time to get out your wallet and order a Mega.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for all the answers. I apologize for not being fully clear on what I want.

I think I will first try to solve the issue in the software (read from both readers taking turns).

If this doesn't work I will order an arduino mega.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What I tried to do is the following:

setup(){
.....
rfidSerial.begin(9600);
rfidSerial2.begin(9600);

....
}

loop(){

if(switchPort % 2 == 0){
rfidSerial.listen();
....
code
...
}

if(switchPort % 2 == 1){
rfidSerial2.listen();
....
code
...
switchPort++;
}

When I use one of the listener calls he will take that port, but for some reason when I add the second port listener he doesn't read either reader anymore.

Is there maybe an unlisten call? or does somebody know why this doesn't work?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 651
Posts: 50841
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How long does each reader spend listening?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How long does each reader spend listening?

in between the switches I have a delay(100);

when the ports see a tag the ports reads until they have read a full code and stored it.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 651
Posts: 50841
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
in between the switches I have a delay(100);
During which time, squat happens.

Get rid of delay(). Do not even consider using it, except for millisecond pauses for switch debouncing.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
in between the switches I have a delay(100);
During which time, squat happens.

Get rid of delay(). Do not even consider using it, except for millisecond pauses for switch debouncing.

I used it for not overloading my processing with data.

Now I have a delay(1), instead of a delay(100); and use a counter to send once every 100 ms to my serial port. I changed the code from if(switchPort%2 == 0) to a counter that allows one reader to read for 50 ms and the other one for 50 ms. Now both readers respond to the code but they don't always work, it seems like they work randomly.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 651
Posts: 50841
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I used it for not overloading my processing with data.

Now I have a delay(1), instead of a delay(100); and use a counter to send once every 100 ms to my serial port.
You need to get rid of the delay, altogether. Use millis() and record when you send data. See if "now" minus "then" is greater than or equal the interval you want between sends. If so, send the data and update "then".

You should probably use a similar technique to have each RFID reader listen for a few milliseconds at a time, while you wait for your Mega to arrive.
Logged

Pages: [1]   Go Up
Jump to: