UART (Universal Asynchronous Receiver/Transmitter) is a commonly used serial communication protocol in electronics and embedded systems. It facilitates the transmission and reception of data between devices using two wires: one for transmitting data (TX) and one for receiving data (RX).
Multiple Nodes Connected Using UART
ATtiny1614
Designing the Student Board
PCB Milling
PCB Soldering
Bootloader
Programming the Eagle Board and the Two Student Board
Eagle Board Code
// Eagle Board [Board 0] CODE
// Define pin numbers for button and RGB LED
#define button 4
#define redPin 5
#define greenPin 8
#define bluePin 9
// Variable to store incoming message
char message;
void setup() {
// Initialize serial communication at a baud rate of 9600
Serial1.begin(9600);
// Set button pin as input
pinMode(button, INPUT);
// Set RGB LED pins as output
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
// Turn off RGB LED initially by setting all colors to HIGH (assuming common anode RGB LED)
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, HIGH);
}
void loop() {
// Check if there is any data available to read from the serial port
if (Serial1.available()) {
// Read the incoming message
message = Serial1.read();
// Check the received message and set the LED color accordingly
if (message == '0') {
// Set LED color to blue
analogWrite(redPin, 255);
analogWrite(greenPin, 255);
analogWrite(bluePin, 0);
}
if (message == '1') {
// Set LED color to green
analogWrite(redPin, 255);
analogWrite(greenPin, 0);
analogWrite(bluePin, 255);
}
if (message == '2') {
// Set LED color to red
analogWrite(redPin, 0);
analogWrite(greenPin, 255);
analogWrite(bluePin, 255);
}
}
// Check if the button is pressed
if (digitalRead(button) == 1) {
// Send '0' character over serial when button is pressed
Serial1.write('0');
// Set LED color to blue
analogWrite(redPin, 255);
analogWrite(greenPin, 255);
analogWrite(bluePin, 0);
}
// Small delay to debounce the button and to prevent spamming the serial port
delay(20);
}
Explanation of the Code
Pin Definitions:
Setup Function:
Main Loop:
Student Board 1 Code
// Board 1 CODE
// Define pin numbers for button and RGB LED
#define button 9
#define redPin 0
#define greenPin 1
#define bluePin 10
// Variable to store incoming message
char message;
void setup() {
// Start serial communication at a baud rate of 9600
Serial.begin(9600);
// Set button pin as input
pinMode(button, INPUT);
// Set RGB LED pins as output
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
// Turn off RGB LED initially by setting all colors to HIGH (assuming common anode RGB LED)
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, HIGH);
}
void loop() {
// Check if there is any data available to read from the serial port
if (Serial.available()) {
// Read the incoming message
message = Serial.read();
// Check the received message and set the LED color accordingly
if (message == '0') {
// Send '0' character back over serial
Serial.write('0');
// Set LED color to blue
analogWrite(redPin, 255);
analogWrite(greenPin, 255);
analogWrite(bluePin, 0);
}
if (message == '1') {
// Set LED color to green
analogWrite(redPin, 255);
analogWrite(greenPin, 0);
analogWrite(bluePin, 255);
}
if (message == '2') {
// Send '2' character back over serial
Serial.write('2');
// Set LED color to red
analogWrite(redPin, 0);
analogWrite(greenPin, 255);
analogWrite(bluePin, 255);
}
}
// Check if the button is pressed
if (digitalRead(button) == 1) {
// Send '1' character over serial when button is pressed
Serial.write('1');
// Set LED color to green
analogWrite(redPin, 255);
analogWrite(greenPin, 0);
analogWrite(bluePin, 255);
}
// Small delay to debounce the button and to prevent spamming the serial port
delay(20);
}
Explanation of the Code
Pin Definitions:
Setup Function:
Main Loop:
Student Board 2 Code
// Board 2 CODE
// Define pin numbers for button and RGB LED
#define button 9
#define redPin 0
#define greenPin 1
#define bluePin 10
// Variable to store incoming message
char message;
void setup() {
// Start serial communication at a baud rate of 9600
Serial.begin(9600);
// Set button pin as input
pinMode(button, INPUT);
// Set RGB LED pins as output
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
// Turn off RGB LED initially by setting all colors to HIGH (assuming common anode RGB LED)
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, HIGH);
}
void loop() {
// Check if there is any data available to read from the serial port
if (Serial.available()) {
// Read the incoming message
message = Serial.read();
// Check the received message and set the LED color accordingly
if (message == '0') {
// Set LED color to blue
analogWrite(redPin, 255);
analogWrite(greenPin, 255);
analogWrite(bluePin, 0);
}
if (message == '1') {
// Set LED color to green
analogWrite(redPin, 255);
analogWrite(greenPin, 0);
analogWrite(bluePin, 255);
}
if (message == '2') {
// Set LED color to red
analogWrite(redPin, 0);
analogWrite(greenPin, 255);
analogWrite(bluePin, 255);
}
}
// Check if the button is pressed
if (digitalRead(button) == 1) {
// Send '2' character over serial when button is pressed
Serial.write('2');
// Set LED color to red
analogWrite(redPin, 0);
analogWrite(greenPin, 255);
analogWrite(bluePin, 255);
}
// Small delay to debounce the button and to prevent spamming the serial port
delay(20);
}