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.
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.
There are two types of communication protocols which are classified below:
- 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.
Different categories of Inter system protocol:
-
UART Protocol : UART stands for universal asynchronous transmitter and receiver .UART Protocols is a serial communication with two wired protocol .The data cable signal lines are labeled as Rx and Tx. Serial communication is commonly used for transmitting and receiving the signal. It is transfer and receives the data serially bit by bit without class pulses.
Ex: Emails, SMS, Walkie-talkie. -
USART Protocol : USART stands for universal synchronous and asynchronous transmitter and receiver. It is a serial communication of two wire protocol. The data cable signal lines are labeled as Rx and TX. This protocol is used to transmitting and receiving the data byte by byte along with the clock pulses. It is a full-duplex protocol means transmitting and receiving data simultaneously to different board rates. Different devices communicate with microcontroller to this protocol.
Ex:-Telecommunications.
-
USB Protocol : USB stands for universal serial bus. Again it is a serial communication of two wire protocol. The data cable signal lines are labeled D+ and D-.This protocol is used to communicate with the system peripherals.USB protocol is used to send and receive the data serially to the host and peripheral devices.USB communication requires a driver software which is based on the functionality of the system.USB device can transfer data on the bus without any request on the host computer.
Ex: Mouse, Keyboard, Hubs, switches, pen drive. -
Intra System Protocol - The Intra system protocol is used to communicate the two devices within the circuit board. While using this intra system protocols, with out going to intra system protocols we will expand the peripherals of the microcontroller. The circuit complexity and power consumption will be increases by using intra system protocol. Using intra system protocols circuit complexity and power consumption, cost is decrease and it is very secure to accessing the data.
Different categories of Inter system protocol:
- I2C Protocol : I2C stands for inter integrated circuit. I2C requires only two wires connecting all peripherals to microcontroller.I2C requires two wires SDA (serial data line) and SCL (serial clock line) to carry information between devices. It is a master to slave communication protocol. Each slave has a unique address. Master device sends the address of the target slave device and read/write flag. The address is match any slave device that device is ON, remaining slave devices are disable mode. Once the address is match communication proceed between master and that slave device and transmitting and receiving the data.
-
SPI Protocol : SPI stands for serial peripheral interface. It is one of the serial communication protocol developed by Motorola. Some times SPI protocol is also called a 4-wire protocol. It requires four wires MOSI, MISO, SS, and SCLK.SPI protocol used to communicate the master and slave devices. The master first configures the clock using a frequency. The master then selects the particular slave device for communication by pulling the chip select button. That particular device is selected and starts the communication between master and that particular slave. The master select only one slave at a time. It is full duplex communication protocol. Not limited to 8 bit words in the case of bit transferring
-
CAN Protocol : CAN stands for controller area network .It is a serial communication protocol. It require two wires CAN High (H+) and CAN low (H-). It was developed by the Robert bosh company in 1985 for in vehicle networks. It is based on a message oriented transmission protocol.
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¶
-
The task here that i wished to accomplish was to run two different motors on two seperate boards using one master board using one analog input. Hence, I used an ultrasonic sensor as input, and for output I used one Micro servo motor and one DC motor.
-
When an object is placed within a certain distance from the ultrasonic, the servo would turn on, if it is at another specific range, the DC motor on second slave board would turn on, and if neither of these condition is fulfilled, neither of the motors would turn on.
-
These are the I2C connections made for this.
Code¶
To start with you will need to install the ultrasonic library.
-
For that go to this link and download the latest version.
-
Next, go to arduino software and select Sketch>Include Library>Add .ZIP Library
-
Select the zip file you previously downloaded and the software will install the library.
-
You can check the installed libraries by going to Sketch>Include Library>Manage Libraries
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