Serial port issue

tristanb293
Posts: 5
Joined: Wed Jul 19, 2017 9:25 am

Serial port issue

Postby tristanb293 » Mon Jul 31, 2017 11:44 am

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);
  }   
}

User avatar
martinayotte
Posts: 141
Joined: Fri Nov 13, 2015 4:27 pm

Re: Arduino for ESP32

Postby martinayotte » Mon Jul 31, 2017 2:16 pm

First, this post should have been posted in Arduino sub-forum ...

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

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: Serial port issue

Postby ESP_Sprite » Tue Aug 01, 2017 1:24 am

Split off from the Arduino announcement post.

Who is online

Users browsing this forum: No registered users and 148 guests