14. Networking and Communications

What is Embedded Communication?

Embedded communication is the process of sending information between two MCUs or from one circuit to other. For a communication to happen there needs to be a transmitter and a receiver. Communication may be in one direction or in both directions, there are different classifications according to this, but the basic classification is Synchronous and Asynchronous communication.

Synchronous: means sender and receiver use the same clock signal.
Asynchronous: means sender provides a synchronization signal to the receiver before starting the transfer of each message.

n&c n&c

Communication protocol

Communication protocols are formal descriptions of digital message formats and rules. They are required to exchange messages in or between computing systems and are required in telecommunications.

Communications protocols cover authentication, error detection and correction, and signaling. They can also describe the syntax, semantics, and synchronization of analog and digital communications. Communications protocols are implemented in hardware and software. There are thousands of communications protocols that are used everywhere in analog and digital communications. Computer networks cannot exist without them.

n&c

There are two types of communication protocols which are classified below:

  1. Inter System Protocol - The inter system protocol using to communicate the two different devices. Like communication between computer to microcontroller kit. The communication is done through a inter bus system.

n&c

Different categories of Inter system protocol:

n&c

n&c

Different categories of Inter system protocol:

n&c

Sources :
Elprocus
Maxembedded

Networking using I2C Communication

Later, I was asked by my global evaluator to use atleast 3 boards instead of 2 for this week’s assignment. Hence, I decided to work with I2C comuunication for this task. The problem here was none of my boards have any I2C pins and hence I used my fellow FabAcademy students’ boards; two board designs belonged to Dhruv Patel and one of Maharshi Solanki.

Objective

n&c

Code

To start with you will need to install the ultrasonic library.

n&c

n&c

Master Code
#include <Ultrasonic.h>
#include <Wire.h>  //This includes wire library of arduino.

Ultrasonic ultrasonic(A1,A0); //Ultrasonic pins

int distance;

    void setup() {
      Serial.begin(9600);
      Wire.begin();
    }

    void loop() //Begins the loop
    {

   distance = ultrasonic.read(); //Reads the ultrasonic distance

   Serial.print("Distance in CM: ");
    Serial.println(distance); //Displays on the serial monitor

    if(distance>10 && distance<30) //Condition1
    {
      Wire.beginTransmission(8); //slave number 8(Board address 1)
      Wire.write(1); 
      Serial.println("1");
      Wire.endTransmission();
      delay(500);
      Wire.beginTransmission(8); //slave number 8
      Wire.write(0);
      Serial.println("0");
      Wire.endTransmission();
      delay(500); //Message to be sent to slave number 8 if the condition is fulfilled
    }
         if(distance>30 && distance<40)  //Condition2
         {   
      Wire.beginTransmission(9); //slave number 9(Board address 2)
      Wire.write(2);
      Serial.println("1");
      Wire.endTransmission();
      delay(500);
      Wire.beginTransmission(9); //slave number 9
      Wire.write(0);
      Serial.println("0");
      Wire.endTransmission();
      delay(500);  //Message to be sent to slave number 9 if the condition is fulfilled
        }

       else{

        }
        delay(100); //Sets delay between loop cycle
      }
Slave Number 8 Code(Runs servo)
    #include <Wire.h> //This includes wire library of arduino.
    #include<Servo.h>

    Servo servo;

    int d1=0;
    void setup() {
      pinMode(13,OUTPUT); //output pin
      Serial.begin(9600);
      servo.attach(6); servo pin
      Wire.begin(8);     //I2C address
      Wire.onReceive(recieveEvent);
    }
    void loop() {
      if (d1 == 1)  //If condition for receiving
      {
        servo.write(180);
        digitalWrite(13, HIGH);
      } 
       else
      {
        servo.write(0);
        digitalWrite(13, LOW);
      }

       delay(200);
    }
    void recieveEvent(int howMany) 
    {
      while (Wire.available())
      {
      d1 = Wire.read(); //reads the transmitted byte
      }
    }
Slave Number 9(Runs DC Motor)
#include <Wire.h> //This includes wire library of arduino.
    int d1=0;

int m1 = 11;
int m2 = 12; //Motor Pins


    void setup() {
      pinMode(13,OUTPUT);
      Serial.begin(9600);
      Wire.begin(9);     //I2C address
      Wire.onReceive(recieveEvent);
        pinMode(m1, OUTPUT);
  pinMode(m2, OUTPUT);
    }
    void loop() {
      if (d1 == 2)  If condition for receiving
      {
        digitalWrite(13, HIGH);

      digitalWrite(m1, HIGH);
      digitalWrite(m2, LOW); 
}

       else
      {
        digitalWrite(13, LOW);
        digitalWrite(m1, LOW);
        digitalWrite(m2, LOW);

      }

       delay(200);
    }


    void recieveEvent(int howMany)
    {
      while (Wire.available())
      {
      d1 = Wire.read(); //reads the transmitted byte
      }
    }

This is the working videos for I2C Communication.

All the files for I2C Communication are attached here

All the board files are attached here

Group Work

The Group Assignment was to send a message between two projects. The group page can be found here