element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Holiday Special 20
  • Challenges & Projects
  • Project14
  • Holiday Special 20
  • More
  • Cancel
Holiday Special 20
Blog A QT Py Christmas - add Cap Sense Buttons
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Holiday Special 20 to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ralphjy
  • Date Created: 14 Dec 2020 1:16 AM Date Created
  • Views 1688 views
  • Likes 5 likes
  • Comments 4 comments
  • oled
  • cap sense
  • neopixel ring
  • holidayspecial20ch
  • adafruit qt py
Related
Recommended

A QT Py Christmas - add Cap Sense Buttons

ralphjy
ralphjy
14 Dec 2020

The SAMD21 processor that is used on the QT Py has a built in Peripheral Touch Controller (PTC) that can detect touch on external capacitive sensors.  The PTC has a mutual-capacitance mode to sense touch on an x-y matrix and a self-capacitance mode to detect touch on a single point (pin).   The QT Py is in the 32 pin package so there are 6 capacitive touch pins available in self-capacitance mode (A0-A3,A6,A7).

 

Here is the PTC Block Diagram from the SAMD21 spec

image

Adafruit has a QTouch compatible Arduino library for the SAMD21.  The library is FreeTouch: https://github.com/adafruit/Adafruit_FreeTouch

QTouch is Microchip's library for the PTC.

 

I decided that I would add 2 touch buttons to the project - one to change the NeoPixel pattern and one to play a sound (haven't implemented that yet).

I am going to use thumb tacks as my buttons and I printed a button holder that I could add to my ornament base.

image

 

Setting up the PTC with the FreeTouch library is reasonably straightforward.  You initialize the button objects with 4 parameters:

  1. Input pin number
  2. Number of oversamples (for averaging)
    • OVERSAMPLE_1
    • OVERSAMPLE_2
    • OVERSAMPLE_4
    • OVERSAMPLE_8
    • OVERSAMPLE_16
    • OVERSAMPLE_32
    • OVERSAMPLE_64
  3. Discharge resistor size
    • RESISTOR_0
    • RESISTOR_20K
    • RESISTOR_50K
    • RESISTOR_100K
  4. Frequency mode - set frequency mode to reject synchronous noise (I haven't found a good description of these modes)
    • FREQ_MODE_NONE
    • FREQ_MODE_HOP
    • FREQ_MODE_SPREAD
    • FREQ_MODE_SPREAD_MEDIAN

 

So, I configured two available pins A0 and A1 (no external components required other than the wire to the thumbtack):

Adafruit_FreeTouch qt_1 = Adafruit_FreeTouch(A0, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);

Adafruit_FreeTouch qt_2 = Adafruit_FreeTouch(A1, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);

 

Initialized them:

qt_1.begin()

qt_2.begin()

 

Then set variables to store the measured values:

long newState =  qt_1.measure();

long switchState = qt_2.measure();

 

I observed that the measured value averaged around 500 +/-50 with no touch and between 800-1000 when I touched the thumbtack, so I added a touch threshold of 750 which seems to work consistently.

 

Here is a very short video demonstrating using the left button to switch NeoPixel patterns.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Something I need to figure out is how to trigger an interrupt when the touch is detected.  Otherwise I'll need to check for button "presses" while I'm running the NeoPixel patterns continuously.

 

Links to previous blogs

A QT Py Christmas

  • Sign in to reply

Top Comments

  • fmilburn
    fmilburn over 4 years ago +2
    Pretty cool. I added in a QT Py on a recent order to Adafruit after reading your posts and will have to try this out.
  • neilk
    neilk over 4 years ago +2
    Neat! Neil
  • ralphjy
    ralphjy over 4 years ago in reply to fmilburn +2
    These little boards are a lot of fun . I'm sure you'll like the QT Py. Seeed offers a couple of breakout boards that are useful for prototyping programs - especially if you use Grove sensors. I've only…
  • shabaz
    shabaz over 4 years ago

    Hi Ralph,

     

    Great idea to use thumb tacks (or drawing pins as they are called here) as touch sensing plates : )

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ralphjy
    ralphjy over 4 years ago in reply to fmilburn

    These little boards are a lot of fun image.  I'm sure you'll like the QT Py.

     

    Seeed offers a couple of breakout boards that are useful for prototyping programs - especially if you use Grove sensors.

     

    I've only used the Grove shield https://www.seeedstudio.com/Grove-Shield-for-Seeeduino-XIAO-p-4621.html ,

    but I've ordered an Expansion board https://www.seeedstudio.com/Seeeduino-XIAO-Expansion-board-p-4746.html  .

     

    The Expansion board is nice because it adds an OLED, micro SD card, and RTC.  I'll post when I get it and try it out.

     

    These boards take forever to get from China, but Seeed has started to carry them in their US warehouse so you can get them in about a week.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • neilk
    neilk over 4 years ago

    Neat!

     

    Neil

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fmilburn
    fmilburn over 4 years ago

    Pretty cool.  I added in a QT Py on a recent order to Adafruit after reading your posts and will have to try this out.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube