-
1Watch the Video
Before you start this project it might be a good idea to watch the video I made.
Watched the video? Let's get the parts you'll need!
-
2Get the Parts You'll Need
This project contains two main parts, a Raspberry Pi Pico and an ILI9488 TFT with touchscreen. You can buy these from various resellers. I have provided some links where you can get them. You will also need a way to connect the screen to the Pico. You can use a breadboard and breadboard wires, use a prototype board and solder everything together, or you can use a combiner PCB I designed.
Raspberry Pi Pico: Buy from the PiHut
ILI9488 TFT with Touch: Buy on AliExpress *
You can order the PCB directly from PCBWay, or download the Gerber files and use your favorite PCB manufacturer.Order from PCBWay: Pico + TFT Combiner *
Download Gerbers: Download from Github
Not all ILI9488 TFT screens are created equally. It is important to make sure you have selected a screen with touch! *Full disclosure: these are affiliate links
-
3Hardware: Connect the TFT Screen to the Pico
The wiring may seem a bit daunting at first. But don't let all the wires scare you. It is pretty straight forward. The images above will help you when you wire your TFT + Touchscreen to your Pi Pico.
This is also decision making time. There are few options when it comes to connecting the two together. You can use a breadboard, you can use prototyping board or you can order a PCB specifically to connect the ILI9488 + touch to the Pi Pico. I'd like to point out that the breadboard option is only an option for testing your connections and screen. It is not very practical to have on your desk and loose connections can cause problems.
It is important to know that these screens run at 3.3V. Connecting them to 5V can cause damage!
These are the connection from the Pi Pico to the TFT:
3.3V -> VCC and LED
GND -> GND
GP20 -> CS
GP21 -> RESET
GP22 - > DC/RS
GP3 -> SDI(MOSI) and T_DIN
GP2 -> SCK and T_CLK
GP14 -> T_CS
GP0 -> T_DO
GP15 -> T_IRQ
SDO(MISO) is not used for the TFT screen, so you are left with one unconnected pin on the TFT module. That's ok!
If you are using the Pico + TFT Combiner, there is only one way it will fit. My advise it to use header pins so you can unplug your Pico and screen to use it in a different project, or if for some reason the screen or Pico do not work you can replace them.
If you decide to solder the Pico and screen directly to the combiner board, It is important to solder the Pico to the board first! Because if you solder the TFT first, you won't be able to solder the Pico to the board anymore!
-
4Software: Installing Arduino IDE Libraries
This build uses the 'arduino-pico' core by Earle Philhower.
To install this core, go to Arduino -> Preferences and click on the icon behind the input field for Additional Board Managers URLs. Next, copy and paste the following link (without quotes) in the popup box:
https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
Click OK and OK. Next, go to Tools -> Board: -> Board Manager and search for "pico". Install the latest version of "Raspberry Pi Pico/RP2040". and click "Close".
Installing the TFT_eSPI library.
At the moment of writing this Instructable the Pi Pico support in TFT_eSPI is not available through the library manager. But installation is very simple. Go to https://github.com/Bodmer/TFT_eSPI, click on "Code" and "Download .ZIP". In the Arduino IDE, go to Sketch -> Include Library -> Add .ZIP library. Locate the library you just downloaded and click "Choose", wait for it to install and you are done!
-
5Download the Sketch and Preparing TFT_eSPI
The simple macro keypad sketch can be downloaded from Github:
https://github.com/DustinWatts/Pico-Matrix-Touch-K...
For this sketch to work with the Pi Pico we have to configure the TFT_eSPI library. To do this, open the following file in your favorite text-editor:
/Documents/Arduino/libraries/TFT_eSPI/User_Setup.h
Select everything (CTRL+A) and hit delete. You now have an empty User_Setup.h. Copy the code below and past it in the User_Setup.h file:
// Stripped down User_Setup.h version for the Pico-Matrix-Touch-Keyboard //<br> #define ILI9488_DRIVER // WARNING: Do not connect ILI9488 display SDO to MISO if other devices share the SPI bus (TFT SDO does NOT tristate when CS is high) #define TFT_MISO 0 #define TFT_MOSI 3 #define TFT_SCLK 2 #define TFT_CS 20 // Chip select control pin #define TFT_DC 22 // Data Command control pin #define TFT_RST 21 // Reset pin (could connect to Arduino RESET pin) #define TOUCH_CS 14 // Chip select pin (T_CS) of touch screen #define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH #define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters #define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters #define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm #define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-. #define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-. //#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT #define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts // Comment out the #define below to stop the SPIFFS filing system and smooth font code being loaded // this will save ~20kbytes of FLASH #define SMOOTH_FONT#define SPI_FREQUENCY 27000000 // Optional reduced SPI frequency for reading TFT #define SPI_READ_FREQUENCY 20000000 // The XPT2046 requires a lower SPI clock rate of 2.5MHz so we define that here: #define SPI_TOUCH_FREQUENCY 2500000
Don't forget to save the file!
This is also the file you will find in the Github repository (https://github.com/DustinWatts/Pico-Matrix-Touch-Keyboard/tree/main/User_Setup)
-
6Flashing the Pico
With the "Pico-Martix-Touch-Keyboard.ino" opened, go to "Tools" -> "Boards" and select the "Raspberry Pi Pico".
You can leave all settings as default, except for the "Flash Size". The keyboard sketch needs a small bit of filesystem storage to store the touch calibration data that is created the first time the sketch runs. So, under "Flash Size" select "2MB (Sketch: 1984KB, FS: 64KB)"
Next, before you flash the sketch, you might want to have a look at it. As I said, each button on the screen can have it's own set of keystrokes that will be sent to your PC after you press it.In the function called buttonpress(); the presses are handled. This function shows you how to use the keyboard functions. I made a few examples, but you can create your own off course!
Basically, there are a few functions you can use (you can find detailed documentation here: https://www.arduino.cc/reference/en/language/functions/usb/keyboard/).
To send modifiers like ALT, CTRL, Shift, etc. use:
Keyboard.press();
To send a letters or numbers use:
Keyboard.print();
To press and release a key like Enter, escape, F1, etc. use:
Keyboard.write();
To release a single key you already pressed using Keyboard.press(), use:
Keyboard.release();
To release all keys you have pressed, use:
Keyboard.releaseAll();
Note: Make sure to always use .releaseAll(); Because if you don't that key will keep being pressed which can have some undesired effects!
Between each Keyboard function, there is a small delay ("delay(keydelay);") which is set to 100ms. This is to give your PC some time to process the key presses.
To flash the keyboard sketch, just hit "Upload", and that's it! Your screen should come alive and you will be presented with a calibration screen. This is only done the first time you run the sketch, but can later always be repeated by setting "#define REPEAT_CAL false" to true.
After the calibration is done, your PC should recognize that there is a new USB keyboard plugged in. After it has been setup, you are now ready to test your Matrix Touch Keyboard.
-
7Printing a case
Because having the the screen just lying around doesn't look nice and is also a bit hard to use, it might be nice to printa case for it. Because the dimensions are exactly the same as for FreeTouchDeck (https://www.instructables.com/A-Bluetooth-ESP32-TFT-Touch-Macro-Keypad/) you can use the same case!
If you are using header pins, choose the front version called "Top_for_TFT_with_Headers.stl". (https://www.thingiverse.com/thing:4661069)
Because the dimension are the same, you can use any case that is designed for FreeTouchDeck, providing it has the space for use with header pins. So be sure to check out all the remixes on Thingiverse to find a case that you like: https://www.thingiverse.com/search?q=FreeTouchDeck&type=things&sort=relevant
-
8Final Note
Done!
I hope this is useful to you and you've had fun building your Raspberry Pi Pico Matrix Touch Keyboard.
If you have any questions or are stuck somehow, do not hesitate to leave a comment, or join me on one of my social channels.
YouTube: https://www.youtube.com/dustinwatts
Twitter: https://twitter.com/DustinWattsNL
Discord: https://discord.gg/RE3XevS
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.