Week 13. Networking and Communications
Image Courtesy: Photo by Jordan Harrison on Unsplash
In this assignment we need to make a communication between microcontroller boards in which any one must be design and build by our own. We can use any protocols to communicate. Wired or wireless.
Assignment Tasks:
-
Individual Assignment: Design, build, and connect wired or wireless node(s) with network or bus addresses.
-
Group Assignment: Send a message between two projects.
Learning Process
Networking
Networking refers to the practice of linking different devices, systems, or networks together to enable communication and data exchange. It involves the creation and management of a network infrastructure that allows devices to connect and communicate efficiently. Networks can be classified based on their geographical scope.
1. LAN (Local Area Network )
2. WAN (Wide Area Network)
3. MAN (Metropolitan Area Networks)
4. Wireless Networks
5. Cellular Networks
Communication
Communication is the process of exchanging information or messages between individuals, devices, or systems. It can take various forms, such as verbal, written, or visual, and occurs through different mediums.
Uses of Network and Communication
Network and communication systems play a crucial role in many areas of modern life, and they have a wide range of uses, including:
-
Data transmission: The transfer of data, such as files, images, and video, between computers and other devices.
-
Remote access: Enabling employees to access company resources, such as applications and data, from remote locations.
-
E-commerce: Facilitating online transactions and commerce, such as online shopping and banking.
-
Telecommuting: Allowing employees to work from home or other remote locations using network and communication systems.
-
Teleconferencing: Enabling real-time audio and video communication between individuals or groups in different locations.
-
Resource sharing: Sharing resources such as printers, scanners, and storage devices among multiple computers and users.
-
Online gaming: Enabling multiplayer gaming experiences and connecting players from around the world.
-
Cloud computing: Providing access to shared computing resources and applications over the internet.
-
Social networking: Connecting people through social media platforms, such as Facebook and Twitter.
-
IoT (Internet of Things): Connecting and communicating with smart devices and other IoT-enabled products.
Communication Protocols
Intersystem Protocol
The intersystem protocol helps to establish communication between two devices. A good example is a computer and a development board via inter bus system.
Intersystem protocols are of three categories:
1. USB
2. UART
3. USART
USB
This can then be sub-divided into four:
UART
USART
Intra system Protocol
The Intra system protocol establishes communication between components within the circuit board. In embedded systems, intra-system protocol increases the population of components connected to the controllers. An increase in components led to circuit complexity and increased power consumption. Intra system protocol promises secure access to data from the peripherals.
The categories of Intersystem protocols are:
1. I2C
2. SPI
3. CAN
I2C Protocol
Philips invented the Inter-Integrated Circuits protocol (IIC or I2C) in 1982. The I2C protocol connects multiple slaves to a single master or various slaves to multiple masters. The I2C protocol operates when two microcontrollers send data to the same memory or send identical data to the LCD with many other applications. The I2C serial communication protocol has two signals: Serial Data (SDA) and Serial Clock (SCL). The master and slave receive data through the SDA line, and SCL is the clock signal line. The I2C protocol supports, depending upon the modes of operation, different data speeds ranging from 100kbit/s in standard mode to 3.4 Mbps in full speed mode.
I2C protocols use data from hardware sensors, communicate with multiple microcontrollers, display control of cellphones, change color settings of the monitor color, assess ADCs and DACs, circuits, and read specific memory ICs. They also operate in control applications like controlling and transmitting user-directed actions and switching on/off the power supply of the internal components.
Here in my assignment, I am following I2C Protocol.
SPI
CAN
Individual Assignment
First, a communication plan needs to be created. Following this, either new or pre-existing boards made during a previous week may be used. Since I had already added I2C pins for communication to my input devices week board, as my lecturer had advised while I was developing, I didn’t understand at the time what this was or why I was doing it, but now I do. Now I chose to use that board.
My input device was an ultrasonic sensor, which locates things in its vicinity and uses a formula in programming to determine their distance. Details in Week 11 Assignment Page.
As mentioned earlier, I have added I2C protocol in thta board. The pin J3 has a VCC, GND, SCL & SDA pins. But i wasn’t aware of the pull up resistor which is need in I2C. So as intructed by my tutor, I have added 2 10k resistor across the VCC and SCL & SDA pins respectively.
A simple sketch showing how I2C functions;
So one of our daughter board is ready (slave 1). Now we need to make a mother board (master) and another daughter board (slave 2). I made a design where the board can be used as both mother and daughter at same time. In the daughter board we can add an output device. I chose a speaker.
So the plan was to use daughter 1 as the input board, reading objects in its vicinity and sending the distance in centimetres calculated within the board itself to the mother board, where it is received and processed using the criteria we provided, and sending signals to daughter 2 to make a beep sound if the object crosses the permissible limit, that we set as 25cm.
I designed a board using ATtiny 1614 microchip, which consists of 1 I2C pin, and another for serial communication as well as programming. That is VCC, UPDI, GND, RX, TX. Along with 2 LEDs, one for power another connected to a digital pin. In the same board I added 2 pins for conncecting speaker which we will be using only for daughetr 2 board.
The PCB design
PCB Production
Once the deisgn is completed, now is the time for production.
Bill Of Materials
Reference | Item | Quantity | Specification |
---|---|---|---|
C1 | Capacitor | 2 | 100nf |
D1 | Diode - LED | 4 | |
J1 | Conn_PinHeader_2x02_P1.27mm_Vertical_SMD | 2 | |
J2 | Conn_PinSocket_FTDI_1x06_P2.54mm_Horizontal_SMD | 2 | |
LS1 | Buzzer | 1 | |
Q1 | MOSFET_N-CH_30V_1.7A | 1 | |
R1, R2 | Resistor | 4 | R499 |
R3 | Resistor | 2 | 1K |
R4 | Resistor | 2 | 10K |
U1 | ATtiny1614-SS | 2 |
Soldering
Once milling is done now we can solder everything in place. This time I feel more comfortable while soldering. And the result looks nice for me considering my previous ones.
Now the board is ready and its time we must load the bootloader by connecting the same using a programmer which was made previuosly by our team for all our future needs.
Once the bootloader is intalled, its time to check the board is fucntioning properly. Like the previous weks, I used blick example to make sure the board is fucntioning properly.
Now is the time to try communication. Lets connect the I2C cable and try with a simple example. With the help of our tutor I used master_read & slave_write examples from Arduino. Which functioned as well.
Now we will program the boards for our plan.
Code Master Board
#include <Wire.h>
void setup() {
Wire.begin(); // join I2C bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop() {
Wire.requestFrom(8, 6); // request 6 bytes from slave device #8
while (Wire.available()) { // slave may send less than requested
int c = Wire.read(); // receive a byte as character
if (c != 255) {
if (c < 25) {
Wire.beginTransmission(15); // transmit to device #8
Wire.write("a"); // sends five bytes
Wire.endTransmission(); // stop transmitting
}
Serial.println(c); // print the character
}
}
delay(500);
}
Code for Daughter Board 1 - The Board with Sensor
#include <Wire.h>
const int echoPin = 15;
const int trigPin = 14;
long duration, distance;
void setup() {
Wire.begin(8); // join I2C bus with address #8
Wire.onRequest(requestEvent); // register event
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
delay(100);
}
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
// Write a pulse to the HC-SR04 Trigger Pin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Measure the response from the HC-SR04 Echo Pin
duration = pulseIn(echoPin, HIGH);
// Determine distance from duration
// Use 343 metres per second as speed of sound
distance= duration*0.034/2;
Wire.write(distance); // respond with message of 6 bytes
// as expected by master
}
Code for daughter Board 2 - the board with Speaker
#include "pitches.h"
#include <Wire.h>
bool play =false;
// notes in the melody:
int melody[] = {
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4, 8, 8, 4, 4, 4, 4, 4
};
void setup() {
Play();
Wire.begin(15); // join I2C bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void loop() {
if(play){
Play();
}
delay(100);
}
void Play()
{
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 8; thisNote++) {
// to calculate the note duration, take one second divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / noteDurations[thisNote];
tone(1, melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(1);
play = false;
}
}
void receiveEvent(int howMany) {
while (0< Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
if(c == 'a' && !play)
{
play =true;
}
c = ' ';
}
}
The Final Result
Hero Shot
Group Assignment
Detailed Study Report on our Group Assignment Page.
Downloads
Help Taken & Other References
Chat GPT used for doubt clearing and content helps.