cicken
Posts: 2
Joined: Wed Dec 16, 2020 3:13 am

Use Pi 400 as Pi Keyboard

Wed Dec 16, 2020 3:23 am

My keyboard for my PC stopped working and im wondering would it be possible to use the Pi 400 as a USB keyboard for a replacement.

cleverca22
Posts: 2888
Joined: Sat Aug 18, 2012 2:33 pm

Re: Use Pi 400 as Pi Keyboard

Wed Dec 16, 2020 10:13 am

cleverca22 wrote:
Sun Nov 29, 2020 12:47 pm
https://hydra.angeldsis.com/build/10480 ... 1/root.zip
https://github.com/librerpi/rpi-tools/b ... oxy/main.c

and this is what happens when people dont stop me, lol

unpack root.zip to a fat32 formatted uSD card, pop it into a pi400, and then plug the usb-c port into any computer with a normal C->A cable

after ~5 seconds, it will function like a normal usb keyboard!
https://hydra.angeldsis.com/build/104811 has a slightly more recent build of it


it has some bugs involving holding multiple keys at once, but ctrl/alt/shift are all fine to be held, so its enough to do basic tasks, but it wont handle gaming well (things like holding w and mashing a/d for ex)

https://twitter.com/Gadgetoid/status/13 ... 9497621505
and this guy beat me to it by about a week, but i suspect my setup process is simpler, i need to review his code and see if i can just bundle it into my root.zip to fix the rollover bugs

cicken
Posts: 2
Joined: Wed Dec 16, 2020 3:13 am

Re: Use Pi 400 as Pi Keyboard

Wed Dec 16, 2020 11:02 am

Oh that sounds like some really impressive work there! Unfortunately, gaming would be one of my use cases so I'll hold of getting a pi 400 for now.

Maybe one day when it works. Good luck to you guys :D

cleverca22
Posts: 2888
Joined: Sat Aug 18, 2012 2:33 pm

Re: Use Pi 400 as Pi Keyboard

Wed Dec 16, 2020 9:47 pm

cicken wrote:
Wed Dec 16, 2020 11:02 am
Oh that sounds like some really impressive work there! Unfortunately, gaming would be one of my use cases so I'll hold of getting a pi 400 for now.

Maybe one day when it works. Good luck to you guys :D
there are also options like synergy/barrier that just share the mouse/keyboard between multiple computers
so the setup will behave like a dual-monitor setup, one on the PC, one on the pi400, and the mouse just seamlessly moves between the 2

rayjoe
Posts: 4
Joined: Sat Dec 19, 2020 7:28 pm

Re: Use Pi 400 as Pi Keyboard

Sat Dec 19, 2020 8:24 pm

cleverca22 wrote:
Wed Dec 16, 2020 10:13 am
https://hydra.angeldsis.com/build/104811 has a slightly more recent build of it
Hi, this idea to use the pi400 as a keyboard sounds great, but it didn't work for me. I've tried it today on three different PCs but it looks like, if there is not enough power from USB? If I connect (USB-C on Raspberry site - USB-A on PC) it, the Power LED of the RPI400 blinks a few time, then it expires and then it is blinking about every 30 seconds or so for 3 times but no reaction on key pressing.

My Rasperry Pi 400 is provided with the latest eeprom update from Dec. 11 (000138a1).

cleverca22
Posts: 2888
Joined: Sat Aug 18, 2012 2:33 pm

Re: Use Pi 400 as Pi Keyboard

Sun Dec 20, 2020 3:08 am

rayjoe wrote:
Sat Dec 19, 2020 8:24 pm
cleverca22 wrote:
Wed Dec 16, 2020 10:13 am
https://hydra.angeldsis.com/build/104811 has a slightly more recent build of it
Hi, this idea to use the pi400 as a keyboard sounds great, but it didn't work for me. I've tried it today on three different PCs but it looks like, if there is not enough power from USB? If I connect (USB-C on Raspberry site - USB-A on PC) it, the Power LED of the RPI400 blinks a few time, then it expires and then it is blinking about every 30 seconds or so for 3 times but no reaction on key pressing.

My Rasperry Pi 400 is provided with the latest eeprom update from Dec. 11 (000138a1).
was it blinking any particular pattern? if you hook an hdmi screen up to it, does the bootloader show any error?

rayjoe
Posts: 4
Joined: Sat Dec 19, 2020 7:28 pm

Re: Use Pi 400 as Pi Keyboard

Sun Dec 20, 2020 9:50 am

Thank you for replying. This is the boot screen Image

cleverca22
Posts: 2888
Joined: Sat Aug 18, 2012 2:33 pm

Re: Use Pi 400 as Pi Keyboard

Sun Dec 20, 2020 9:59 am

rayjoe wrote:
Sun Dec 20, 2020 9:50 am
Thank you for replying. This is the boot screen Image
is the start4.elf from the zip file in the root directory of that fat32 fs?

rayjoe
Posts: 4
Joined: Sat Dec 19, 2020 7:28 pm

Re: Use Pi 400 as Pi Keyboard

Sun Dec 20, 2020 10:18 am

Yes, I've unzipped build 104811 on a empty SD-Card:

bcm2711-rpi-4-b.dtb
config.txt
kernel7l.img
bcm2711-rpi-cm4.dtb
fixup4.dat
overlays
cmdline.txt
initrd
start4.elf

cleverca22
Posts: 2888
Joined: Sat Aug 18, 2012 2:33 pm

Re: Use Pi 400 as Pi Keyboard

Sun Dec 20, 2020 11:47 am

rayjoe wrote:
Sun Dec 20, 2020 10:18 am
Yes, I've unzipped build 104811 on a empty SD-Card:

bcm2711-rpi-4-b.dtb
config.txt
kernel7l.img
bcm2711-rpi-cm4.dtb
fixup4.dat
overlays
cmdline.txt
initrd
start4.elf

does it behave any differently with the older build in https://hydra.angeldsis.com/build/10480 ... 1/root.zip ?

rayjoe
Posts: 4
Joined: Sat Dec 19, 2020 7:28 pm

Re: Use Pi 400 as Pi Keyboard

Sun Dec 20, 2020 12:47 pm

Just tried it with the older build (more files; start4.elf looks like the same). Unfortunately the same behaviour as before.

cleverca22
Posts: 2888
Joined: Sat Aug 18, 2012 2:33 pm

Re: Use Pi 400 as Pi Keyboard

Sun Dec 20, 2020 1:10 pm

rayjoe wrote:
Sun Dec 20, 2020 12:47 pm
Just tried it with the older build (more files; start4.elf looks like the same). Unfortunately the same behaviour as before.
not sure what it could be then, maybe the eeprom version? or the fat32 format?

i just popped https://hydra.angeldsis.com/build/104811 onto an old 2gig card, and it worked

Code: Select all

[root@system76:~]# fdisk -l /dev/mmcblk0
Disk /dev/mmcblk0: 1.85 GiB, 1990197248 bytes, 3887104 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xf37b4e56

Device         Boot  Start     End Sectors  Size Id Type
/dev/mmcblk0p1        2048  133119  131072   64M  c W95 FAT32 (LBA)
maybe try making a smaller partition? it could be that the size is upsetting the bootloader in the pi400

DavidBowman
Posts: 3
Joined: Thu Jan 28, 2021 10:48 pm

Re: Use Pi 400 as Pi Keyboard

Thu Jan 28, 2021 11:03 pm

cleverca22 wrote:
Wed Dec 16, 2020 10:13 am
cleverca22 wrote:
Sun Nov 29, 2020 12:47 pm
https://hydra.angeldsis.com/build/10480 ... 1/root.zip
https://github.com/librerpi/rpi-tools/b ... oxy/main.c

and this is what happens when people dont stop me, lol

unpack root.zip to a fat32 formatted uSD card, pop it into a pi400, and then plug the usb-c port into any computer with a normal C->A cable

after ~5 seconds, it will function like a normal usb keyboard!
https://hydra.angeldsis.com/build/104811 has a slightly more recent build of it


it has some bugs involving holding multiple keys at once, but ctrl/alt/shift are all fine to be held, so its enough to do basic tasks, but it wont handle gaming well (things like holding w and mashing a/d for ex)

https://twitter.com/Gadgetoid/status/13 ... 9497621505
and this guy beat me to it by about a week, but i suspect my setup process is simpler, i need to review his code and see if i can just bundle it into my root.zip to fix the rollover bugs
Hey! I tried out both of the builds you have posted here (thank you for sharing!). I really like how quickly it boots and becomes a normal keyboard. I cannot get the period key to work at all, however, and that makes it tough to use. Have you run into that? I'm using the US keyboard layout model.

I also tried out the method that Philip Howard posted (using it to type this reply to you now), and while I like that it works, you are correct that yours is easier to get setup. I also don't really need my Pi 400 running a full OS just to make it a USB keyboard.

Could I buy you a beverage of some sort as a thank you and a bit of a bribe to take a look at this for me?

Thank you again!
Best
DavidBowman

cleverca22
Posts: 2888
Joined: Sat Aug 18, 2012 2:33 pm

Re: Use Pi 400 as Pi Keyboard

Fri Jan 29, 2021 10:11 am

https://github.com/librerpi/rpi-tools/b ... main.c#L97

Code: Select all

  [KEY_RIGHT]     = 0x4f,
  [KEY_LEFT]      = 0x50,
  [KEY_DOWN]      = 0x51,
  [KEY_UP]        = 0x52,
  [KEY_NUMLOCK]   = 0x53,
  [KEY_SYSRQ]     = 0,
  [KEY_DOT]       = 0,
};
*doh*, i forgot to assign a keycode to period!

https://www.usb.org/sites/default/files ... 1_12v2.pdf
page 53
0x37 i think
"modprobe usbmon" + wireshark confirms, 0x37...
https://github.com/librerpi/rpi-tools/c ... e4f766ee91

https://hydra.angeldsis.com/build/105445
and CI should be building the fix!

DavidBowman
Posts: 3
Joined: Thu Jan 28, 2021 10:48 pm

Re: Use Pi 400 as Pi Keyboard

Fri Jan 29, 2021 10:26 pm

cleverca22 wrote:
Fri Jan 29, 2021 10:11 am
https://github.com/librerpi/rpi-tools/b ... main.c#L97

Code: Select all

  [KEY_RIGHT]     = 0x4f,
  [KEY_LEFT]      = 0x50,
  [KEY_DOWN]      = 0x51,
  [KEY_UP]        = 0x52,
  [KEY_NUMLOCK]   = 0x53,
  [KEY_SYSRQ]     = 0,
  [KEY_DOT]       = 0,
};
*doh*, i forgot to assign a keycode to period!

https://www.usb.org/sites/default/files ... 1_12v2.pdf
page 53
0x37 i think
"modprobe usbmon" + wireshark confirms, 0x37...
https://github.com/librerpi/rpi-tools/c ... e4f766ee91

https://hydra.angeldsis.com/build/105445
and CI should be building the fix!
Ah, excellent!! It is working as it should now (like literally right now as I'm typing).

I was serious when I'd buy you a "beverage" (i.e. send you a small donation) as a thank you. Please PM me your info if you want. I really do appreciate this!

Also, would you be okay if I were to write about your implementation of this in an article about the two methods? I don't want to send a ton of traffic and support requests in your direction if that is not your wish. If you would want someone to help you test it further first, I have done professional software QA before (as well as informal with things like this). I'd be happy to help!

Thank you again!

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13691
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Use Pi 400 as Pi Keyboard

Sat Jan 30, 2021 2:46 pm

Personal messages are not supported on this form for legal reasons (to protect kids)

cleverca22
Posts: 2888
Joined: Sat Aug 18, 2012 2:33 pm

Re: Use Pi 400 as Pi Keyboard

Sat Jan 30, 2021 6:06 pm

DavidBowman wrote:
Fri Jan 29, 2021 10:26 pm
Also, would you be okay if I were to write about your implementation of this in an article about the two methods? I don't want to send a ton of traffic and support requests in your direction if that is not your wish. If you would want someone to help you test it further first, I have done professional software QA before (as well as informal with things like this). I'd be happy to help!
sure, you can write up an article

i also hang out on the #raspberrypi irc channel if you want to chat about anything else in a more real-time fashion

DavidBowman
Posts: 3
Joined: Thu Jan 28, 2021 10:48 pm

Re: Use Pi 400 as Pi Keyboard

Sun Jan 31, 2021 9:32 pm

mahjongg wrote:
Sat Jan 30, 2021 2:46 pm
Personal messages are not supported on this form for legal reasons (to protect kids)
That makes total sense, and I completely support that. Sorry about that, wasn't trying to violate any rules!
cleverca22 wrote:
DavidBowman wrote:
Fri Jan 29, 2021 10:26 pm
Also, would you be okay if I were to write about your implementation of this in an article about the two methods? I don't want to send a ton of traffic and support requests in your direction if that is not your wish. If you would want someone to help you test it further first, I have done professional software QA before (as well as informal with things like this). I'd be happy to help!
sure, you can write up an article

i also hang out on the #raspberrypi irc channel if you want to chat about anything else in a more real-time fashion
Thank you! I will remember that if I can think of anything to ask you about. Actually, I can think of one thing right now: Does your super key work on your keyboard? That is - I think - the only key that is not working for me right now as I type booted to your solution (which has been working better for me than Philip Howard's method that has locked up on me multiple times, requiring a yank of the power cord).

I really appreciate your work on this! Thanks again!

cleverca22
Posts: 2888
Joined: Sat Aug 18, 2012 2:33 pm

Re: Use Pi 400 as Pi Keyboard

Sun Jan 31, 2021 10:26 pm

DavidBowman wrote:
Sun Jan 31, 2021 9:32 pm
Does your super key work on your keyboard?
checking with evtest on my desktop, linux calls that key KEY_LEFTMETA, and checking my source, i also forgot that one!
and wireshark shows its just an 0x08 in the modifier field

https://github.com/librerpi/rpi-tools/c ... 04081a0494
https://hydra.angeldsis.com/build/105493
and fixed!

marimo
Posts: 7
Joined: Sun Feb 21, 2021 8:15 am

Re: Use Pi 400 as Pi Keyboard

Sun Feb 21, 2021 8:40 am

cleverca22 wrote:
DavidBowman wrote:
Sun Jan 31, 2021 9:32 pm
Does your super key work on your keyboard?
checking with evtest on my desktop, linux calls that key KEY_LEFTMETA, and checking my source, i also forgot that one!
and wireshark shows its just an 0x08 in the modifier field

https://github.com/librerpi/rpi-tools/c ... 04081a0494
https://hydra.angeldsis.com/build/105493
and fixed!
Hi. Firstly, I want to say thanks for doing this. I'm actually using my Pi 400 to type this on my other computer right now! But I think I've found another key that you forgot to map: the back slash key (just above the Fn key). It's not working for me, anyway.

Edit: I had a look at the US version of the Pi 400 and I don't think it actually has this key. So if you are using the US version as well, that will be why this key isn't mapped. Oh well, it still works pretty well for most purposes.

Also, to anyone having trouble getting the Pi to work as a keyboard, I had some difficulties too until I copied the files from the folder directly onto the SD card I was using (mine initially unzipped into a folder called "root". So in other words, don't leave them in the folder). Hope that makes sense.

cleverca22
Posts: 2888
Joined: Sat Aug 18, 2012 2:33 pm

Re: Use Pi 400 as Pi Keyboard

Tue Feb 23, 2021 1:40 am

marimo wrote:
Sun Feb 21, 2021 8:40 am
Hi. Firstly, I want to say thanks for doing this. I'm actually using my Pi 400 to type this on my other computer right now! But I think I've found another key that you forgot to map: the back slash key (just above the Fn key). It's not working for me, anyway.

Edit: I had a look at the US version of the Pi 400 and I don't think it actually has this key. So if you are using the US version as well, that will be why this key isn't mapped. Oh well, it still works pretty well for most purposes.
if you boot the pi400 normally, then run `sudo evtest` and select the keyboard, what KEY code comes up when your hitting the backslash key?

marimo
Posts: 7
Joined: Sun Feb 21, 2021 8:15 am

Re: Use Pi 400 as Pi Keyboard

Tue Feb 23, 2021 4:33 pm

I ran the test for you and I think this is the information you want:

value 70064
code 86
(KEY_102ND)

I think it's called the backslash and pipe key.

cleverca22
Posts: 2888
Joined: Sat Aug 18, 2012 2:33 pm

Re: Use Pi 400 as Pi Keyboard

Tue Feb 23, 2021 4:45 pm

marimo wrote:
Tue Feb 23, 2021 4:33 pm
I ran the test for you and I think this is the KEY code you want:

code 86 (KEY_102ND)

I think it's called the backslash and pipe key.
ah, thats weird, backslash is KEY_BACKSLASH on both a regular machine and my US pi400

https://hydra.angeldsis.com/build/105677

the new build maps KEY_102ND as a second backslash key

marimo
Posts: 7
Joined: Sun Feb 21, 2021 8:15 am

Re: Use Pi 400 as Pi Keyboard

Tue Feb 23, 2021 8:00 pm

Well, it definitely registers as a key now, but instead of the backslash and pipe it returns the #~ symbols

(like the key next to the Enter button on a UK Keyboard does). See this link for a better idea of what my UK Pi 400 Keyboard layout looks like:

https://upload.wikimedia.org/wikipedia/ ... ingdom.svg

I checked again with the test to see what code it returned and got:

value 70031
code 43
KEY_BACKSLASH

for both keys, even for the one that definitely isn't a backslash key on my computer. Weird. In any case, both keys return a different key code when booted as a Raspberry Pi 400.

cleverca22
Posts: 2888
Joined: Sat Aug 18, 2012 2:33 pm

Re: Use Pi 400 as Pi Keyboard

Tue Feb 23, 2021 8:16 pm

try running wireshark and usbmon (see further up in this thread) and capture the packet when your hitting that magic backslash key

it sounds like the UK layout is doing something very funky

Return to “Raspberry Pi 400”