Low Cost USB RFID Plug n Play

Hi

There are a lot of low cost usb rfid plug n play available, but I want to locate a device that when it enters the data into a spreadsheet or notepad type application it prefixes or suffex a reference for the ID of that device in use. So that if I have several usb in a multiport hub I can identify which device or maybe port number it came from. Linux Mint 21.3 OS.
Something like:

tag number-id3
tag number-id1
or
id4-tag number
id2-tag number

Info can then be manipulated in spreadsheet.

Thanks

Charles Harris

You mean you want to have multiple readers and to be able to detect which one scanned a given tag?

Just for clarity
 what exactly was the question/ask here??

I’m not sure if you’re wanting help with a software, a hardware, or to write a script


IF you want to find about a piece of hardware (device) that:

  • all you need to do is plug into the computer so

  • when you scan a tag in it it would automatically find/create an excel sheet,
  • locate a new line,
  • add the scanned tag’s ID
  • And amend with extra information such as a prefix, suffix, port number, etc


then the short answer is: “that does not exist”.

You need a software for that.

Most likely you’ll need to either make/adjust one yourself (maybe starting from an open source logistics framework), or find a company that offers you that service.
I would not know any to recommend, but those tend to be expensive

2 Likes

Yes. That is correct. In the spreadsheet it should show 2 pieces of data. The tag ID number and the USB device number that sent the data.
Thanks

Charles

Hi
Thanks for your comments.
As an individual usb device the hid works well and end up with the tag data ion spreadsheet. None of the devices seem to have a unique id. They all have same vid pid.
Need some advice on Linux software to id the usb port number and send with the tag read.
This allows manipulation into different groups within the spreadsheet.
Your comments appreciated.

Charles

This thread:

Suggests you could use udevadm monitor --property while plugging in the readers to get some uniquely identifying info for them

1 Like

I am still not sure on what’s the ask.

Are you creating a script?
Are you using a specific software?
are you scanning the tag on a KBR style reader while with the excel sheet open?

I think it’s sort of all at once

I think he just wants any solution to it

There are so many open-ended variables there, though, that I wouldn’t even know what to suggest


Worse
 if it’s someone coming into a custom made setup and trying to just “add one new bit of functionality”, something I suggest blindly might just bring everything down instead :grimacing:

1 Like

Hi
Thanks for all lmessages.

With a spreadsheet open, the normal HID device when activated with a tag, records the tag number in spreadsheet. They work good.
When you have say 10 devices attached to USB hub each recording tag reads at a different location, they all appear in spreadsheet in the same column and just the tag number.
To be able to manipulate the tag reads in the spreadsheet by location, I need to have a unique id of some sort to enable sorting to be done.

I am upside down here in New Zealand so could be the reason for my unclear statements ! lol

Thanks
Charles

It seems like using off the shelf USB keyboard-wedge style readers is unlikely to work, I’m not aware of any that allow customizing the output beyond “send tab or enter at the end of the string”, and they will all just get merged together as HID input.

Serial connected readers might be an option. You could use USB to serial adaptors, or something like a Moxa N-Port to connect multiple readers to your PC, each reader would be accessed through a specific serial port, you then have a script that opens all the ports, listens for incoming data, and stores it along with info about which port it came in on. This approach has the benefit that reads occurring on multiple devices simultaneously can be handled gracefully.

If you are open to DIY, one of the arduino boards that supports USB HID emulation (google “arduino keyboard”) connected to a PN532 could very easily read the ID from a tag, combine it with a reader ID and send it to the host as keypresses.

You could also combine those two, and have an arduino+PN532 presenting to the host as a serial device.

1 Like

I think I could use some KBR1 readers and python with this library:
https://python-evdev.readthedocs.io/en/latest/

To do what you’re describing, but I have only played with it for a second

If you’re comfortable with python

2 Likes

I could modify the DT wedge application for this and you could use acr1252u readers (or any pcsc compliant readers) if you need a consultation

2 Likes

Ok, that clears most of the confusion!!

I’m assuming those are KBR style readers (they read the tag, then convert it into keyboard input and send it to your computer).

That being the case, there are three approaches you can use:

  • A: Modify the readers themselves so that they append/prepend a unique identifier code to the beginning or end of the keyboard input.

That is the easiest approach, especially since @amal already offered you help!
i would take that help if I were you.

But for the sake of clarity, there’s a second option, which doesn’t need much coding either:

  • B: Configure each of those Keyboards to send input either bound to something (area, monitor, file
) or piped through “something” (thus appending or prepending some characters to each input stream)

I said “not much code”, but instead this requires a lot of config. To the point where you might first have to disable some automatic features on your system
 and if you’re not careful you might break things.

For example, I once took an old trackpad style mouse and bound it to work as a touch pad for only one of my monitors. While my other mouse should behave freely.
In doing so I accidentally broke the part of the system that automatically detected the boundaries of my second monitor’s touch screen capabilities, so I had to manually set the binding every time I turned the computer on (which was easily automated
 but still, it’s something I broke)

Ok, if you are considering this route, this is the gist of it:

  • each one of your input devices are identified by your computer and assigned a unique ID. This includes all your mouses, keyboards, buttons, readers, touch screens

  • So you can tell the Operating System to bind that input to something. By default it’s bound to “whatever is on focus” (in a nutshell)
  • You can also take a specific device and make so that it always outputs into a specific file.

Yet, the problems with this are:

  • complexity level is High
  • You may break the GUI (“computer”) if you don’t know what you’re doing
  • Depends on you having full access to your system
  • The device ID might change if you plug/unplug anything on the system
 sometimes it might even change just from restarting the computer (depending on what else you have installed). Then you need a clever way to figure out which is which

  • Might conflict with other system setup
  • I would only be confident with helping out of my head with Arch Linux


And then we go to option 3, which @amal also mentioned!

  • C: Get a bunch of PCSC compliant readers, then write a script that identifies them and outputs their read UID’s, with some appended/prepended identifiers, straight into a file.

Again, I would take amal’s offered help there!

1 Like

It’s actually modifying a piece of software I made
 the kbr1 readers won’t work for this option. You’d need several pcsc compliant readers, which are not HID devices, and a modified version of DT wedge software.

2 Likes

Option 3 it is!! :unicorn_joy:

Being for windows, it makes sense that it’s based on pcsc

I had some issues trying to use pcsc readers on Linux (Arch)

usually the system tries to handle it in a “brutish” way, so I need to turn off all the OS pcsc daemons (through something like systemctl stop pcscd) so my scripts could then “be allowed” to handle the device
 which in turn makes it so I lose all the advantages of that.

Have you encountered similar issues (on Linux)?

Dunno
 my only experience with Linux is in the server space, not user mode desktop client OS use cases.

I’m a Windows lameo

It should be trivial to set up ONE arduino that can read from MULTIPLE RFID wiegand readers and send, over the USB port emulating a keyboard, two pieces of information to say which reader and which tag. I’m 100% sure this can be done.

Example: Arduino Leonardo with 3 RFID readers numbered “one”, “two”, “three”, and reader number “two” receives 13579 as a card number:

keyboard output:
two[TAB]13579[ENTER]

I suggested Arduino Leonardo because it is both native 5V functionality (for Wiegand) and native HID USB emulation.

By “Wiegand Readers” I’m referring to the numerous readers you can buy on Amazon that support the 2-wire Wiegand protocol. You can get them for both 125KHz and 13.56MHz. These are typically wall-mountable or desktop, so you’re not geeking out with bare circuit boards.

Wiegand is a 5 volt protocol, so, selecting an Arduino that runs 5 volts prevents the need for extra “conversion” hardware. I believe the Arduino Leonardo will also fit in the enclosure available on Amazon titled “UNO Screw Terminal Block Breakout Module with Aluminum Enclosure”, again so you are working with devices that can go on a desk or wall, and not geeking out with bare circuit boards.

Yep. but that requires the same work that OP could do straight on their Linux system anyway.

If anything, the Arduino would require an extra step to be developed, to create the new output.

Would be a cool project, though. and offer more portability! ^^

Wiegand is a nightmare to code for. :smiling_face_with_tear:

There’s a lot more out of the shelf libs for PCSC out there. (even though I have my bone to pick with those, they are the best protocol to work with)

Or even some Open Source direct PN532 drivers that offer more functionality.

I think any arduino can set output pins to run from 3 to 5V regardless of input current. no need to worry with conversion.

Wiegand is one of the simplest line protocols in existence, and at worst, is a nightmare to code for on Linux because it takes work to detect very brief pulses on a multitasking OS. Arduino won’t have that problem. Here’s code you can flash right now to a $5 Arduino Nano from Amazon that will turn it into a USB Wiegand-to-Serial converter for your Linux box, which you can then open directly as a serial port. Flash this code to your board with the free Arduino IDE at arduino.cc. Connect D0 and D1 (from your Wiegand RFID reader) to pins 2 and 3 (respectively). (Arduino GND must also go to reader’s GND)

(*The Chinese knockoffs of Arduino Nano work just as well as the original)
(Pins 2 and 3 are labeled “D2” and “D3” on the Nano board.)

// Define the Wiegand pins.
#define D0_PIN 2
#define D1_PIN 3

// Variables to store incoming data
volatile unsigned long wiegandData = 0;
volatile int bitCount = 0;

// Timeout to reset bitCount if no bits received for a while
unsigned long lastWiegand = 0;
#define WIEGAND_WAIT_TIME 25 // milliseconds

void readD0() {
  // Shift wiegand data to left and add 0
  wiegandData <<= 1;
  bitCount++;
  lastWiegand = millis();
}

void readD1() {
  // Shift wiegand data to left and add 1
  wiegandData <<= 1;
  wiegandData |= 1;
  bitCount++;
  lastWiegand = millis();
}

void setup() {
  // Begin serial communication at 9600 baud rate
  Serial.begin(9600);
  
  // Set digital pins as inputs
  pinMode(D0_PIN, INPUT);
  pinMode(D1_PIN, INPUT);

  // Attach interrupts
  attachInterrupt(digitalPinToInterrupt(D0_PIN), readD0, FALLING);
  attachInterrupt(digitalPinToInterrupt(D1_PIN), readD1, FALLING);
}

void loop() {
  if (bitCount > 0 && (millis() - lastWiegand > WIEGAND_WAIT_TIME)) {
    if (bitCount >= 4) Serial.println(wiegandData);
		
    // Reset variables
    bitCount = 0;
    wiegandData = 0;
    lastWiegand = millis();
  }
}

Here’s a python script you can run on Raspberry Pi / your Linux box / that will pipe the successful card reads from the Arduino to the terminal (first, run pip install pyserial to install python serial support)

# first, pip install pyserial
import serial
import time

port = '/dev/ttyUSB0'  # Change this to your serial port name 

serial_port = serial.Serial(9600, baudrate, timeout=1)
  while True:
    if serial_port.in_waiting > 0:
      data = serial_port.readline().decode().strip()
      if data:  # Only print non-empty lines
        print(data)
    time.sleep(0.1)

The pins are being used as inputs not outputs (since Wiegand is output from the RFID reader to the Arduino). The voltages must be respected.

Most Arduinos run their I/O at 3.3 volts (as do Raspberry Pi’s) and will fry rather quickly by putting 5 volts here. Wiegand D0 and D1 lines are held at 5 volts full time by the RFID reader, and drop to 0 only during a card read. Pretty much all of the non-8-bit Arduinos use 3.3 volt I/O (with the only notable exception being Arduino’s recent 32-bit Uno based on R4 chipset). Rumor on the Internet is that the ESP32 chips will unofficially tolerate 5 volts on their inputs, and this code will also work on ESP32 so you’re welcome to try it if you have one handy.

This code requires only 2.4 kilobytes of the Arduino Nano’s available 32 kilobytes of flash
 this 5 dollar 8 bit processor is a great fit for the job.

The Arduino Nano’s USB can only do Serial, it can’t emulate a USB keyboard so you either need an Arduino Leonardo, or something to convert the 5 volts to 3.3 to safely use the wide range of 32-bit Arduinos that support USB HID.

1 Like