four_button - wolfen351/public-micropython-iot-platform GitHub Wiki

The four_button module is designed to expose the functionality of the 4 built in buttons on the esp32r4 development board. It sends the fact that the button is pressed as telemetry as well as a command for other modules to respond to if they wish.

UI

The 4 buttons are displayed on the UI like this:

4 buttons ui

Hardware / Pinout

The hardware is usually already soldered to the main board. This is designed to allow the user to assign a function to the button. The pinout is board specific, and can be found in the documentation for the board.

Here is the board I was using for this:

board image

For example the esp32r4 board has the following pinout:

  • Button 1 -> GPIO 34
  • Button 2 -> GPIO 35
  • Button 3 -> GPIO 36
  • Button 4 -> GPIO 39

The buttons already have the correct pullup/pulldown resistors on the board.

The buttons go LOW when pressed, but this module inverts the logic so that the telemetry is sent as 1 when the button is pressed.

Configuration

This module is configured by setting the four_button key in the profile.json file. The value of this key is a dictionary with the following keys:

"four_button": {
    "commandsOn": [ "/relay/flip/1","/relay/flip/2","/relay/flip/3","/relay/flip/4"],
    "commandsOff": [ "","","",""]
},

The commandsOn key is an array of commands that are sent when the button is pressed. The string in position 0 is sent when button 1 is pressed, the string in position 1 is sent when button 2 is pressed, and so on.

The commandsOff key is an array of commands that are sent when the button is released. The string in position 0 is sent when button 1 is released, the string in position 1 is sent when button 2 is released, and so on.

The commands are sent to the command queue and can be consumed by other modules.

Currently the pinout (GPIO pins 34, 35, 36, 39) is hardcoded and cannot be changed via configuration.

Telemetry provided

The main point of this module is to provide telemetry showing the current state of the buttons. It provides this as telemetry on each cycle.

def getTelemetry(self):
    return {
        "button/B1" : self.States[0],
        "button/B2" : self.States[1],
        "button/B3" : self.States[2],
        "button/B4" : self.States[3]
    }

Telemetry consumed

This module consumes no telemetry from other modules.

Commands provided

This module provides the following commands:

  • /button/B1/1 - Button 1 is pressed
  • /button/B1/0 - Button 1 is released
  • /button/B2/1 - Button 2 is pressed
  • /button/B2/0 - Button 2 is released
  • /button/B3/1 - Button 3 is pressed
  • /button/B3/0 - Button 3 is released
  • /button/B4/1 - Button 4 is pressed
  • /button/B4/0 - Button 4 is released

The module will also send the custom commands that have been specified in the profile.json file.

These commands are sent to the command queue and can be consumed by other modules.

Commands consumed

This module does not consume any commands from other modules.

⚠️ **GitHub.com Fallback** ⚠️