Skip to content

GPIOs Configuration

José Antonio Jiménez Campos edited this page Apr 12, 2023 · 59 revisions

THIS IS STILL IN A BETA STAGE AND CAN CHANGE

Since HAA V12 Merlin, GPIOs behavior must be configured in an array to determine how hardware will work.

This array is declared by the key "io":[...] and contains other arrays. Each other array is a GPIO declaration.

By default, GPIOs are disabled, but they must be configured as INPUT, OUTPUT, OPEN-DRAIN... with different options, like pull-up resistors, modes, PWM...

Structure of "io":[...] array is:

"io" : [ 
  [ gpio, mode, pull-up/down, options... ], 
  [ gpio, mode, pull-up/down, options... ], 
  [ gpio, mode, pull-up/down, options... ], 
  ...
]
  • gpio is the GPIO number, according to hardware.
  • mode is the main operation mode for that gpio.

Depending of selected mode, different options are available.

ADC pin of ESP8266 doesn't need any declaration here.

- Options with * are available only for ESP32 models. They are incompatible with ESP8266 models.

Mode Description
0 Disable input and output (default at boot)
1 Input only
2 Output only
3 Output only with open-drain
4 * Output and input with open-drain
5 * Output and input
6 Input only with binary input (button/switch) support
7 PWM Software only output
8 PWM Software only output with open-drain

Depending on the hardware attached to a GPIO there may be a need for enabling an internal pull-up or pull-down resistor.

Pull-up/down Description
-1 Don't apply any pull-up/down setting to GPIO and leave it as SDK init.
0 Floating. Disable internal pull-up and pull-down resistors. (default)
1 Enable internal pull-up resistor
2 * Enable internal pull-down resistor
3 * Enable internal pull-up and pull-down resistors

Modes 2, 3, 4 and 5. Output options:

[ gpio, mode, pull-up/down, initial value ]

Initial value Description
0 Set GPIO output to LOW value (default)
1 Set GPIO output to HIGH value

Mode 6. Input only with binary input (button/switch) support options:

If MCP23017 interfaces are used, remember to use hundreds to select MCP23017 of GPIO. For example, GPIO 6 of first MCP23017 will be 106.

[ gpio, mode, pull-up/down, button mode, button filter ]

With some peripherals and hardware the actual GPIO signal may need to be inverted to ensure the correct action is performed when the GPIO changes state. This is normal for binary inputs that are active low.

Button mode Description
0 Normal input (default)
1 Inverted input
2 Normal input with pulse detection. Not available with MCP23017
3 Inverted with pulse detection. Not available with MCP23017

The binary input filter "f" can be set to any integer value between 1 (soft) and 255 (hard) to avoid interference such as debounce from the input when a button pressed.

Button filter Description
5 Default GPIO filter value (default)
1 to 255 Set filter value to avoid bounces and interferences. 1 is the softer value.

Modes 7 and 8. PWM Software options:

[ gpio, mode, pull-up/down, initial value, PWM mode, PWM dithering ]

Initial value Description
0 Set initial PWM output value to 0 (default)
0 to 65535 Initial PWM output value
PWM Mode Description
0 Normal Trailing (default)
1 Inverted Trailing
2 Normal Leading
3 Inverted Leading
PWM Dithering Description
0 No PWM Dithering (default)
0 to 32768 Deformation of PWM to avoid noises and armonic interferences.
Clone this wiki locally