SoftwareSerial library

Go To Last Post
30 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

I want to interface 5  EM-18 RFID reader with Arduino Uno. I see Arduino only support 3 UART.

 

Can I use SoftwareSerial library to read data from reader ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Dare to be naïve." - Buckminster Fuller

Last Edited: Fri. Aug 5, 2022 - 05:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


When I go here:

 

https://www.microchip.com/maps/M...

 

and dial in "8bit AVR" and "min UART: 5" it says:

 

 

 

if you are at the start of a project then I wouldn't compromise by trying to find "workaround" solutions. If the project calls for 5+ UART I'd pick a chip with 5+ UART.

 

Another approach might be to simply put a I2C/SPI "backpack" using very small AVRs onto each RFID then have them talk on a common SPI or I2C "bus" to a core micro.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You don't need 5 UARTs, you only need 1.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

12king wrote:
I want to interface 5  EM-18 RFID reader with Arduino Uno. I see Arduino only support 3 UART.

Well the UNO (ie. Mega328) only has one hardware USART, so any additional serial connections would need to be supported by software serial!

There are other Arduino platforms with more then one hardware USARTs, choose another platform model for your project.

 

Jim

 

 

FF = PI > S.E.T

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

Well the UNO (ie. Mega328) only has one hardware USART, so any additional serial connections would need to be supported by software serial!

 

Not true Jim. It's quite possible to do it with just one USART on an Uno.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Brian, I was only commenting on the OPs original posting of "needing" multiple USARTs.  As I have no experience with rfid readers, I don't know how many the OP really needs.

Perhaps you can explain to the OP and the rest of us, why only one is needed for the project.  This is what is great about this group, it's wide experience level and willingness to share.

Jim

 

 

FF = PI > S.E.T

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Could it be they support MPCM ? (ie 9bit UART with addressing) ?

 

EDIT: looking at this: https://www.electronicwings.com/... it does not seem so. Sure that is only using TX from RFID to RX of AVR but if you hang 5 off RX and they "all talk at once" how do you prevent conflict? Even if you are sure they only "talk one at a time" then how do you ID which if the 5 you are receiving data from ?

Last Edited: Fri. Aug 5, 2022 - 02:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My solution is a combination of electronic and human engineering.

 

These are RFID card readers. Low speeds devices as used on access control, and used infrequently.

 

Take the five incoming TX lines into a 5-input AND gate which feeds the RX pin of the AVR. Also take the five lines into a group of 5 PCINT lines. Set up the PCINT lines to cause an interrupt on those 5 lines if anything changes.

 

The falling edge of the start bit on any incoming message will cause a PCINT and you'll be able to see which of the 5 it was. At the end of the first byte you'll get an RXC interrupt and can start reading the message.

 

But what happens if another RFID tag is scanned? Won't it corrupt the ongoing read? Yes it will but I contend that it doesn't matter. This is the human engineering bit, we've all scanned a tag somewhere and all we got was a beep and red light. What do we do? We simply swipe again. My idea uses the human as the collision avoidance mechanism. Collision; wait a random time; retry.

 

Any LEDs and beeps are controlled by the AVR.

 

You can mitigate against some collisions with 10 resistors. The incoming lines go via a series pair of resistors sized so that the PCINT pins can be set to output and used to pull the 4 lines not in communication up to avoid any corruption getting to the RX pin.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nice!  Thanks for the clarification!

 

 

FF = PI > S.E.T

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

12king wrote:
Can I use SoftwareSerial library to read data from reader ?

 

Bear in mind that although you can construct as many instances of SoftwareSerial as there are pins (well almost) you can only "listen" to one port instance at a time.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

I can't find any reference to "EM-18 RFID " with googlesearch.  Do you mean a RFID module board reader with serial interface like this?:

If yes, then the best way to connect 16 of them to an Arduino is to use a 16-channel analog multiplexer chip and connect the TX output of each module board to one of the multiplexed channels.  This isn't an analog signal so you don't need to connect any negative voltage to the 16-bit multiplexer chip (Vee, usually).

  Use four outputs of the Arduino to select the multiplexed channel.  If the readers issue an interrupt upon the receipt of a signal, then tie all the interrupts of the devices together and feed it into the External Interrupt on INT0 or INT1 (D2 or D3).  On an interrupt scan all 16 devices to find the one the sending the signal.  

  Can multiple RFID reader units receive the same RFID signal from a single RFID tag at the same time?

  How much experience do you have dealing with RFID technology?

 

  Keep us updated.

 

Last Edited: Fri. Aug 5, 2022 - 03:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:
5-input AND gate

 

74hc4068, or one PNP, 2 resistors and 5 diodes.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:

I can't find any reference to "EM-18 RFID " with googlesearch.  Do you mean a RFID module board reader with serial interface like this?:

 

The data I found indicated that these units are transmit only. Bring a tag within range and they send a 12 byte message at 9,600 baud. So there's no way to use a multiplexer.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As I understand it, there is a single RFID master unit at each exit of a store.   When a person exits the store, a light gate is pushed open or an Infra-Red detects this person.  The RFID master unit will start transmitting at the carrier frequency.  The RFID tag uses the energy of the transmission of this carrier frequency to energize the extremely-low clock frequency and extremely-low power CPU located in the RFID tag.  

 

This CPU harvests just enough power from the master unit's carrier frequency to transmit a 12-byte string at 9600 baud back to the master unit at a different frequency from the carrier frequency.  This 12-byte sequence is a unique identification number for the RFID tag.  Every one of the millions of RFID tags has a unique number.

 

The store will record the number of the RFID tag and pair it with the description or serial number of the item being sold in the store's inventory database.   When the item is sold, the RFID is removed from the item and reprogrammed (in the store's inventory database) for another item.  The 12-byte number of the RFID tag on the sold item is transferred (in the store's inventory database) to a list of sold items.  When the shopper exits the store,  the RFID tag has been removed and therefore won't trigger to RFID master unit at the exit.  Or, if the RFID tag is embedded into the item at the factory, the store will check the RFID number scanned at the exit with the list of purchased items in its database.  As the item was just purchased, it will pass through the exit without notifying the store shoplifting staff.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:

ki0bk wrote:

Well the UNO (ie. Mega328) only has one hardware USART, so any additional serial connections would need to be supported by software serial!

 

Not true Jim. It's quite possible to do it with just one USART on an Uno.

 

The SoftwareSerial library allows serial communication on other digital pins of an Arduino board,
It is possible to have multiple software serial ports with speeds up to 115200 bps

 

https://docs.arduino.cc/learn/built-in-libraries/software-serial

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If i understand correctly you need to receive multiple (5) independent UART messages at slow baudrate (9600). What about to simply connect all 5 uarts to 5 pins, then set up PCINT to catch any edge at any of these pins. Run some timer at frequency about 100kHz. In PCINT IRQ routine read and save timer value with channel number and edge type. Then you'll have all necessary informations to decode incoming byte (in form "falling edge at time xy us, rising edge about xy us after fallign edge" etc.). Probably this "decoding" engine can run also in PCINT IRQ routine. 
IF you also need to transmit, then you can use single UART instance and add external demultiplexor. Or if you are running on AVRs equiped with CCL, you can probably build demux inside MCU.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Have you actually read the 'limitations' section on that page? 

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:

 

Have you actually read the 'limitations' section on that page? 

 

I am using this reader for attendance and door access control system. Not all peoples will log in at same time and I think Arduino is enough capable to read all incoming signal    

 

What are the limitations that you think doesn't best fit with serial library for my project

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

12king wrote:

What are the limitations that you think doesn't best fit with serial library for my project

 

  • If using multiple software serial ports, only one can receive data at a time.

 

You haven't provided a link to the readers you are using but many of them are transmit only. A tag is scanned and the reader transmits. Software Serial only listens to one channel at a time. So how will it be able to monitor all 5 incoming datastreams?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

12king wrote:
What are the limitations that you think doesn't best fit with serial library for my project
N.Winterbottom wrote:
Bear in mind that although you can construct as many instances of SoftwareSerial as there are pins (well almost) you can only "listen" to one port instance at a time.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:

So how will it be able to monitor all 5 incoming datastreams?

 

This is sample code for two ports 

#include <SoftwareSerial.h>

#define RX1 2
#define TX1 3

#define RX2 10
#define TX2 11

// Set up a new SoftwareSerial object with RX in digital pin 10 and TX in digital pin 11
SoftwareSerial portOne(RX1, TX1);

// Set up a new SoftwareSerial object with RX in digital pin 8 and TX in digital pin 9
SoftwareSerial portTwo(RX2, TX2);

void setup()  {
    // Define pin modes for TX and RX
    pinMode(RX1, INPUT);
    pinMode(TX1, OUTPUT);

    pinMode(RX2, INPUT);
    pinMode(TX2, OUTPUT);
    
    // Set the baud rate for the SerialSoftware objects
    portOne.begin(9600);
    portTwo.begin(9600);
}

void loop() {
    if (portOne.available() > 0) {
        portOne.read();
        Serial.print(portOne.read());
    }
    if (portTwo.available() > 0) {
        portTwo.read();
        Serial.print( portTwo.read());
    }
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

12king wrote:

This is sample code for two ports 

 

Does it work?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

12king wrote:

This is sample code for two ports 

Someone hasn't read the documentation linked above, NOR the relevant example:

https://docs.arduino.cc/tutorials/communication/TwoPortReceive

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Assuming that the five RFID units are out-of-range of each other, and, that their data is 12 bytes at 9600 baud (which takes @12 milliseconds to receive for a 60 millisecond length of the data from all units).  The main AVR can use a TTL chip to multiplex 5 streams into one stream if it is a digital 0_Vcc signal.   Do these RFID units put out their serial signal in RS232 format (-9 to +9v)?

 

Is this 9600 baud serial bi-directional?  How does the main AVR tell each RFID unit to begin transmitting a carrier signal (that energizes the RFID tag).  Does the main AVR send a serial message to the RFID unit to begin the RFID-linking process?  If so then the AVR can select one-of-five channels as an RX input and TX output.  Then send a message that is received by each unit in sequence to broadcast the carrier signal and check for a return of 12 bytes from the selected unit.

Last Edited: Tue. Aug 9, 2022 - 06:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@12king

 

please provide a link to the RFID readers that you are using.

 

This will help people provide the right answer.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This presumably... 

 

https://www.electronicwings.com/sensors-modules/rfid-reader-em18 

 

So they are Tx only 9600 UART

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

This presumably... 

 

That's the type I keep seeing as well.

 

If that's the case then the OP really isn't understanding the problem they have.

 

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:

Does the main AVR send a serial message to the RFID unit to begin the RFID-linking process? 

 

Think about it. What starts off the whole scanning process? It certainly isn't the AVR, it's the act of putting an RFID tag near the scanner.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmm...

 

a fag-packet calculation would indicate that it might possible to write an rx only, 5 port, software serial implementation that would receive 5 channels simultaneously.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."