Arduino Mega 2560 ↔ Raspberry Pi Pico I2C echo test with addressing, wiring, and troubleshooting.
Last updated: August 15, 2026
0x18(24 decimal)0x32(50 decimal, Pico's own)100 kHzArduino Mega 2560 Raspberry Pi Pico
───────────────── ─────────────────
GND ──────────────── GND
3.3V* ──────────────── 3V3
SDA (20) ───┬──4.7kΩ──┬── GPIO 4
│ │
SCL (21) ───┴──4.7kΩ──┴── GPIO 5
*Note: Consider using a level shifter for 3.3V ↔ 5V conversion4.7kΩ pull-up resistors are required on both SDA and SCL lines.
Key configuration for the Arduino sketch:
// I2C slave addresses (queried from Pico)
uint8_t pico_target_address = 0x18; // What Mega sends TO
uint8_t pico_self_address = 0x32; // Pico's own address (receives)
// 100 kHz I2C clock on Arduino Mega
#define I2C_CLOCK_100K 72 // TWBR register value1. Arduino → Pico (write):
Address: 0x18 (24)
Data: [0xA5, 0x5A]
2. Pico processes (ECHO mode):
Stores received bytes
3. Arduino → Pico (read):
Address: 0x18 (24)
Expected: [0xA5, 0x5A]
4. Arduino verifies:
If read data == written data → TEST PASSED ✓========================================
Arduino Mega 2560 - I2C/SPI/UART Test
========================================
[I2C] Initialized at 100 kHz (TWBR=72)
[SPI] Initialized
[UART] Initialized (Serial1 @ 9600 baud)
--- I2C TEST (Echo Mode) ---
[I2C] Target Address: 0x18 (24)
[I2C] Pico Self Address: 0x32 (50)
[I2C] Writing 0xA5 0x5A to target device...
[I2C] Write OK
[I2C] Reading echo from target device...
[I2C] Read OK: 0xA5 0x5A
[I2C] ✓ ECHO VERIFIED - Data matches!
--- Waiting 3 seconds before next test ---The address of the device the Pico will talk to. Usually another device on the I2C bus. In echo mode, this is where Mega sends data TO.
Pico's own address on the I2C bus. Other masters use this to talk to the Pico. Must match Arduino's write target address.
In ECHO mode:
Arduino writes to 0x18 → Pico receives at 0x18 (self_address) → Pico echoes back
Arduino reads from 0x18 → Receives echo
python test_mega_pico_i2c.pycurl -X POST https://auth.ferqon.dev/api/pin/testmode \
-H "Content-Type: application/json" \
-d '{"gpio": 4, "mode": 1}'curl -X PATCH https://auth.ferqon.dev/api/pin/reconfigure \
-H "Content-Type: application/json" \
-d '{"gpio": 4, "device_address": 24, "self_address": 50}'