← Back to All Weeks
Week 11

Week 11: Networking and Communications

A two-board I²C example

I prepared an I²C example that separates a touch input from an LED output across two boards. One board reads a digital touch signal and sends a byte. The second board has the address 0x08 and uses that byte to set its LED. The code is archived below; a physical two-board demonstration has not yet been recorded.

Group assignment: communication between projects

Our group assignment is to send a message between projects and explain how it travels from one device to the other. The shared work belongs on our group assignment page. We still need to record the actual message exchange and its observed result there.

Bus structure and wiring plan

I²C uses a shared data line, SDA, and a shared clock line, SCL. The controller initiates a transaction and selects the receiving device by address. Both boards need a common ground, compatible logic levels and suitable pull-ups for the bus.

For this example, the sender’s touch input is D9 and the receiver’s LED output is D1. The board-specific SDA and SCL pins must be checked against the selected Arduino core and board pinout before wiring; the sketches use the default Wire interface. The final wiring and pull-up arrangement are not established by the source alone.

Part of exampleRole
SenderReads D9 and initiates a transmission
Receiver at 0x08Receives the byte and sets D1
Message 0Request LED off
Message 1Request LED on

Sender program

The sender calls Wire.begin() as the bus controller. Every 100 ms it reads D9, begins a transaction to 0x08, writes the byte and ends the transmission. The code does not currently log the acknowledgement status, so it does not by itself prove that another board received the data.

#include <Wire.h>
#define TOUCH_PIN D9
#define RECEIVER 0x08

void setup() {
  Wire.begin();              // join the bus as the controller
  pinMode(TOUCH_PIN, INPUT);
}

void loop() {
  byte msg = digitalRead(TOUCH_PIN);  // 1 = touched, 0 = not
  Wire.beginTransmission(RECEIVER);
  Wire.write(msg);
  Wire.endTransmission();
  delay(100);
}

Receiver program

The receiver joins at 0x08 and registers onMessage as its receive handler. The handler reads one byte and writes its value to D1. The intended protocol is deliberately small: the receiver expects a single 0 or 1 from the sender. A more general protocol would need validation of message length and values.

#include <Wire.h>
#define LED_PIN D1
#define MY_ADDRESS 0x08

void setup() {
  pinMode(LED_PIN, OUTPUT);
  Wire.begin(MY_ADDRESS);    // join the bus with my address
  Wire.onReceive(onMessage);
}

void onMessage(int howMany) {
  byte msg = Wire.read();
  digitalWrite(LED_PIN, msg);  // 1 turns the LED on, 0 off
}

void loop() {}

Planned physical test and reflection

I will first check the wiring and supply, then run the sender and receiver together. Touching and releasing the input should change the LED on the other board. Recording both boards, the connections and the response will distinguish a real bus exchange from two independent programs.

This example helped me separate a device address from a pin number and define the meaning of the transmitted data. The next step is to verify that the selected boards and Arduino cores support the roles used in these sketches, then document the actual exchange.

Making the bus exchange easier to check

I prepared a revised sender and receiver with Codex assistance for two XIAO RP2040 boards using Arduino-Pico 4.5.3. Both use D4/GPIO6 for SDA and D5/GPIO7 for SCL, with compatible 3.3 V signals and a common ground. I still need to identify the existing pull-ups on the actual setup before adding more.

The sender logs the selected address, transmitted 0/1 and the result of Wire.endTransmission(). The receiver accepts exactly one byte with value 0 or 1, buffers it in the receive callback and changes its LED in the main loop. Invalid messages do not change the output. Both source versions compile, which confirms core/API compatibility but not a real bus exchange.

For the addressing check I will leave the sender at 0x08 and change only the receiver to 0x09. I should lose that receiver's acknowledgement; after changing the sender to 0x09 I should recover it. I will record the logs and physical LED response together. A bus acknowledgement alone does not prove the intended device output changed.

The Arduino-Pico Wire documentation describes the supported bus roles and pin configuration.