15. Networking and communications¶
Group Assigment¶
PCM Also known as pulse code modulation. PCM audio data is a raw stream of uncompressed audio sample data, which is standard digital audio data that is sampled, quantized, and encoded by analog signals.
First of all we dowloaded an Arduino model for Proteus’ library. We were making a simulations because of the pandemic.
In the simulator we added two Arduinos, connected a button in one of them, a led in the other and we connected TXD to RXD and RXD to TXD
After that we writted a little code to send a message between the two Arduinos and we selected the Arduino mega’s board and the procesor Atmega2560 in tools
Here are the codes for the transmisor and the receptor
We upload the code in each Arduino by coping the .hex file from Arduino to the board settings in Proteus.
First we were no able to know if the message was being sended so we added a Serial.print() line.
After that started the simulation and we opened the VIRTUAL TERMINAL in Proteus. The message was being sended and received correclty
Finally we make an excercise with a Master and two Slaves
Learning¶
Basically I learned that to run a comunication between multiple boards there is a protocol to be followed in the code. The principle is like a serial comunication process but with diferent codes. The information exchange operates in the same way by EMISION and RECEPTION of electric stimulations.
Programming process¶
Master¶
Activating the I2C bus, a serial communication bus
#include <Wire.h>
Variable setting. byte converts a value to the byte data type.
byte pin[] = {9, 10, 11, 12, 13};
byte estado = 0;
byte retardo = 100;
int ValorSensor = 0;
Pin configuration and comunication begins
void setup() {
pinMode(3,INPUT);
Wire.begin();
}
Slaves configuration
void loop() {
for (int i = 0; i < 5; i++)
{
Wire.beginTransmission(1); // Transmite al Esclavo 1
Wire.write(pin[i]);
Wire.write(estado);
Wire.endTransmission();
Wire.beginTransmission(2); // Transmite al Esclavo 2
Wire.write(estado);
Wire.endTransmission();
Wire.beginTransmission(3); // Transmite al Esclavo 3
Wire.write(i);
Wire.endTransmission();
delay(retardo);
}
```
Configuration of the input (button)
```
if (estado == 0)
{
estado = 1;
}
else
{
estado = 0;
}
}
Slave¶
#include <Wire.h>
Pins configuration
void setup() {
// Pines en modo salida
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
```
Slave related to I2C bus with a name (1)
```
// Unimos este dispositivo al bus I2C con dirección 1 (Esclavo 1)
Wire.begin(1);
// Registramos el evento al recibir datos
Wire.onReceive(llegaDato);
}
Function used each time of receiving information from the master
void loop() {
delay(30);
}
// Función que se ejecuta siempre que se reciben datos del maestro
// siempre que en el master se ejecute la sentencia endTransmission
// recibirá toda la información que hayamos pasado a través de la sentencia Wire.write
void llegaDato()
{
Activating the reception if there is infomation available
int pinOut = 0;
int estado = 0;
// Si hay dos bytes disponibles
if (Wire.available() == 2)
pinOut = Wire.read();
if (Wire.available() == 1)
estado = Wire.read();
Activating the pinout writing form the masters instruccions
// Activamos/desactivamos salida
digitalWrite((pinOut),estado);
}
Learning outcomes¶
*[x] Demonstrate workflows used in network design
*[x] Implement and interpret networking protocols and/or communication protocols
Have you?¶
*[x] Linked to the group assignment page
*[x] Documented your project.
*[x] Documented what you have learned from implementing networking and/or communication protocols
*[x] Explained the programming process/es you used.
*[x] Outlined problems and how you fixed them
*[x] Included design files (or linked to where they are located if you are using a board you have designed and fabricated earlier) and original code.