Design, build, and connect wired or wireless node(s) with network or bus addresses
Serial communication is used for the exchange of information between the microcontrollers and a computer or other devices. All microcontroller have at least one serial port that allows communication in a direct way or also gives the possibility of connecting wireless communication modules such as Bluetooth, ZigBee, LiFi and others. First of all, we were understanidng everything posible about the purposes, serial buses, physical media, modulation, channel sharing, errors, networking and RF form this page link with more information
We started the practice.
//Slave 1
#include
void setup() {
// Pines en modo salida
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
// Unimos este dispositivo al bus I2C con dirección 1 (Esclavo 1)
Wire.begin(1);
// Registramos el evento al recibir datos
Wire.onReceive(llegaDato);
}
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()
{
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();
// Activamos/desactivamos salida
digitalWrite((pinOut),estado);
Preparing the software to learn about it.
Working with some basic tools.
Editing colors and some basic stuff.
Having the results.
//Slave 2
#include
void setup() {
pinMode(13, OUTPUT); // Pines en modo salida
Wire.begin(2); // Unimos este dispositivo al bus I2C con dirección 2 (Esclavo 2)
Wire.onReceive(llegaDato);
}
void loop() {
delay(30);
}
void llegaDato(){
int estado = 0;
if (Wire.available() == 1) // Si hay un byte disponible
{
estado = Wire.read();
}
digitalWrite(13,estado); // Activamos/desactivamos salida depende del Maestro
}
I added some other options to still learn about this software.
//Slave 3
#include
void setup() {
// Pines en modo salida
pinMode(13, OUTPUT);
pinMode(8, OUTPUT);
Wire.begin(3);// Unimos este dispositivo al bus I2C con dirección 3 (Esclavo 3)
Wire.onReceive(llegaDato);
}
void loop() {
delay(30);
}
void llegaDato() {
int estado = 0;
// Si hay un byte disponible
if (Wire.available() == 1)
{
estado = Wire.read();
}
// Activamos/desactivamos salidas po pin 8 y 13,
//el esto lo determina el Maestro
digitalWrite(13,estado);
digitalWrite(8,estado);
}
//Master
#include
byte pin[] = {9, 10, 11, 12, 13};
byte estado = 0;
byte retardo = 100;
int ValorSensor = 0;
void setup() {
pinMode(3,INPUT);
Wire.begin();
}
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);
}
if (estado == 0)
{
estado = 1;
}
else
{
estado = 0;
}
//Rceptor
char dato;
void setup()
{
pinMode(12,OUTPUT);
Serial.begin(9600);
}
void loop()
{
if(Serial.available()>0)
{
dato=Serial.read();
if(dato=="E")
{
digitalWrite(12,HIGH);
}
if(dato=="A")
{
digitalWrite(12,LOW);
}
}
delay(500);
}
//Transmitter
void setup()
{
pinMode(7,INPUT); //configura al pin de entrada
Serial.begin(9600); //configura la comunicación
}
void loop()
{
if(digitalRead(7)==LOW)
{
Serial.print("E");
}
else
{
Serial.print("A");
}
delay(500);
}
We couldn´t work in the laboratory that´s why we made all the practice for the virtual way.