Sending info from Arduino Due to Elecrow ESP32 display
Hi there!
This seems like a very simple task to me but I can seem to get it right. So if anyone could help me out I'd really appreciate it.
I got this project where I want to display one of the 5 pictures stored in the SD card root of my Elecrow display depending on the keyword recieved on the serial channel. For that, I have an Arduino Due board whit the job of sending just one of the keywords at a time through Serial. The ESP32 in the Elecrow display's job is to just read whichever word has been sent last throgh Serial, compare this word to the five keyword it has stored and, if it matches with one of them, it will send a call to a function that displays the picture that corresponds to that word. Simple as that.
I'm a novice at programming this way, so I'm not seeing why I can't get the esp32 to read and compare the words in Serial as I want.
I will provide the code for the esp32 as well as a test code for the Arduino Due that just sends one of the keywords through serial after a set amount of seconds. So if anyone knows what I'm missing please let me know.
If you need more info please ask through a reply on this post and I will gladly answer the best I can.
Thank you in advance.
https://drive.google.com/drive/folders/1PejmQ7iH-jdN0bWx-j52AlENlIpiPas-?usp=sharing
Comments
May I ask how many inches of screen is your ESP32 hmi?> @rvm47 said:
It is 5 inches, sorry for not specifying.
@rvm47 ,
Can you display the image properly? This is serial data transmission, where the Arduino Due sends data and the ESP32 receives and checks it. Based on the received result, it displays the image. Can you make sure it successfully sends and receives data first? The serial connection between the Arduino Due and ESP32 needs a common ground, consistent power supply, and RX connected to TX, TX connected to RX.
The following is a sample program to implement this function, using Arduino Due to send data, ESP32 to receive the data and call the corresponding function to display the picture after keyword matching.
Arduino Due send program
include <string.h>
define MAX_DATA_LENGTH 50 // maximum received data length
// List of keywords
const char* keywords[] = {“apple”, “banana”, “cherry”, “date”, “elderberry”};
const int numKeywords = sizeof(keywords) / sizeof(keywords[0]);
void setup() {
Serial.begin(9600); // initialize serial port
Serial2.begin(9600, SERIAL_8N1, 16, 17); // use GPIO16 (RX) and GPIO17 (TX)
Serial.println(“ESP32 Ready to receive data...”); // Use GPIO16 (RX) and GPIO17 (TX).
Serial.println(“ESP32 Ready to receive data...”) ;
}
void loop() {
static char receivedData[MAX_DATA_LENGTH] = {0}; // Cache the received data.
static int index = 0; // buffer index
// check if data is received through Serial2
while (Serial2.available()) {
char incomingByte = Serial2.read(); // check if data is received through Serial2 while (Serial2.available()) {
}
}
// Process the received data
void processReceivedData(const char* data) {
for (int i = 0; i < numKeywords; i++) {
if (strcmp(data, keywords[i]) == 0) {
Serial.printf(“Keyword matched: %s\n”, data);
displayImage(i); // call the display function
return; }
}
}
Serial.println(“No matching keyword found.”); }
}
// Display the corresponding image by index
void displayImage(int index) {
Serial.printf(“Displaying image %d for keyword: %s\n”, index, keywords[index]); // Add specific code to display the image here.
// Add the specific code for displaying the image here, e.g. call the display library
// display.showImage(index); // example function
}
``
Functionality Explanation
Arduino Due:
Serial.println
to send the data, and automatically add the newline character\n
at the end to make it easier for ESP32 to split the data.ESP32:
Serial2
).displayImage
function to display the corresponding image.Keyword Matching:
strcmp
to compare the received string with the keywords.Display function:
displayImage
is a placeholder function that can be extended according to your display library (e.g. call the image display function).Hardware connections
Serial communication:
ESP32 Display Connection:
Test
Above is the case reference, the serial port pin is changed to the pin number of our master control