Networking and Communications
This week's aim is to get two microcontroller boards to communicate with each other. To accomplish so, we must first understand about serial communication protocols. Serial communication is the process of transferring data via a communication channel or computer bus one bit at a time. In class we discussed many forms of serial buses, such as asynchronous, I2C, SPI, CAN, and USB. As a protocol, we use I2C (Inter-Integrated Circuit). Philps designed it in 1982 for a two-wire interface to link low-speed devices in embedded systems such as microcontrollers, EEPROMs, A/D and D/A converters, I/O interfaces, and other similar peripherals. It enables communication between several "slave" digital integrated circuits ("chips") and one or more "master" chips. The slave and master's SDA and SCL pins, as well as VCC and GND for power, must be linked for communication.
SDA - data signal
SCL - clock signal
Assignment
Julia, George, and I collaborated to build a serial communication system using two ESP 32 boards and some cables. We began with a simple UART connection utilising the TX and RX pins on our device. We chose to have our boards transmit and receive messages to and from one another, which we could control using our Arduino serial ports. We used wires with female ends to link the TX pins to the RX pins of the other board and the ground to ground to connect the boards.
We began with a basic arduino code to ensure that we could send a message from the "host" to the "device." We added more to the code to make it more interesting once we made this link. We added "char" before the line of code to read the "incomingByte" to translate the numbers into characters because the messages were sent 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).
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("Roberto: ");
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("Julia: ");
newline = false;
}
char incomingByte = Serial.read();
Serial1.write(incomingByte);
if (incomingByte == 13) {
newline=true;
Serial.println();
}
Serial.print(incomingByte);
}
}