Arduino Yún - Passing USB Keyboard input to Arduino Sketch

Hello Forums.

I am sorry for posting, but i have read many threads and did not get it to work, many of them are outdated and wont work anymore due to Updates of OpenWRT...

My Idea:

I got an Arduino YUN because of it's USB Port and the possibility to bridge it over to the 32u4.

I want to connect an external RFID-reader which behaves like a normal keyboard to the USB Host of the Arduino Yun.

(Reader is a TWN3 Legic NFC)

Following the steps from user "sonnyyu", i get at least the output on the SSH terminal.

https://forum.arduino.cc/index.php?topic=314526.0

but i just cant figure out how to pass this value to the 32u4

it seems like the bridge wont work right or im just too dumb to find out how.

the initial plan is that the RFID reader scans the chips identifier key, sends it to the arduino, the arduino will check if this identifier is "allowed" and then change the output of an IO pin.

(Should open a door if chip-reading is correct)

Much time ago i used an MFRC522 that worked well but the reading range is much to short.

So, could anybody help me with this?

Best regards

Sammy1596:
Following the steps from user "sonnyyu", i get at least the output on the SSH terminal.

That's a big step, it seems like you are 90% of the way there.

but i just cant figure out how to pass this value to the 32u4

it seems like the bridge wont work right or im just too dumb to find out how.

What have you tried already?

While seeing the code you've tried already would be best, it would be helpful to have at least a hint of what you've tried so far. That way we can try to figure out what is going wrong, and give some advice to fix it. There are many ways to do this, and without even a little bit of information, all we can do is guess at you may be having trouble with.

Knowing what you've done tried already would also let us figure out your level of experience - do you just need a basic hit as to what direction to go, or do you need complete step by step instructions?

the initial plan is that the RFID reader scans the chips identifier key, sends it to the arduino, the arduino will check if this identifier is "allowed" and then change the output of an IO pin.

I would take it one step further. Rather than simply pass the received ID string from the Linux side to the sketch, and making the sketch do all of the work, I would put as much intelligence on the Linux side as possible. Let it figure out whether it is a valid identifier, and just pass the required state of the output pin to the sketch. Then, the sketch just needs to read that information, and control the pin - it becomes a very simple I/O processor.

My approach would be to write a script in Python (or the language of your choice) that can be run from the Linux command line. You could test this on the command line by reading cards, and having it print the desired command out to the console (simple on/off commands, for example.)

Then, when that is working the way you want, write the sketch- you won't have to make any other changes to the Python code. Use a Process class object to start the Python script, and communicate with it. Anything that the Python script prints to the console output can be read by the script using the Process object - you read from it exactly the same way you would from a serial port. The sketch then decodes the command from the Python script, and controls the outputs accordingly.

You could put just a little bit of intelligence in the script: for example, if you are unlocking a door, it's probably an electromagnetic strike plate, something that needs to be turned on a few seconds and turned off. The Python script could send a command to unlock the door, and the sketch would turn on the output, delay a few seconds, and turn the output off.

When using a Process object to start a Python script, it's important to include the "-u" option in the command line, for example: "python -u rfid_reader.py" because Python normally buffers its output. Without the "-u" option to set unbuffered mode, the Linux side will save up the output from the Python script until there is a substantial amount of data, and then send it all at once. This is not what you want, as soon as the Python script prints something, you want the sketch to be able to see it.

Hi, sorry for loong delay..

What ive tried was the steps from sonnyyu including Bridge Code and Arduino code that he uploaded.. A couple of days later i asked myself why make it so complicated? Why dont let linux do the work.. Exactly what you wrote..

I want this part to be done with python, but i have to start from zero with it..
thats how it should be (Let the Linux Part do the work and just send on off to arduino)

Thats the stuff im struggling with and thats one of the reasons for the long delay.. Sorry for that.. also had a nice vacation in Spain ^^

Thank you very much for your answer.