Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Texting Via Serial Communication Use Arduino to write code that will connect two

ID: 2079802 • Letter: T

Question

Texting Via Serial Communication

Use Arduino to write code that will connect two platforms via serial communication (TX and RX pins), (Arduino Uno & Intel Galileo Gen 2).

Text messages sent from a either platform is received and displayed in the other platform.  As for components, two LEDs for each platform (one red and the other green color), (b) an analog input device (potentiometer); and (c) a Seeed Grove LCD RGB Backlight module.

The message communication for this lab should follow our class' own 456 Protocol (please see below). The completed work should function as follows:

(1) A platform works at a given time as one of the two modes: transmitter or a receiver (but not both);

(2) One time selection (right after uploading of the code or right after a reset button is pressed and releases) of the initial mode for transmitter or receiver is done by the position of the analog input (for example, a value or a position below a certain threshold would set the platform as a transmitter and a value higher as a receiver, or vice versa);

(3) The LEDs in different color should indicate the selected mode in the following manner: {Red LED ON - Green LED OFF} for transmitter and {Green LED ON - Red LED OFF} for receiver mode.

(4) When the transmitter mode is selected, the code first pause for 2 seconds, then sends a secret text message (embedded in the code), following the 456 Protocol, of maximum 12 letters or numbers or combination of them at the speed of 9600 bps, repeatedly 3 times with 500 milli-second pause between messages and, after the transmission is completed, immediately changes its mode to receiver;

(5) When the receiver mode is selected, with no delay, the code receives at 9600 bps the data stream (remember that there are multiple number of but the same text message coming in) and, at the end of the data receipt, decodes the data stream by the 456 Protocol, displays the Sender ID only (when the message is intended for another platform) or Sender ID and the message (when the message is intended for the platform) on the LCD and, after the receipt and display is done, pauses 2 seconds and changes its mode to transmitter.

456 Protocol

1. What is the 456 Protocol?

(Ans) 456 Protocol is an arbitrary communication protocol which include platform-to-platform(s) communications.

2. What is the basic feature of 456 Protocol?

(Ans) In the 456 Protocol, any message in communication is comprised of multiple bytes, and these bytes

include some head-bytes followed by the message bytes. Therefore when a message is transmitted, the additional

head-bytes should precede the message itself.

3. What are the head-bytes in the 456 Protocol?

(Ans) There are 5 head bytes and their purposes are listed below.

Head Byte

Contents

Purpose

1st Byte

“4”

This is Preamble which indicates some data present over the communication system.

2nd Byte

“5”

This is Sync byte for the receiver should catch even though it may miss the preamble, and if this Sync byte is not correct in the receiver, the receiver assumes that the message is sent from Mars or Moon (not from the class), and ignores it.

3rd Byte

“6”

This indicates our Embedded class Group (Group A or Group B). If this byte is not correct in the receiver, the receiver assumes that the message is sent from another class, and ignores it.

4th Byte

Any ASCII

character

This serves as the Source ID of the message. If the receive knows and expects a message from a known ID, then the following message may be directed for the receiver; otherwise, it’s not from someone the receiver expects.

5th Byte

Any ASCII character

This serves as the Destination ID of the message. If the receiver’s ID is the same as this 5th Byte, then finally the following message is for it to receive and display.

4. Can you show an example when one platform (whose ID is, for example, A) sends a message of “Hi Tom” to another platform (Whose ID is B)?

(Ans) In a pseudo-code, this is message transmission complied with the 456 Protocol:

Send “456ABHi Tom”

5. Can you tell how the receiver handles the stream of data and knows and extracts the message?

(Ans) In a pseudo-code, this is the receiver would do:

     Read data stream and save as M

     Check if M(1) = “5” and M(2) =” 6” ; Check the Sync and Group Byte from the message M

                                                                   ; here we ignore M(0) preamble

     Check if M(3)=”A” ; from a known transmitter

     Check if M(4) =”B” ; this is for the receiver

    If all yes, extract M(5 – end) as D

    Display “A” (the Source) and D on the LCD screen.

Head Byte

Contents

Purpose

1st Byte

“4”

This is Preamble which indicates some data present over the communication system.

2nd Byte

“5”

This is Sync byte for the receiver should catch even though it may miss the preamble, and if this Sync byte is not correct in the receiver, the receiver assumes that the message is sent from Mars or Moon (not from the class), and ignores it.

3rd Byte

“6”

This indicates our Embedded class Group (Group A or Group B). If this byte is not correct in the receiver, the receiver assumes that the message is sent from another class, and ignores it.

4th Byte

Any ASCII

character

This serves as the Source ID of the message. If the receive knows and expects a message from a known ID, then the following message may be directed for the receiver; otherwise, it’s not from someone the receiver expects.

5th Byte

Any ASCII character

This serves as the Destination ID of the message. If the receiver’s ID is the same as this 5th Byte, then finally the following message is for it to receive and display.

Explanation / Answer

Code that will connect two platforms via serial communication
#include <stdio.h>
#include< conio.h>
void main()
   {
   FILE *fptr;
    char name[20];
  
    int age;
   float salary;
/* open for writing */
    fptr = fopen("emp.rec", "w");
   if (fptr == NULL)
       {
           printf("File does not exists ");

       return;
       }  
printf("Enter the name ");
scanf("%s", name);

fprintf(fptr, "Name = %s ", name);

printf("Enter the age ");
scanf("%d", &age);
fprintf(fptr, "Age = %d ", age);

printf("Enter the salary ");

scanf("%f", &salary);
fprintf(fptr, "Salary = %.2f ", salary);
fclose(fptr);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote