← Back to All Weeks
Week 11

Networking and Communications

My I2C networking exercise

I have prepared a sender/receiver example using two RP2040 boards. The sender reads a touch input and writes one byte to I2C address 0x08; the receiver uses that byte to control an LED. The source is archived below.

Evidence pending: I do not yet have the wired setup, an addressed-message test or a working-result recording in this archive. The earlier text stated that the test succeeded, but I cannot substantiate that statement from the files currently available.

At least one node must be my own designed and fabricated board. I will identify its revision using my board design and fabrication record.

Connections and address

My intended wiring is SDA to SDA, SCL to SCL and a common ground between the two boards. I still need to record the actual header pins, supply arrangement and I2C pull-up arrangement used on the physical setup. I will not assume those are correct merely because the code builds.

The sender uses Wire.beginTransmission(0x08). The receiver uses Wire.begin(0x08) and registers its receive callback. A byte of 1 requests LED on; 0 requests LED off.

Sender source

#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);
}

Download sender.ino

Receiver source

#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() {}

Download receiver.ino

How I will verify it

  • Photograph the two nodes and identify which PCB I designed and fabricated.
  • Record the board package, pin mapping, supply voltage, common ground and bus wiring.
  • Demonstrate that the receiver at 0x08 responds to touched and untouched states; record a second address test to show that addressing selects the intended receiver.
  • Save the uploaded source versions and a video showing the input on one node and output on the other.
  • Add actual faults, measurements and fixes after the test. The existing examples have no Serial logging, so they cannot produce the Serial Monitor screenshot described in the earlier draft.

Group work

The group assignment page is still a template. I need the actual inter-project message test and results there. A working link does not make that group work complete.