Page 1 of 1

Serial port issue

Posted: Mon Jul 31, 2017 11:44 am
by tristanb293
Hi,

I'm trying to use the HardwareSerial library for UART comms. I get an error within the void loop() that says that 'Serial1 was not declared in this scope'. Also will I be able to use the standard arduino serial library functions with this serial port after it is configured? (such as Serial1.readBytesUntil).

Thanks!

Code: Select all

#include "esp32-hal-uart.h"
#include "HardwareSerial.h"
#include "HardwareSerial.cpp"

void setup() {
  // put your setup code here, to run once:
  HardwareSerial Serial1(1);
  Serial.begin(4800);
  Serial1.begin(4800, SERIAL_8N1, 19, 18);
  // config - 8 data bits, no parity bit, 1 stop bit
}

void loop() {
  // put your main code here, to run repeatedly:
  byte dataBuffer[200];
  // if there's any serial available, read it:
  while (Serial1.available() > 0) {
    Serial1.readBytesUntil('$', (char *)dataBuffer, 200);
    Serial.println("Sentence Read");
    Serial.write(dataBuffer, 200);
  }   
}

Re: Arduino for ESP32

Posted: Mon Jul 31, 2017 2:16 pm
by martinayotte
First, this post should have been posted in Arduino sub-forum ...

The "HardwareSerial Serial1(1);" needs to be global, not local to setup() !

Re: Serial port issue

Posted: Tue Aug 01, 2017 1:24 am
by ESP_Sprite
Split off from the Arduino announcement post.