w.1.homw web.jpg

Week 13
Networking and communications.

Happy to see you once again, This week we are studing about various types of Networking and communications use in embbeded technology. 😀

The task list for this week:

  • Group assignment:
    • Send a message between two projects.
  • Individual assignments.
    • design, build, and connect wired or wireless node(s) with network or bus addresses.

Group assignment:

Communication between project boards:

This Group assignment is about studying the various type of communication proto-call in Embedded systems. For this week's group assignment, we try to communicate between two of our project boards via wi-fi. we use two of our project boards from the lab having ESP32-Wroom microcontrollers to establish communication between them.

image not found

Check here to read more about our group assigment.

Individual assignments:

Introduction to Networking and communication:

In an Embedded system Communication is the receiving and transmitting of the data between two or more devices with the help of some formats as well as rules. Communication between electronic devices is like communication between humans. Both sides need to speak the same language.

Data communication:

There are two types of communication mediums:

  • Wired
  • Wireless

And two types of DATA communication type :

  • Paraller communication
  • Serial communication

(1) PARALLEL: In parallel communication, all the bits of data are transmitted simultaneously on separate communication lines.

  • Used for shorter distance.
  • In order to transmit n bit, n wires or lines are used.
  • More costly.
  • Faster than serial transmission.
  • Data can be transmitted in less time.
(2) SERIAL: In serial communication the data bits are transmitted serially one by one i.e. bit by bit on single communication line
  • It requires only one communication line rather than n lines to transmit data from sender to receiver.
  • Thus all the bits of data are transmitted on single lines in serial fashion.
  • Less costly.
  • Long distance transmission.
image not found

Serial communication uses two methods:

  • Synchronous transmission :In this type of serial communication, the sender and receiver are synchronized using an external synchronization clock. Since the data being transmitted has no gaps between them, the receiver identifies the starting of character or data using a common clock pulse. This synchronous clock pulse provides a constant time interval between the data transmission which depends on the frequency of the clock pulse.. Examples of synchronous communication are: I2C, SPI etc.
  • image not found

  • Asynchronous transmission :In Asynchronous transmission is a type of serial transmission that follows a non-synchronized form of communication. Thus start and stop bits are required in order to intimate the receiver about the beginning and end of the data stream. Examples of asynchronous communication are Universal Asynchronous Receiver Transmitter (UART), CAN etc.
  • image not found

Data Transmission Modes in a network:


Data Transmission mode defines the direction of the flow of information between two communication devices. It is also called Data Communication or Directional Mode.
The data transmission modes can be characterized in the following three types based on the direction of exchange of information:
  • Simplex
  • Half-Duplex
  • Full Duplex

(1)Simplex:Simplex is the data transmission mode in which the data can flow only in one direction, i.e., the communication is unidirectional.

image not found

(2)Half-Duplex:Half-Duplex is the data transmission mode in which the data can flow in both directions but in one direction at a time. It is also referred to as Semi-Duplex. image not found

(3) Full-Duplex:Full-Duplex is the data transmission mode in which the data can flow in both directions at the same time. It is bi-directional in nature. image not found

Bit rate & Baud Rate Concepts:

1. Bit rate :
Bit rate is the number of binary bits (1s or 0s) transmitted per second.

Bit rate = number of bits transmitted/ total time (in seconds)

The bit rate can also be defined in terms of baud rate:
Bit rate = Baud rate x bits per signal or symbol

2. Baud rate :
Baud rate is the rate at which the number of signal elements or changes to the signal occurs per second when it passes through a transmission medium. The higher a baud rate is the faster the data is sent/received

Baud rate = number of signal elements/total time (in seconds)

Example: image not found

In Image , Number of signal elements (marked in red color) = 6, Number of bits transmitted (1, 1, 0) = 3. So, Here Bit rate = 3/1 = 3 bits per second. and, Baud rate = 6/1 = 6 baud per second.

Communication Protocall:

Communication Protocols are a set of rules that allow two or more communication systems to communicate data via any physical medium.
In Embedded systems, communication protocols hold a special place as it opens up ways to efficiently exchange data between devices. A Communication protocol is a set of rules agreed upon by both the sender and receiver on the bases of data packed., bits constituting a character,data begins and ends.

Types of Communication Protocall:

There are two types of communication protocols :

  • Inter System Protocol.
  • Intra System Protocol

(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 an inter bus system. image not found

The different categories of intersystem protocol mainly include the following.
  • UART Protocol:UART stands for a universal asynchronous transmitter and receiver. UART Protocols is a serial communication with two wired protocols. The data cable signal lines are labeled as Rx and Tx. Serial communication is commonly used for transmitting and receiving the signal. It is transferred and receives the data serially bit by bit without class pulses. The UART takes bytes of data and sends the individual bits in a sequential manner.
  • USART Protocol:USART stands for a universal synchronous and asynchronous transmitter and receiver. It is a serial communication of a 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 that means transmitting and receiving data simultaneously to different board rates. Different devices communicate with microcontroller to this protocol.
  • 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 driver software that is based on the functionality of the system.
(2)Intra System Protocol:The Intra system protocol establishes communication between components within the circuit board. In embedded systems, intra system protocol increases the number of components connected to the controller.
Increase in components lead to circuit complexity and increase in power consumption. Intra system protocol promises secure access of data from the peripherals. image not found

The different categories of intrasystem protocol mainly include the following.
  • SPI Protocol:SPI stands for the serial peripheral interface. It is one of the serial communication protocol developed by Motorola. Sometimes 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.
  • CAN Protocol:CAN stands for the controller area network. It is a serial communication protocol. It requires 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.
  • I2C Protocol:I2C stands for the inter-integrated circuit and it requires only two wires connecting all peripherals to the microcontroller. I2C requires two wires SDA (serial data line) and SCL (serial clock line) to carry information between devices. It is a master to a slave communication protocol. Each slave has a unique address. The master device sends the address of the target slave device and reads/writes the flag.

I2C Bus Communication:

What is I2C ?

Introduction to I2c communication .

I2C stand for Inter-Integrated circuit bus it is also called I2C, IIC as well, TWI ( Two-Wire Interface) is a subset of I2C protocol.I2C is a serial bidirectional Low speed 2 wire interface . Developed by Phillips in 1982 for the telephonic industry. but nowadays every semiconductor manufacturer is useless due to its low cost and less logic gate count and 2 wire requirement. It is suitable over short distances over 1meater.

I2c Interfaces

image not found

I2C protocall block digram.

I2C protocol uses two wires for data transfer between devices: Serial Data Line (SDA) and Serial Clock Line (SCL). Any device connected to the bus must act as a master or a slave. The master generates a clock signal and initiates a data transaction by addressing a slave on the bus and telling whether it wants to transmit or receive data. Each Slave has its own unique address starting with 7-bit and can attach up to 128 devices max for a 7-bit address also some new protocol fallows up to a 10-bit address which extends the device connectivity up to 1024 devices max.

Open-Drain Outputs: The two pull-up resistance are always connected to the SDA and SCK with VDD because SDL and SCL pins of the master device are designed with the transistors in the open state, so data transfer is possible only when these transistors are conducted.

I2C Waveform Characteristics:

image not found

Bit transfer:No. of bits transfer per clock pulse is called bits transfer. One data bit is transferred during each clock pulse.
Start and Stop Bit Condition:All I2C transactions are initiated with the start condition. And end with a stop condition. when the master micro-control wants to talk to a slave it activates the start condition.
Start Condition:

  • Master SDA=HIGH to LOW
  • Master SCL=Hold HIGH

STOP Condition:
  • Master SDA=LOW to HIGH
  • Master SCL=Hold HIGH
  • From Idle state (no clock)
  • Master SCL=SDA=HIGH.
Slave Address:A slave address is a unique address followed by 7 bits .which is help full to target the specific device during communication. .
Read /Write Bit:R/W bit together with slave address forms control byte .This bit inform the slave a master wants to read or wright. .
  • R/W:HIGH =Read data request.
  • R/W:LOW =Data will be sent.
Acknowledge:: Each frame in a message is followed by an acknowledge/no-acknowledge bit. If an address frame or data frame was successfully received, an ACK bit is returned to the sender from the receiving device. .
  • ACK= =Acknowledge=LOW(zero)
  • NACK =Acknowledge=HIGH(one)

Board I am using this week:

For this week I am continuing with my final project bord. I make in my output devices assignment. I am using It as a master device to communicate with the LCD display with the I2c module. Following is the schematic and board design in the eagle of my final board from week 10.

Scametic Designe:

image not found

Final board piout and funcanality.

Board design:

image not found

Final board piout and funcanality.

Final Board V1:

image not found

Final board piout and funcanality.

Final Board V1:

image not found

Final board piout and funcanality.

I2C bus with LCD display with I2c module (PCF8574 ) and my final bord. :

I2C bus in ATtiny1614. :

image not found

Attiny1614-TWI.

To demonstrate I2c communication .I decided to use my final project board(ATtiny1614).I started searching the I2c protocol in ATtiny 1614 IC .But it was not there with same name.

image not found

TWI-block digram.

I found TWI - Two-Wire Interface protocol which I then come to know is a subset of a I2C communication. I read a bit and ensure the I2C bus works and proceed forward.

I2C Interface Adapter Module.

image not found

I2C Interface Adapter Module.

I2C Interface Adapter Module is used for 16x2 LCD Display.It uses the PCF8574T IC chip which converts I2C serial data to parallel data for the LCD display. Also this interface module simplifies 16 header pins out of 16x2 Liquid Crystal display into only 4 wires SDA, SCL, Vcc and Gnd.

It also provides division where one can change the address of a module just by soldering one of the connections.

Chenging I2C address.

image not found

Device address.

To know about it further I read the data sheet of PCF8574T IC . where I come to know that the last 3 bits of the Slave address are hardware selectable. So I can change the Address of one of the modules externally by LOW down the one of address bit Bit among A0, A1, A2.

image not found

Address maps.

There are 8 address combinations that can be found among these 3 connections.I solder A0 bit of one of my modules to change its Address. According to the datasheet, the changed combination should give 26h as a 7-bit hexadecimal address.

image not found

Changing address of I2C module.

I2C Serial BUS connection .

image not found

I2C Serial BUS connection.

Above I show how I connect I2C Interface Adapter Module as slave in the I2C Serial BUS connection with my board as master device.

image not found

Parallel connector.

To connect this module physically.I make a small 4-pin header connector. Using a through-hole board and header pin connector and soldering them in parallel.

image not found

I2C Serial BUS connection setup.

Here is the setup ready for the I2C protocol between 2 I2C Interface Adapter Module with 16x2 LCD Display as Slave devise and my Board as Master devise.

Scanning I2C address.

For confirming the address once again I refer to this blog from last-minute engineers. Where I found this code for Determining the I2C Address.

             
      
  /* This code is to find the I2C Address of LCD_I2C module 
  Use for Fab Accademy 2022 by vrushabh zunjurkar
  original source :  https://lastminuteengineers.com/i2c-lcd-arduino-tutorial/
  */
  
  
  #include < Wire.h >
  
  void setup() {
    Serial.begin (9600);
  
    // Leonardo: wait for serial port to connect
    while (!Serial) 
      {
      }
  
    Serial.println ();
    Serial.println ("I2C scanner. Scanning ...");
    byte count = 0;
    
    Wire.begin();
    for (byte i = 8; i < 120; i++)
    {
      Wire.beginTransmission (i);
      if (Wire.endTransmission () == 0)
        {
        Serial.print ("Found address: ");
        Serial.print (i, DEC);
        Serial.print (" (0x");
        Serial.print (i, HEX);
        Serial.println (")");
        count++;
        delay (1);  // maybe unneeded?
        } // end of good response
    } // end of for loop
    Serial.println ("Done.");
    Serial.print ("Found ");
    Serial.print (count, DEC);
    Serial.println (" device(s).");
  }  // end of setup
  
  void loop() {
      while (!Serial) 
      {
      }
  
    Serial.println ();
    Serial.println ("I2C scanner. Scanning ...");
    byte count = 0;
    
    Wire.begin();
    for (byte i = 8; i < 120; i++)
    {
      Wire.beginTransmission (i);
      if (Wire.endTransmission () == 0)
        {
        Serial.print ("Found address: ");
        Serial.print (i, DEC);
        Serial.print (" (0x");
        Serial.print (i, HEX);
        Serial.println (")");
        count++;
        delay (1);  // maybe unneeded?
        } // end of good response
    } // end of for loop
    Serial.println ("Done.");
    Serial.print ("Found ");
    Serial.print (count, DEC);
    Serial.println (" device(s).");
  delay(5000);
      }
      
      

I2C Address Scanning code.

Scanning I2C Address.

After scanning the Address of I2C Modules I found I scan two Devices of address as follows.

  1. Found address:38(0x26)
  2. Found address:39(0x27)
Which are same as per the data sheet as I found.

I2C Communication using 16x2 LCD Display.

Now for making I2C communication between the 16×2 LCD Display and my board. I use the same code from the Input devices assignment for the LCD display code. Customizing it for 2 Individual LCDs with two different addresses naming them LiquidCrystal_I2C lcd1 & LiquidCrystal_I2C lcd2 And define each lcd.print() function to display ,Display1 and Display 2 on LiquidCrystal_I2C lcd1 and LiquidCrystal_I2C lcd2 respectively.

  
#include <Wire.h>
  #include <LiquidCrystal_I2C.h>
  
  LiquidCrystal_I2C lcd1(0x27, 16, 2);// display 1
  LiquidCrystal_I2C lcd2(0x26, 16, 2);// display 2
  
  
  byte Heart[8] = {
  0b00000,
  0b01010,
  0b11111,
  0b11111,
  0b01110,
  0b00100,
  0b00000,
  0b00000
  };
  
  void setup()
  {
    lcd1.init();                      // initialize the lcd 
    lcd1.createChar(0, Heart);
    // Print a message to the LCD.
    lcd1.backlight();
    lcd1.clear();
  
    lcd2.init();                      // initialize the lcd 
    lcd2.createChar(0, Heart);
    // Print a message to the LCD.
    lcd2.backlight();
    lcd2.clear();
  }
  
  void loop()
  {
    lcd1.setCursor(0, 0);
    lcd1.print("Display 1");
    lcd1.setCursor(10,0);
    lcd1.write(0);
    
    lcd1.setCursor(0, 1);
    lcd1.print("Fab academy2022");
  
  
    lcd2.setCursor(0, 0);
    lcd2.print("Display 2");
    lcd2.setCursor(10,0);
    lcd2.write(0);
    
    lcd2.setCursor(0, 1);
    lcd2.print("Fab academy2022");
  
    //lcd1.clear();
    //lcd2.clear();
  }
         
  

Code I use to display the display no.of individual display.

display the display no. of individual display.

image not found

Output.

After establishing the I2C communication between two LCDs display successfully and confirm the display address with display no. ( luckily it was the same) . I decided to try to print the temperature on each Display using the K-type thermocouple.So I custom the code to print degree celsius on Display 1 and Fahrenheit on Display 2.

      /*
      AnalogReadSerial
      This Code is costum by vrushabh zunjurkar for fab accademy 2022.
      Networking and communications.projecting data on LCD 16*2 screan using there addresses by I2c communication. 
    */
    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>
  #include "max6675.h"
  
  LiquidCrystal_I2C lcd1(0x27, 16, 2);// display 1
  LiquidCrystal_I2C lcd2(0x26, 16, 2);// display 2
  
  int thermoDO = 9;
  int thermoCS = 8;
  int thermoCLK = 10;
  
  MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
  
  void setup()
  {
    Serial.begin(9600);
  
    Serial.println("MAX6675 test");
    // wait for MAX chip to stabilize
    
    lcd1.init();                      // initialize the lcd 
    lcd1.backlight();
    lcd1.clear();
  
    lcd2.init();                      // initialize the lcd 
    lcd2.backlight();
    lcd2.clear();
  
    delay(500);
  }
  
  void loop()
  {
    Serial.print("C = "); 
    Serial.println(thermocouple.readCelsius());
    Serial.print("F = ");
    Serial.println(thermocouple.readFahrenheit());
   
    // For the MAX6675 to update, you must delay AT LEAST 250ms between reads!
    delay(1000);
  
   
   lcd1.setCursor(0, 0);
   lcd1.print("Display 1");
   lcd1.setCursor(0, 1);
   lcd1.print("C =");
   lcd1.setCursor(3, 1);
   lcd1.print(thermocouple.readCelsius());
  
   lcd2.setCursor(0, 0);
   lcd2.print("Display 2");
   lcd2.setCursor(0, 1);
   lcd2.print("F = ");
   lcd2.setCursor(3, 1);
   lcd2.print(thermocouple.readFahrenheit());
   
  //  lcd1.clear();
  //  lcd2.clear();
  
  }
         
    

Code I use to Display temprature in degree celsius and fahrenheit on display1 & display2 respectively.

Display temprature in degree celsius and fahrenheit on display1 & display2 respectively.

image not found

Output.