15. Networking and Communications


  • individual assignment:
    • design, build, and connect wired or wireless node(s) with network or bus addresses
  • group assignment:
    • send a message between two projects

Group assignment

This week we tried sending messages between two projects using I2C protocol. I2C (Inter Integrated Circuits) is a serial communication protocol that allows two or more boards to share information through a common clock signal. It has only two wires to share information: Serial Clock (SCL) and Serial Data (SDA).

We followed a simple chat program for Arduino tutorial and tried to chat in Serial monitor with SoftwartSerial library.

“The SoftwartSerial library has been developed to allow serial communication on other digital pins of the Arduino, using software to replicate the functionality. It is possible to have multiple software serial ports with speeds up to 115200 bps. A parameter enables inverted signaling for devices which require that protocol.”


It is very important to connect two devices’ GND together, otherwise it might bring in garbled even signal has been transmitted.

Here is the code:

  Simple Chat Program

 Receives from the hardware serial, 
 sends to hardware & software serial.
 Receives from software serial, 
 sends to hardware serial.

 The circuit: 
 * RX is A4 (connect to TX of other device)
 * TX is A5 (connect to RX of other device)

 created 16 August 2014
 modified 25 April 2019
 by Flavie Liu
 based on SoftwareSerial example
#include <SoftwareSerial.h>

SoftwareSerial chat(A4, A5); // RX, TX

int text;

void setup()  
  // open hardware serial, TX = 1, RX = 0
  Serial.println("Starting Chat Program...");
  // set the data rate for the SoftwareSerial port
  delay(1000); // delay 1s to stabilize serial ports
  chat.println("Hello World");

void loop() 
  if (chat.available()) 

  if (Serial.available()) 
    while (Serial.available()) 
      text = Serial.read();


Individual assignment

I was trying to make a test for a I2C communication with more than one slave. Each slave would send its adress to the master one by one like report number. Then the master will print them through serial monitor:

Here is the code for master:

#include <Wire.h>

void setup() {
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output

void loop() {
  for(int i=0; i<=3; i++){
  Wire.requestFrom(i, 13);    // request 13 bytes from slave device #i

  while (Wire.available()) { // slave may send less than requested
    char c = Wire.read(); // receive a byte as character
    Serial.print(c);         // print the character
  Serial.print("OK, let's do it again\n");

Here is the code for slaves:

#include <Wire.h>

void setup() {
  Wire.begin(1);                // join i2c bus with address #1
  Wire.onRequest(requestEvent); // register event

void loop() {

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
  Wire.write("hello I'm S1\n"); // respond with message of 12 bytes
  // as expected by master

Change the slave adress from 1 to 3 – upload to corresponding board – then connect all the VCC and GND – See from the master serial monitor

Some useful command for I2C protocol:

Wire.begin() & Wire.begin(address)
Initialize the wire library and add it to the I2C network.

The master device requests a byte from the slave device. This byte can be accepted by the master device using read() or available().

Start a data transfer and send an I2C start character.

End a slave transmission started by beginTransmission() and arranged by write().

Send data to slave.

Wire.requestFrom() request slave data, you can use read to receive.

Wire.requestFrom() request slave data, you can use available to receive.

My final project plan about communications

At first I intend to directly connect every input and output device to the main controller’s pin header. But I realized that if my table use a lot of modules to connect, the pin header won’t be enough.

Here is the connection way:

So I decided to use I2C protocol to connect every table module and make an independent MCU for each.

Here is the connection way:

Now I can add unlimited number of table module I want. And futher more, I would like to use magnet to make the joint instead of cables to make the table can separtate and combine more easily.

Designing indepentant control module and WIFI module

I decide to use RC circuit as the input device part:

To make this function works, I need a MCU for each of it, so I choose the simple chip: ATtiny44.

(I’m still working on designing it)

Some useful refference:

“ESP8266 is a wifi SOC (system on a chip) produced by Espressif Systems. It is an highly integrated chip designed to provide full internet connectivity in a small package. ESP8266 can be used as an external Wifi module, using the standard AT Command set Firmware by connecting it to any microcontroller using the serial UART, or directly serve as a Wifi-enabled micro controller, by programming a new firmware using the provided SDK.”