Skip to content

Instantly share code, notes, and snippets.

@todbot
Created October 15, 2024 22:37
Show Gist options
  • Save todbot/8cabb198af261e84de0f3b33ae1826b0 to your computer and use it in GitHub Desktop.
Save todbot/8cabb198af261e84de0f3b33ae1826b0 to your computer and use it in GitHub Desktop.
Debug raw touchio values in CircuitPython
# touchio_debug_code.py -- debug raw touchio values
# 15 Oct 2024 - @todbot / Tod Kurt
# This sketch shows the raw_value and threshold value for each
# touchio TouchIn input, as well as the normal ".value" boolean
# Hopefully this will help to debug touchio circuits.
import time
import board
import touchio
# these pins are for the first 8 picotouch midi board pads,
# your board will likely use different pins
touch_pins = (
board.GP0, board.GP1, board.GP2, board.GP3,
board.GP4, board.GP5, board.GP6, board.GP7,
)
touch_ins = [] # holder of all the touchio objects
for pin in touch_pins:
print("creating TouchIn for pin", pin)
touch_in = touchio.TouchIn(pin)
touch_ins.append(touch_in)
while True:
# print out threshold and raw value for each pin
for i, touch_in in enumerate(touch_ins):
raw_value = touch_in.raw_value
threshold = touch_in.threshold
touched = touch_in.value # same as "if raw_value > threshold"
touched_str = "*" if touched else " "
print("%4d/%4d%s " % (raw_value, threshold, touched_str), end='')
print()
time.sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment