Stemma qt / qwiic direct to GPIO pins for capacitive touch sensor

Hmm, seems like you need to set the pins as well as the bus, like this guy does (though this example is in C++ instead of Python)

Having a quick look through the python code, it appears it’s not enough to just set the pins, you also need to set the frequency or it’ll ignore your pin request inputs.

You’ll also need to import from machine I2C, Pin, or alternatively, just import machine if you’ve got the space. Then you can set your sda and scl pins, and create your object using:
touchSensor = PiicoDev_CAP1203(touchmode='single', freq=400000, sda=Pin(0), scl=Pin(1))

Here are some examples from the documentation:

from machine import Pin

p0 = Pin(0, Pin.OUT)    # create output pin on GPIO0
p0.on()                 # set pin to "on" (high) level
p0.off()                # set pin to "off" (low) level
p0.value(1)             # set pin to on/high

p2 = Pin(2, Pin.IN)     # create input pin on GPIO2
print(p2.value())       # get value, 0 or 1

p4 = Pin(4, Pin.IN, Pin.PULL_UP) # enable internal pull-up resistor
p5 = Pin(5, Pin.OUT, value=1) # set pin high on creation
from machine import Pin, I2C

i2c = I2C(0)   # default assignment: scl=Pin(9), sda=Pin(8)
i2c = I2C(1, scl=Pin(3), sda=Pin(2), freq=400_000)

PS, here are the default I2C values if you don’t specify them:
image

See:
https://docs.micropython.org/en/latest/library/machine.Pin.html
https://docs.micropython.org/en/latest/library/machine.I2C.html

https://docs.micropython.org/en/latest/rp2/quickref.html#general-board-control

5 Likes