11. Networking and Communications

Group Assignment

This week’s group assignment had us practicing communications between two Arduino Unos. The two were then connected with wires, using a code that allows us to send messages to one another. We noticed that when sending a message, you can’t see it on the sending end. We then altered the code to solve that problem.

My Work

This week, I did not have a very strong understanding of the lesson. I chose to do a simple project.


The project I chose demonstrates serial communication between two microcontroller boards using Serial1. The Sender board, being the rectangular one, transmits a message every second, and the Receiver Board, being the circular one, listens and prints the received message to its serial monitor.


Overall, this code enables a simple one-way comminication system between two boards.

Both Codes

Codes

Sender Code

        
            void setup() {
                // Start Serial1 for TX/RX communication
                Serial1.begin(9600);
              }
              
              
              void loop() {
                // Send a message
                Serial1.println("Hello from Sender!");
                delay(1000);  // send every second
              }
    

Reciever Code

        
            void setup() {
                // Start USB Serial for debug output
                Serial.begin(9600);
                // Start Serial1 for receiving messages
                Serial1.begin(9600);
              }
              
              void loop() {
                if (Serial1.available()) {
                  String msg = Serial1.readStringUntil('\n');
                  Serial.println("Received: " + msg);
                }
              }
    

Quick Overview

Wire Male to Male Placement

For this connection to take place, I used two wires. One wire connected the TX on the sending end to the RX on the receiving end. The other connected the ground from the sending board to the ground on the receiving board. It should look like the following:

CommunicationsBoards