Networking and Communications

Tasks of the week

Individual Assignment.

  • Design and build a wired and/or wireless network connecting at least two processors.
  • Group Assignment

  • Send a message between two projects.
  • This Week's Task

    Designing and building a network where two or more devices communicate with each other specifically, that network might be wired or wireless.

    I2C Communication

    I am following I2C method to communicate different microcontrollers at same time. In I2C method of communication of devices we can communicate devices through serial computer bus. This is pronounced as I2C (I squared C), or I2C (I two C), or IIC (Inter-Integrated Circuit). The I2C bus communication is broadly used in many electronic devices because it can be easily implemented in circuits where communication between devices is required. In this method a master board and different slaves board or multiple master communicate simaltaneousy. This method allows communication between upto 112 slave devices when using 7-bit addressing, and 1008 devices while using 10-bit addressing.

    How I2C works?

    Only two wires are used of each device to be common. These two wire are SDA(Serial Data Line) and SCL (Serial Clock Line). Where the SCL line is the clock signal which synchronize the data transfer between the devices on I2C bus, and it is generated by the master device. And, SDL line's function is to carry the data.

    My designed I2C Communication bus

    I used one board for Master and two boards for Slaves. For master device, I used my atmega32U4 (Arduino Leonardo) board which I designed in Week 09 Embedded programming. And, for Slaves (slave1 and slave2): For Slave1, I used my board of attiny44 which I designed for Week 11 Input Devices. For Slave2, I used my board of attiny44 which I designed for Week 12 Output Devices.

    I followed this architecture design to allow devices to communicate.


    Connection of SDA, SCL on breadboard for serially I2C communication between two Slaves and one Master.


    Pin no 18(3) and 19(2) of atmega32u4 IC are for SCL and SDA respectively.




    Pin no 7(6) and 9(4) of attiny44 IC are for SDL and SCL respectively.


    For source code of slaves and master, I explored the fab academy website and found my required source, then I modified the source bit according to my scenario. There are several libraries in arduino which supports this communication. For Master, I downloaded and installed Wire library, and for slaves I downloaded and installed tinywireS library. Without installing these libraries I was unable to upload the code to the devices, so, one must do these pre-requisite things to be on safe side.

    Code for Master board: #include "Wire.h"
    void setup() {
    Wire.begin(); // join i2c bus (address optional for master)
    }
    void loop() {
    Wire.beginTransmission(0x26); // transmit to device #26
    Wire.write(0x00); // sends one byte
    Wire.endTransmission(); // stop transmitting
    Wire.beginTransmission(0x27); // transmit to device #27
    Wire.write(0x00); // sends one byte
    Wire.endTransmission(); // stop transmitting
    delay(2000);
    Wire.beginTransmission(0x26); // transmit to device #26
    Wire.write(0x01); // sends one byte
    Wire.endTransmission(); // stop transmitting
    Wire.beginTransmission(0x27); // transmit to device #27
    Wire.write(0x01); // sends one byte
    Wire.endTransmission(); // stop transmitting
    delay(2000);
    }

    Code for Slave boards: //Slave 1 address is 0x26
    //Slave 2 address is 0x27
    //used board of week 11 for slave 1
    //used board of week 12 for slave 2
    //attiny44
    #include "TinyWireS.h"
    #define I2C_SLAVE_ADDR 0x26 //define slave address, 2nd slave has address 0x27
    #define LED1_PIN 8 //PB2 (pin5 of tiny44)
    void setup(){
    pinMode(LED1_PIN, OUTPUT);
    Blink(LED1_PIN,3); // show it's alive, blink three times
    TinyWireS.begin(I2C_SLAVE_ADDR); //initialize I2C lib and setup slave address
    }
    void loop (){
    byte byteRcvd = 0x00;
    if (TinyWireS.available()){ // get I2C input from slave
    digitalWrite(LED1_PIN, HIGH);
    delay(100);
    byteRcvd = TinyWireS.receive(); //get the byte from master, returns next byte in received buffer
    if (byteRcvd == 0){
    digitalWrite(LED1_PIN, !digitalRead(LED1_PIN));
    delay(200);
    }
    if (byteRcvd == 0x01){ //is the byte equivalent of decimal 1
    digitalWrite(LED1_PIN, !digitalRead(LED1_PIN));
    delay(200);
    }}}
    void Blink(byte led, byte times){ // poor man's display
    for (byte i=0; i(less than) times; i++){
    digitalWrite(led,HIGH);
    delay (250);
    digitalWrite(led,LOW);
    delay (250);
    }}
    I uploaded the slave code in Slave1 board.


    Uploaded the slave code in Slave2 board.


    Done uploading the master code in atmega32u4 board.


    ON/OFF LEDs of both slaves blinking on same time as defined in arduino programming


    This video illustrates the successful completion of I2C communication between Master and Slaves.


    Learning outcomes

    Download all files from here

    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.