Embedded Networking and Communications¶
This week we made two of our boards communicate via I2C.
For this we used one Anna had made a few weeks ago and one of Julian’s boards.
Since both of them are variations of the Seeed Studio XIAO we were able to simply use the Arduino IDE to program them.
In the documentation for Wire.h, the integrated library that lets you use the I2C communications protocol, we came across an example called Controller Writer
.
You can take a closer look at the original code right here, but we slightly modified it to our liking and produced the following code.
Sender
#include <Wire.h>
void setup() {
Wire.begin(2);
Wire.onRequest(requestEvent);
}
void loop() {
delay(100);
}
void requestEvent() {
Wire.write("Fab Academy 2025 ");
}
Receiver
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(9600);
}
void loop() {
Wire.requestFrom(2, 17);
while (Wire.available()) {
char c = Wire.read();
Serial.print(c); // print the characters till all characters are complete
}
delay(500);
}
When the code portion was finished, we connected the two boards.
SCL to SCL, SDA to SDA, GND to GND.
We could have gone the route of having one board power the other but didn’t feel like it.
Either way it would have been only one more cable from one board’s 3.3V pin to the other board’s 3.3V pin.
After that we only had to upload the sender sketch to Julian’s and the receiver sketch to Anna’s board and watch as a child screams the same thing over and over again at one of their parents.