Speed O Meter serial display to LCD

Hi all . im racking my brain at this alittle harder than i think i should be im new to all this and trying to learn as I go

Iv added a doppler sensor to my esp32 using serial 2 and can get a serial output via the serial monitor

I want to get this value that on serial monitor (well most of it ) to be displayed on an LCD but not sure what code goes where

My final giving up and asking for help point

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#define RXD2 16
#define TXD2 17
#define SDA 21 //Define SDA pins
#define SCL 22 //Define SCL pins


LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display
char c;
String readString;

void setup() {
  // Note the format for setting a serial port is as follows: Serial2.begin(baud-rate, protocol, RX pin, TX pin);
  Serial.begin(115200);
  Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
  Serial2.println("serial2test");
  Serial.println("Serial Txd is on pin: " + String(TX));
  Serial.println("Serial Rxd is on pin: " + String(RX));
 Wire.begin(SDA, SCL); // attach the IIC pin
 lcd = LiquidCrystal_I2C(0x27,16,2);
 lcd.init(); // LCD driver initialization
 lcd.backlight(); // Open the backlight

  
}

 void loop() {
    char ch=Serial2.println();
    Serial.write(ch);
    Serial.println();
    lcd.setCursor(0,0);
    lcd.print(ch);

}

im sure its going to be really simple for someone on here ,

Thanks

This should help get you on track:

One additional hint:

char ch=Serial2.println();

You're trying to print something you haven't read yet, or even looked for in the buffer.

So: review the IDE example sketch
Examples >> Communication >> Multi Serial

This will print an empty line on Serial2; the value that you assign to ch is the number of bytes that were sent (2 bytes, carriage return and linefeed).
You write that value to Serial (the serial monitor?); what do you see? And to the LCD; what do you see?

If Serial2 is your doppler sensor, I guess that you wanted to do a read() instead of a println().

You will have to provide the details (datasheet) of the sensor that you're using if you get stuck further down the line.

Serial Monitor works fine showing the correct information " V-002.2" 11 times a second if something is detected showing a new line each time
V+001.8
V+001.7
V+001.1
V+001.6
V+001.6
V+001.3
V+000.9

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#define RXD2 16
#define TXD2 17
#define SDA 21 //Define SDA pins
#define SCL 22 //Define SCL pins

boolean newData = false;
char receivedChar;

LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display
char c;
String readString;

void setup() {
  // Note the format for setting a serial port is as follows: Serial2.begin(baud-rate, protocol, RX pin, TX pin);
  Serial.begin(115200);
  Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
  Serial2.println("serial2test");
  Serial.println("Serial Txd is on pin: " + String(TX));
  Serial.println("Serial Rxd is on pin: " + String(RX));
 Wire.begin(SDA, SCL); // attach the IIC pin
 lcd = LiquidCrystal_I2C(0x27,16,2);
 lcd.init(); // LCD driver initialization
 lcd.backlight(); // Open the backlight

}

 void loop() {
    char ch=Serial2.read();
    Serial.write(ch);
    Serial.println(ch);
    lcd.setCursor(1,0);
    lcd.print(ch);

}

Currently this with no change. i looked at the serial intro and not sure how to make it effect my issue I can get serial monitor to display the output from doppler and can get the lcd to print data like a countdown or what ever but not sure how to get the link

do I need to float the serial 2 data or something ? like I say coooommmmplete noob at this

Also who else hates these firebeetles . the amount of times i have to press the reset button during upload so it unlocks and accepts code makes me want to throw it out the window

try reading the data into an array, e.g. something along the lines of

 void loop() {
  if(Serial2.available()){
    char data[20]={0};
    Serial2.readBytesUntil('\n',data,20);
    Serial.write(data);
    Serial.println(ch);
    lcd.setCursor(1,0);
    lcd.print(data);
 }
}

how have you connected the LCD to the ESP32?

yeah LCD works fine

void loop() {
if (Serial2.available()) {
char ch = Serial2.read();
Serial.write(Serial2.read());
lcd.setCursor(1, 0);
lcd.print(Serial2.read());
lcd.write(Serial2.read());
}
}

This got the lcd to display -1 .....least its a number lol

After you have read a character from Serial2, that character is gone. Reading again with no new data received will result in -1.

But incoming data is continuous?

None of the code you have posted so far will do that. Show us that code!

that data in the serial monitor is from the doppler. its the output in speed. thats what I want sent to the LCD

We don't know. In post #3 I've asked you to post the datasheet of the sensor if you got stuck further down the line.

did you try reading a line of text into an array and display as sample code in post 7?

here is a complete ESP32 test program which receives data on Serial2 from an FTDI USB-TTL-3v3 cable connected to a PC - text entered on PC terminal emulator is transmitted to the ESP32

// ESP32  20*4 Blue LCD - display text from Serial2

//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 20, 4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

// Serial2 pins
#define RXD2 16
#define TXD2 17

void setup() {
  Serial.begin(115200);
  delay(3000);
  Serial.println("\n\nESP32 LCD Serial2 test");
  Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);    // initialise Serial2
  lcd.init();                                     // initialize the lcd
  lcd.backlight();                                // backlight on
  lcd.setCursor(0, 0);
  lcd.print("ESP32 Serial2 test1");
}

void loop() {
   // if Serial2 data read and display on LCD
  if (Serial2.available()) {
    char data[20] = { 0 };    // read data
    Serial2.readBytesUntil('\n', data, 20);
    Serial.println(data);
    lcd.clear();          // clear the screen
    lcd.setCursor(0, 0);
    lcd.print(data);      // display data on LCD
  }
}

terminal emulator on PC displays
image

ESP32/LCD displays
image

yes I can make the lcd display what i type into serial monitor

Refer to post #4 "Serial Monitor works fine showing the correct information " V-002.2" 11 times a second if something is detected showing a new line each time"

Not sure how the the data sheet will help there is no info about serial

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.