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

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.