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:

  • @Jennie said:
    May I ask how many inches of screen is your ESP32 hmi?> @rvm47 said:

    It is 5 inches, sorry for not specifying.

  • edited December 5

    @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

    void setup() {
      Serial.begin(9600); // initialize serial communication
    }
    
    void loop() {
      // Simulate sending keyword data
      const char* keywords[] = {“apple”, “banana”, “cherry”, “date”, “elderberry”}; static int index = 0; // send the keyword data to the serial port.
      static int index = 0;
    
      Serial.println(keywords[index]); // send keywords
      index = (index + 1) % 5; // take turns sending keywords
      delay(2000); // send at 2 second intervals
    }
    
    
    ### **ESP32 Receive and Handler Programs**
    
    

    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()) {

    // If a newline is encountered, a data entry has been received.
    if (incomingByte == '\n') {
      receivedData[index] = '\0'; // end string
      Serial.printf(“Received: %s\n”, receivedData); processReceivedData(receivedData); // processReceivedData(receivedData)
      processReceivedData(receivedData); // process received data
      index = 0; // reset index
    } else if (index < MAX_DATA_LENGTH - 1) {
      receivedData[index++] = incomingByte; // store the received characters
    }
    

    }
    }

    // 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

    1. Arduino Due:

      • Send predefined keywords periodically.
      • Use 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.
    2. ESP32:

      • Receives keywords transmitted over the serial channel (Serial2).
      • Checks if the data matches the stored keyword list.
      • If it matches, call the displayImage function to display the corresponding image.
    3. Keyword Matching:

      • Use strcmp to compare the received string with the keywords.
    4. 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

    1. Serial communication:

      • Arduino Due TX (Serial1 TX)ESP32 RX (GPIO16).
      • Arduino Due RX (Serial1 RX)ESP32 TX (GPIO17).
      • GND must be connected.
    2. ESP32 Display Connection:

      • Configure the interface according to your screen type (e.g. I2C or SPI).

    Test

    • After uploading the program, Arduino Due sends a keyword every 2 seconds.
    • ESP32 receives the keyword, matches it and prints a log on the serial monitor with the corresponding image.

    Above is the case reference, the serial port pin is changed to the pin number of our master control

Sign In or Register to comment.