Closed Vacant0mens closed 1 year ago
The TTP223 module as pictured has two solder-bridge pads on the back labelled A and B. These determine whether a touch drives the OUT pin HIGH or LOW, and whether it's momentary or latching (stays on until pressed again). https://github.com/mcauser/micropython-ttp223#trigger-mode
On my TTP223 both A and B are no bridged, which means: Momentary, output HIGH (when pressed).
The PCF8575's interrupt should fire on any rising or falling edge when the pin is in input mode.
Here's a working example on my TinyPICO.
TinyPICO | PCF8575 | TTP223 |
---|---|---|
3V3 | VCC | VCC |
GND | GND | GND |
22 | SCL | |
21 | SDA | |
5 | INT | |
P0 | OUT |
import pcf8575
from machine import Pin, I2C
i2c = I2C(scl=Pin(22), sda=Pin(21))
pcf = pcf8575.PCF8575(i2c, 0x20)
# set all pins as inputs (HIGH)
pcf.port = 0xffff
# make sure the pin is being pulled up as the PCF int will pull it LOW when it fires
p5 = Pin(5, Pin.IN, Pin.PULL_UP)
print(p5.value())
# shows 1 (high)
print(pcf.port)
# shows 65534 or 0xFFFE
# meaning all pins are HIGH except for P0 which is being pulled LOW by the TTP223
# simple interrupt handler that prints the INT pin value and the PCF pin values
def handler(p):
print(f'Pin5: {p5.value()}, Port: {pcf.port}')
# trigger on rising and falling edges
p5.irq(trigger=Pin.IRQ_RISING|Pin.IRQ_FALLING, handler=handler)
# press and hold and the TTP223 button prints
Pin5: 0, Port: 65535
Pin5: 1, Port: 65535
# release and the TTP223 button prints
Pin5: 0, Port: 65534
Pin5: 1, Port: 65534
# switch int off
p5.irq(None)
# trigger on falling edge only
p5.irq(trigger=Pin.IRQ_FALLING, handler=handler)
# pressing the TTP223 button prints
# Pin5: 0, Port: 65535
# releasing the TTP223 button prints
# Pin5: 0, Port: 65534
Make sure you pull Pin 15 HIGH for it to detect when the PCF pulls it LOW on INT.
On the ESP8266, GPIO15 is usually pulled to GND as BOOT fails if it's pulled HIGH. (Your script can set it HIGH after booting, but you shouldn't use a hardware pull up (resistor) to be safe) https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/
Maybe it's better if you use a different GPIO for the INT. GPIO0 and GPIO2 are normally pulled HIGH and driven LOW.
If I'm not using SPI, I could use pin 14 for my interrupts, right?
Sure can. If not using SPI, it's just a regular GPIO pin.
That worked! thank you! Seems like using the wrong pin is the bane of my existence.
I have the
PCF-8575
connected to anESP8266
using standard I2C (pins 4 and 5 for SDA and SCL respectively, and pin 15 for the interrupts). The PCF is sharing Vcc and GND from the ESP with aTTP223
-based capacitive touch button (specifically a BA6-variant-based board which has 3 pins: Vcc, Gnd, and Data), which I have connected to P0. I've also tried passing Vcc from the PCF to the TTP button, as well as using 5v and 3v for Vcc (in separate tests).Everything seems to work, except that the PCF isn't sending interrupts to the ESP8266.
The TTP board has an LED that lights up when the button is touched (so I know that's working), and I can see it sending voltage when it does so (using a multimeter), and I followed the examples in my python code for interrupts in this repo, but I don't see any interrupts coming in when I run my code.
The TTP button works great when directly connected to the ESP8266, but I need to use more buttons than the ESP has pins available for, so I was hoping this expander would be a good option.
I'm not sure what I'm doing wrong here. I was hoping that this would be fairly straight forward, but it's now been days of troubleshooting and I'm out of ideas. 🤷
Specific parts/sheets: TTP223 Data Sheet TTP223-based board from Amazon This PCF-8575-based board, also from Amazon Lolin D1 Mini v4 (ESP8266)