Internal GPIO handling¶
The ESP module can control things with it’s build-in GPIO output pins. We can turn these on or off or we can set these pins to a special pulse modulated value (PWM output). And it’s also possible to send short pulses (single pulse) to one of these pins to control specific devices that are switched with a single short high or low signal.
Plugin details¶
Type: GPIO handling
Name: Internal
Status: NORMAL CLIMATE
GitHub: P001_Switch.ino
Maintainer: Core
Used libraries: .
Supported hardware¶
Relay, Servo motor, Buzzer (RTTTL), Piezo element, Speaker, Relay, Servo motor, Level converter
Switch: Switch
Doorswitch: Door switch
Relay: Relay
PIR: PIR sensor
Servo: Servo motor
Buzzer: Buzzer (RTTTL)
Speaker RTTTL: Speaker
Piezo element: Piezo element
Commands available¶
Internal GPIO¶
Internal GPIO handling NORMAL CLIMATE
Supported hardware: Relay, Servo motor
Command (GPIO/Value) |
Extra information |
---|---|
GPIO: 0 … <max supported GPIO pin> State: 2 (HIGH-Z, input) 1 (HIGH, output) 0 (LOW, output) |
Basic on/off.. We can control a pin with simple http URL commands. To change the pin to high or low steady output. Setting GPIO to 2 means that it will be able to detect low level relays (with high impedance, Z). |
GPIO: 0 … <max supported GPIO pin> |
Toggle on/off.. Toggle the current (output) state of the given GPIO pin. When executed, it changes the pin mode to output, for output-capable GPIO pins. |
GPIO: All GPIO pins with output capabilities State: 1/0 Duration low/high: 1 … 999 S Nr of Repeats: |
To send a *long* pulse to a certain pin.. A long pulse is basically the same as the plain pulse. Duration is defined in seconds, which makes it more suitable for longer duration. This command is not blocking, but will send 2 events to start and stop the pulse. This may have some variation depending on the system load of the module. Variation is typically up-to 10 msec, but may be up-to a second, depending on active plugins and controllers performing blocking operations. Changed: 2022/10/15
Example: |
GPIO: All GPIO pins with output capabilities State: 1/0 Duration low/high: 1 … 15000 msec Nr of Repeats: |
To send a (non blocking) *long* pulse to a certain pin. A Changed: 2022/10/15
Example: |
GPIO: All GPIO pins with output capabilities State: 1/0 Duration: 0 … 1000 msec |
To send a *short* pulse to a certain pin. Example to send an active high (1) pulse on GPIO 14 for 500 mSeconds. Pulse duration is in milliseconds. State is 1 or 0. N.B. this is a blocking call, meaning no other actions will be performed during the pulse. |
ESP8266 GPIO: 0 … 15 ESP32 GPIO: All GPIO pins with output capabilities Duty: 0 … 1023 Duration: 100 … 15000 msec (optional) Frequency: 100 … 40000 Hz (optional) |
To set a certain PWM level. If you have set a certain GPIO to a PWM level and want to use it as a regular HIGH/LOW pin you need to reset by setting the PWM level to 0. Duration (in msec) parameter will create a fading. Value of 0 will not set a duration. Frequency (in Hz) will be set to 1000 Hz when not given. Frequencies above 30 kHz are not stable and will likely crash the ESP. |
ESP8266 GPIO: 0 … 15 ESP32 GPIO: All GPIO pins with output capabilities Servo: 1/2 Position: -180 … 180 (see warning below) |
To control a servo motor.
Builds before 2020/11/22 only supported a maximum of 2 servos. Later builds allow more and no longer need the Warning Most servos are not able to turn full 360°! Normally the servos are able to go from -90° to 90°, some rare servos do allow for -135° to 135°. A position value of 9000 will stop the PWM signal. This can be useful to save energy on servos which do not need power to remain at the same position. |
GPIO: 0 … <max supported GPIO pin> |
To monitor a GPIO state. By the use of the command you will receive events when the GPIO state of that pin is changed from 1 to 0 and from 0 to 1. |
GPIO: 0 … <max supported GPIO pin> |
To cancel the monitor of a GPIO state. By the use of the command you will stop receiving events when the GPIO state of that pin is changed from 1 to 0 and from 0 to 1. |
GPIO: 0 … <max supported GPIO pin> |
Returns the status of a pin. By the use of the command you will receive the status of the relevant pin. |
External MCPGPIO¶
Command (MCPGPIO/Value) |
Extra information |
---|---|
MCPGPIO: 1 … 128 State: 2 (HIGH-Z, input) 1 (HIGH, output) 0 (LOW, output) -1 (OFFLINE, disconnected) |
Basic on/off.. We can control a pin with simple http URL commands. To change the pin to high or low steady output. Setting MCPGPIO to 2 means that it will be able to detect low level relays (with high impedance, Z). |
MCPGPIO: 1 … 128 |
Toggle on/off.. Toggle the current (output) state of the given MCPGPIO pin. When executed, it changes the pin mode to output. |
MCPGPIO: 1 … 128 State: 1/0 Duration: 1 … 999 S |
To send a *long* pulse to a certain pin.. A long pulse is basically the same as the plain pulse. Duration is defined in seconds, which makes it more suitable for longer duration. This command is not blocking, but will send 2 events to start and stop the pulse. This may have some variation depending on the system load of the module. Variation is typically up-to 10 msec, but may be up-to a second, depending on active plugins and controllers performing blocking operations. |
MCPGPIO: 1 … 128 State: 1/0 Duration: 10 … 15000 msec |
To send a *long* pulse to a certain pin.
A |
MCPGPIO: 1 … 128 State: 1/0 Duration: 0 … 1000 msec |
To send a *short* pulse to a certain pin. Example to send an active high (1) pulse on MCPGPIO 14 for 500 mSeconds. Pulse duration is in milliseconds. State is 1 or 0. N.B. this is a blocking call, meaning no other actions will be performed during the pulse. |
MCPGPIO: 1 … 128 |
Returns the status of a pin. By the use of the command you will receive the status of the relevant pin. |
MCPGPIO: 1 … 128 |
To monitor a MCPGPIO state. By the use of the command you will receive events when the state of that pin is changed from 1 to 0 and from 0 to 1. |
MCPGPIO: 1 … 128 |
To cancel the monitor of a MCPGPIO state. By the use of the command you will stop receiving events when the state of that pin is changed from 1 to 0 and from 0 to 1. |
MCPGPIOfrom/MCPGPIOto: 1 … 128 (end has to be > start) |
To monitor a MCPGPIO state. By the use of the command you will receive events when the state of that pin is changed from 1 to 0 and from 0 to 1. |
MCPGPIO start/MCPGPIO end: 1 … 128 (end has to be > start) |
To cancel the monitor of a MCPGPIO state. By the use of the command you will stop receiving events when the state of that pin is changed from 1 to 0 and from 0 to 1. |
MCPGPIO start pin: 1 … 128
MCPGPIO end pin: 1 … 128 (end has to be > start)
value: 0 or 1
bitmask:
- if not present assume to operate in all pins
- if present is used as a mask (1=update, 0=do not update)
- pins are numbered from right to left (i.e. 87654321)
- if number of bit lower than number of pins, then padded with 0
- if number of bit higher than number of pins, then it’s truncated
|
Change the status of a pin for a given range applying the given mask
examples:
- mcpgpioRange,1,8,1 -> set pins 1 to 8 to 1
- mcpgpioRange,3,12,1 -> set pins 3 to 12 to 1
- mcpgpioRange,5,17,0 -> set pins 5 to 17 to 0
- mcpgpioRange,3,12,1,525 or mcpgpioRange,3,12,1,0b0100001101
mask = ‘0100001101’
write pattern after mask = ‘x1xxxx11x1’ where x indicates that the pin will not be changed
(only pin 1,3,4,9 will be changed)
- mcpgpioRange,3,12,1,973 or mcpgpioRange,3,12,1,0b1111001101
mask = 973 = ‘1111001101’
write pattern after mask = ‘1111xx11x1’ where x indicates that the pin will not be changed
|
MCPGPIO start pin: 1 … 128
MCPGPIO end pin: 1 … 128
write pattern: it’s a write pattern. Write 0 or 1.
- Example: use decimal number 15 (in binary is 00001111) to set to 1 pin 1,2,3 and 4 and to set to 0 pins 5,6,7,8
- if number of bit lower than number of pins, then padded with 0;
- if number of bit higher than number of pins, then it’s truncated.
bitmask:
- if not present assume to operate in all pins
- if present is used as a mask (1=update, 0=do not update)
- if number of bit lower than number of pins, then padded with 0
- if number of bit higher than number of pins, then it’s truncated
|
Change the status of a pin for a given range applying the given mask
examples:
- mcpgpioPattern,1,8,13
write pattern = ‘1101’ that will be padded as: ‘0000001101’
mask not present, assume mask = ‘1111111111’
- mcpgpioPattern,3,12,13
write pattern = ‘1101’ that will be padded as: ‘0000001101’
mask not present, assume mask = ‘1111111111’
- mcpgpioPattern,3,12,525
write pattern = 525 = ‘100001101’
mask not present, assume mask = ‘1111111111’
- mcpgpioPattern, 3, 12, 525, 973
write pattern = 525 = ‘100001101’
mask = 973 = ‘1111001101’
write pattern after mask = ‘1000xx11x1’ where x indicates that the pin will not be changed
|
MCPGPIO: 1 … 128
mode:
0 = OUTPUT
1 = INPUT PULLUP
2 = INPUT
|
To change the mode of an MCPGPIO pin. example: mcpMode,1,0 (set pin 1 as output)
|
MCPGPIO start pin: 1 … 128
MCPGPIO end pin: 1 … 128 (end has to be > start)
mode:
0 = OUTPUT
1 = INPUT PULLUP
2 = INPUT
|
To change the mode of an MCPGPIO range of pin. example: mcpModeRange,1,8,0 (set pin 1 to 8 as output)
|
External PCFGPIO¶
Command (PCFGPIO/Value) |
Extra information |
---|---|
PCFGPIO: 1 … 128 State: 2 (HIGH-Z, input) 1 (HIGH, output) 0 (LOW, output) -1 (OFFLINE, disconnected) |
Basic on/off.. We can control a pin with simple http URL commands. To change the pin to high or low steady output. Setting PCFGPIO to 2 means that it will be able to detect low level relays (with high impedance, Z). |
PCFGPIO: 1 … 128 |
Toggle on/off.. Toggle the current (output) state of the given PCFGPIO pin. When executed, it changes the pin mode to output. |
PCFGPIO: 1 … 128 State: 1/0 Duration: 1 … 999 S |
To send a *long* pulse to a certain pin.. A long pulse is basically the same as the plain pulse. Duration is defined in seconds, which makes it more suitable for longer duration. This command is not blocking, but will send 2 events to start and stop the pulse. This may have some variation depending on the system load of the module. Variation is typically up-to 10 msec, but may be up-to a second, depending on active plugins and controllers performing blocking operations. |
PCFGPIO: 1 … 128 State: 1/0 Duration: 10 … 15000 msec |
To send a *long* pulse to a certain pin.
A |
PCFGPIO: 1 … 128 State: 1/0 Duration: 0 … 1000 msec |
To send a *short* pulse to a certain pin. Example to send an active high (1) pulse on PCFGPIO 14 for 500 mSeconds. Pulse duration is in milliseconds. State is 1 or 0. N.B. this is a blocking call, meaning no other actions will be performed during the pulse. |
PCFGPIO: 1 … 128 |
Returns the status of a pin. By the use of the command you will receive the status of the relevant pin. |
PCFGPIO: 1 … 128 |
To monitor a PCFGPIO state. By the use of the command you will receive events when the state of that pin is changed from 1 to 0 and from 0 to 1. |
PCFGPIO: 1 … 128 |
To cancel the monitor of a PCFGPIO state. By the use of the command you will stop receiving events when the state of that pin is changed from 1 to 0 and from 0 to 1. |
PCFGPIO start/PCFGPIO end: 1 … 128 (end has to be > start) |
To monitor a PCFGPIO state. By the use of the command you will receive events when the state of that pin is changed from 1 to 0 and from 0 to 1. |
PCFGPIO start/PCFGPIO end: 1 … 128 (end has to be > start) |
To cancel the monitor of a PCFGPIO state. By the use of the command you will stop receiving events when the state of that pin is changed from 1 to 0 and from 0 to 1. |
PCFGPIO start pin: 1 … 128
PCFGPIO end pin: 1 … 128 (end has to be > start)
value: 0 or 1
bitmask:
- if not present assume to operate in all pins
- if present is used as a mask (1=update, 0=do not update)
- pins are numbered from right to left (i.e. 87654321)
- if number of bit lower than number of pins, then padded with 0
- if number of bit higher than number of pins, then it’s truncated
|
Change the status of a pin for a given range applying the given mask
examples:
- pcfgpioRange,1,8,1 -> set pins 1 to 8 to 1
- pcfgpioRange,3,12,1 -> set pins 3 to 12 to 1
- pcfgpioRange,5,17,0 -> set pins 5 to 17 to 0
- pcfgpioRange,3,12,1,525 or pcfgpioRange,3,12,1,0b0100001101
mask = ‘0100001101’
write pattern after mask = ‘x1xxxx11x1’ where x indicates that the pin will not be changed
(only pin 1,3,4,9 will be changed)
- pcfgpioRange,3,12,1,973 or pcfgpioRange,3,12,1,0b1111001101
mask = 973 = ‘1111001101’
write pattern after mask = ‘1111xx11x1’ where x indicates that the pin will not be changed
|
PCFGPIO start pin: 1 … 128
PCFGPIO end pin: 1 … 128 (end has to be > start)
write pattern: it’s a write pattern. Write 0 or 1.
- Example: use decimal number 15 (in binary is 00001111) to set to 1 pin 1,2,3 and 4 and to set to 0 pins 5,6,7,8
- if number of bit lower than number of pins, then padded with 0;
- if number of bit higher than number of pins, then it’s truncated.
bitmask:
- if not present assume to operate in all pins
- if present is used as a mask (1=update, 0=do not update)
- if number of bit lower than number of pins, then padded with 0
- if number of bit higher than number of pins, then it’s truncated
|
Change the status of a pin for a given range applying the given mask
examples:
- pcfgpioPattern,1,8,13
write pattern = ‘1101’ that will be padded as: ‘0000001101’
mask not present, assume mask = ‘1111111111’
- pcfgpioPattern,3,12,13
write pattern = ‘1101’ that will be padded as: ‘0000001101’
mask not present, assume mask = ‘1111111111’
- pcfgpioPattern,3,12,525
write pattern = 525 = ‘100001101’
mask not present, assume mask = ‘1111111111’
- pcfgpioPattern, 3, 12, 525, 973
write pattern = 525 = ‘100001101’
mask = 973 = ‘1111001101’
write pattern after mask = ‘1000xx11x1’ where x indicates that the pin will not be changed
|
PCFGPIO: 1 … 128
mode:
0 = OUTPUT
1 = INPUT PULLUP
2 = INPUT
|
To change the mode of an PCFGPIO pin. example: pcfMode,1,0 (set pin 1 as output)
|
PCFGPIO start pin: 1 … 128
PCFGPIO end pin: 1 … 128
mode:
0 = OUTPUT
1 = INPUT PULLUP
2 = INPUT
|
To change the mode of an PCFGPIO range of pin. example: pcfModeRange,1,8,0 (set pin 1 to 8 as output)
|
Ringtone Internal GPIO¶
Internal GPIO handling NORMAL CLIMATE
Supported hardware: Buzzer (RTTTL), Piezo element, Speaker (Ringtones etc.)
Command (GPIO/Value) |
Extra information |
---|---|
ESP8266 GPIO: 0 … 16 ESP32 GPIO: All GPIO pins with output capabilities Tone: 20 … 13000 Hz Duration: 100 … 15000 msec |
ESP8266: You should try to use GPIO 12…16 since these generally aren’t used. The recommended tone range is 20 Hz … 13 kHz. Up-to 40 kHz should be possible to generate, but will be inaudible for humans. Frequencies above 30 kHz are not stable and will likely crash the ESP. Duration is set in ms. N.B. tones with a duration less than 50 msec will be blocking. Longer duration will use the scheduler, which may cause some fluctuations in the duration. |
ESP8266 GPIO: 0 … 16 ESP32 GPIO: All GPIO pins with output capabilities Value: d=<duration>,o=<octave>,b=<tempo>,<notes…> |
ESP8266: You should try to use GPIO 12…16 since these generally aren’t used by ESP internal functions. Value can be defined like <name_of_melody:duration,octave,beat,notes….> For example:
Since 2023-09-15: The Also, the previous implementation may not have stopped sound correctly after playing a song, but as this has been corrected, so there is no longer a need to turn off the GPIO after playing a song. |
Change log¶
Changed in version 2.0: …
added Major overhaul for 2.0 release.
Added in version 1.0: …
added Initial release version.