This is the easiest Raspberry Pi Pico to Keyboard tutorial. You can make in easy visualized steps a functioning Macro keyboard, Password keyboard, or anything that you can do with a keyboard.
I am also the original author and have made this tutorial in Dutch for the Makersbase. I am Tomodesigns and I do cool stuff on my Youtube and also Instagram! I am a dutch student with a passion for making and teaching others.
This tutorial is well tested on an audience with a beginner knowledge of soldering and coding. So you can also do this!
You can make your button casing with my laser-cut wood file or 3dprint file. You will only have to follow the wood or 3dprint steps depending on your chosen method. If you have a Pico and a button you can also follow this tutorial without building the buttonholder.
Supplies
These are all the parts we need for this Instructables:
- Button: https://amzn.to/3HKzllj (Diameter of 7mm)
- Wire (Red and color of your choice):
- 4mm wood or 3dprint filament
- Micro USB cable
- Raspberry Pi Pico:Â https://amzn.to/3neec9Q
- Solder tin
Here are all the tools weâre going to need for this Instructables:
- Soldering Iron https://amzn.to/39NkQk9
- Lasercutter or 3Dprinter (Or nothing if you donât want to make a case)
- Cable stripper:Â https://amzn.to/39KrTdh
Step 1: Preparation Gluing (Wood)
Before we start making the box that contains all your electronics, we first have to collect the right parts. These are:
- Wood glue
- Wooden box parts
The wooden box parts file is included. You can laser cut this part or go to step 3 for the 3dprinted box if you donât have a laser cutter.
Step 2: Gluing (wood)
As you can see in the video above, you can now glue the box together.
NB! Do not glue the lid on the box yet. This must still be able to open to put in all the electronics.
Step 3: Download and Printing Parts (3D Printing)
Download these files from this link:Â https://www.printables.com/model/241877-pico-keyboard
You donât have to use any supports for this print and it is around 1,5 hours of printing.
Infill doesnât matter.
Step 4: Preparation Soldering
For soldering you need a number of things:
- The Pico
- A button
- Two wires (red and color of your choice)
- solder tin
And we need some tools:
- Cutting pliers
- Cable stripper
- Soldering iron
- Little helper
Step 5: Little Helper (Info)
This is the Little Helper. This handy tool has a magnifying glass and two little hands.
With these hands he can, for example, hold your Raspberry Pi Pico while soldering. So that everything is easily kept in one place. In the other hand, it can even hold the cables that you are going to attach to the Pico.
Here is a link to buy this handy tool!
Always use the Little Helper when you can when soldering!
Step 6: Cable Stripper
To solder cables to your Knop and Pico, you must first remove the casing from the cables. This is called stripping cables.
We do this to expose the part of the cable that conducts the current hole. You can recognize these conductive smaller cables by the silver/bronze color. We are going to solder these on the Pico and Button.
Strip both sides of both your cables.
Step 7: Pico Soldering
In this step, we are going to solder both cables to the Pico.
We do this by first putting some solder tin on the pico where we will connect the wires.
We are going to do this on pin 3.3V and GP10 (see image)
Step 8: Button Soldering
In this step, we will solder the cables that we soldered to the pico in the previous step to a button. You have 2 pins on the button. Solder one wire per terminal.
Make sure the ends of the wire do not touch!
Make sure you soldered everything to the right points!
Step 9: Attaching Button
Now we put the knob through the hole in the lid and tighten it with the nut!
Step 10: Download Ciruitpython
Put the downloaded file in a folder that you can access.
Step 11: Put CircuitPython on the Raspberry Pi Pico
Press and hold the Bootsel button (see photo above) of the pico and place it in the PC via the USB cable.
Copy and paste the file (adafruit-circuitpython-rasâŠ) on the Raspberry Pi Pico which will show up as a USB device,
If all goes well, the Pico will restart. And now you can see whatâs on the Pico. Here you are going to put files in the next stepâŠ
Step 12: Install and Copy From HID
Install the https://github.com/adafruit/Adafruit_CircuitPython_HID/archive/refs/heads/main.zip HID Library that we are going to use in we are going to use to communicate from the Pico to the computer.
Copy the Zip folder to a separate folder.
Then extract the zip folder
Then go to Adafruit_CircuitPython_HID-main > adafruit_hid
Then copy the adafruit_hid folder to the Pico.
Step 13: Install Thonny
Install Thonny https://github.com/thonny/thonny/releases/download/v3.3.13/thonny-3.3.13.exe
After installing you start up Thonny
Step 14: Select Interpreter
Now we are going to indicate in which code language we are going to code. So that the microcontroller that we are going to connect in this way can understand this.
From the taskbar, go to Run>Select Interpreter
Now that we are in the Interpreter menu, click on the down arrow to select CircuitPython(generic). Click OK.
Step 15: The Code
Now download the code provided in this step. And open it in Thorny.
button1 = digitalio.DigitalInOut(board.GP10)
button1.direction = digitalio.Direction.INPUT
button1.pull = digitalio.Pull.DOWN
This is an important piece of code. This indicates that we are using a pin on the Pico. That is GP10 (see photo above). The names of all pins are also on the Pico if you look closely at the photo.
Step 16: What We Are Going to Change
while True:
  if button.value:
   kbd.send(Keycode.T, Keycode.O, Keycode.M, Keycode.O,)
time.sleep(0.1)
In the part While True we look when the button is pressed, we will execute the part below.
This is the most important piece of code weâll be modifying.
The part kbd.send(Keycode.T, Keycode.O, Keycode.M, Keycode.O,) contains Keycode.T, which means that we will send the letter T when we press the button. So you can change this letter into anything. So Keycode.A or BcdeâŠ.
NB! You can only send 1 letter per Keycode. Do you want to send a whole word? Then you put several Keycodes in a row like this: Keycode.M, Keycode.A, Keycode.K, Keycode.E, Keycode.R, Which finally makes âMakerâ when you press the button.
time.sleep(0.1) This piece of code causes him to wait 0.1 seconds to repeat your code.
Note you can only send 6 letters per loop.
Step 17: Save Code on Pico
Now we need to save the code to the pico.
We do this by going to File > save copy and select the Pico.
Name your code to Main.py for it to work indipended from Thonny
Step 18: It Runs!
Remove your pico from the computer and then put it back in your computer. And now he runs!
If you want to change the code, you have to save your new code again and replace the old code.
Step 19: Examples!
For typing a capital âAâ.
kbd.send(Keycode.SHIFT, Keycode.A)
For typing Control X
kbd.send(Keycode.CONTROL, Keycode.X)
Step 20: Send Big Sentences (extra Assignment)
We can also start sending large sentences. But for this we need to use different code. You can download the code in this step!
We have added 4 sentences so that we can now send, for example, whole sentences or links.
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
kbd = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(kbd)
These are at the top and let us know that we are going to imitate a keyboard.
layout.write(âTomodesigns\nâ)
This is the most important piece weâre going to edit. To be precise, weâre going to edit whatâs in the parentheses (). Make sure everything you write is inside the parentheses () and the â quotes!
So for example you can change (âTomodesigns\nâ) to (âSubscribe to Tomodesigns\nâ).
or
(âwww.google.com\nâ)
\n means that you press enter after entering your text. If you remove this it wonât hit enter anymore!
Source: The Super Easy Pico Keyboard