Try It: GPIO Pin Budget Calculator
Try Keep Microcontroller on ESP32 (34 GPIO), then raise SPI devices from 2 while leaving I2C devices at 4.
Observe The opening budget uses 11 of 34 pins and leaves 23 free. Increasing SPI devices adds one pin per device, while the four I2C devices share two pins.
Explain I2C devices use a shared pair when present; SPI devices use three shared lines plus one select each, and UART devices need two pins each.
Calculate pin budget
Reset
Technical boundaries. The count assumes all listed board GPIO are usable and that each bus can share its common lines. It does not check reserved pins, bus addresses, peripheral limits or electrical compatibility.
Plan your wiring by entering how many I2C, SPI, and UART devices you need. The calculator shows total GPIO pin usage and whether your microcontroller has enough pins.
viewof gpioBoardType = Inputs. select (["ESP32 (34 GPIO)" , "Arduino Uno (20 GPIO)" , "Raspberry Pi Pico (26 GPIO)" , "STM32 Blue Pill (33 GPIO)" ], {value : "ESP32 (34 GPIO)" , label : "Microcontroller" })
viewof gpioI2cDevices = Inputs. range ([0 , 15 ], {value : 4 , step : 1 , label : "I2C devices" })
viewof gpioSpiDevices = Inputs. range ([0 , 8 ], {value : 2 , step : 1 , label : "SPI devices" })
viewof gpioUartDevices = Inputs. range ([0 , 4 ], {value : 1 , step : 1 , label : "UART devices" })
viewof gpioExtraPins = Inputs. range ([0 , 10 ], {value : 2 , step : 1 , label : "Extra GPIO (LEDs, buttons, etc.)" })
gpioTotalAvailable = gpioBoardType. includes ("ESP32" ) ? 34 :
gpioBoardType. includes ("Uno" ) ? 20 :
gpioBoardType. includes ("Pico" ) ? 26 : 33
// Pin calculations
gpioI2cPins = gpioI2cDevices > 0 ? 2 : 0 // SDA + SCL shared
gpioSpiPins = gpioSpiDevices > 0 ? 3 + gpioSpiDevices : 0 // MISO + MOSI + SCK + 1 CS per device
gpioUartPins = gpioUartDevices * 2 // TX + RX per device
gpioTotalUsed = gpioI2cPins + gpioSpiPins + gpioUartPins + gpioExtraPins
gpioRemaining = gpioTotalAvailable - gpioTotalUsed
gpioFits = gpioRemaining >= 0
gpioUsagePercent = Math . min (100 , Math . round ((gpioTotalUsed / gpioTotalAvailable) * 100 ))
html `<div style="background: var(--bs-light, #f8f9fa); padding: 1.2rem; border-radius: 8px; border-left: 4px solid ${ gpioFits ? '#16A085' : '#E74C3C' } ; margin-top: 0.5rem;">
<h4 style="margin: 0 0 10px 0; color: #2C3E50;">GPIO Budget: ${ gpioTotalUsed} / ${ gpioTotalAvailable} pins used</h4>
<div style="background: #dee2e6; border-radius: 6px; height: 24px; margin-bottom: 14px; overflow: hidden;">
<div style="height: 100%; width: ${ gpioUsagePercent} %; background: ${ gpioUsagePercent > 90 ? '#E74C3C' : gpioUsagePercent > 70 ? '#E67E22' : '#18AA90' } ; border-radius: 6px; transition: width 0.3s; display: flex; align-items: center; justify-content: center; color: white; font-size: 0.8em; font-weight: bold;">
${ gpioUsagePercent} %
</div>
</div>
<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px;">
<div style="background: white; padding: 8px 12px; border-radius: 4px; border-left: 3px solid #16A085;">
<span style="color: #7F8C8D; font-size: 0.85em;">I2C bus</span><br/>
<strong> ${ gpioI2cPins} pins</strong> <span style="color: #7F8C8D; font-size: 0.8em;">( ${ gpioI2cDevices} devices share 2 wires)</span>
</div>
<div style="background: white; padding: 8px 12px; border-radius: 4px; border-left: 3px solid #3498DB;">
<span style="color: #7F8C8D; font-size: 0.85em;">SPI bus</span><br/>
<strong> ${ gpioSpiPins} pins</strong> <span style="color: #7F8C8D; font-size: 0.8em;">(3 shared + ${ gpioSpiDevices} CS)</span>
</div>
<div style="background: white; padding: 8px 12px; border-radius: 4px; border-left: 3px solid #E67E22;">
<span style="color: #7F8C8D; font-size: 0.85em;">UART</span><br/>
<strong> ${ gpioUartPins} pins</strong> <span style="color: #7F8C8D; font-size: 0.8em;">( ${ gpioUartDevices} x 2 pins each)</span>
</div>
<div style="background: white; padding: 8px 12px; border-radius: 4px; border-left: 3px solid #9B59B6;">
<span style="color: #7F8C8D; font-size: 0.85em;">Extra GPIO</span><br/>
<strong> ${ gpioExtraPins} pins</strong> <span style="color: #7F8C8D; font-size: 0.8em;">(LEDs, buttons, etc.)</span>
</div>
</div>
<p style="font-size: 0.9em; color: ${ gpioFits ? '#16A085' : '#E74C3C' } ; font-weight: bold; margin: 0;">
${ gpioFits ? 'Design fits - ' + gpioRemaining + ' GPIO pins remaining for future expansion.' : 'Not enough pins! Consider moving ' + (gpioSpiDevices > 0 ? 'SPI devices to I2C' : 'some devices' ) + ' or using a GPIO expander (PCF8574 over I2C adds 8 pins for just 2 pins).' }
</p>
</div>`
Back to the chapter