
Overview
This project is an 8-key macro pad featuring a rotary encoder, OLED display, and STM32F103 microcontroller. It has two modes: Macro mode for custom hotkeys and Media mode for media controls. The rotary encoder controls volume and switches between modes, while the OLED displays a simple animation. The PCB uses a 4-layer stackup for easier routing and USB impedance matching, and the case was designed in Fusion 360 and optimized for support-free 3D printing.
PCB Design
This PCB uses a 4-layer stackup: signal, ground, ground, and signal/power. Similar to the PCB for the spot welder, this design would most certainly have worked on a 2-layer board. However, using a 4-layer board makes routing easier and allows for the required 90 Ω impedance matching for the USB differential lines.
I used an STM32F103 as the main microcontroller because it was inexpensive and I already had some on hand. It also provides built-in USB support, I2C, and timers for reading the rotary encoder, all of which are used in the software design.



Hardware Design
To make designing the case as straightforward as possible, I first imported the 3D model generated by KiCad into Fusion 360. This allowed me to easily project dimensions from the PCB into the case design instead of having to manually measure everything with calipers.

The final result is shown below. When 3D printed at a 45° angle, the case requires no supports. I printed mine using PLA, but other easy-to-print materials like PETG would work just as well.

To hide some of the print artifacts, I used a fuzzy skin print configuration to give the surface a more textured and uniform appearance.

Software Design
This was the most involved part of the design, as it required integrating the key matrix, rotary encoder, and OLED display.
I used a timer to read the rotary encoder, which made implementing the encoder functionality very straightforward as it required no additional polling logic. For the rotary encoder button, I used an interrupt rather than polling it in the main loop. Since the button is infrequently used, continuously polling it would add unnecessary overhead, whereas an interrupt allows the microcontroller to respond immediately when the button is pressed. To read the key matrix, I scanned through each row and column by driving one pin high at a time and checking the corresponding input pin to determine whether a button was pressed.
In the current build, I used the blocking HAL_I2C_Master_Transmit() function to communicate with the OLED. While this works reliably, switching to a DMA-based implementation would improve performance by allowing the microcontroller to continue executing other tasks while the display data is being transmitted, especially because a relatively large amount of data must be sent over I2C when clearing and redrawing the display.
Results
This macro pad has two modes: Macro and Media. In Macro mode, the eight keys are mapped to F13 through F20, allowing them to be used as custom hotkeys that can be assigned to functions or shortcuts on a computer. In Media mode, the keys are mapped to commonly used media controls: play next, play/pause, play previous, page forward, page refresh and page backward. Media mode also includes dedicated hotkeys for quickly launching File Explorer and the Calculator app. The rotary encoder adjusts the system volume, and pressing the encoder button switches between Macro and Media modes.



Update 1
Although the 3D-printed case worked fine, it looked more like a DIY project than a finished product. I gave my CAD drawings to a CNC machinist, who machined a case out of solid wood instead. I think it gives the macro pad a much more refined look than before.
