NETWORK AND COMMUNICATIONS
For this week's assignment we were tasked to build and connect wired or wireless node(s) with network or bus addresses and a local input and/or output devices
First I needed to understand the terms network and communication.
From chatgpt, it is said;
MY APPROACH
For this assignment I created a wired network, using the PCB I have made on Week 8 and the other PCBs from my colleagues. The network was between the SEED XIAO RP2040s. The network was made using I2C pins, where I had a master and slave. The connections were like these;
The connection was through a breadboard and it was like this:

COMMUNICATION
I then created a programs on Arduino IDE, for both a slave and a master. After the programming I then uploaded them on the board separately. The code was for slave to print water sensor values on its serial monitor following the request from the master. The codes are below;
MASTER CODE
#include < Wire.h>
#define SLAVE_ADDR 0x08
void setup() {
Wire.begin(); // Master
Serial.begin(9600);
}
void loop() {
Wire.requestFrom(SLAVE_ADDR, 10); // Request up to 10 bytes
String response = "";
while (Wire.available()) {
char c = Wire.read();
response += c;
}
Serial.print("Slave response: ");
Serial.println(response);
if (response == "WATER") {
// React to water alert
Serial.println(" WATER DETECTED BY SLAVE!");
}
delay(1000); // Poll rate
}
SLAVE CODE
#include < Wire.h>
#define SLAVE_ADDR 0x08
#define SENSOR_PIN A0
String sensorStatus = "DRY"; // Default status
void setup() {
Wire.begin(SLAVE_ADDR);
Wire.onRequest(sendSensorStatus); // Handler when master requests
Serial.begin(9600);
}
void loop() {
int value = analogRead(SENSOR_PIN);
Serial.print("Sensor value: ");
Serial.println(value);
// Update status
if (value < 500) {
sensorStatus = "WATER";
} else {
sensorStatus = "DRY";
}
delay(500); // Update rate
}
void sendSensorStatus() {
Wire.write(sensorStatus.c_str()); // Respond with current status
}
PRINTING A SENSOR VALUE
The code enabled a communication between the boards. One board (MASTER) sends a request for a water sensor value and the other board(SLAVE)responds by printing the water value in serial monitor. The results are shown in the video below.
FILES