This project allows you to run actions in Python on a Raspberry Pi(like control Elgato lights) using an Adafruit MacroPad RP2040. The MacroPad sends key codes via HID to a Python script on the Raspberry Pi that interprets these codes to have Python perform actions (like turning the lights on or off).
- Python 3.6+
- CircuitPython 9.x
hidapi
libraryrequests
library
-
Clone the repository:
git clone https://github.com/mhuot/padactions.git cd padactions
python3 -m venv venv source venv/bin/activate
-
Install required packages:
pip install -r requirements.txt
-
Configure udev rules: Create a new file /etc/udev/rules.d/99-macropad.rules:
sudo nano /etc/udev/rules.d/99-macropad.rules
-
Validate the VendorID is 239a and ProductID is 8108
$ lsusb Bus 001 Device 029: ID 239a:8108 Adafruit Macropad RP2040 $
-
Add the following line to the file:
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="239a", ATTRS{idProduct}=="8108", MODE="0666", GROUP="plugdev"
Adjust the ID's if they are different. Save and close the file.
-
Reload udev rules:
sudo udevadm control --reload-rules sudo udevadm trigger
-
Add your user to the plugdev group:
sudo usermod -aG plugdev $USER
-
Log out and log back in for the group change to take effect.
-
Change to the directory of the repository
cd /path/to/your/repository
-
Activate the virtual environment:
source venv/bin/activate
-
Run the script:
python padactions.py
This script listens for key presses from the MacroPad and sends requests to turn Elgato lights on or off based on the key codes received.
Key codes and actions:
Keycode 30: Turns the lights on Keycode 31 : Turns the lights off
- Move your project to the /opt directory:
sudo mv /path/to/your/repository /opt/padactions cd /opt/padactions
- Create a systemd service file
sudo nano /etc/systemd/system/padactions.service
- Add the following content to the service file:
Replace YOUR_USERNAME with your actual username and /path/to/your/repository with the path to your project directory.
[Unit] Description=MacroPad Light Control Service After=network.target [Service] Type=simple User=YOUR_USERNAME WorkingDirectory=/path/to/your/repository ExecStart=/opt/padactions/venv/bin/python /opt/padactions/padactions.py Restart=on-failure Environment="PYTHONUNBUFFERED=1" [Install] WantedBy=multi-user.target
- Reload systemd to apply the new service
sudo systemctl daemon-reload
- Enable the service to start on boot:
sudo systemctl enable padactions.service
- Start the service
sudo systemctl start padactions
This will ensure your script runs as a systemd service and starts automatically on boot.
Set the DEBUG variable to True to enable debug output.
You will need to install the macropad/code.py onto your MacroPad.
This list is what I have on my MacroPad, it is possible I have more than needed. You should be able to put these in /lib on the MacroPad. See https://learn.adafruit.com/adafruit-macropad-rp2040/macropad-circuitpython-library for more information.
- adafruit_bitmap_font
- adafruit_debouncer
- adafruit_displayio_layout
- adafruit_display_shapes
- adafruit_display_text
- adafruit_hid
- adafruit_led_animation
- adafruit_macropad
- adafruit_midi
- adafruit_pixelbuf
- adafruit_simple_text_display
- adafruit_ticks
- neopixel
Add the MacroPad info to the README Allow DEBUG, vendor ID and product ID to be specified by environment variables Have the host send feedback on actions to set key and display Add the encoder for making changes
This project is licensed under the MIT License. See the LICENSE file for more details.