Posted on

How to add Rotary Encoders to Lily58 Pro Guide

This is a guide on how to handwire Rotary Encoders EC11 to Lily58 Pro using Pro Micro controller.
Main resource which i strongly recommend to read is the QMK Encoders docs page on which this guide is based.
The Rotary Encoder will be added to the left (master) half and after that to the right (slave) half. The encoder position can be anywhere you desire on the Lily58’s layout.

Hardware

💡We are working on the left half of the Lily58 Pro here.

1) Bend the 3 pins on EC11 encoder until they are horizontal. Do the same for the side 2 pin holders. Cut from each of them about 2mm in order to make them slightly shorter.

2) ⚠️Be careful with the hot glue in this step. Apply some hot glue on the top of the PCB in the place where you want your encoder. Place the encoder over the glue and keep it pressed until it stays there firmly and the glue colds down. Apply any extra glue around the encoder if needed after. Remove any excess of the glue after it colds down.

3) Bend the 2 top encoder pins (Switch and GND) and solder them to the kailh socket footprint. Now you should have the encoder as a working key when pressed down.

4) Solder 3 wires to the 3 bottom pins of the encoder (Out A, GND and Out B).

5) Solder the wire from Out A to the F5 pin on the controller.
GND to the bottom pin of the Reset Switch (you could solder it directly to the GND of the controller if you wish).
Out B to the F4 pin on the controller.
Make sure the soldering is clean and there are no shorts.

Free Pro Micro Pins for Lily58 Pro Before installing Rotary Encoders

6) Done. Now you need to configure the installed encoder in QMK software and flash the controllers in order to have it working. At this point it only should work as a key when the encoder is pressed, just as it would be a normal switch.


In case you want to add another encoder on the right half here is how:

Repeat all the above steps on the right Lily58 PCB half until Step 5.

On the right half you can use only one of the pins used on the left half. In this case i used the same pin F4 for the Out A on the encoder and a new pin D4 for the Out B.
Please check the software section below for necessary changes for this additional encoder to work.

Right Half handwired to the Rotary Encoder
Left and Right Halves handwired for Rotary Encoders
Lily58: Left Half encoder uses F4 and F5 pins, Right HalfF4 and D4

Software

The following code is if you want only one encoder on left half of the Lily58 Pro.

1) Add the following code to your config.h in your keymap folder:

#define ENCODERS_PAD_A { F5 } //Pro Micro pin on Out A
#define ENCODERS_PAD_B { F4 } //Pro Micro pin on Out B
#define ENCODER_RESOLUTIONS 4 //Pulses the encoder registers between each detent

2) Add the following code to your rules.mk in your keymaps folder:

EXTRAKEY_ENABLE = yes       # Audio control and System control
ENCODER_ENABLE = yes        # Activate Encoder

3) Add the following code to your keymap.c in your keymaps folder:

bool encoder_update_user(uint8_t index, bool clockwise) {
    if (index == 0) { /* First encoder */
        if (clockwise) {
            tap_code_delay(KC_VOLU, 10);
        } else {
            tap_code_delay(KC_VOLD, 10);
        }
    }
    return false;
}

This will make the Encoder to turn up and down System’s Volume on turning it clockwise/counterclockwise.

4) Compile and flash both Pro Micros. Substitute yourKeymapName with your now edited keymap’s name and run it in QMK MSYS.

qmk flash -kb lily58 -km yourKeymapName

5) Done. Now you should have a working encoder on left half. When pressed act like a switch and when turning as a volume up/down.


If you want to have 2 encoders, one on each half then you’ll need to specify the pinout the wires are soldered to each encoder in your config.h like this example:

#define ENCODERS_PAD_A { F4 } //Master half pin Out A
#define ENCODERS_PAD_B { F5 } //Master half pin Out B
#define ENCODER_RESOLUTIONS { 4 } //Master's pulses the encoder registers between each detent
#define ENCODERS_PAD_A_RIGHT { F4 } //Slave half pin Out A
#define ENCODERS_PAD_B_RIGHT { D4 } //Slave half pin Out B
#define ENCODER_RESOLUTIONS_RIGHT { 4 } //Slave's pulses the encoder registers between each detent

And add to your keymap.c the second encoder’s function, as in this example page up and page down:

bool encoder_update_user(uint8_t index, bool clockwise) {
    if (index == 0) { /* First encoder */
        if (clockwise) {
            tap_code_delay(KC_VOLU, 10);
        } else {
            tap_code_delay(KC_VOLD, 10);
        }
    } else if (index == 1) { /* Second encoder */
        if (clockwise) {
            tap_code(KC_UP);
        } else {
            tap_code(KC_DOWN);
        }
    }
    return false;
}

Compile and flash both Pro Micros:

qmk flash -kb lily58 -km yourKeymapName

Done. Now you should have a working encoder on left as a volume up/down and the encoder on the right as Up/Down Arrow.

Top Lily58 Pro: Low Profile Acrylic Case. Mid: High Profile Case. Bottom: Aluminum Low Profile Case

Miscellaneous: Full description of the Pro Micro MCU Pinout

Pro Micro has 18 accessible pins that can be used as a digital input or output, enough for a board with up to (9×9) 81 keys .

Source: sparkfun