Assignment 14: Embedded Networking and Communications

Design and build a wired &/or wireless network connecting at least two processors


Learning outcomes:

  • Demonstrate workflows used in network design and construction

  • Implement and interpret networking protocols

Group assignment:

  • Send a message between two projects.

Individual assignment:

  • Implement and interpret networking protocols

For this assignment connect three cards to a microcontroller. Each card had the function of reading the distance with an ultrasound sensor. Each ultrasonic sensor was programmed to turn on a led when it detected objects located 20 centimeters away..

I have used this library for the OIC communication between the Attiny 44 microcontrollers: TinyWire.



To develop this assignment, follow the next steps:

Step 1: First I investigated about the meaning of the following concepts: Wired network, wireless, network design, network construction and network protocols.

Step 2: I designed a PCB with the necessary components that receive the signal from an ultrasound sensor and that can turn on an LED depending on the distance of the object received by the sensor. The Eagle program was used to design the card.

Step 3:Next, the tracer and interior images are exported in .png format to be milled.

Step 4: The cards were then milled using a Roland Modela MDX 20 milling machine. For the milling of the PCB, 1/64 and 1/32 cutters were used.

Step 5: The components of the PCB were then welded according to the schematic previously designed in the Eagle program.

Step 6: The process of milling and welding components of the PCB was repeated four times. It was necessary to have 4 PCBs to be able to locate the 4 cardinal points within the smart helmet: north, south, east and west.

Step 7: Then the card was connected to an ultrasound sensor.

Step 8: Next, the necessary code was written to make the PCB detect objects near the ultrasound sensor and turn on a led if an object is located 20 centimeters away from the sensor. The programming was done using the Arduino program.

// Slave Sender

#include <TinyWire.h>

int triger = 3;   // digital pin 10

int echo   = 2;   // digital pin 11

int r    = 8;

int g    = 9;

int b    = 10;

byte own_address = 12;

void setup()


    pinMode(triger, OUTPUT);

    pinMode(r, OUTPUT);

    pinMode(g, OUTPUT);

    pinMode(b, OUTPUT);

    pinMode(echo, INPUT);

    TinyWire.begin( own_address );





void loop()


    float duration;

    int distance=0;





    duration = pulseIn(echo,HIGH);

    // distance =((time(us)*sound_speed(m/s))/2)*(100(cm)/1(m)*1(s)/1000000(us))

    distance = round(duration*340/20000.0); // distance in cm                                            

    if (distance<20)


      TinyWire.onRequest( onI2CRequest );

      for(int i =0;i<5;i++)













void onI2CRequest() {



Step 10: For the 4 PCBs to connect to each other I used the I2C protocol. I2C is a synchronous protocol. I2C uses only 2 cables, one for the clock (SCL) and one for the data (SDA). This means that the master and the slave send data through the same cable, which is controlled by the master, who creates the clock signal. I2C does not use slave selection, but addressing.

The main characteristic of I²C is that it uses two lines to transmit the information: one for the data and another for the clock signal. A third line is also necessary, but this is only the reference (mass). As circuits are usually communicated in the same plate that share the same mass, this third line is not usually necessary.

The lines are called:

SDA: data
SCL: watch
GND: ground

The communication process on the I2C bus is:

The teacher begins the communication by sending a pattern called "start condition". This alerts the slave devices, putting them waiting for a transaction.
The master goes to the device with which he wants to speak, sending a byte that contains the seven bits (A7-A1) that make up the address of the slave device with which he wants to communicate, and the eighth bit (A0) of less weight is corresponds to the desired operation (L / E), reading = 1 (receive from the slave) and writing = 0 (send to the slave).
The address sent is compared by each slave of the bus with its own address, if both coincide, the slave is considered as slave-transmitter or slave-receiver depending on the R / W bit.
Each byte read / written by the master must be recognized by an ACK bit by the master / slave device.
When the communication ends, the master transmits a "stop condition" to clear the bus.

Code. Networking


Step 11: Finally, several corrections were made and several tests were carried out until the PCPs were connected to the same microprocessor and each one allowed the ultrasound sensor to recognize the presence of an object at least 20 centimeters away and to turn on an LED.