#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16x2 LCD
void setup() {
lcd.init();
lcd.backlight();
lcd.clear();
Serial1.begin(9600); // Initialize Serial1 for communication
lcd.setCursor(0, 0);
lcd.print("Waiting for data");
// Debug message to Serial1
Serial1.println("Hello, Raspberry Pi Pico W!");
}
void loop() {
// Check if there is data available on Serial1
if (Serial1.available() > 0) {
lcd.clear(); // Clear the display before showing new data
String incomingData = "";
// Read the incoming data
while (Serial1.available() > 0) {
char incomingChar = Serial1.read();
incomingData += incomingChar;
}
Serial1.println(incomingData); // Echo the received data back
// Display the received data on the LCD
lcd.setCursor(0, 0);
lcd.print("Received Data:");
// Clear the second line before printing new data
lcd.setCursor(0, 1);
lcd.print(" "); // Clear previous message
lcd.setCursor(0, 1);
lcd.print(incomingData); // Show the received data
}
delay(100); // Add a slight delay to avoid overwhelming the LCD
}