In this tutorial, you will learn how to interact with the input pins by touch.

Parts you need in this tutorial:

  • Adafruit Feather M4 Express
  • 1M resistor
  • Male-male jumper wire
  • USB-Micro USB connector cable
  • Breadboard
  • (Optional) Copper tape
  • (Optional) Cardboard

Preview

Step 1: Code

Step 2: Circuit

(Optional) Step 3: Create a touch pad and try on other materials


Step 1: Code

Make sure you are ready with CircuitPython on your board. Check out here to Get Ready for Circuit Python on your M4 Express.

There are 6 touch capable pins (A0 – A5) on your M4 Express board. In this tutorial we will use A0 pin as example.

# NYUAD IM
# Desert Media Art
# Modified by Lydia Yan
#
# SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
# SPDX-License-Identifier: MIT
#
# Reference: https://learn.adafruit.com/circuitpython-essentials/circuitpython-cap-touch

"""CircuitPython Essentials Capacitive Touch example"""
import time
import board
import touchio

# Please change the pin code if you want to use other pins. (A0-A5)
touch_pad0 = board.A0

touch0 = touchio.TouchIn(touch_pad0)

while True:
    if touch0.value:
        print("A0 Touched!")
    time.sleep(0.05)

Github: Code

Step 2: Circuit

For M4 Express board, you will need to add a 1M (1 megaohm) resistor from the pin to ground.

No extra hardware is required, because you can directly touch the jumper attached to the pin.

When you touch the pin, the Serial Console may show the line “A0 Touched”.

(Optional) Step 3: Create a touch pad and try on other materials

Cut a piece of cardboard and attach the jumper wire to it using copper tape.

This touching pad enlarges the touching space as well as preventing you from touching the pins directly.

Now you have your little touching pad ready.

Try metal flatware, fruit or other foods, liquids, aluminum foil, plants, or other items lying around your desk!

Categories: Tutorial

0 Comments

Leave a Reply

Avatar placeholder

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