Using Arduino Micro as a USB keyboard for Raspberry Pi

Desperate times call for desperate measures. I recently found out that a club at my school is essentially a hackerspace equipped with 3D printers so I could finally print enclosures for the PiPlanter and the DSFU. But that means I would need to finial the designs for both of them. I needed to find a way to interface with this thing here. So being the idiot that I am, I forgot a USB keyboard, I forgot an analog video cable, I forgot a monitor for the pi and forgot to update the Pi to the latest Raspian build.

What I did bring was an Easy Cap Capture Card in addition to my standard idea-kit which among other things consists of an Arduino Micro, some buttons, some resistors, and wire.

Essentially all I needed to do was connect the Pi to the EasyCap, and be able to send 4 different phrases to it over the keyboard. I needed to be able to send ‘pi’,’password’ (not my actual password), ‘ifconfig’ and enter. I realized that I could easily send this data to the Pi via the Micro as it has the Keyboard. functions built in.

As you can see in the video it worked! And I’m kind of stunned that it did. I can now SSH into the Pi.

Here’s the code for the Arduino:

C

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

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

intuname=3;

intpass=4;

intcommand=5;

intenter=6;

intgreen=7;

intred=8;

voidsetup(){

pinMode(3,INPUT);

pinMode(4,INPUT);

pinMode(5,INPUT);

pinMode(6,INPUT);

pinMode(7,OUTPUT);

pinMode(8,OUTPUT);

Serial.begin(9600);

Keyboard.begin();

}

voidloop(){

if(digitalRead(uname)==HIGH){

Serial.print("1");

Keyboard.print("pi");

digitalWrite(green,HIGH);

digitalWrite(red,LOW);

delay(1000);

}

else{

Serial.print("0");

digitalWrite(green,LOW);

digitalWrite(red,HIGH);

}

Serial.print(",");

if(digitalRead(pass)==HIGH){

Serial.print("1");

Keyboard.print("password");

digitalWrite(green,HIGH);

digitalWrite(red,LOW);

delay(1000);

}

else{

Serial.print("0");

digitalWrite(green,LOW);

digitalWrite(red,HIGH);

}

Serial.print(",");

if(digitalRead(command)==HIGH){

Serial.print("1");

Keyboard.print("ifconfig");

digitalWrite(green,HIGH);

digitalWrite(red,LOW);

delay(1000);

}

else{

Serial.print("0");

digitalWrite(green,LOW);

digitalWrite(red,HIGH);

}

Serial.print(",");

if(digitalRead(enter)==HIGH){

Serial.print("1");

Keyboard.press(KEY_RETURN);

delay(10);

Keyboard.releaseAll();

digitalWrite(green,HIGH);

digitalWrite(red,LOW);

delay(1000);

}

else{

Serial.print("0");

digitalWrite(green,LOW);

digitalWrite(red,HIGH);

}

Serial.println("");

delay(10);

}

Thanks for Reading!

Hey! This post was written a long time ago, but I'm leaving it up on the off-chance it may help someone, but proceed with caution. It may not be a good idea to blindly integrate this code or work into your project, but instead use it as a starting point.

At 2:46 in your video, you unplug the USB-A connector from your laptop and plug it into something labeled “DYNEX” which is plugged into the R-Pi.
I searched https://www.dynexproducts.com but didn’t find anything like it.
Can you explain what the part is or provide a link to it?