Here’s a video:
So in my last post I showed you a way that I used a single arduino to talk to a Raspberry Pi (or any other computer) over HID. I’ve updated the project a bit and now I can input any number of things into the pi. Basically this is how it works.
Serial Console on computer -> Arduino Mega -> software serial port -> Arduino micro -> HID on other second computer (in this case the Pi)
There are two buttons that handle pressing the enter key and the delete key as those are hard to send over serial.
There are a few bits of relevant code, both for the arduino. Here’s the mega’s code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
int sent_led = 44; int test_button = 30; byte inread; #include <SoftwareSerial.h> SoftwareSerial SoftSerial(34, 36); // RX, TX void setup(){ pinMode(sent_led, OUTPUT); pinMode(test_button, INPUT); Serial.begin(9600); SoftSerial.begin(4800); SoftSerial.println("Hello, world?"); } void loop(){ if (Serial.available()>0){ digitalWrite(sent_led, HIGH); Serial.print("Sending: "); inread = Serial.read(); Serial.write(inread); SoftSerial.write(inread); Serial.print(" , "); Serial.print(inread); Serial.println(""); digitalWrite(sent_led, LOW); } } |
And here’s the side for the arduino micro, that writes as an HID.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
int stat_led = 3; int enter_led = 4; int delete_led = 5; int enter_button = 6; int delete_button = 7; int engage_switch = 8; #include <SoftwareSerial.h> SoftwareSerial SoftSerial(11, 10); // RX, TX void setup(){ pinMode(enter_led, OUTPUT); pinMode(delete_led, OUTPUT); pinMode(stat_led, OUTPUT); pinMode(enter_button, INPUT); pinMode(delete_button, INPUT); pinMode(engage_switch, INPUT); Serial.begin(9600); SoftSerial.begin(4800); Keyboard.begin(); // } void loop(){ if (SoftSerial.available()){ digitalWrite(stat_led, HIGH); Keyboard.write(SoftSerial.read()); digitalWrite(stat_led, LOW); } if (digitalRead(enter_button) == HIGH){ Keyboard.press(KEY_RETURN); delay(100); Keyboard.release(KEY_RETURN); digitalWrite(enter_led, HIGH); } else if (digitalRead(enter_button) == LOW){ digitalWrite(enter_led, LOW); } if (digitalRead(delete_button) == HIGH){ digitalWrite(delete_led, HIGH); Keyboard.press(KEY_BACKSPACE); delay(100); Keyboard.release(KEY_BACKSPACE); } else if (digitalRead(delete_button) == LOW){ digitalWrite(delete_led, LOW); } } |
Looks like pointless noob rubbish to me. What is the point of this? Why not develop something useful or challenging?
Point was i’m broke and don’t have access to a USB keyboard. What was the point of that comment?
I find this brilliantly. First i am just starting micro, with a keyboard project. This gives me a place to start of. Second i like the way you solve the problem with what on hand 🙂