I want a simple matrix keypad with tactile buttons, but the button of row 0 column 0 does not work.
I used this schema to connect my tactile buttons:
Right now i’ve got a simple matrix on a breadboard with 2 rows of 4 columns of tactile switches, with a led that will be switched on when the buttons are pressed.
When I change the wires of the rows (GPIO5 becomes R1 and GPIO2 becomes R0), still button R0 C0 is the one that does not work. It will work, when i manually touch a cable that is connected to the GPIO of R0 or C0. When i remove the connector of R1, all buttons on R0 will also work.
Measuring the resistance between the GPIOs of R0 en C0 shows that the button/cabling is not the problem.
Why is it that when i add myself parallel to the circuit of button R0C0 that it registers the click? And what should i do to have it functioning without me clinging on to the circuit?
# Board: Generic ESP32-C3 Board (Generic)
# Definition: definitions/boards/generic-esp32c3/manifest.yaml
esphome:
name: matrix-buttons
friendly_name: Matrix buttons
on_boot:
- priority: 250
then:
- lambda: |-
id(last_active) = millis() / 1000;
auto cause = esp_sleep_get_wakeup_cause();
if (cause == ESP_SLEEP_WAKEUP_EXT0) {
ESP_LOGI("main", "Device woke up by EXT0");
} else if (cause == ESP_SLEEP_WAKEUP_TIMER) {
ESP_LOGD("main", "Device woke up by timer.");
} else {
ESP_LOGD("main", "Device woke up by other cause: %d", cause);
}
- delay: 1s
- script.execute:
id: apply_rgb_color
esp32:
variant: esp32c3
framework:
type: esp-idf
logger:
ota:
- platform: esphome
captive_portal:
globals:
- id: last_active
type: int
restore_value: no
initial_value: '0'
script:
- id: reset_idle_timer
then:
- light.turn_on: rgb_led
- lambda: |-
id(last_active) = millis() / 1000;
- id: led_on
mode: single
then:
- light.turn_on: rgb_led
- id: led_off
mode: single
then:
- delay: 50ms
- light.turn_off: rgb_led
- id: button_event
parameters:
button: string
type: string
then:
- script.execute: led_on
- script.execute: reset_idle_timer
- homeassistant.event:
event: esphome.remote_button_pressed
data:
button: !lambda 'return button;'
type: !lambda 'return type;'
- id: apply_rgb_color
then:
- lambda: |-
std::string color = "Red";
auto index = id(rgb_color_select).active_index();
if (index.has_value()) {
auto option = id(rgb_color_select).at(index.value());
if (option.has_value()) {
color = option.value();
} else {
ESP_LOGE("alarmdisplay", "Index %d does not exist", index.value());
}
} else {
ESP_LOGE("alarmdisplay", "There is no active index at rgb_color_select");
}
auto call = id(rgb_led).turn_on();
if (color == "Red") {
call.set_rgb(1.0, 0.0, 0.0);
} else if (color == "Green") {
call.set_rgb(0.0, 1.0, 0.0);
} else if (color == "Blue") {
call.set_rgb(0.0, 0.0, 1.0);
}
call.perform();
id(rgb_led).turn_off().perform();
deep_sleep:
id: deep_sleep_ctrl
sleep_duration: 2800 min
wakeup_pin:
number: GPIO5
inverted: false
allow_other_uses: true
interval:
- interval: 60s
then:
- if:
condition:
lambda: return (millis() / 1000) - id(last_active) >= 120;
then:
- deep_sleep.enter: deep_sleep_ctrl
output:
- platform: ledc
pin: GPIO0
id: red_output
- platform: ledc
pin: GPIO1
id: green_output
- platform: ledc
pin: GPIO3
id: blue_output
light:
- platform: rgb
default_transition_length: 25ms
name: "RGB LED"
id: rgb_led
red: red_output
green: green_output
blue: blue_output
select:
- platform: template
id: rgb_color_select
name: "Led Color"
optimistic: true
restore_value: true
options:
- "Red"
- "Green"
- "Blue"
on_value:
then:
- logger.log:
format: "Chosen option: %s (index %d)"
args: ["x.c_str()", "i"]
- script.execute:
id: apply_rgb_color
matrix_keypad:
id: mykeypad
rows:
- pin:
number: GPIO5
allow_other_uses: true
- pin: GPIO2
columns:
- pin: GPIO20
- pin: GPIO6
- pin: GPIO7
- pin: GPIO8
keys: "12345678"
has_diodes: false
on_key:
- lambda: ESP_LOGI("KEY", "key %d pressed", x);
binary_sensor:
- platform: matrix_keypad
keypad_id: mykeypad
id: back
name: "Back"
key: 1
on_multi_click:
- timing:
- ON for at most 350ms
then:
- script.execute:
id: button_event
button: "back"
type: "single"
- timing:
- ON for at least 500ms
then:
- script.execute:
id: button_event
button: "back"
type: "long"
on_release:
then:
- script.execute: led_off
- platform: matrix_keypad
keypad_id: mykeypad
id: power
name: "Power"
key: 2
on_multi_click:
- timing:
- ON for at most 350ms
then:
- script.execute:
id: button_event
button: "power"
type: "single"
- timing:
- ON for at least 500ms
then:
- script.execute:
id: button_event
button: "power"
type: "long"
on_release:
then:
- script.execute: led_off
- platform: matrix_keypad
keypad_id: mykeypad
id: home
name: "Home"
key: 3
on_multi_click:
- timing:
- ON for at most 350ms
then:
- script.execute:
id: button_event
button: "home"
type: "single"
- timing:
- ON for at least 500ms
then:
- script.execute:
id: button_event
button: "home"
type: "long"
on_release:
then:
- script.execute: led_off
- platform: matrix_keypad
keypad_id: mykeypad
id: play_pause
name: "Play Pause"
key: 4
on_multi_click:
- timing:
- ON for at most 350ms
then:
- script.execute:
id: button_event
button: "play_pause"
type: "single"
- timing:
- ON for at least 500ms
then:
- script.execute:
id: button_event
button: "play_pause"
type: "long"
on_release:
then:
- script.execute: led_off
- platform: matrix_keypad
keypad_id: mykeypad
id: up
name: "Up"
key: 5
on_multi_click:
- timing:
- ON for at most 350ms
then:
- script.execute:
id: button_event
button: "up"
type: "single"
- timing:
- ON for at least 500ms
then:
- script.execute:
id: button_event
button: "up"
type: "long"
on_release:
then:
- script.execute: led_off
- platform: matrix_keypad
keypad_id: mykeypad
id: down
name: "Down"
key: 6
on_multi_click:
- timing:
- ON for at most 350ms
then:
- script.execute:
id: button_event
button: "down"
type: "single"
- timing:
- ON for at least 500ms
then:
- script.execute:
id: button_event
button: "down"
type: "long"
on_release:
then:
- script.execute: led_off
- platform: matrix_keypad
keypad_id: mykeypad
id: volume_down
name: "Volume down"
key: 7
on_multi_click:
- timing:
- ON for at most 350ms
then:
- script.execute:
id: button_event
button: "volume_down"
type: "single"
- timing:
- ON for at least 500ms
then:
- script.execute:
id: button_event
button: "volume_down"
type: "long"
on_release:
then:
- script.execute: led_off
- platform: matrix_keypad
keypad_id: mykeypad
id: volume_up
name: "Volume Up"
key: 8
on_multi_click:
- timing:
- ON for at most 350ms
then:
- script.execute:
id: button_event
button: "volume_up"
type: "single"
- timing:
- ON for at least 500ms
then:
- script.execute:
id: button_event
button: "volume_up"
type: "long"
on_release:
then:
- script.execute: led_off

