Chapter 7 - GPIO Expander

There are only a limited number of ESP GPIO pins available to use, particularly on devices like ESP-01 and Sonoffs modules.

One of the excellent features of >Basic is its ability for 'non-contact' OTA updates even on 1Mb devices.
This makes it practical to utilise TX and RX as gpio01 and gpio03, as demonstrated in this: TX RX Hack 
But 2 extra GPIOs won't go very far, unless they are utilised for connecting i2c multi-IO Port expanders.

One PCF8574 multi-IO module offers 8 additional ports, which can be configured as Inputs or Outputs.
More modules can be added to the i2c bus to increase the available gpio's in banks of 8, ie: 8, 16, 24, 32.
Other platforms typically continuously loop to check for change of port input status, so are always 'busy'.
Because >Basic is 'event-driven' it can take advantage of interrupts to snooze in between pin changes.
This means it can monitor many inputs while doing other tasks and still respond immediately to triggers.

Some like these blue ones are designed to be physically connected into each other.
User-selectable 3-bit addressing theoretically allows addressing of up to 8 devices.
Port direction is software defined, so these could be 16 inputs or 16 outputs or 8 each.
And of course other types of i2c modules might also be daisy-chained on the i2c bus.
Subpages (1):Project - Multi-IO