Skip to content

Making a Capacitive Board for Interactive Scratch Games

QTPy board

This project takes advantage of the new Adafruit QTPy board’s 6 capacitive pins to create platform for creating an interactive board that may be connected to Scratch for games and activities or other computer platforms. This is a step by step beginner tutorial and uses the CircuitPython language and library which has a smaller learning curve than the Arduino environment (QTPy is Arduino supported if you want to go that route). At $6 each, the QTPy is a great way of introducing physical computing or creating accessible games without a lot of overhead cost.

Here is a quick video of how it all works. The board contains conductive pads wired to the QTPy which are sending arrow presses to a Scratch project that reads out the arrow direction.

Why Capacitive Touch?

diagram illustrating closed circuit sending input to board
Circuit System

Boards such as the Makey Makey use the concept of a circuit to trigger key presses to a computer connected through the USB cable. The user connects conductive surfaces and using our conductive body closes the circuit to trigger a button press. Although most reliable, the downfall with this system is that a ground cable is always needed to ensure a complete circuit.

diagram of hands touching fruit with signal detection sent to board
Capacitive System

Without getting too technical, a capacitive system works by detecting changes in electrical current to the pin. Since our bodies emit slight electrical pulses, this is just enough to trigger a pin change. This means that a grounding cable in not needed. Capacitive systems however may be a bit more finicky so ensuring proper spacing and use of non conductive surface to limit unwanted inputs is key.

The QTPy board has the following 6 pins that support capacitive touch (Note: this project only uses 4 of the 6 pins):

  • A0/D0
  • A1/D1
  • A2/D2
  • A3/D3
  • TX/A6/D6
  • RX/A7/D7

Now let’s get to building!

Materials:

  • Adafruit QTPy board
  • USB C cable (ensure this is a data transfer cable and not charge only)
  • QTPy Case (optional)
  • (2) 1/2″ screws (optional)
  • (4) Female header cables
  • Rubber or non-conductive board
  • Aluminum tape
  • Soldering Iron + Solder

Solder the headers

The QTPy comes headerless (the pins are not soldered into the board). You will need to solder the pins into the board for easier access. Adafruit has a great beginner video on how to solder headers.


Print and fasten the QTPy case

QTpy board 3D printed incase

If desired, open and download the STL file for the case from Tinkercad. The case was printed with 25% infill using PLA. You may then insert the QTPy into the case and fasten them to the board you’ll be using using screws if appropriate.


Connect the Female header cables

QTPy board with header cable and USB cable connected

Plug in the USB cable and connect the header cables to pins A0, A2, TX, and RX. Ensure that the cables do not intersect. For this project, I’ve wired and run them under a rubber mat to decrease unwanted charges and pin presses.



Strip and connect the raw end of the cable to foil

stripped cable under foil.

Ensure that a conductive end is available by either cutting and stripping a double female cable or using a female/ male cable. Fasten the conductive end under the foil. Purchasing a roll of adhesive aluminum foil is well worth the cost, however, standard foil will work as well.

You can also play around with other conductive materials such as fruits or conductive dough. Ensure that the materials are not too close to either other and that your wires are well insulated and spaced far enough from each other.


This project uses CircuitPython so you will need to install both the .uf2 file for the board as well as the HID libraries for sending key strokes to the computer.

Install the CircuitPython .uf2 file

Head over the the CircuitPython website and download the most current version of CP for this board. This tutorial is using 6.0.1.

Plugin the USB to your computer and press the reset button twice. You should now see a “QTPY_BOOT” drive visible.

Drag the .uf2 file (most likely from your downloads folder) into the drive. You will see a quick flash and the drive will reboot. You should now see the drive as “CIRCUITPY” drive.

Download and Install the HID Library

This project uses an additional library which will need to be downloaded and installed from the CP library website. You may download the CP Library Bundle which includes our needed HID library. Be sure to select the bundle version that matches the CP version you are using. For this tutorial, the 6.x version was downloaded and unzipped.

On your “CIRCUITPY” drive within the “lib” folder, create a new folder titled “adafruit_hid”. From the downloaded and unzipped library folder (most likely in your downloads folder), locate the “adafuit_hid” folder and copy/paste the __init__.mpy, keyboard.mpy, and keycode.mpy files into the QTpy folder.

finder window indicating path to HID folder
Path to downloaded adafruit_hid folder

Note: the QTPy may not have enough memory to store the full hid library and only these .mpy files are needed for this project.

Finder window showing the lib folder containing an adafruit_hid folder and .mpy files.
Library files pasted into QTPy board

Create the code.py file

CP looks for a code.py file upon completing the boot sequence and runs the code provided within this file. If you already have a code editor program of your choice, you may copy and paste the code below and save it to the “CIRCUITPY” drive. Note, the code the will execute a few seconds after the file is saved. Provide enough time for the action to complete.

If you have not worked with code before nor have a code editor of your choice, Adafruit provides a great step by step tutorial on how to get started using the beginner friendly MU editor. Visit their tutorial here.

Customizing your Code

If you would like to make use of the additional pins or change the pins being used. You may add pins by creating a new instance of a pin following this sequence. Be sure to use a novel name for the pin and indicate the desired pin number between the parenthesis using the board.pin# syntax. See example below:

touch0 = touchio.TouchIn(board.A0)

If you would like to change the keys that are being pressed, you may change the keycode that is being sent. For example, this code sends an up arrow to the computer when pin A0 is enabled. Here is a list of available keycodes you may use.

if touch0.value:
        print("Pin 0 touched")
        keyboard.press(Keycode.UP_ARROW)
        keyboard.release_all()

If you would like to speed up or slow down the rate that key presses are being sent to the computer, change the sleep duration on line 43. Increasing the number will slow the rate and decreasing the number will increase the rate. The time indicated is in seconds.

time.sleep(.5)

Once your code.py file is saved, the code will automatically begin executing. The pins will use the initial state for the baseline reading and attempt to detect any changes from that baseline. If you are getting unwanted key presses, try hitting the reset button to re- initialize the baseline state. Alternatively, you may need to play around with the location and conductivity of the materials you are using.

Scratch project screenshot

Check out this starter Scratch project to test out if your pins are properly connected and working.

This project uses the “arrow press” event block to trigger a costume change and speak text commands.

From there it’s up to your imagination! Scratch supports a wide variety of games and activities which may be customized and support uploading of images and sound files as well. Projects may be “remixed” and customized once you create a free account. Good luck!

Leave a Reply

Your email address will not be published. Required fields are marked *