Skip to content

Serial trigger 1 byte is possible???? #5620

Closed
@tv4you2016

Description

@tv4you2016

Hardware:

Board ESP32 Dev Module
Version/Date 2.0.0
IDE name Arduino IDE
Flash Frequency 80Mhz
PSRAM enabled no
Upload Speed 115200
Computer OS Windows 10

Description:

Hey Good afternoon,

I have a doubt, and it is possible to make a trigger for each byte received by Serial.
I'm using the following code but it doesn't.

#include <Arduino.h>


#define PIN_NOT_RE 18   // LOW = Recived
#define PIN_DE 19  // HIGH = SEND

void setup() {
  // put your setup code here, to run once:

  Serial.begin(14400);
  Serial.setRxBufferSize(1);
  Serial.println(Serial.getTimeout()); // print the default value
  Serial.setTimeout(1);
  Serial.println(Serial.getTimeout()); // print the new value
  pinMode(4, OUTPUT);
  pinMode(PIN_NOT_RE, OUTPUT);
  pinMode(PIN_DE, OUTPUT);

  delay(5000);


  digitalWrite(4, HIGH);

  digitalWrite(PIN_NOT_RE, LOW);
  digitalWrite(PIN_DE, LOW);
}


void loop() {

}



void serialEvent() {

  if (Serial.available()) {
    digitalWrite(4, LOW);
    // get the new byte:
    char inChar = (char)Serial.read();
    digitalWrite(4, HIGH);
  }

}

Captura de ecrã 2021-09-01 155422

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions