# Using QMK on RP2040 Microcontrollers

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/113/408/medium800/rp2040_PXL_20220725_145112895.NIGHT.jpg?1658761392)

Love mechanical keyboards? You're among friends. Friends who want to show you how to use QMK with the great RP2040 microcontroller from Raspberry Pi. Support for this was added in July 2022 to the **develop** branch by the QMK community.

If you don't care to set up your computer to compile QMK, each example also includes a **.uf2** file that you can download and immediately start using on a compatible RP2040 board, no software installation required.

## Install QMK on your computer

Each kind of operating system has different steps for this, and if you run into trouble [check the official instructions](https://docs.qmk.fm/#/newbs_getting_started) from qmk for more information and troubleshooting info!

### Windows-based systems

For Windows, the best practice is to install "[QMK WSL](https://qmk.github.io/qmk_distro_wsl/)" following the official instructions. If you prefer, you can install the older "[QMK MSYS](https://msys.qmk.fm/)" instead, but in general QMK WSL is faster and more reliable for compiling QMK code.

Heading 3 Delete Cancel Save

![](https://cdn-learn.adafruit.com/assets/assets/000/113/802/medium800/projects_terminal.png?1659300715)

### Debian-based systems including Ubuntu

For Debian-based Linux distributions (including Ubuntu and Raspberry Pi OS), install git and pip using the package manager and then install the qmk command:

```terminal
sudo apt install -y git python3-pip
python3 -mpip install --user qmk
```

### For macOS systems

For macOS, you will need to install Homebrew. Follow the instructions on [https://brew.sh](https://brew.sh). Then, install the `qmk` command using brew:

```terminal
brew install qmk/qmk/qmk
```

## Finish setting up the qmk environment

Check that the `qmk` command is working for you by asking it to report its version:

```terminal
$ qmk --version
1.1.0
```

Next, for any kind of system, run

```terminal
qmk setup
```

Answer "y" when asked to clone the firmware and install dependencies. Depending on your system, this may also prompt you for your password to install additional operating system packages.

![](https://cdn-learn.adafruit.com/assets/assets/000/113/414/medium800/rp2040_Screenshot_2022-07-25_10-12-07.png?1658761934)

![](https://cdn-learn.adafruit.com/assets/assets/000/113/413/medium800/rp2040_Screenshot_2022-07-25_10-11-21.png?1658761900)

![](https://cdn-learn.adafruit.com/assets/assets/000/113/415/medium800/rp2040_Screenshot_2022-07-25_10-16-09.png?1658762190)

Once this is done, you will have the `qmk` command available, and an up to date copy of the source code in **qmk\_firmware** folder within your home folder. The following pages of this guide show how to build and install a firmware.

## Switching back to CircuitPython or Arduino

Your RP2040 is fully reprogrammable through the RPI-RP2 bootloader, but automatic reset to upload from the Arduino environment does not work when the board has a QMK firmware installed. Instead, you need to manually access the bootloader. For more details on how to access the bootloader, check the guide for your particular board. Here are some general instructions:

- If a RESET button is available, double click it. This works only when the firmware is correctly functioning. If it doesn't work, use one of the below methods.
- If a RESET button is available, hold down the BOOT button and click RESET once.
- Hold down the BOOT button while plugging in the device

Once your computer has recognized the RPI-RP2 bootloader, you can either drag a new UF2 to the drive (CircuitPython, QMK, or Arduino) or initiate the build and upload of a firmware (Arduino or `qmk flash`)

## Parts
Ready to get down to business? Pick up some compatible hardware, then continue to one of the other pages in this guide to flash the QMK firmware to your RP2040 board, and learn more about how to modify and customize QMK along the way. If you don't feel like compiling software right now, we've also provided a **.uf2** file for each example so you can load it on your board right away.

### Adafruit MACROPAD RP2040 Bare Bones - 3x4 Keys + Encoder + OLED

[Adafruit MACROPAD RP2040 Bare Bones - 3x4 Keys + Encoder + OLED](https://www.adafruit.com/product/5100)
Strap yourself in, we're launching in T-minus 10 seconds...Destination? A new Class M planet called MACROPAD! M here, stands for Microcontroller because this 3x4 keyboard controller features the newest technology from the Raspberry Pi sector: say hello to the RP2040. It's a speedy...
Out of Stock
[Buy Now](https://www.adafruit.com/product/5100)
[Related Guides to the Product](https://learn.adafruit.com/products/5100/guides)
![Angled shot of MacroPad](https://cdn-shop.adafruit.com/640x480/5100-00.jpg)

### Adafruit KB2040 - RP2040 Kee Boar Driver

[Adafruit KB2040 - RP2040 Kee Boar Driver](https://www.adafruit.com/product/5302)
A wild Kee Boar appears! It’s a shiny **KB2040**! An Arduino Pro Micro-shaped board for Keebs with RP2040. (#keeblife 4 evah) A lot of folks like using Adafruit parts for their Keeb builds – but with the ItsyBitsy not being pin-compatible with the Pro Micro pinout, it...

Out of Stock
[Buy Now](https://www.adafruit.com/product/5302)
[Related Guides to the Product](https://learn.adafruit.com/products/5302/guides)
![Angled shot of short black microcontroller.](https://cdn-shop.adafruit.com/640x480/5302-07.jpg)

### Raspberry Pi Pico RP2040

[Raspberry Pi Pico RP2040](https://www.adafruit.com/product/4864)
The Raspberry Pi foundation changed single-board computing [when they released the Raspberry Pi computer](https://www.raspberrypi.org/archives/723), now they're ready to do the same for microcontrollers with the release of the brand new **Raspberry Pi Pico**. This...

In Stock
[Buy Now](https://www.adafruit.com/product/4864)
[Related Guides to the Product](https://learn.adafruit.com/products/4864/guides)
![Angle shot of Raspberry Pi Pico RP2040](https://cdn-shop.adafruit.com/640x480/4864-00.jpg)

### Tactile Button switch (6mm) x 20 pack

[Tactile Button switch (6mm) x 20 pack](https://www.adafruit.com/product/367)
Little clicky switches are standard input "buttons" on electronic projects. These work best in a PCB but [can be used on a solderless breadboard as shown in this tutorial](https://learn.adafruit.com/adafruit-arduino-lesson-6-digital-inputs?view=all). The pins are normally...

In Stock
[Buy Now](https://www.adafruit.com/product/367)
[Related Guides to the Product](https://learn.adafruit.com/products/367/guides)
![angled shot of 20 6mm mini tactile button switches.](https://cdn-shop.adafruit.com/640x480/367-01.jpg)

### Half Sized Premium Breadboard - 400 Tie Points

[Half Sized Premium Breadboard - 400 Tie Points](https://www.adafruit.com/product/64)
This is a cute, half-size breadboard with&nbsp;400 tie points, good for small projects. It's 3.25" x 2.2" / 8.3cm&nbsp;x 5.5cm&nbsp;with a standard double-strip in the middle and two power rails on both sides.&nbsp;You can pull the power rails off easily to make the breadboard as...

Out of Stock
[Buy Now](https://www.adafruit.com/product/64)
[Related Guides to the Product](https://learn.adafruit.com/products/64/guides)
![Angled shot of half-size solderless breadboard with red and black power lines.](https://cdn-shop.adafruit.com/640x480/64-06.jpg)

### Monochrome 0.91" 128x32 I2C OLED Display - STEMMA QT / Qwiic

[Monochrome 0.91" 128x32 I2C OLED Display - STEMMA QT / Qwiic](https://www.adafruit.com/product/4440)
These displays are small, only about 1" diagonal, but very readable due to the high contrast of an OLED display. This display is made of 128x32 individual white OLED pixels, each one is turned on or off by the controller chip. Because the display makes its own light, no backlight is...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4440)
[Related Guides to the Product](https://learn.adafruit.com/products/4440/guides)
![Monochrome OLED module wired to Feather showing text and circles](https://cdn-shop.adafruit.com/product-videos/640x480/4440-06.jpg)

### STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long

[STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long](https://www.adafruit.com/product/4399)
This 4-wire cable is&nbsp;50mm / 1.9" long and fitted with JST SH female 4-pin connectors on both ends. Compared with the chunkier JST PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/4399)
[Related Guides to the Product](https://learn.adafruit.com/products/4399/guides)
![Angled of of JST SH 4-Pin Cable.](https://cdn-shop.adafruit.com/640x480/4399-00.jpg)

# Using QMK on RP2040 Microcontrollers

## RP2040 One-Key Keyboard

![](https://cdn-learn.adafruit.com/assets/assets/000/113/416/medium800/rp2040_PXL_20220725_153342563.jpg?1658763357)

Some keyboard definitions are designed for the RP2040. A simple example is the "onekey" keyboard. You can easily test this on a breadboard with a Raspberry Pi Pico and a simple button, so it's a great way to get started. This guide shows how to build the firmware file yourself, but if you want to take a short cut you can use the uf2 file below:

[One-Key UF2 for RP2040](https://cdn-learn.adafruit.com/assets/assets/000/113/316/original/handwired_onekey_rp2040_default.uf2?1658260686)
- Connect **GP4** to one terminal of the button
- Connect **GP5** to the diagonally opposite terminal of the button

![rp2040_pico_onekey_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/113/440/medium640/rp2040_pico_onekey_bb.png?1658772685)

Now, open up the terminal/command window, and change to the **qmk\_firmware** directory.

Next, plug in you Pico while holding down the BOOT button so that the RPI-RP2 drive appears.

To build and install the firmware, issue the following command:

```terminal
cd ~/qmk_firmware
qmk flash -kb handwired/onekey/rp2040 -km default
```

This will produce a lot of output. The start and end should look something like this:

```terminal
~/qmk_firmware$ qmk flash -kb handwired/onekey/rp2040 -km default
Ψ Compiling keymap with gmake --jobs=1 handwired/onekey/rp2040:default:flash


QMK Firmware 0.17.5
Making handwired/onekey/rp2040 with keymap default and target flash

arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10-2020-q4-major) 10.2.1 20201103 (release)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Generating: .build/obj_handwired_onekey_rp2040/src/info_config.h                                    [OK]
…[many lines skipped]
Copying handwired_onekey_rp2040_default.uf2 to qmk_firmware folder                                  [OK]

Size after:
   text	   data	    bss	    dec	    hex	filename
      0	  30824	      0	  30824	   7868	handwired_onekey_rp2040_default.uf2

Flashing /media/jepler/RPI-RP2 (RPI-RP2)
Wrote 61952 bytes to /media/jepler/RPI-RP2/NEW.UF2
```

The Raspberry Pi Pico will automatically restart with the new firmware. Your computer may notify you that a new keyboard has been connected. When you press the button, it will type the letter "a".

To change the key, you can open the file **qmk\_firmware/keyboards/handwired/onekey/keymaps/default/keymap.c**. Just change `KC_A` to any valid key. For instance, to make it a mute button, use `KC_KB_MUTE` — generally, this special key will mute or unmute the computer's main sound output. QMK has a [Frequently Asked Questions page about keycodes and keymaps](https://docs.qmk.fm/#/faq_keymap) as well as a [full list of all keycodes](https://docs.qmk.fm/#/keycodes), so head over there to learn more about the possibilities.

```cpp
#include QMK_KEYBOARD_H

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    LAYOUT_ortho_1x1(KC_A) // Try changing KC_A to KC_KB_MUTE
};
```

# Using QMK on RP2040 Microcontrollers

## Adafruit MacroPad with QMK

Adafruit's MacroPad sports an RP2040 microcontroller, and a community member contributed support for it to QMK! This makes it easy to compile and install a QMK firmware on your MacroPad. If you just want to try out QMK without compiling anything, take a short-cut and use this pre-compiled uf2 file:

[QMK for Adafruit MacroPad](https://cdn-learn.adafruit.com/assets/assets/000/113/318/original/adafruit_macropad_default.uf2?1658260765)
Plug in your MacroPad while pressing down on the encoder knob, so that it enters boot mode and your computer recognizes the RPI-RP2 boot drive.

Open up the terminal/command window, and change to the **qmk\_firmware** directory.

In this case the keyboard is **adafruit/macropad** and the keymap is **default**. Knowing this, you can issue the command to build and flash the firmware:

```terminal
cd ~/qmk_firmware
qmk flash -kb adafruit/macropad -km default
```

This will produce a lot of output, similar to the following:

```terminal
~/qmk_firmware$ qmk flash -kb adafruit/macropad -km default -c
QMK Firmware 0.17.5
Making adafruit/macropad with keymap default and target clean

Ψ Compiling keymap with gmake --jobs=1 adafruit/macropad:default:flash


QMK Firmware 0.17.5
Making adafruit/macropad with keymap default and target flash

arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10-2020-q4-major) 10.2.1 20201103 (release)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Generating: .build/obj_adafruit_macropad/src/info_config.h                                          [OK]
…[Lots of lines omitted]
Copying adafruit_macropad_default.uf2 to qmk_firmware folder                                        [OK]

Size after:
   text	   data	    bss	    dec	    hex	filename
      0	  47664	      0	  47664	   ba30	adafruit_macropad_default.uf2

Flashing /media/jepler/RPI-RP2 (RPI-RP2)
Wrote 95744 bytes to /media/jepler/RPI-RP2/NEW.UF2
```

Your MacroPad will automatically restart with the QMK firmware. Simply press the keys on the MacroPad to type the digits 0-9, enter, and backspace. Rotate the encoder knob to increase/decrease system volume, and click the encoder knob in to mute/unmute.

To customize the layout, you can edit the file **adafruit/macropad/keymaps/default/keymap.c**. Look for this part of the file:

```cpp
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  [0] = LAYOUT(
                    KC_MUTE,
      KC_ENT, KC_0, KC_BSPC,
      KC_7,   KC_8, KC_9,
      KC_4,   KC_5, KC_6,
      KC_1,   KC_2, KC_3
  )
};

#ifdef ENCODER_MAP_ENABLE
const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][2] = {
  [0] = { ENCODER_CCW_CW(KC_VOLU, KC_VOLD) },
};
#endif
```

For instance, to change the layout to be more like a telephone dial pad than a computer numeric keypad, just re-arrange the rows of the keymap like so:

```auto
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  [0] = LAYOUT(
                    KC_MUTE,
      KC_1,   KC_2, KC_3
      KC_4,   KC_5, KC_6,
      KC_7,   KC_8, KC_9,
      KC_ENT, KC_0, KC_BSPC,
  )
};
```

There's a lot more to know about QMK keycodes, so start with with their [Keymap FAQ](https://docs.qmk.fm/#/faq_keymap). You can go really deep here—for instance, [layers](https://docs.qmk.fm/#/keymap?id=keymap-and-layers) are a powerful way to use the same physical key to perform different functions depending on the currently selected layer.

# Using QMK on RP2040 Microcontrollers

## Adafruit KB2040 on the PB Gherkin 30% Keyboard

![](https://cdn-learn.adafruit.com/assets/assets/000/113/517/medium800/rp2040_PXL_20220725_142915335.jpg?1658793437)

The PB Gherkin is a "30% Keyboard", indicating that it has 30 keys (about 30% of the number of keys on a classic PC keyboard). This can be a challenging keyboard to use, since the keyboard layout is organized in "layers". However, it's a comparatively inexpensive way to enter the world of hand-soldered custom keyboards!

This keyboard is designed for a "pro micro" microcontroller board. The Adafruit KB2040 is in the same form factor, and QMK can automatically convert a "pro micro" keyboard firmware to work on the KB2040.

Assembly of this keyboard requires soldering skills and the instructions must be followed closely. You can find our [assembly instructions in this dedicated guide](https://learn.adafruit.com/pb-gherkhin-30-keyboard-with-kmk-circuitpython-kb2040/assembly). It's highly recommended to get the keyboard working with CircuitPython first before switching to QMK.

Don't feel like building the firmware yourself? You can give QMK a quick try by dragging the UF2 file below to the RPI-RP2 bootloader drive:

[QMK for Gherkin with KB2040](https://cdn-learn.adafruit.com/assets/assets/000/113/368/original/40percentclub_gherkin_default_kb2040.uf2?1658339565)
The build steps similar to for the other firmware we've followed in this guide. The keyboard is **40percentclub/gherkin** &nbsp;and the keymap is **default**. This time, since the firmware was originally designed for the pro micro, we have to specify that QMK should "convert to" the KB2040 using the `CONVERT_TO` setting. Just add that to the command line when making the firmware:

```terminal
cd ~/qmk_firmware
qmk flash -kb 40percentclub/gherkin -km default -e CONVERT_TO=kb2040
```

In either case, you should get a build log displayed in the terminal, and at the end a .uf2 file is created:

```terminal
Ψ Compiling keymap with gmake --jobs=1 40percentclub/gherkin:default:flash


QMK Firmware 0.17.5
Making 40percentclub/gherkin with keymap default and target flash

arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10-2020-q4-major) 10.2.1 20201103 (release)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Size before:
   text	   data	    bss	    dec	    hex	filename
      0	  32256	      0	  32256	   7e00	40percentclub_gherkin_default_kb2040.uf2

Compiling: keyboards/40percentclub/gherkin/gherkin.c                                                [OK]
Compiling: .build/obj_40percentclub_gherkin/src/default_keyboard.c                                  [OK]
[many lines deleted]
Linking: .build/40percentclub_gherkin_default_kb2040.elf                                            [OK]
Creating binary load file for flashing: .build/40percentclub_gherkin_default_kb2040.bin             [OK]
Creating load file for flashing: .build/40percentclub_gherkin_default_kb2040.hex                    [OK]
Creating UF2 file for deployment: .build/40percentclub_gherkin_default_kb2040.uf2                   [OK]
Copying 40percentclub_gherkin_default_kb2040.uf2 to qmk_firmware folder                             [OK]

Size after:
   text	   data	    bss	    dec	    hex	filename
      0	  32240	      0	  32240	   7df0	40percentclub_gherkin_default_kb2040.uf2

Flashing /media/jepler/RPI-RP2 (RPI-RP2)
Wrote 64512 bytes to /media/jepler/RPI-RP2/NEW.UF2
```

## The Default Keymap
The first layer contains the standard alphabet, escape, backspace, space, and enter. To access further features, hold one or more keys on the bottom row.

For instance, to type an uppercase "Z", hold the "Enter" key (which functions as shift when held) and press the "Z" key.

The second image is "layer 1", so to type a "0" hold down "Space" and press "P". The symbols that go with shifted numbers also appear on "layer 2" without shift, so to type a ")", hold down "Space", "Enter", and press "P" (Layer1+Shift) OR hold down "Backspace" and press "P" (Layer2).

Use further layers to access punctuation, cursor movement keys, and operating system special keys.

The symbol ▽ indicates that this layer doesn't define the key, so the base layer's definition is used. So for example, holding C and pressing L types ";" but holding C and pressing S types "s".

For more on layers, see the [dedicated page in QMK's documentation](https://docs.qmk.fm/#/feature_layers).

![rp2040_Screenshot_2022-07-20_at_11-37-04_QMK_Configurator.png](https://cdn-learn.adafruit.com/assets/assets/000/113/346/medium640/rp2040_Screenshot_2022-07-20_at_11-37-04_QMK_Configurator.png?1658335566)

![rp2040_Screenshot_2022-07-20_at_11-37-18_QMK_Configurator.png](https://cdn-learn.adafruit.com/assets/assets/000/113/347/medium640/rp2040_Screenshot_2022-07-20_at_11-37-18_QMK_Configurator.png?1658335573)

![rp2040_Screenshot_2022-07-20_at_11-37-25_QMK_Configurator.png](https://cdn-learn.adafruit.com/assets/assets/000/113/348/medium640/rp2040_Screenshot_2022-07-20_at_11-37-25_QMK_Configurator.png?1658335581)

![rp2040_Screenshot_2022-07-20_at_11-37-33_QMK_Configurator.png](https://cdn-learn.adafruit.com/assets/assets/000/113/349/medium640/rp2040_Screenshot_2022-07-20_at_11-37-33_QMK_Configurator.png?1658335589)

![rp2040_Screenshot_2022-07-20_at_11-37-40_QMK_Configurator.png](https://cdn-learn.adafruit.com/assets/assets/000/113/350/medium640/rp2040_Screenshot_2022-07-20_at_11-37-40_QMK_Configurator.png?1658335596)

![rp2040_Screenshot_2022-07-20_at_11-37-45_QMK_Configurator.png](https://cdn-learn.adafruit.com/assets/assets/000/113/351/medium640/rp2040_Screenshot_2022-07-20_at_11-37-45_QMK_Configurator.png?1658335604)

# Using QMK on RP2040 Microcontrollers

## Editing a keymap with QMK Configurator

You can edit a QMK keymap online with the QMK Configurator, then build and flash locally to customize the keymap according to your preference.

First, open this link to the configurator: [https://config.qmk.fm/#/40percentclub/gherkin/LAYOUT\_ortho\_3x10](https://config.qmk.fm/#/40percentclub/gherkin/LAYOUT_ortho_3x10) and make any changes you like. For instance, if you use the "Pause" key to active your computer's lock screen or screen saver, you will find that it is missing on the default layout. Let's add it to Layer 5 in the position of the Enter key, so that holding B (layer 5) and pressing Enter will send the Pause key to the computer.

Select "Layer 5", then click the key in the lower right corner.

On the image of a full-size keyboard, click the Pause key.

Now the function of this key within this layer has been changed to "Pause".

![rp2040_ksnip_20220720-115931.png](https://cdn-learn.adafruit.com/assets/assets/000/113/352/medium640/rp2040_ksnip_20220720-115931.png?1658336493)

![rp2040_ksnip_20220720-115955.png](https://cdn-learn.adafruit.com/assets/assets/000/113/353/medium640/rp2040_ksnip_20220720-115955.png?1658336509)

![rp2040_ksnip_20220720-120030.png](https://cdn-learn.adafruit.com/assets/assets/000/113/354/medium640/rp2040_ksnip_20220720-120030.png?1658336525)

![rp2040_ksnip_20220720-120014.png](https://cdn-learn.adafruit.com/assets/assets/000/113/355/medium640/rp2040_ksnip_20220720-120014.png?1658336544)

Near the top of the page, click the button to download the keymap as a json file.

![rp2040_ksnip_20220720-120242.png](https://cdn-learn.adafruit.com/assets/assets/000/113/356/medium640/rp2040_ksnip_20220720-120242.png?1658336605)

Import the keymap file into **qmk\_firmware** :

```terminal
cd ~/qmk_firmware/keyboards/40percentclub/gherkin
qmk import-keymap ~/Downloads/40percentclub_gherkin_layout_ortho_3x10_mine.json
```

This should produce output similar to:

```terminal
Ψ Importing 40percentclub_gherkin_layout_ortho_3x10_mine.json.

Ψ Imported a new keymap named 40percentclub_gherkin_layout_ortho_3x10_mine.
Ψ To start working on things, `cd` into keyboards/40percentclub/gherkin/keymaps/40percentclub_gherkin_layout_ortho_3x10_mine,
Ψ or open the directory in your preferred text editor.
Ψ And build with qmk compile -kb 40percentclub/gherkin -km 40percentclub_gherkin_layout_ortho_3x10_mine.
```

Now let's build and flash it:

```auto
cd ~/qmk_firmware
qmk flash -e CONVERT_TO=kb2040 -kb 40percentclub/gherkin -km 40percentclub_gherkin_layout_ortho_3x10_mine
```

# Using QMK on RP2040 Microcontrollers

## KB2040 One-Key Keyboard with OLED Display

![](https://cdn-learn.adafruit.com/assets/assets/000/113/437/medium800/rp2040_PXL_20220725_145112895.NIGHT.jpg?1658770819)

The KB2040 sports a [Stemma QT connector](https://learn.adafruit.com/introducing-adafruit-stemma-qt?view=all&gclid=EAIaIQobChMIxej3xvSU-QIV1cfICh3OEwvzEAAYASAAEgIa8vD_BwE), which is handy for connecting OLED displays. This is supported by QMK, though to make it even easier the author of this guide also contributed a [pull request to provide a ready-to-use example with the KB2040](https://github.com/qmk/qmk_firmware/pull/17786).

- Connect pins D3 and D4 to diagonally opposite pins of the tactile switch
- Use a cable to connect the STEMMA QT connectors of the KB2040 and OLED display.

![rp2040_kb2040-oled_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/113/442/medium640/rp2040_kb2040-oled_bb.png?1658772874)

You can follow the instructions on GitHub to fetch the pull request to your computer and build it for yourself, or just use the pre-built version below, it's ready to be copied to the RPI-RP2 bootloader drive of a KB2040:

[QMK OLED Demo for KB2040](https://cdn-learn.adafruit.com/assets/assets/000/113/418/original/handwired_onekey_kb2040_oled.uf2?1658763711)
The build steps similar to for the other firmware we've followed in this guide. The keyboard is **handwired/onekey/kb2040** (note it is now **kb2040** and not **rp2040** to indicate the use of the kb2040's Stemma QT connector) and the keymap is **oled**.

Warning: 

```terminal
cd ~/qmk_firmware
git fetch origin refs/pull/17786/merge
git checkout FETCH_HEAD
qmk flash -kb handwired/onekey/kb2040 -km oled
```

In either case, you should get a build log displayed in the terminal, and at the end a .uf2 file is created:

```terminal
Ψ Compiling keymap with gmake --jobs=19 --output-sync=target handwired/onekey/kb2040:oled:flash


QMK Firmware 0.17.5
Making handwired/onekey/kb2040 with keymap oled and target flash

arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10-2020-q4-major) 10.2.1 20201103 (release)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Generating: .build/obj_handwired_onekey_kb2040/src/layouts.h                                        [OK]
[Many lines deleted]
Creating binary load file for flashing: .build/handwired_onekey_kb2040_oled.bin                     [OK]

Size after:
   text	   data	    bss	    dec	    hex	filename
      0	  38284	      0	  38284	   958c	handwired_onekey_kb2040_oled.uf2

Creating UF2 file for deployment: .build/handwired_onekey_kb2040_oled.uf2                           [OK]
Copying handwired_onekey_kb2040_oled.uf2 to qmk_firmware folder                                     [OK]

Flashing /media/jepler/RPI-RP2 (RPI-RP2)
Wrote 64512 bytes to /media/jepler/RPI-RP2/NEW.UF2
```

## Operating the demo

Rather than working as a keyboard, the one button is used to control the demo.

Click the button a short time to switch the mode.

Hold down the button to rotate the display by 90 degree increments.

After a short time, the OLED display will be set to all-black to prevent burn-in.

## STEMMA QT Configuration in QMK

The following settings are needed in the appropriate&nbsp; **config.h** file to use the I2C port on the STEMMA QT connector:

```cpp
#define I2C_DRIVER I2CD1
#define I2C1_SDA_PIN GP12
#define I2C1_SCL_PIN GP13
```

The following settings are needed in the appropriate&nbsp; **mcuconf.h** file:

```auto
#pragma once

#include_next &lt;mcuconf.h&gt;

#undef RP_I2C_USE_I2C0
#define RP_I2C_USE_I2C0 TRUE

#undef RP_I2C_USE_I2C1
#define RP_I2C_USE_I2C1 FALSE
```

If your board has a different pinout, first determine the GP or GPIO number of the pins, and use that instead of GP12/13 in **config.h** for `SDA_PIN` and `SCL_PIN`. Then, determine whether they are on I2C peripheral 0 or 1 according to the pinout of the RP2040, and set the appropriate `USE_I2C` line to `TRUE` and the other to `FALSE` in **mcuconf.h**.

QMK numbers the I2C peripherals differently when it comes to defining the `I2C_DRIVER` so add 1 (I2C0 is I2CD1 and I2C1 is I2CD2). This way, you can use any appropriate pair of pins that are capable of I2C on the RP2040.

To enable the I2C driver and the OLED display, you place lines in&nbsp; **rules.mk** :

```cpp
OLED_ENABLE = yes
OLED_DRIVER = SSD1306

OPT_DEFS += -DHAL_USE_I2C=TRUE
```

The function&nbsp;`oled_task_user` contains code to actually draw to the screen. In the oled example, this is in the file&nbsp; **keyboards/handwired/onekey/keymaps/oled/keymap.c**. The code can draw letters or work by individual pixels. For full info, [check out the documentation from QMK's website](https://docs.qmk.fm/#/feature_oled_driver?id=oled-driver). Here's a snippet of the code that fills the screen with a test pattern made out of ASCII characters:

```cpp
static void test_characters(void) {
    uint8_t cols       = oled_max_chars();
    uint8_t rows       = oled_max_lines();
    bool    invert     = false;
    uint8_t char_index = 0;
    for (uint8_t row = 0; row &lt; rows; ++row) {
        for (uint8_t col = 0; col &lt; cols; ++col) {
            oled_write_char(get_test_char(char_index), invert);
            if (++char_index &gt;= TEST_CHAR_COUNT) {
                char_index = 0;
                invert     = !invert;
            }
        }
    }
}
```


## Featured Products

### Adafruit MACROPAD RP2040 Bare Bones - 3x4 Keys + Encoder + OLED

[Adafruit MACROPAD RP2040 Bare Bones - 3x4 Keys + Encoder + OLED](https://www.adafruit.com/product/5100)
Strap yourself in, we're launching in T-minus 10 seconds...Destination? A new Class M planet called MACROPAD! M here, stands for Microcontroller because this 3x4 keyboard controller features the newest technology from the Raspberry Pi sector: say hello to the RP2040. It's a speedy...
Out of Stock
[Buy Now](https://www.adafruit.com/product/5100)
[Related Guides to the Product](https://learn.adafruit.com/products/5100/guides)
### Adafruit KB2040 - RP2040 Kee Boar Driver

[Adafruit KB2040 - RP2040 Kee Boar Driver](https://www.adafruit.com/product/5302)
A wild Kee Boar appears! It’s a shiny **KB2040**! An Arduino Pro Micro-shaped board for Keebs with RP2040. (#keeblife 4 evah) A lot of folks like using Adafruit parts for their Keeb builds – but with the ItsyBitsy not being pin-compatible with the Pro Micro pinout, it...

Out of Stock
[Buy Now](https://www.adafruit.com/product/5302)
[Related Guides to the Product](https://learn.adafruit.com/products/5302/guides)
### Raspberry Pi Pico RP2040

[Raspberry Pi Pico RP2040](https://www.adafruit.com/product/4864)
The Raspberry Pi foundation changed single-board computing [when they released the Raspberry Pi computer](https://www.raspberrypi.org/archives/723), now they're ready to do the same for microcontrollers with the release of the brand new **Raspberry Pi Pico**. This...

In Stock
[Buy Now](https://www.adafruit.com/product/4864)
[Related Guides to the Product](https://learn.adafruit.com/products/4864/guides)
### Tactile Button switch (6mm) x 20 pack

[Tactile Button switch (6mm) x 20 pack](https://www.adafruit.com/product/367)
Little clicky switches are standard input "buttons" on electronic projects. These work best in a PCB but [can be used on a solderless breadboard as shown in this tutorial](https://learn.adafruit.com/adafruit-arduino-lesson-6-digital-inputs?view=all). The pins are normally...

In Stock
[Buy Now](https://www.adafruit.com/product/367)
[Related Guides to the Product](https://learn.adafruit.com/products/367/guides)
### Half Sized Premium Breadboard - 400 Tie Points

[Half Sized Premium Breadboard - 400 Tie Points](https://www.adafruit.com/product/64)
This is a cute, half-size breadboard with&nbsp;400 tie points, good for small projects. It's 3.25" x 2.2" / 8.3cm&nbsp;x 5.5cm&nbsp;with a standard double-strip in the middle and two power rails on both sides.&nbsp;You can pull the power rails off easily to make the breadboard as...

Out of Stock
[Buy Now](https://www.adafruit.com/product/64)
[Related Guides to the Product](https://learn.adafruit.com/products/64/guides)
### Monochrome 0.91" 128x32 I2C OLED Display - STEMMA QT / Qwiic

[Monochrome 0.91" 128x32 I2C OLED Display - STEMMA QT / Qwiic](https://www.adafruit.com/product/4440)
These displays are small, only about 1" diagonal, but very readable due to the high contrast of an OLED display. This display is made of 128x32 individual white OLED pixels, each one is turned on or off by the controller chip. Because the display makes its own light, no backlight is...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4440)
[Related Guides to the Product](https://learn.adafruit.com/products/4440/guides)
### STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long

[STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long](https://www.adafruit.com/product/4399)
This 4-wire cable is&nbsp;50mm / 1.9" long and fitted with JST SH female 4-pin connectors on both ends. Compared with the chunkier JST PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/4399)
[Related Guides to the Product](https://learn.adafruit.com/products/4399/guides)

## Related Guides

- [Adafruit MacroPad RP2040](https://learn.adafruit.com/adafruit-macropad-rp2040.md)
- [Adafruit KB2040](https://learn.adafruit.com/adafruit-kb2040.md)
- [AdaBox 019](https://learn.adafruit.com/adabox019.md)
- [Breakbeat Breadboard](https://learn.adafruit.com/breakbeat-breadboard.md)
- [An Introduction to RP2040 PIO with CircuitPython](https://learn.adafruit.com/intro-to-rp2040-pio-with-circuitpython.md)
- [May Pad Macropad with the KB2040, KMK, and CircuitPython](https://learn.adafruit.com/maypad-macropad-with-the-kb2040-kmk-and-circuitpython.md)
- [Stepper Motor Turntable](https://learn.adafruit.com/stepper-motor-turntable.md)
- [Minecraft Turbopad](https://learn.adafruit.com/minecraft-turbopad.md)
- [DIY Decorative Resin Keycaps](https://learn.adafruit.com/diy-decorative-resin-keycaps.md)
- [MacroPad 2FA TOTP Authentication Friend](https://learn.adafruit.com/macropad-2fa-totp-authentication-friend.md)
- [MACROPAD Hotkeys](https://learn.adafruit.com/macropad-hotkeys.md)
- [Fisher-Price USB Foot Pedal](https://learn.adafruit.com/fisher-price-usb-foot-pedal.md)
- [Dragon Drop: a CircuitPython Game for MacroPad](https://learn.adafruit.com/dragon-drop-a-circuitpython-game-for-macropad.md)
- [DOOM Keeb](https://learn.adafruit.com/doom-keeb.md)
- [Super Nintendo USB Controller](https://learn.adafruit.com/super-nintendo-usb-controller.md)
- [Ableton Live MacroPad Launcher](https://learn.adafruit.com/ableton-live-macropad-launcher.md)
- [MacroPad Summer Olympics Hotkeys](https://learn.adafruit.com/macropad-olympic-hotkeys.md)
