viewof i2cSpeed = Inputs.select(
[100, 400, 1000],
{ label: "I2C Speed (kHz):", value: 100 }
)
viewof busCap = Inputs.range(
[10, 1000],
{ label: "Bus Capacitance (pF):", value: 500, step: 10 }
)
viewof vcc = Inputs.range(
[3.0, 5.0],
{ label: "Supply Voltage (V):", value: 3.3, step: 0.1 }
)
// Calculate maximum rise time based on I2C spec
riseTimeMax = i2cSpeed === 100 ? 1000 : (i2cSpeed === 400 ? 300 : 120)
// Calculate maximum pull-up resistance
rMax = busCap > 0 ? (riseTimeMax / (0.8473 * busCap)) : 0
// Calculate minimum pull-up resistance: R_min = (VCC - VOL) / IOL
// VOL_max = 0.4V per I2C spec, IOL = 3 mA max sink current
rMin = vcc > 0.4 ? ((vcc - 0.4) / 0.003) / 1000 : 0
// Standard resistor values in kΩ
standardResistors = [1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2, 10.0]
// Find recommended resistor
recommendedR = standardResistors.find(r => r >= rMin && r <= rMax) || null
busWithinLoadLimit = busCap <= 400
// Calculate actual rise time for recommended resistor
actualRiseTime = recommendedR && busCap > 0 ? (recommendedR * busCap * 0.8473) : 0
// Calculate current draw for recommended resistor
currentDraw = recommendedR && vcc > 0 ? (vcc / recommendedR) : 0
html`
<div style="background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%); border-radius: 12px; padding: 20px; margin: 15px 0; border: 2px solid #2C3E50;">
<div style="font-size: 18px; font-weight: bold; color: #2C3E50; margin-bottom: 20px; text-align: center;">
I2C Pull-Up Resistor Calculator
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px;">
<!-- Left Column: Constraints -->
<div style="background: white; border-radius: 8px; padding: 15px; border-left: 4px solid #3498DB;">
<div style="font-weight: bold; color: #2C3E50; margin-bottom: 10px;">Design Constraints</div>
<div style="margin: 8px 0; font-size: 13px;">
<span style="color: #7F8C8D;">Max Rise Time:</span>
<strong style="color: #2C3E50;">${riseTimeMax} ns</strong>
</div>
<div style="margin: 8px 0; font-size: 13px;">
<span style="color: #7F8C8D;">Bus Capacitance:</span>
<strong style="color: #2C3E50;">${busCap} pF</strong>
</div>
<div style="margin: 8px 0; font-size: 13px;">
<span style="color: #7F8C8D;">Supply Voltage:</span>
<strong style="color: #2C3E50;">${vcc.toFixed(1)} V</strong>
</div>
</div>
<!-- Right Column: Calculated Limits -->
<div style="background: white; border-radius: 8px; padding: 15px; border-left: 4px solid #E67E22;">
<div style="font-weight: bold; color: #2C3E50; margin-bottom: 10px;">Resistor Limits</div>
<div style="margin: 8px 0; font-size: 13px;">
<span style="color: #7F8C8D;">Maximum R:</span>
<strong style="color: ${rMax < rMin ? '#E74C3C' : '#2C3E50'};">${rMax.toFixed(2)} kΩ</strong>
<div style="font-size: 11px; color: #7F8C8D;">from rise time limit</div>
</div>
<div style="margin: 8px 0; font-size: 13px;">
<span style="color: #7F8C8D;">Minimum R:</span>
<strong style="color: #2C3E50;">${rMin.toFixed(2)} kΩ</strong>
<div style="font-size: 11px; color: #7F8C8D;">from 3 mA current limit</div>
</div>
</div>
</div>
<!-- Recommendation Box -->
<div style="background: ${recommendedR && busWithinLoadLimit ? 'linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%)' : 'linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%)'};
border-radius: 8px; padding: 20px; border: 2px solid ${recommendedR && busWithinLoadLimit ? '#16A085' : '#E74C3C'};">
${recommendedR ? html`
<div style="text-align: center; margin-bottom: 15px;">
<div style="font-size: 14px; color: ${busWithinLoadLimit ? '#155724' : '#721c24'}; font-weight: bold; margin-bottom: 5px;">
${busWithinLoadLimit ? '✓ RESISTOR CALCULATION PASSES' : '⚠ RESISTOR CALCULATION PASSES; BUS LOAD LIMIT EXCEEDED'}
</div>
<div style="font-size: 36px; font-weight: bold; color: #16A085; font-family: monospace;">
${recommendedR.toFixed(1)} kΩ
</div>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px;">
<div style="background: rgba(255,255,255,0.7); border-radius: 6px; padding: 10px; text-align: center;">
<div style="font-size: 11px; color: #155724; margin-bottom: 3px;">Actual Rise Time</div>
<div style="font-size: 18px; font-weight: bold; color: #2C3E50;">${actualRiseTime.toFixed(0)} ns</div>
<div style="font-size: 10px; color: ${actualRiseTime <= riseTimeMax ? '#16A085' : '#E74C3C'};">
${actualRiseTime <= riseTimeMax ? '✓ Within spec' : '✗ Exceeds limit!'}
</div>
</div>
<div style="background: rgba(255,255,255,0.7); border-radius: 6px; padding: 10px; text-align: center;">
<div style="font-size: 11px; color: #155724; margin-bottom: 3px;">Current Draw</div>
<div style="font-size: 18px; font-weight: bold; color: #2C3E50;">${currentDraw.toFixed(1)} mA</div>
<div style="font-size: 10px; color: ${currentDraw <= 3 ? '#16A085' : '#E74C3C'};">
${currentDraw <= 3 ? '✓ Within limit' : '✗ Too high!'}
</div>
</div>
</div>
<div style="margin-top: 15px; padding: 10px; background: rgba(255,255,255,0.5); border-radius: 6px; font-size: 12px; color: #155724; text-align: center;">
<strong>Formula:</strong> t<sub>rise</sub> = R × C<sub>bus</sub> × 0.8473 = ${recommendedR}kΩ × ${busCap}pF × 0.8473 = ${actualRiseTime.toFixed(0)}ns
</div>
` : html`
<div style="text-align: center;">
<div style="font-size: 14px; color: #721c24; font-weight: bold; margin-bottom: 10px;">
✗ NO SUITABLE RESISTOR FOUND
</div>
<div style="font-size: 13px; color: #721c24; margin-bottom: 10px;">
The maximum resistance (${rMax.toFixed(2)} kΩ) is lower than the minimum resistance (${rMin.toFixed(2)} kΩ).
</div>
<div style="font-size: 12px; color: #721c24; background: rgba(255,255,255,0.5); border-radius: 6px; padding: 10px;">
<strong>Solutions:</strong><br/>
• Reduce bus capacitance (shorter wires, fewer devices)<br/>
• Use a lower I2C speed (e.g., 100 kHz instead of 400 kHz)<br/>
• Use an I2C buffer or active pull-up circuit
</div>
</div>
`}
</div>
${busWithinLoadLimit ? '' : html`<div role="alert" style="margin-top: 12px; padding: 10px; background: #f8d7da; color: #721c24; border: 1px solid #dc3545; border-radius: 6px; font-size: 13px;"><strong>This bus exceeds the 400 pF Standard/Fast-mode load limit.</strong> Reduce or segment capacitance, or qualify an extended-load design; a passing resistor calculation alone is insufficient.</div>`}
<div style="margin-top: 15px; padding: 12px; background: #fff3cd; border-radius: 6px; font-size: 12px; color: #856404; border: 1px solid #ffc107;">
<strong>Pro Tip:</strong> High-capacitance devices like OLED displays (400 pF) can dominate your bus capacitance.
If you can't find a suitable resistor, try reducing the I2C speed or using an I2C buffer chip.
</div>
</div>
`I2C Pull-Up Calculator
I2C Pull-Up Calculator
animation
sensors
Try Begin at I2C Speed (kHz): 100, Bus Capacitance (pF): 500 and Supply Voltage (V): 3.3. Reduce capacitance and compare the resistor result with the load warning.
Observe The starting limits are 0.97 to 2.36 kilohms, and the selected resistor is 1.0 kilohm. At 500 pF the bus-load warning remains, while the current readout shows 3.3 mA.
Explain At the opening 100 kHz setting, the rise-time limit divided by capacitance and the RC factor gives maximum resistance; the first listed resistor within both resistance limits is selected.
Technical boundaries. The resistance calculation assumes a 0.4 V low level and a 3 mA sink limit, using 0.8473 for the rise-time factor. The separate current readout uses supply voltage divided by resistance, and the load warning uses a fixed 400 pF threshold.
I2C Pull-Up Calculator
Choose a pull-up that meets both rise-time and current limits for the bus.
Tip
Estimate the maximum pull-up resistance from bus capacitance and rise time. Also check the minimum from each device’s sink-current limit before choosing a resistor.
Diagnosing Pull-Up Issues: Use the endTransmission() return code to identify whether communication failures stem from missing pull-ups, wrong addresses, or bus faults:
| Return Code | Meaning | First Thing to Check |
|---|---|---|
| 0 | Success | Device responded at that address |
| 2 | Address NACK | Wrong address, missing pull-ups, or device not powered |
| 3 | Data NACK | Register or command byte rejected |
| 4 | Other bus error | SDA/SCL short, stuck line, or bus conflict |
Symptom of missing pull-ups: I2C scanner finds no devices, or communication works intermittently. If you see error code 2 on all addresses, check your pull-up resistors first.