Comm between ESP32-CAM and Arduino Uno/Mega

Hi, what if I want to transfer the decoded qrcode from esp32-cam to arduino uno/mega? As when I use the code below, Uno only show int 255 when connect with esp32-cam, but it couldnt show the string For example, for esp32-cam:

void loop() {
if (!QRCodeResult.isEmpty()) {
Serial.println( QRCodeResult);
QRCodeResult = ""; }
delay(1);
}

For Arduino Uno/Mega:

void loop() {
if (Serial.available()) {
qrcode= Serial.read();
Serial.println(qrcode); }

Could you please provide any suggestion?
Thanks.

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

A good place to start would be the Serial Input Basics tutorial.

What is the type of QRCodeResult? Byte array?

It would help if you posted complete code as well as links to libraries that you use.

Hi,
Thanks for your reply. The QR code is decoded into a string. Below is the code from esp32-cam and the link I'm using is from ESP32QRCodeReader_Page:


/* ======================================== Including the libraries. */
#include "esp_camera.h"
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"
#include "quirc.h"
/* ======================================== */


// creating a task handle
TaskHandle_t QRCodeReader_Task;

/* ======================================== Select camera model */
#define CAMERA_MODEL_AI_THINKER
/* ======================================== */

/* ======================================== GPIO of camera models */
#define PWDN_GPIO_NUM 32
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 0
#define SIOD_GPIO_NUM 26
#define SIOC_GPIO_NUM 27

#define Y9_GPIO_NUM 35
#define Y8_GPIO_NUM 34
#define Y7_GPIO_NUM 39
#define Y6_GPIO_NUM 36
#define Y5_GPIO_NUM 21
#define Y4_GPIO_NUM 19
#define Y3_GPIO_NUM 18
#define Y2_GPIO_NUM 5
#define VSYNC_GPIO_NUM 25
#define HREF_GPIO_NUM 23
#define PCLK_GPIO_NUM 22

/* ======================================== */

/* ======================================== Variables declaration */
struct QRCodeData {
  bool valid;
  int dataType;
  uint8_t payload[1024];
  int payloadLen;
};

struct quirc *q = NULL;
uint8_t *image = NULL;
camera_fb_t *fb = NULL;
struct quirc_code code;
struct quirc_data data;
quirc_decode_error_t err;
struct QRCodeData qrCodeData;
String QRCodeResult = "";
/* ======================================== */

/* ________________________________________________________________________________ VOID SETTUP() */
void setup() {
  // put your setup code here, to run once:

  // Disable brownout detector.
  WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);

  /* ---------------------------------------- Init serial communication speed (baud rate). */
  Serial.begin(115200);
  Serial.setDebugOutput(true);
  Serial.println();
  /* ---------------------------------------- */

  /* ---------------------------------------- Camera configuration. */
  Serial.println("Start configuring and initializing the camera...");
  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = Y2_GPIO_NUM;
  config.pin_d1 = Y3_GPIO_NUM;
  config.pin_d2 = Y4_GPIO_NUM;
  config.pin_d3 = Y5_GPIO_NUM;
  config.pin_d4 = Y6_GPIO_NUM;
  config.pin_d5 = Y7_GPIO_NUM;
  config.pin_d6 = Y8_GPIO_NUM;
  config.pin_d7 = Y9_GPIO_NUM;
  config.pin_xclk = XCLK_GPIO_NUM;
  config.pin_pclk = PCLK_GPIO_NUM;
  config.pin_vsync = VSYNC_GPIO_NUM;
  config.pin_href = HREF_GPIO_NUM;
  config.pin_sscb_sda = SIOD_GPIO_NUM;
  config.pin_sscb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 10000000;
  config.pixel_format = PIXFORMAT_GRAYSCALE;
  config.frame_size = FRAMESIZE_QVGA;
  config.jpeg_quality = 15;
  config.fb_count = 1;

#if defined(CAMERA_MODEL_ESP_EYE)
  pinMode(13, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
#endif

  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);
    ESP.restart();
  }

  sensor_t *s = esp_camera_sensor_get();
  s->set_framesize(s, FRAMESIZE_QVGA);

  Serial.println("Configure and initialize the camera successfully.");
  Serial.println();
  /* ---------------------------------------- */

  /* ---------------------------------------- create "QRCodeReader_Task" using the xTaskCreatePinnedToCore() function */
  xTaskCreatePinnedToCore(
    QRCodeReader,        /* Task function. */
    "QRCodeReader_Task", /* name of task. */
    10000,               /* Stack size of task */
    NULL,                /* parameter of the task */
    1,                   /* priority of the task */
    &QRCodeReader_Task,  /* Task handle to keep track of created task */
    0);                  /* pin task to core 0 */
  /* ---------------------------------------- */
}
/* ________________________________________________________________________________ */
void loop() {
  // put your main code here, to run repeatedly:
  if (!QRCodeResult.isEmpty()) {
    Serial.println(QRCodeResult);
    QRCodeResult = "";
  }
  delay(1);
}
/* ________________________________________________________________________________ */

/* ________________________________________________________________________________ The function to be executed by "QRCodeReader_Task" */
// This function is to instruct the camera to take or capture a QR Code image, then it is processed and translated into text.
void QRCodeReader(void *pvParameters) {
  /* ---------------------------------------- */
  Serial.println("QRCodeReader is ready.");
  Serial.print("QRCodeReader running on core ");
  Serial.println(xPortGetCoreID());
  Serial.println();
  /* ---------------------------------------- */

  /* ---------------------------------------- Loop to read QR Code in real time. */
  while (1) {
    q = quirc_new();
    if (q == NULL) {
      Serial.print("can't create quirc object\r\n");
      continue;
    }

    fb = esp_camera_fb_get();
    if (!fb) {
      Serial.println("Camera capture failed");
      continue;
    }

    quirc_resize(q, fb->width, fb->height);
    image = quirc_begin(q, NULL, NULL);
    memcpy(image, fb->buf, fb->len);
    quirc_end(q);

    int count = quirc_count(q);
    if (count > 0) {
      quirc_extract(q, 0, &code);
      err = quirc_decode(&code, &data);

      if (err) {
        // Serial.println("Decoding FAILED");
        // QRCodeResult = "Decoding FAILED";
      } else {
        //Serial.printf("Decoding successful:\n");
        dumpData(&data);
      }
      Serial.println();
    }

    esp_camera_fb_return(fb);
    fb = NULL;
    image = NULL;
    quirc_destroy(q);
  }
  /* ---------------------------------------- */
}
/* ________________________________________________________________________________ */

/* ________________________________________________________________________________ Function to display the results of reading the QR Code on the serial monitor. */
void dumpData(const struct quirc_data *data) {

  //Serial.printf("%s\n", data->payload);

  QRCodeResult = String((const char *)data->payload);  // Store the payload as a String

  // Print the QR code result using Serial.print and Serial.println
}

Code for Arduino Uno:

#include <SoftwareSerial.h>

void setup() {
  Serial.begin(115200);

}

void loop() {
  if (Serial.available()) {
    String qrcode = Serial.readStringUntil('\n');
    Serial.println(qrcode);
}
}

Can you confirm that string (say: "Arduino") sent by ESP32-CAM using UART Port is received by UNO? Are you aware that ESP32-CAM is a 3.3V device; whereas, UNO is a 5V device? Do you think that there is no need of level shifter while transferring data from ESP32-CAM to UNO?


I am aware of it but from Power Pins for ESP32-CAM
It is recommended to use 5v and that's why I'm using the DC regulator to step down as shown in the image

You can safely connect UOT-pin of ESP32-CAM with RX-pin of UNO without level shifter as 3.3V will always be recognized by UNO as HIGH.

However, have you checked by running a simple program that UNO does receive the string "Arduino" from ESP32-CAM?

Why do you want to do that? Why can't you do whatever processing that's required right in the ESP32? It's more powerful and has more resources.

Hi,

Thank you to everyone for the suggestions and answers. After various attempts, I don't think it's possible to transfer the decoded QR result from the ESP32 CAM to the Arduino board. Consequently, I am now using a barcode scanner, which works well with software serial communication.

Thanks again!

Of course it is. But you haven't answered the question why you want to:

I guess if that works for you. It's probably less finicky than an ESP32-CAM.

Hi, I'm currently conducting a test or project to determine if the ESP32 Cam can communicate with Arduino. This is in case I want to add more sensors or features in the future.

No problem, if you use logic level shifters with a 5V Arduino (not required with 3.3V Arduinos).

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