▷ Practica 3 #PlcLab: Control salidas de esclavo por medio de entradas de master (Dos ESP32)
Repositorio:
Materiales:
- 2 PLC-LAB
Requisitos previos:
RS485:
Es una capa física de comunicación que consta de 3 cables, data (A), data invertida (B) y GND. La principal función de esta capa es transportar información atreves de dos cables (A y B). Esta capa es utilizada en gran parte de la industria gracias a su resistencia ante el ruido y largas distancias.
Actualmente muchos dispositivos, sensores, equipo industrial, utiliza esta capa física para comunicarse entre si. Gracias que soporta varios protocolos de comunicación, como el conocido Modbus.
Para nuestro modulo tenemos los siguientes pines dedicados para el modulo RS485.
Código Master:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Autor: Vidal Bazurto (avbazurt@espol.edu.ec) | |
GitHub: https://github.com/avbazurt/CURSO-PLC-LAB | |
Practica #3: Envio de dato entre un master a un esclavo | |
de master (Dos ESP32) | |
Master | |
*/ | |
//Pines Dedicados modulo PLC-LAB | |
#define RS485_SERIAL Serial2 | |
#define RS485_DE GPIO_NUM_27 // Define DE Pin to Arduino pin. Connect DE Pin of Max485 converter module | |
#define RS485_RE GPIO_NUM_26 // Define RE Pin to Arduino pin. Connect RE Pin of Max485 converter module | |
#define RS485_SERIAL_RX GPIO_NUM_25 | |
#define RS485_SERIAL_TX GPIO_NUM_14 | |
#define Analog_pin GPIO_NUM_36 | |
void setup() | |
{ | |
//Serial para monitorear datos por monitor serial | |
Serial.begin(115200); | |
//Serial para transmision datos por RS485 | |
RS485_SERIAL.begin(9600, SERIAL_8N1, RS485_SERIAL_RX, RS485_SERIAL_TX); | |
//Habilitamos los pines como salida | |
pinMode(RS485_DE, OUTPUT); | |
pinMode(RS485_RE, OUTPUT); | |
//Para configurar este equipo como master debemos dejar en alto el pin Enable | |
digitalWrite(RS485_DE, HIGH); | |
//Un pequeño delay | |
delay(10); | |
} | |
void loop() | |
{ | |
//Obtenemos el dato del potenciometro | |
int ADC_Value = analogRead(Analog_pin); | |
//Serial Write ADC_Value to RS-485 Bus | |
RS485_SERIAL.println(ADC_Value); | |
//Mostramos por monitor serial para verificar el envio | |
Serial.printf("Dato enviado: %d\n", ADC_Value); | |
delay(100); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Autor: Vidal Bazurto (avbazurt@espol.edu.ec) | |
GitHub: https://github.com/avbazurt/CURSO-PLC-LAB | |
Practica #3: Envio de dato entre un master a un esclavo | |
de master (Dos ESP32) | |
Slave | |
*/ | |
//Pines Dedicados modulo PLC-LAB | |
#define RS485_SERIAL Serial2 | |
#define RS485_DE GPIO_NUM_27 // Define DE Pin to Arduino pin. Connect DE Pin of Max485 converter module | |
#define RS485_RE GPIO_NUM_26 // Define RE Pin to Arduino pin. Connect RE Pin of Max485 converter module | |
#define RS485_SERIAL_RX GPIO_NUM_25 | |
#define RS485_SERIAL_TX GPIO_NUM_14 | |
void setup() | |
{ | |
//Serial para monitorear datos por monitor serial | |
Serial.begin(115200); | |
//Serial para transmision datos por RS485 | |
RS485_SERIAL.begin(9600, SERIAL_8N1, RS485_SERIAL_RX, RS485_SERIAL_TX); | |
//Habilitamos los pines como salida | |
pinMode(RS485_DE, OUTPUT); | |
pinMode(RS485_RE, OUTPUT); | |
//Para configurar este equipo como slave debemos dejar en bajo el pin Enable | |
digitalWrite(RS485_DE, LOW); | |
//Un pequeño delay | |
delay(10); | |
} | |
void loop() | |
{ | |
while (RS485_SERIAL.available()) | |
{ | |
int ADC_Value = RS485_SERIAL.parseInt(); | |
Serial.printf("Dato recibido: %d\n",ADC_Value); | |
} | |
} |
Comments
Post a Comment