Serial Communication between ESP32CAM and Arduino UNO

Hi, I want to send a signal from ESP32CAM that runs FOMO model, to Arduino UNO via UART after ESP32CAM detects the object.

I tried to integrate this code below into Examples ESP32 Camera code generated from Arduino Library

#define RXp2 14
#define TXp2 15

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial2.begin(115200, SERIAL_8N1, RXp2, TXp2);
}
void loop() {
  for (int i =0; i<301; i++)
  {
    Serial2.println(i);
    //Serial.println(Serial2.readString());
    Serial.print("sent packet ");Serial.println(i);
    delay(500);
    
  }
}

Here’s is how I put the serial2.println to test it

void setup()
{
    // put your setup code here, to run once:
    Serial.begin(115200);
    Serial2.begin(115200, SERIAL_8N1, RXp2, TXp2);
    //comment out the below line to start inference immediately after upload
    while (!Serial);
    Serial.println("Edge Impulse Inferencing Demo");
    if (ei_camera_init() == false) {
        ei_printf("Failed to initialize Camera!\r\n");
    }
    else {
        ei_printf("Camera initialized\r\n");
    }

    ei_printf("\nStarting continious inference in 2 seconds...\n");
    ei_sleep(2000);
}

#if EI_CLASSIFIER_OBJECT_DETECTION == 1
    bool bb_found = result.bounding_boxes[0].value > 0;
    for (size_t ix = 0; ix < result.bounding_boxes_count; ix++) {
        auto bb = result.bounding_boxes[ix];
        if (bb.value == 0) {
            continue;
        }
        ei_printf("    %s (%f) [ x: %u, y: %u, width: %u, height: %u ]\n", bb.label, bb.value, bb.x, bb.y, bb.width, bb.height);
    }
    if (!bb_found) {
        ei_printf("    No objects found\n");
    }
#else
    for (size_t ix = 0; ix < EI_CLASSIFIER_LABEL_COUNT; ix++) {
        ei_printf("    %s: %.5f\n", result.classification[ix].label,
                                    result.classification[ix].value);
                                            
        if (result.classification[ix].value > 0.1)
        {
          
          Serial2.println("Detected");
          Serial.println("Detected"); //local serial print
          delay(500);
                   
        }
        
    }
#endif

The problem is how can I serial print the results of result.classification[ix].label and
result.classification[ix].value
Thank you.

Hello @sio_yx,

If I am not mistaken, the ESP32-CAM has only one Serial interface.
I’d suggest to have a look at Espressif or Arduino’s forum as it’s more related to the code logic than the inference itself.

Best,

Louis

Hi @louis , the serial communication is successful if I try with other code. But I can’t integrate with code from edge impulse. Because when I serial print using the code below after ei_printf, it doesn’t show anything. So I wonder where should I put if else code to serial print result.classification[ix].label and result.classification[ix].value.

image

Your putting your code in wrong side of the compiler directive since you are doing FOMO.

#if EI_CLASSIFIER_OBJECT_DETECTION == 1

    bool bb_found = result.bounding_boxes[0].value > 0;
    for (size_t ix = 0; ix < result.bounding_boxes_count; ix++)
    {
        auto bb = result.bounding_boxes[ix];
        if (bb.value == 0) { continue; }
        ei_printf("    %s (%f) [ x: %u, y: %u, width: %u, height: %u ]\n", bb.label, bb.value, bb.x, bb.y, bb.width, bb.height);

        if (result.classification[ix].value > 0.1)
        {
          Serial2.println("Detected");
          Serial.println("Detected"); //local serial print
          delay(500);
        }
    }
    if (!bb_found) { ei_printf("    No objects found\n");  }

#else

    for (size_t ix = 0; ix < EI_CLASSIFIER_LABEL_COUNT; ix++) 
    {
        ei_printf("    %s: %.5f\n", result.classification[ix].label,
                                    result.classification[ix].value);                                                    
    }
#endif
2 Likes

Thank you ! Sorry, hadn’t seen your reply until now.