A Python class for controlling the Pimoroni RGB Keypad for Raspberry Pi Pico

Overview

rgbkeypad

A Python class for controlling the Pimoroni RGB Keypad for the Raspberry Pi Pico.

Compatible with MicroPython and CircuitPython.

keypad = RGBKeypad()

# make all the keys red
keypad.color = (255, 0, 0)

# turn a key blue when pressed
while True:
    for key in keypad.keys:
        if key.is_pressed():
            key.color = (0, 0, 255)

pimoroni rgb keypad

Status

Beta - version 0.1.1

Install

Copy the rbgkeypad code into your program.

Usage

Below is some typical use cases and examples for using the RGBKeypad class. See the API documentation for more information.

Create a keypad object.

keypad = RGBKeypad()

Display

The color of all the keys can be changed by setting the key pad's color property to a tuple of (red, green, blue) values between 0 and 255.

# red
keypad.color = (255, 0, 0)

# green
keypad.color = (0, 255, 0)

# blue
keypad.color = (0, 0, 255)

# white
keypad.color = (255, 255, 255)

# yellow
keypad.color = (255, 255, 0)

# purple
keypad.color = (128, 0, 128)

The brightness can be changed by setting the brightness property to a value between 0 and 1. Where 1 is full brightness and 0 is off. By default the brightness is set to 0.5.

keypad.brightness = 1

The keypad can be cleared (turned off) using the clear() method.

keypad.clear()

Individual keys can be referenced using their x,y position e.g. [0,0]

key1 = keypad[0, 0]

Individual key's color and brightness can be set using the color and brightness properties.

# red
key1.color = (255, 0, 0)

# full brightness
key1.brightness = 1

An individual key can also be cleared using the clear() method.

key1.clear()

Press

The status of the key can be retrieved using the is_pressed() method of an individual key.

key1 = keypad[0, 0]
pressed = key1.is_pressed()

Use a loop to continuously check the status of a key.

while True:
    if key1.is_pressed():
        print("key 1 pressed")

To check the status of all the keys, loop through the keypad's keys property, check each individually.

while True:
    for key in keypad.keys:
        if key.is_pressed():
            print("key", key.x, key.y, "pressed)

Alternatively a list of all the keys pressed status can be obtained using the key pad's get_keys_pressed() method.

keys_pressed = keypad.get_keys_pressed()
print(keys_pressed)
You might also like...
Turn your Raspberry Pi Pico into a USB Rubber Ducky
Turn your Raspberry Pi Pico into a USB Rubber Ducky

pico-ducky Turn your Raspberry Pi Pico into a USB Rubber Ducky Install Requirements CircuitPython for the Raspberry Pi Pico adafruit-circuitpython-bun

Play music on Raspberry Pi Pico Without CPU involvement

MicroPython_PIO_Music_DMA Play music on Raspberry Pi Pico Without CPU involvement This is based on PIOBeep (https://github.com/benevpi/pico_pio_buzz)

Raspberry Pi Pico as a Rubber Ducky
Raspberry Pi Pico as a Rubber Ducky

Raspberry-Pi-Pico-as-a-Rubber-Ducky Kurulum Raspberry Pi Pico cihazınız için CircuitPython'u indirin. Boot düğmesine basılı tutarken cihazı bir USB ba

A rubiks cube timer using a distance sensor and a raspberry pi 4, and possibly the pi pico to reduce size and cost.
A rubiks cube timer using a distance sensor and a raspberry pi 4, and possibly the pi pico to reduce size and cost.

distance sensor cube timer A rubiks cube timer using a distance sensor and a raspberry pi 4, and possibly the pi pico to reduce size and cost. How to

🔆 A Python module for controlling power and brightness of the official Raspberry Pi 7
🔆 A Python module for controlling power and brightness of the official Raspberry Pi 7

rpi-backlight A Python module for controlling power and brightness of the official Raspberry Pi 7" touch display. Note: This GIF was created using the

A PYTHON Library for Controlling Motors using SOLO Motor Controllers with RASPBERRY PI, Linux, windows, and more!

A PYTHON Library for Controlling Motors using SOLO Motor Controllers with RASPBERRY PI, Linux, windows, and more!

An embedded application for toy-car controlling based on Raspberry Pi 3 Model B and AlphaBot2-Pi.
An embedded application for toy-car controlling based on Raspberry Pi 3 Model B and AlphaBot2-Pi.

An embedded application for toy-car controlling based on Raspberry Pi 3 Model B and AlphaBot2-Pi. This is the source codes of my programming assignmen

USB Rubber Ducky with the Rasberry Pi pico microcontroller

pico-ducky Install Install and have your USB Rubber Ducky working in less than 5 minutes. Download CircuitPython for the Raspberry Pi Pico. Plug the d

Hourglass on the pi pico using circuitpython

hourglass-on-pico "Hourglass" on the raspberry pi pico using circuitpython circuitpython version 7.0.0 Components used: Raspberry Pi Pico ADXL345 acce

Comments
  • Problem with using macros of inactive windows

    Problem with using macros of inactive windows

    Hi,

    thank you so much for the code and explanation, I managed to mostly modify it to make it work as a very simple macro keyboard for OBS and Zoom for me.

    One issue I have is that when I want to switch scenes in OBS (I have two buttons on the keypad assigned to this) it works flawlessly when OBS is my active window, but when I have Zoom open in the foreground, it becomes very random when I hit the buttons. Zoom doesn't use the hotkeys I use for OBS and this also happens with other apps like Chrome. It does work, but I might have to hit the keys 10 times to activate the key function or maybe it works 3 times in a row without a problem.

    I also have a button for muting my mic in Zoom and (inelegantly) another one to unmute me. I haven't figured out a good way to have the mute button light up when I am muted and switch the led off when i click the key again to unmute myself. Here I have a similar issue where I click the button and it somehow activates the key press multiple times at once.

    I have next to zero experience with Python, just learning it now, so what is wrong in the code? I just paste the modified bit below (instead of your hid_keyboard.py).

    > keypad = RGBKeypad()
    > kbd = Keyboard(usb_hid.devices)
    > 
    > key0 = keypad[0, 0]
    > key1 = keypad[1, 0]
    > key2 = keypad[2, 0]
    > key3 = keypad[3, 0]
    > key4 = keypad[0, 1]
    > key5 = keypad[1, 1]
    > key6 = keypad[2, 1]
    > key7 = keypad[3, 1]
    > key8 = keypad[0, 2]
    > key9 = keypad[1, 2]
    > keyA = keypad[2, 2]
    > keyB = keypad[3, 2]
    > keyC = keypad[0, 3]
    > keyD = keypad[1, 3]
    > keyE = keypad[2, 3]
    > keyF = keypad[3, 3]
    > 
    > key3.color = (255, 100, 50)
    > key3.brightness = 0.2
    > 
    > while True:
    >     if key3.is_pressed():
    >        keypad.clear()
    >        key3.color = (255, 100, 50)
    >     if keyC.is_pressed():
    >        kbd.send(Keycode.CONTROL, Keycode.SHIFT, Keycode.NINE)
    >        keyD.clear()
    >        keyC.color = (60, 220, 240)
    >     if keyD.is_pressed():
    >        kbd.send(Keycode.CONTROL, Keycode.SHIFT, Keycode.EIGHT)
    >        keyC.clear()
    >        keyD.color = (60, 220, 240)
    >     if keyF.is_pressed():
    >        kbd.send(Keycode.ALT, Keycode.A)
    >        keyF.color = (155, 120, 255)
    

    Any help at all would be much appreciated! Thank you.

    edited to add code tags

    opened by drtimoschrader 6
  • LEDs not working with CircuitPython

    LEDs not working with CircuitPython

    I have been using your code in MicroPython and it worked great. All of the LEDs and buttons functioned properly. I then realizes to use USB_HID inputs I needed to switch to CircuitPython.

    Here is the issue, the buttons remain working and I can get USB_HID output, but the LEDs will no longer work. I placed the rgbkeypad.py file in my lib folder and I have run other CircuitPython files with no issue on this board. I have made sure that my soldered connections on the raspberry pi pico are good for the SCK and MOSI (GP18 and GP19) pins. I can link some of my code that I have been using below and maybe that will help but I cannot figure out this problem.

    from rgbkeypad import RGBKeypad
    import time
    
    keypad = RGBKeypad() # initialize keypad
    
    keypad.color = (0, 0, 0) # initialize keypad lights off
    
    
    WHITE = (255, 255, 255)
    RED = (255, 0, 0)
    GREEN = (0, 255, 0)
    BLUE = (0, 0, 255)
    YELLOW = (255, 255, 0)
    PURPLE = (128, 0, 128)
    OFF = (0, 0, 0)
    
    
    def colorPress(y):
        if y == 0:
            return WHITE
        elif y == 1:
            return PURPLE
        else:
            return GREEN
    
    def functionPress(x, y):
        return print(key.y, key.x)
    
    animation_speed = 0.2 # seconds per state
    
    
    while True:
        for key in keypad.keys:
            if key.is_pressed():
                key.color = colorPress(key.y)
                functionPress(key.x, key.y)
                while key.is_pressed():
                    time.sleep(0.05) 
                key.color = OFF 
                
        time.sleep(0.05)
    
    
    opened by tjzetty 5
Owner
Martin O'Hanlon
Professional nerd, amateur snowboarder, creator of content and projects for Raspberry Pi.
Martin O'Hanlon
a library for using WS2812b leds (aka neopixels) with Raspberry Pi Pico

pico_ws2812b a library for using WS2812b leds (aka neopixels) with Raspberry Pi Pico You'll first need to save the ws2812b.py file to your device (for

null 76 Nov 25, 2022
Raspberry Pi Pico development platform for PlatformIO

Raspberry Pi Pico development platform for PlatformIO A few words in the beginning Before experimental please Reinstall the platform Version: 1.0.0 Th

Georgi Angelov 160 Dec 23, 2022
Raspberry Pi Pico support for VS Code

Pico-Go VS Code Extension Pico-Go provides code auto-completion and allows you to communicate with your Raspberry Pi Pico board using the built-in REP

Chris Wood 114 Dec 28, 2022
A Raspberry Pi Pico powered Macro board, like a Streamdeck but cheaper and simpler.

Env-MCRO A Raspberry Pi Pico powered Macro board, like a Streamdeck but cheaper and simpler. (btw this image is a bit outdated, some of the silkscreen

EnviousData 68 Oct 14, 2022
A Macropad using the Raspberry Pi Pico, programmed with CircuitPython.

A Macropad using the Raspberry Pi Pico, programmed with CircuitPython.

null 15 Oct 14, 2022
Raspberry Pi Pico and LoRaWAN from CircuitPython

Raspberry Pi Pico and LoRaWAN from CircuitPython Enable LoRaWAN communications on your Raspberry Pi Pico or any RP2040-based board using CircuitPython

Alasdair Allan 15 Oct 8, 2022
A Raspberry Pi Pico plant sensor hub coded in Micropython

plantsensor A Raspberry Pi Pico plant sensor hub coded in Micropython I used: 1x Raspberry Pi Pico - microcontroller 1x Waveshare Pico OLED 1.3 - scre

null 78 Sep 20, 2022
Raspberry Pi Pico Escape Room game.

Pico Escape Room Raspberry Pi Pico Escape Room game. Parts Raspberry Pi Pico Set of 2 x 20-pin Headers for Raspberry Pi Pico 4PCS Breadboards Kit Incl

Kevin Thomas 5 Feb 2, 2022
An open source operating system designed primarily for the Raspberry Pi Pico, written entirely in MicroPython

PycOS An open source operating system designed primarily for the Raspberry Pi Pico, written entirely in MicroPython. "PycOS" is an combination of the

null 8 Oct 6, 2022
New armachat based on Raspberry Pi PICO an Circuitpython code

Armachat-circuitpython New Armachat based on Raspberry Pi PICO an Circuitpython code Software working features: send message with header and store to

Peter Misenko 44 Dec 24, 2022