Touch pHAT: auto_leds

I got a script to to:

  • Control the leds of the Touch pHAT via mqtt as mqtt switches
  • send a payload via mqtt upon touch of the button

now the issue I have is that upon touching, the led turn on, and then off upon release, independently of the previous status of the led that was changed via mqtt.

how can i disable that? i would like the leds to be disconnected from the capacitive control.


import threading
import paho.mqtt.client as mqtt
import time
import touchphat

back_status = 0
a_status = 0
b_status = 0
c_status = 0
d_status = 0
enter_status = 0

def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))

# Set up and connect to MQTT broker
client = mqtt.Client(protocol=mqtt.MQTTv31)
client.username_pw_set("*********", password="************")
client.on_connect = on_connect
client.on_message = on_message
client.connect("************", 1883, 60)
client.publish("touchphat/MQTTclient/state", "ON")

@touchphat.on_touch(['Back', 'A', 'B', 'C', 'D', 'Enter'], handler=None)
def handle_touch(event):


I would think that function is in the init file. You’ll likely have to find it and edit it?
touch-phat/ at master · pimoroni/touch-phat (

Thank you alpha, does it mean to set them to false

auto_leds = False

And / or to comment as below

def _handle_press(event):
    global _on_press
    channel = = NAMES[channel]
    event.pad = NUMMAP[channel]

#    if auto_leds:
#        captouch.set_led_state(LEDMAP[channel], True)

    if callable(_on_press[channel]):
        except TypeError:

def _handle_release(event):
    global _on_release
    channel = = NAMES[channel]
    event.pad = NUMMAP[channel]

#    if auto_leds:
#        captouch.set_led_state(LEDMAP[channel], False)

    if callable(_on_release[channel]):
        except TypeError:

I did set auto_led = False on top of my script.

I also cloned into touch-phat, changed auto_leds to False, and python install it, but did not work: did this should have sorted any effect?

I did not try to comment the specific auto_leds lines yet.

Thank you for your support.

That I don’t know? It’s just a hunch, if I’m honest. It’s what I would look at if it was me. I don’t own one so your a bit on your own.

I edited the library in



auto_leds = False

and it worked. Not sure why would not work on top of my script

Might be how things are called up, order wise? What was in that file overrided what you did in your file.