Read data from RS232 device in Olimex ESP32-EVB

Started by roger.peralba, March 23, 2023, 11:56:35 AM

Previous topic - Next topic

roger.peralba

Hello,

I have an RFID card reader that works with RS232 protocol. I'm trying to read the seria data when I pass a card using GPIO4 and GPI36 (Pin 5 and 31 respectivelly) using the HardwareSerial library for now without success.

Is it possible to read directly from an RS232 device?

Here my code:
#include <HardwareSerial.h>
#define RELAY1 32 // Define pin 32 as RELAY1
HardwareSerial SerialRS232(1); // use 1st serial port

void setup() {
  Serial.begin(19200); // Inicializa el puerto serie para imprimir mensajes de depuración
  SerialRS232.begin(19200, SERIAL_8N1, 5, 31); // Inicialize RS232 at pins 5 and 31
  pinMode(RELAY1, OUTPUT); // Configura la salida digital D12 para controlar el relé
}

void loop() {
  if (SerialRS232.available()) { // Comprueba si hay datos disponibles en el puerto serie RS232
    Serial.print("Datos disponibles");
    char c = SerialRS232.read();
    digitalWrite(RELAY1, HIGH);
    Serial.print("RELAY ON");
    delay(5000);
    digitalWrite(RELAY1, LOW);
    Serial.print("RELAY OFF");
    delay(5000);
    Serial.write(c);
  }
}