One of the biggest features of the Pi 500 Plus is its RGB mechanical keyboard. If you have one, chances are you've played around with some of the RGB presets that come loaded with it. But there's actually a crazy world of possibilities with that RGB because you can program it to do pretty much anything you want. How about custom animations like a game of life, an epic flaming cool keyboard with a flame background, or a game of snake? You could even build a screensaver or write code to create a notification system within your keyboard's RGB itself.
Welcome back to Core Electronics. Today, we are diving into everything custom RGB on the Pi 500, both through terminal commands, which you might have seen already, and through custom Python scripts. We'll be using the official Raspberry Pi keyboard configuration library, which you can install with this line here. While we're here, we'll also update the firmware of our keyboard by first installing it onto our Pi and then flashing it to our keyboard with this command here.
This is my first time using Trixie OS, and it seems like a lot of it's already installed and ready to go. On Bookworm, these commands actually installed a whole bunch of stuff, but do it just to ensure you're up to date. By the way, there's a link below to the written guide, which has all the commands you can just copy and paste instead of writing them out. There, you'll also find all the code we'll be using in this guide.
First things first, let's mess around with the presets. If you press Fn and F4 on your keyboard, you can cycle through a bunch of preset colors, and the keyboard can hold seven of these. In the terminal, we can choose which preset we want with the following command, and we can choose preset 0 to 6 here. This is pretty much just like pressing Fn and F4, but from the terminal. Sweet. Let's do another one, for example. Bang. RGB mode activate.
The keyboard also has more effects and patterns to choose from as well. Just a quick distinction here: the effects are the patterns that the keyboard can actually use, the colors and everything that you see. The keyboard presets are just the slots where you can store your keyboard effects. If you punch in the list effects command, you can see a list of all the keyboard effects available. To try one of these, you can use the following command. Here, I'm going to try effect 25, which is Jelly Bean Raindrops. Let's give that a go and see what that looks like. Oh, very nice. Go through and try them all. There are some really cool ones in here. If I could recommend some, I enjoy numbers 25, the Jelly Bean one here, 40, and the GOAT number 29, which is one of the defaults you've probably already seen.
There are also some input options we can add with our command. For example, you can set the speed, saturation, and hue of these effects with the following command. You can use one of these or all of these options at a time, and they just take a number from 0 to 255. Not every effect has optional inputs, so just keep an eye out.
Now, being able to invoke these patterns from the terminal is nice and all, but you can actually assign an effect to your keyboard preset slot so you can easily access them in the future. To do so, we're going to use the following set command. In this example, I'm going to take effect 25 and put it into pre-slot 2. I'm going to hit enter to save that, and let's just check that. So, slot 0, slot 1, and slot 2. And that is our Jelly Bean Rainbow effect. Now, even if you reboot your Pi, this effect will still be saved in that preset slot. If you ever want to see what effects you've got assigned to what preset, you can do so with the following command here. By the way, whatever effect is assigned to index 0 here, or preset slot 0, is what the Pi will automatically load when it turns on. So go ahead and put your favorite animation in there to automatically boot it up on start.
If you press Fn and then F5 or F6, you can change the global brightness of the keyboard. We can do this in the terminal simply with the brightness command, which again takes a number between 0 and 255. Bam, full brightness.
Now we start to get into the fun stuff: completely custom color scheming. We're going to do this in the terminal first to get a feel for it, and then we'll go ahead and do it in a Python script. The first command you might want to run is this LEDs clear command, which will give us a blank canvas to start with. Next, let's use a basic command to set all the LEDs to a certain color with this LEDs set color command. Let's run that, and bam, look at that, we're all red. There are actually two methods of doing it here. This one uses HSV or hue saturation value, and the other command uses RGB, which you might be more familiar with. Both achieve the exact same thing, setting it to red at full brightness, just different ways of representing that color.
Now let's set an individual LED color. Let's clear everything so we can see what's going on more clearly. Then we'll set it with our LED set command, but this time we're specifying a row and column to light up here. Hit enter, and there our W key lights up. To get a nice little visualization of what number row and column is what key, you can punch in the follow info dash dash ASCII and get this nice little visual ASCII art of the keyboard layout. Now I've just gone ahead and assigned some random keys just for our demo here. And let's say...
You go ahead and create a work of art like this, you can save it with this save command here. This is going to save it as an effect that you can use and assign however you like, and it's going to save it as effect number one. So let's use our effect command here, or let's just change it first of all to something random. Then we're going to punch in our set effect here, and we're just going to go to ID one, and there is our color back. This is just a nice way of creating a custom layout and saving it permanently. Unfortunately, though, you can only save one custom effect at a time.
Now, assigning colors like this is good, but there is a better way, which we're about to do with some Python scripts. That will allow you to save as many effects as you want. Before we get to that, though, let's wrap up our terminal adventures with this reset command here, which will nuke everything and start from scratch. Punch it in if you want to reset everything back to how it was. Now if we go to slot 0, 1, 2, we're back to our RGB profile, and our jelly bean is gone.
Just one more thing: punch in RPI keyboard config game, and you will get a quite difficult game of Flappy Birds to play directly on your keyboard. We'll look at this later, but you first need to unlock your keyboard before you can start detecting key presses. Like so. Beautiful.
Alrighty, let's move on to some Python scripts. Now, why would we want to use a Python script over the terminal? Well, when we update a color through the terminal, it takes about a second for it to apply. So if we wanted to set a random color on every single key, because we can only update one key at a time, and we have 84 keys, it would take about 84 seconds just to do that simple task. With the Python script, though, we can update keys many times a second, and we can update every key at once many times a second as well. And because it's Python code, we can do a whole heap of extra things like animations and making it interactive.
Let's just go ahead and take a look. In the written guide, you'll be able to download the zip file with all the pieces of code we're about to look at. In there, if you open up the script called simple color, which we're going to be using Thonny here, we'll see the most stripped-back basic way of setting colors on the keyboard. First of all, we import the keyboard config library that we installed, and then we go ahead and initialize our keyboard and set it to direct LED control. This is just saying, hey, we want to set our LEDs manually through this script. Then in our while true loop, we're going to go ahead and set the color of the LED to red. Unfortunately, I don't think you can use RGB colors in our Python script here. I think you have to use HSV, but it's not too difficult to learn. It's pretty straightforward. All we're going to be doing here is setting it to red, waiting half a second, setting it to orange, and then waiting another half a second. So in this first line here, we're going to go ahead and set it to red. This dot set LED doesn't actually update the color on the keyboard yet. You have to then call send LEDs to actually push that kind of frame to the keyboard. So you can go ahead and set a whole bunch of LED colors and queue up this kind of image. Then once you go send LEDs, that image goes to your keyboard. All we're doing here is setting a key to red, sending the update, waiting half a second, setting it to orange, sending the update, and waiting half a second. So one of our keys is going to flash between orange and red.
Now these two lines are actually a little bit different. In this bottom one, we're using the row and the column kind of matrix naming convention that we saw in the terminal commands. In this one, we're using the ID of the key. So essentially imagine counting your keys across. So 0, 1, 2, 3, 4, all the way to 15, 16, 17, all the way to 30, and then 31, 32, 33. So let's go ahead and run that script. Sorry, I goofed there and didn't actually update the code. This is the HSV value for orange, and this is the HSV value for purple. But that is the essential building block that you can use to go out and do a whole bunch of cool stuff.
For example, if you go ahead and open up gameoflife.py and run it, you will get a game of life running on your keyboard. This is using the exact same simple building blocks of setting key colors. It's just got extra code telling it what keys to light up according to the rules of the game of life simulation. Another example using the same simple building blocks is this epic cool fire flaming keyboard animation. Bad to the bone riff. Please insert that editor. Again, it's the exact same line to set the LED colors. We've just got extra code figuring out what LEDs to light up what color.
Now creating things like this can be a lot of work and can sometimes require quite a bit of math, but you can very easily take any of the demo scripts from this zip file and whack it into an LLM like Claude or ChatGPT and get them to help you code one up. Also, side tangent while we're here, I had to get Claude to help me write this. If you are doing this, you might want to maybe ask them to interpolate the pixel movements. In this fire example, every time an ember wants to move up as kind of the math is simulating it like it's fire, it looks a bit choppy because it jumps from pixel to pixel, which is quite a distance. If you go ahead and open up and run fire interpolation though, you will find pretty much the exact same code and simulation just with interpolation, which transitions the colors of each pixel...
...and gives it kind of a nice smoother movement. Just some food for thought if you're designing any animations. Speaking of thoughts, at this time I was thinking how much of a toll is this actually having on our system and how fast can we push this? To test this, we wrote speedtest.py, which just fills each LED with a random color and then pushes it to the keyboard and does it for a certain amount of times. I'm just going to go ahead and run it for 100 iterations here and that is pretty full on the eyes. I don't think the camera is picking that up. As you can see, we're looking at about 0.03 updates a second, which is about 30 FPS. 30 FPS while updating every single key at once is much faster than taking one second to update just one key like we were doing through the terminal. So definitely, definitely worthwhile doing your Python scripts.
I'm just going to go ahead and run it for a thousand iterations here just to keep it going for a while. I'm going to open up a new terminal and punch in HTOP, which will give us a little resource manager look of all of this. As you can see, we're using a non-negligible amount of our CPU, but probably averaging somewhere around 10, maybe 15%. But we're doing a full refresh rate here. Depending on the complexity of your animation and how fast you're updating it, it's going to take more or less CPU resources to do this. Just something to keep in mind. Just don't do anything too crazy because you have to use the Pi to simulate what you're going to be showing on your keyboard.
Now we can pre-program some fancy LED colors and animations or really whatever we want, but we are using Python here. We can do much more complex things such as reacting to keyboard inputs. Now Raspberry Pi's keyboard package that we've been using here does support detecting key presses and does so perfectly fine. But I have one gripe with it, and that is that there is a security feature that forces you to unlock the keyboard before detecting inputs. Basically, when you write code, before you start detecting key presses, you need to write unlock, and then to unlock it, you need to go to your keyboard and press and hold escape and enter for five seconds. It's not a biggie, but it means that you have to have manual input to start things automatically. So if you had your interactive keyboard RGB layout and you set it to automatically start on boot, you wouldn't be able to interact with it before you pressed escape and enter. It's just a little hurdle that I want to build around. If that isn't a fuss for you, go ahead and use it. It's probably a bit nicer to use their nice integrated solution. But for the rest of this guide, we're going to be using PyInput, which does the same job. We can go ahead and install PyInput with the following line here. We are being a little bit naughty here and not installing it in a virtual environment, but it's just one Python package we're installing here, and it's PyInput. It's pretty safe. It's not going to cause too many conflicts. It's also just going to simplify it. We're not going to have to deal with virtual environments here.
If you go ahead and open up snake.py, as the name suggests, it's going to be using PyInput for controls and create a game of snake on your keyboard. Let's go ahead and run that. Press enter to start, and we can use our WASD keys here to control the snake. It's unfortunately in the bottom right there, so it's a bit hard to see, but it's a game of snake. There's not really much exciting stuff going on here. I'm sure you've played snake before. Now, this code might look pretty big, and it's not, you know, it's not tiny, but most of it is just, you know, simulating a game of snake. At the end of the day, all it's doing is choosing what keys to light up and just using PyInput to, you know, control what keys are going to be lit up. It's not really much. I didn't actually write this, by the way. It was completely vibe-coded with Claude.
By the way, the things we did in the terminal before, all those commands, you can also use them here in some form or another. If you take a look at flash demo, we can see some of this in action. This code is going to randomly choose a number between one and five, and if it's three, it's going to go ahead and get our current preset index. Essentially, it's just going to say, whatever preset you're using, remember it. Then we go ahead and say, we're going to start manually setting LED colors. We fill the board with random LEDs, push it to the keyboard to actually flash that color. We're going to hold that random pattern for a second, and then we're going to go ahead and clear the board, update it so that we completely blank it out again, and then we grab that preset slot number that we remembered and go ahead and set the preset on our keyboard. It's a bit hard to explain, so let's run that to see what it actually looks like.
So I've got my rainbow preset going here, and I'm going to go ahead and run this script, and it's going to keep generating numbers until it hits a three. No, that's not a three. Three, come on. So your preset's running normally. Some external event triggers that if statement and flashes a color, interrupting your regularly programmed preset. Once that flashing is done, it restores your preset as if kind of nothing happened. Now, this might seem like a bit of a weird demo, but we've essentially created a sort of notification or heads-up system here. You could have your favorite preset running, and then, I don't know, the doorbell rings, and you have some sort of Python integration for that. You can flash your keyboard that, hey, the doorbell's ringing. Or maybe you could connect it to Home Assistant and display information on here periodically or when some automation triggers like that. You have a sort of low-resolution screen here to play around with. You could very easily use this to create timers and build...
...into your keyboard, maybe something like a Pomodoro timer. That got me through uni, and I don't think I would have gotten through uni without a Pomodoro timer, and having it built into my keyboard would be really nice. There really are a million different use cases here, and you can use that reading and loading presets to achieve it.
Alright, final thing, let's put this all together and create something really cool: a screensaver for our keyboard. Go ahead and open up screensaver.py. There is quite a lot going on in this one, but essentially it's going to be using PyInput to register keyboard inputs, and if it doesn't read anything for 5 seconds, it will remember the preset you're using and then change the global brightness, that global brightness command we used in the terminal, to fade the keyboard out to darkness. Then it's going to go ahead and set key colors individually to display a sort of firefly animation, and when you press the key again, PyInput's going to detect that, it restores the preset and brightness. It's just kind of a nice little screensaver but for your keyboard, just a nice little thing that you can run in the background. And of course, this is set to start after 5 seconds of no keyboard inputs; you can set this to 500 seconds or whatever you want the screensaver to start.
Now we have all of our beautiful presets running out of Thonny just fine, but this is not very practical in day-to-day use. You don't want to go ahead and open up Thonny just to automatically start all of this. There is a way to make these Python scripts run automatically on launch so it just does its thing in the background and you don't need to think about it, and in the written guide, you will find instructions on how to do that. We wanted to include that in this guide, but recently the way you kind of do this has changed a bit, and the method might break in the near future, and we can update the guide on the fly so it always works.
Well, that about wraps us up. You now have the basic building blocks and some ideas to go out and start making custom RGB profiles and integrations and animations and really whatever you can for the Pi 500 Plus keyboard. If you do make something cool with this, whether it's just a cool animation or, I don't know, maybe you've got Doom running on this thing because there's quite a clear pathway to getting that going here, you should post about it on our community forums. There you can also get a hand with anything we cover in this video if you get stuck. Until next time though, happy making.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.