Protocol Selector
Try Keep Number of sensors/devices at 3 and Available GPIO pins at 10, then raise Data rate requirement from Low (<10 KB/s).
Observe Initially I2C leads with 97 points; SPI has 72 and UART has 53, and all three pin counts fit within 10 GPIO pins.
Explain The score combines speed, pin fit, device count and power priorities; with 3 devices it counts 2 I2C pins, 6 SPI pins and 6 UART pins.
Calculate protocol scores
Reset
Technical boundaries. The scoring assumes fixed heuristic weights of 30% speed, 25% GPIO efficiency, 25% multi-device support and 20% power efficiency. Battery power multiplies the power score by 1.3; electrical timing, address conflicts and actual measured current are not checked.
Select your project requirements and see which protocol is the best fit. The tool scores each protocol across your priorities and highlights the recommended choice.
viewof protoNumSensors = Inputs. range ([1 , 20 ], {value : 3 , step : 1 , label : "Number of sensors/devices" })
viewof protoSpeedNeeded = Inputs. select (["Low (<10 KB/s)" , "Medium (10-500 KB/s)" , "High (>500 KB/s)" ], {value : "Low (<10 KB/s)" , label : "Data rate requirement" })
viewof protoGpioPins = Inputs. range ([2 , 30 ], {value : 10 , step : 1 , label : "Available GPIO pins" })
viewof protoBusPower = Inputs. radio (["Battery (minimize current)" , "USB/Mains (power not critical)" ], {value : "Battery (minimize current)" , label : "Power source" })
protoSpeedScore = protoSpeedNeeded === "Low (<10 KB/s)" ? {i2c : 90 , spi : 70 , uart : 85 } :
protoSpeedNeeded === "Medium (10-500 KB/s)" ? {i2c : 60 , spi : 95 , uart : 30 } :
{i2c : 20 , spi : 100 , uart : 5 }
// GPIO efficiency: I2C uses 2 pins for N devices, SPI uses 3+N, UART uses 2 per device
protoI2cPins = 2
protoSpiPins = 3 + protoNumSensors
protoUartPins = 2 * protoNumSensors
protoI2cPinFit = protoI2cPins <= protoGpioPins
protoSpiPinFit = protoSpiPins <= protoGpioPins
protoUartPinFit = protoUartPins <= protoGpioPins
protoGpioScore = ({
i2c : protoI2cPinFit ? 95 : 30 ,
spi : protoSpiPinFit ? (protoNumSensors <= 3 ? 70 : 50 ) : 10 ,
uart : protoUartPinFit ? (protoNumSensors === 1 ? 80 : 20 ) : 5
})
// Multi-device score
protoMultiScore = ({
i2c : protoNumSensors <= 10 ? 95 : 75 ,
spi : protoNumSensors <= 4 ? 80 : 40 ,
uart : protoNumSensors === 1 ? 90 : 10
})
// Power score
protoPowerWeight = protoBusPower === "Battery (minimize current)" ? 1.3 : 0.8
protoPowerScore = ({
i2c : 85 * protoPowerWeight,
spi : 50 * protoPowerWeight,
uart : 75 * protoPowerWeight
})
// Weighted total
protoTotalI2c = Math . round ((protoSpeedScore. i2c * 0.3 + protoGpioScore. i2c * 0.25 + protoMultiScore. i2c * 0.25 + protoPowerScore. i2c * 0.2 ))
protoTotalSpi = Math . round ((protoSpeedScore. spi * 0.3 + protoGpioScore. spi * 0.25 + protoMultiScore. spi * 0.25 + protoPowerScore. spi * 0.2 ))
protoTotalUart = Math . round ((protoSpeedScore. uart * 0.3 + protoGpioScore. uart * 0.25 + protoMultiScore. uart * 0.25 + protoPowerScore. uart * 0.2 ))
protoWinner = protoTotalI2c >= protoTotalSpi && protoTotalI2c >= protoTotalUart ? "I2C" :
protoTotalSpi >= protoTotalUart ? "SPI" : "UART"
protoWinnerColor = protoWinner === "I2C" ? "#16A085" : protoWinner === "SPI" ? "#3498DB" : "#E67E22"
html `<div style="background: var(--bs-light, #f8f9fa); padding: 1.2rem; border-radius: 8px; border-left: 4px solid ${ protoWinnerColor} ; margin-top: 0.5rem;">
<h4 style="margin: 0 0 12px 0; color: #2C3E50;">Recommendation: <span style="color: ${ protoWinnerColor} ; font-size: 1.3em;"> ${ protoWinner} </span></h4>
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 12px;">
${ [{name : "I2C" , score : protoTotalI2c, pins : protoI2cPins, color : "#16A085" , fit : protoI2cPinFit},
{name : "SPI" , score : protoTotalSpi, pins : protoSpiPins, color : "#3498DB" , fit : protoSpiPinFit},
{name : "UART" , score : protoTotalUart, pins : protoUartPins, color : "#E67E22" , fit : protoUartPinFit}]. map (p => html `
<div style="background: white; border-radius: 6px; padding: 12px; text-align: center; border: 2px solid ${ p. name === protoWinner ? p. color : '#dee2e6' } ;">
<div style="font-weight: bold; color: ${ p. color } ; font-size: 1.1em;"> ${ p. name } </div>
<div style="font-size: 2em; font-weight: bold; color: #2C3E50; margin: 4px 0;"> ${ p. score } </div>
<div style="font-size: 0.8em; color: #7F8C8D;">score / 100</div>
<div style="margin-top: 6px; font-size: 0.85em; color: ${ p. fit ? '#16A085' : '#E74C3C' } ;">
${ p. pins } GPIO pins ${ p. fit ? '(fits)' : '(exceeds available!)' }
</div>
</div>
` )}
</div>
<p style="font-size: 0.85em; color: #7F8C8D; margin: 0;">Scoring weights: speed 30%, GPIO efficiency 25%, multi-device support 25%, power efficiency 20%. ${ protoNumSensors > 1 && protoWinner !== "UART" ? "A direct UART link needs extra hardware and protocol rules for multiple devices, so it scores poorly here." : "" } </p>
</div>`
Back to the chapter