The Super Easy Pico Keyboard

by TomoDesigns in Circuits > Raspberry Pi

3800 Views, 13 Favorites, 0 Comments

The Super Easy Pico Keyboard

Pico keyboard.png

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:

Here are all the tools we're going to need for this Instructables:

Preparation Gluing (Wood)

Wood overviewq.png

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.

Downloads

Gluing (wood)

Eindresultaat lijmen hout.png
Hout igf.gif

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.

Download and Printing Parts (3D Printing)

render doos.png
Overview 3dprint.png

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.

Preparation Soldering

Button solder overview.png
Solder overview.png

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

Little Helper (Info)

Little helper 1.png
Little helper 3.png
Little helper 4.png
Little helpergif.gif

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!

Cable Stripper

Kabel strip.png
Kabel strippen.gif

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.

Pico Soldering

Soldeer pico.gif
Draaden solderen gif.gif
soldeeer overview.png

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)

Button Soldering

Knop soldeer result.png
Knop solderen gif.gif

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!

Attaching Button

button attach keyboard.gif
Button.gif
Eindresultaat alles.png

Now we put the knob through the hole in the lid and tighten it with the nut!

Download Ciruitpython

Gif circuit python.gif

Put CircuitPython on the Raspberry Pi Pico

Button pico.png
Gif bootsel button.gif
why.gif

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...

Install and Copy From HID

Hid instaleren.gif

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.

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

Select Interpreter

select inter.gif

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.

The Code

gp10.png

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.

Downloads

What We Are Going to Change

New chagne word gif.gif

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.

Save Code on Pico

1.gif

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

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.

Examples!

For typing a capital 'A'.

kbd.send(Keycode.SHIFT, Keycode.A)


For typing Control X

kbd.send(Keycode.CONTROL, Keycode.X)

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!

Downloads