🗓 30 March 2022
Network & Communications
In this class we learned about networks and protocols and their functions.
A network is a group of computers connected among themselves through communication lines.
A protocol is the set of rules that specify message formatsand procedures that allow machines and programs to exchange information.
Networks and protocols are used for different reasons: when we can't use the same hardware, we want to do serveral things at the same time, to develop modules, and avoid interference between systems.
Things to keep in mind when choosing a network:
- Power consumption
- Range
- Bandwidth
- Existing networks? or adhoc?
- Mobility
Assignment:
Paula and I got together to make a serial communication with two ESP 32 boards and some wires.
We started with a simple example of an UART connection, using the TX and RX pins on our board.
We decided to make our boards send and receive messages to and from eachother, which we could control from our Arduino serial ports.
Connecting the boards was pretty straight forward, we used wires with female ends to connect the TX pins to the RX pins of the other board and the ground to ground.
Then we started with a simple code in arduino to make sure we could send a message from the "host" to the "device".
Once we had this connection established, we added more to the code to make it more interesting.
The messages were sending using ASCII codes (American Standard Code for Information Interchange, a set of digital codes representing letters, numerals, and other symbols, widely used as a standard format in the transfer of text between computers),
so we added "char" before the line of code to read the "incomingByte" to translate the numbers into characters.
We also wanted to test if we were able to add our individual names so we can identify which person was sending the message (essentially creating a chat box).
We were able to add a line that printed our names (or whatever we decided) along with our message, but the name was not placed before but following our message.
It wasn't clear why the name wouldn't print before the message, so we asked for Jeremy's help in modifying this code.
Essentially, we had to separate the lines of code that would print our names from the lines of code that would print our messages,
and place it before the message codes within the "void loop".
Our final code:
bool newline = true;
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
if (Serial1.available() > 0) {
if (newline == true){
Serial.print("Paula: ");
newline = false;
}
char incomingByte = Serial1.read();
if (incomingByte == 13) {
newline=true;
Serial.println();
}
Serial.print (incomingByte);
}
if (Serial.available() > 0) {
if (newline == true){
Serial.print("Angel: ");
newline = false;
}
char incomingByte = Serial.read();
Serial1.write(incomingByte);
if (incomingByte == 13) {
newline=true;
Serial.println();
}
Serial.print(incomingByte);
}
}