hello to both of you !!..
I just bought your super beautiful book on cameras...
I tested the esp32 cam several times before i purchased your e-bookwith with success
and suddenly I receive distorted photos
with the esp32cam and esp-eye ...at the beginning everything was correct but then after a
while the esp32 cam no longer works well...after having tried with several other esp32cam
(which no longer works either...laugh((maybe scrap now ))) I decided to try with
the esp-eye ....
after having uploaded the code (after having changed the configuration of the pins)
here are the photos sent by e-mail were very good ... the next day without having
changed anything
i think ...
it used to sent photos by e-mail deformed again... I have read several of your
tutorials and following your information I have changed the resolution ()
config.frame_size = FRAMESIZE_UXGA;
config.jpeg_quality = 30;
config.fb_count = 2;
config.frame_size = FRAMESIZE_SVGA;
config.jpeg_quality = 32;
config.fb_count = 1;
after these tests I have never been able to receive good photos by e-mail.....
but I am able to upload the code to view the mjpeg videos...???
i even add aluminium cool block on the esp32cam and that helped for a longer periode
to receive good picture by email....can we use 24 hrs on a longer periode of time???
can i only upload the code 1 time to take pictures and send by e-mail???
so i bought a brand new one esp-32 and programmer ftdi and now i just can't upload the code
anymore..even the reset button doesn't work...
in some other youtube tutorials some said to remove a resistor...and other said to install
another rest button ....???? it is so small oufff...
it is possible that i bought defected esp-cam ??? maybe ....well i would like to receive
some advise from you ....
some people said the esptool.py is no longer supported and the new arduino IDE is so slow
i can't wait alomost 5 minutes every time i upload any code so i still using the 1.8.16 version
any help is welcome ...thanks for your time.....( Denis Deschenes )
Hi.
I’m sorry for those issues.
Which specific project are you following?
Does the issue happen with all ESP32 camera boards? It is always at the same time that you start receiving deformed pictures?
Which is the board that you have that you mention you cannot upload code to? Do you get any errors when trying to upload?
Regards,
Sara
Hi Sara !!
I tried so many things that nothing worked anymore...laugh...I had to reinstall
arduino IDE 1.8.9 anew because the higher version does not work well with esp32cam...
I managed to install esp-mail-client but the sketch in the book I just bought from you
has a ""littlefs.h"" difference and that's where the problem arose ... I tried to
install several littlefs versions including esp8266littlefs...but no ..esp32littelefs..
but no ..I even changed littleFS to lowercase for LITTLEFS because one of the libraries
is written in uppercase ...everything has started to compile but here is this error
“”struct camera_config_t’ has no member named ‘grab_mode'””
I tried the links in the book for “”preference”” but it doesn’t seem to work..here are the ones I managed to find as a replacement ==
“” https://arduino.esp8266.com/stable/package_esp8266com_index.json,https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json,https://dl.espressif.com/dl/package_esp32_index.json, http://arduino.esp8266.com/stable/package_esp8266com_index.json “”
I changed the camera from esp32cam to esp-eye...here is my code==
here ‘s the code
/*********
Rui Santos
Complete instructions at https://RandomNerdTutorials.com/esp32-cam-projects-ebook/
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*********/
#include “esp_camera.h”
#include “SPI.h”
#include “driver/rtc_io.h”
#include <ESP_Mail_Client.h>
#include <FS.h>
#include <LITTLEFS.h> // i had to modify this part here so everywhere i LITTLEFS instead of littleFS
#include <WiFi.h>
// REPLACE WITH YOUR NETWORK CREDENTIALS
const char* ssid = “************”;
const char* password = “***********”;
// To send Email using Gmail use port 465 (SSL) and SMTP Server smtp.gmail.com
// You need to create an email app password
#define emailSenderAccount “***************”
#define emailSenderPassword “************”
#define smtpServer “smtp.gmail.com”
#define smtpServerPort 465
#define emailSubject “ESP32-CAM coucou !!”
#define emailRecipient “****************”
//#define CAMERA_MODEL_AI_THINKER // i had to modify this part
#define CAMERA_MODEL_ESP_EYE
#if defined(CAMERA_MODEL_ESP_EYE)
//#if defined(CAMERA_MODEL_AI_THINKER)
#define PWDN_GPIO_NUM -1
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 4
#define SIOD_GPIO_NUM 18
#define SIOC_GPIO_NUM 23
#define Y9_GPIO_NUM 36
#define Y8_GPIO_NUM 37
#define Y7_GPIO_NUM 38
#define Y6_GPIO_NUM 39
#define Y5_GPIO_NUM 35
#define Y4_GPIO_NUM 14
#define Y3_GPIO_NUM 13
#define Y2_GPIO_NUM 34
#define VSYNC_GPIO_NUM 5
#define HREF_GPIO_NUM 27
#define PCLK_GPIO_NUM 25
#else
#error “Camera model not selected”
#endif
/* The SMTP Session object used for Email sending */
SMTPSession smtp;
/* Callback function to get the Email sending status */
void smtpCallback(SMTP_Status status);
// Photo File Name to save in LittleFS
#define FILE_PHOTO “photo.jpg”
#define FILE_PHOTO_PATH “/photo.jpg”
void setup() {
#if defined(CAMERA_MODEL_ESP_EYE)
pinMode(13, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
#endif
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
Serial.begin(115200);
Serial.println();
// Connect to Wi-Fi
WiFi.begin(ssid, password);
Serial.print(“Connecting to WiFi…”);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
}
Serial.println();
if (!LITTLEFS.begin(true)) {
Serial.println(“An Error has occurred while mounting LittleFS”);
ESP.restart();
}
else {
delay(500);
Serial.println(“LittleFS mounted successfully”);
}
// Print ESP32 Local IP Address
Serial.print(“IP Address: http://”);
Serial.println(WiFi.localIP());
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 = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
config.grab_mode = CAMERA_GRAB_LATEST;
if(psramFound()){
config.frame_size = FRAMESIZE_UXGA;
config.jpeg_quality = 30;
config.fb_count = 1;
} else {
config.frame_size = FRAMESIZE_SVGA;
config.jpeg_quality = 32;
config.fb_count = 1;
}
// Initialize camera
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf(“Camera init failed with error 0x%x”, err);
return;
}
capturePhotoSaveLittleFS();
sendPhoto();
}
void loop() {
}
// Check if photo capture was successful
bool checkPhoto( fs::FS &fs ) {
File f_pic = fs.open( FILE_PHOTO_PATH );
unsigned int pic_sz = f_pic.size();
return ( pic_sz > 100 );
}
// Capture Photo and Save it to LittleFS
void capturePhotoSaveLittleFS( void ) {
camera_fb_t * fb = NULL; // pointer
bool ok = 0; // Boolean indicating if the picture has been taken correctly
do {
// Take a photo with the camera
Serial.println(“Taking a photo…”);
// Clean previous buffer
camera_fb_t * fb = NULL;
fb = esp_camera_fb_get();
esp_camera_fb_return(fb); // dispose the buffered image
fb = NULL; // reset to capture errors
// Get fresh image
fb = esp_camera_fb_get();
if(!fb) {
Serial.println(“Camera capture failed”);
delay(1000);
ESP.restart();
}
// Photo file name
Serial.printf(“Picture file name: %s\n”, FILE_PHOTO_PATH);
File file = LITTLEFS.open(FILE_PHOTO_PATH, FILE_WRITE);
// Insert the data in the photo file
if (!file) {
Serial.println(“Failed to open file in writing mode”);
}
else {
file.write(fb->buf, fb->len); // payload (image), payload length
Serial.print(“The picture has been saved in “);
Serial.print(FILE_PHOTO_PATH);
Serial.print(” – Size: “);
Serial.print(fb->len);
Serial.println(” bytes”);
}
// Close the file
file.close();
esp_camera_fb_return(fb);
// check if file has been correctly saved in LittleFS
ok = checkPhoto(LITTLEFS);
} while ( !ok );
}
void sendPhoto( void ) {
/** Enable the debug via Serial port
* none debug or 0
* basic debug or 1
*/
smtp.debug(1);
/* Set the callback function to get the sending results */
smtp.callback(smtpCallback);
/* Declare the session config data */
ESP_Mail_Session session;
/* Set the session config */
session.server.host_name = smtpServer;
session.server.port = smtpServerPort;
session.login.email = emailSenderAccount;
session.login.password = emailSenderPassword;
session.login.user_domain = “”;
/* Declare the message class */
SMTP_Message message;
/* Enable the chunked data transfer with pipelining for large message if server supported */
message.enable.chunking = true;
/* Set the message headers */
message.sender.name = “ESP32-CAM”;
message.sender.email = emailSenderAccount;
message.subject = emailSubject;
message.addRecipient(“Sara”, emailRecipient);
String htmlMsg = “<h2>Photo captured with ESP32-CAM and attached in this email.</h2>”;
message.html.content = htmlMsg.c_str();
message.html.charSet = “utf-8”;
message.html.transfer_encoding = Content_Transfer_Encoding::enc_qp;
message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_normal;
message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay;
/* The attachment data item */
SMTP_Attachment att;
/** Set the attachment info e.g.
* file name, MIME type, file path, file storage type,
* transfer encoding and content encoding
*/
att.descr.filename = FILE_PHOTO;
att.descr.mime = “image/png”;
att.file.path = FILE_PHOTO_PATH;
att.file.storage_type = esp_mail_file_storage_type_flash;
att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64;
/* Add attachment to the message */
message.addAttachment(att);
/* Connect to server with the session config */
if (!smtp.connect(&session))
return;
/* Start sending the Email and close the session */
if (!MailClient.sendMail(&smtp, &message, true))
Serial.println(“Error sending Email, ” + smtp.errorReason());
}
// Callback function to get the Email sending status
void smtpCallback(SMTP_Status status){
/* Print the current status */
Serial.println(status.info());
/* Print the sending result */
if (status.success())
{
Serial.println(“—————-“);
Serial.printf(“Message sent success: %d\n”, status.completedCount());
Serial.printf(“Message sent failled: %d\n”, status.failedCount());
Serial.println(“—————-\n”);
struct tm dt;
for (size_t i = 0; i < smtp.sendingResult.size(); i++)
{
/* Get the result item */
SMTP_Result result = smtp.sendingResult.getItem(i);
time_t ts = (time_t)result.timestamp;
Serial.printf(“Message No: %d\n”, i + 1);
Serial.printf(“Status: %s\n”, result.completed ? “success” : “failed”);
Serial.printf(“Date/Time: %d/%d/%d %d:%d:%d\n”, dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec);
Serial.printf(“Recipient: %s\n”, result.recipients);
Serial.printf(“Subject: %s\n”, result.subject);
}
Serial.println(“—————-\n”);
// You need to clear sending result as the memory usage will grow up.
smtp.sendingResult.clear();
}
}
here’s the error message ==
C:\Users\propu\Documents\Arduino\esp_eye_send_pic_email_rui_new\esp_eye_send_pic_email_rui_new.ino: In function ‘void setup()’:
esp_eye_send_pic_email_rui_new:119:10: error: ‘struct camera_config_t’ has no member named ‘grab_mode’
config.grab_mode = CAMERA_GRAB_LATEST;
^
esp_eye_send_pic_email_rui_new:119:22: error: ‘CAMERA_GRAB_LATEST’ was not declared in this scope
config.grab_mode = CAMERA_GRAB_LATEST;
^
Plusieurs bibliothèque trouvées pour “SD.h”
Utilisé : C:\Users\propu\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\SD
Non utilisé : C:\Users\propu\Desktop\arduino-1.8.19\libraries\SD
exit status 1
‘struct camera_config_t’ has no member named ‘grab_mode’
i already succeded for sending picture by email but now i’m facing new difficulties ..i wanted to use the esp-eye because they look more tuff…i scraped many other esp32cam …i even use aluminium block for the heat ..i thought that what the problem cause after 2 or 3 days( 24hrs ) they just don’t woks anymore and i wasn’t able to upload any code anymore to the esp32 ….reset button doesn’t want to work anymore… so i thought that esp-eye would solve this problem….here’s the code i was using and suddenly received deformed picture
here’s the code i was using before ==
/*********
Rui Santos
Complete instructions at https://RandomNerdTutorials.com/esp32-cam-projects-ebook/
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*********/
#include “esp_camera.h”
#include “SPI.h”
#include “driver/rtc_io.h”
#include “ESP32_MailClient.h”
#include <FS.h>
#include <SPIFFS.h>
#include <WiFi.h>
// REPLACE WITH YOUR NETWORK CREDENTIALS
const char* ssid = “*********”;
const char* password = “************8”;
// To send Emails using Gmail on port 465 (SSL), you need to create an app password: https://support.google.com/accounts/answer/185833
#define emailSenderAccount “*********************”
#define emailSenderPassword “****************”
#define smtpServer “smtp.gmail.com”
#define smtpServerPort 465
#define emailSubject “ESP32_cam_A”
#define emailRecipient “*******************”
#define CAMERA_MODEL_ESP_EYE
//#define CAMERA_MODEL_AI_THINKER
#if defined(CAMERA_MODEL_ESP_EYE)
//#if defined(CAMERA_MODEL_AI_THINKER)
#define PWDN_GPIO_NUM -1
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 4
#define SIOD_GPIO_NUM 18
#define SIOC_GPIO_NUM 23
#define Y9_GPIO_NUM 36
#define Y8_GPIO_NUM 37
#define Y7_GPIO_NUM 38
#define Y6_GPIO_NUM 39
#define Y5_GPIO_NUM 35
#define Y4_GPIO_NUM 14
#define Y3_GPIO_NUM 13
#define Y2_GPIO_NUM 34
#define VSYNC_GPIO_NUM 5
#define HREF_GPIO_NUM 27
#define PCLK_GPIO_NUM 25
#else
#error “Camera model not selected”
#endif
int photoo = 0;
int detec = 13;
int detecc = 0;
int d = 0;
int dd = 0;
int swf = 12;
int swff = 0;
#define LED 4 // flash
// The Email Sending data object contains config and data to send
SMTPData smtpData;
// Photo File Name to save in SPIFFS
#define FILE_PHOTO “/photo.jpg”
void setup() {
#if defined(CAMERA_MODEL_ESP_EYE)
pinMode(13, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
#endif
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
pinMode(LED, OUTPUT);
Serial.begin(115200);
Serial.println();
digitalWrite(LED, LOW);
digitalWrite(swf, INPUT);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
Serial.print(“Connecting to WiFi…”);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
}
Serial.println();
if (!SPIFFS.begin(true)) {
Serial.println(“An Error has occurred while mounting SPIFFS”);
ESP.restart();
}
else {
delay(500);
Serial.println(“SPIFFS mounted successfully”);
}
// Print ESP32 Local IP Address
Serial.print(“IP Address: http://”);
Serial.println(WiFi.localIP());
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 = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
// select the lower framsize if the camera doesn’t support psram
if(psramFound()){
config.frame_size = FRAMESIZE_UXGA;
config.jpeg_quality = 30; //40// 10-63 lower number = higher quality
config.fb_count = 2;
} else {
config.frame_size = FRAMESIZE_SVGA;
config.jpeg_quality = 32; // 42
config.fb_count = 1;
}
// Initialize camera
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf(“Camera init failed with error 0x%x”, err);
return;
}
capturePhotoSaveSpiffs();
sendPhoto();
}
void loop() {
detecc = digitalRead(detec);
if (detecc == HIGH)
{
d++;
if (d == 1)
{
capturePhotoSaveSpiffs();
sendPhoto();
//delay(5000);
photoo++;
Serial.print(“photo == “);
Serial.println(photoo);
//delay(1000);
}// if d
Serial.print(“d == “);
Serial.println(d);
if (d > 7)
{
d = 0;
}
}// if detecc
if (detecc == LOW)
{
Serial.print(“photo == off “);
d = 0;
}
}
// Check if photo capture was successful
bool checkPhoto( fs::FS &fs ) {
File f_pic = fs.open( FILE_PHOTO );
unsigned int pic_sz = f_pic.size();
return ( pic_sz > 100 );
}
// Capture Photo and Save it to SPIFFS
void capturePhotoSaveSpiffs( void ) {
camera_fb_t * fb = NULL; // pointer
bool ok = 0; // Boolean indicating if the picture has been taken correctly
do {
// Take a photo with the camera
Serial.println(“Taking a photo…”);
swff = digitalRead(swf);
if (swff == HIGH) //////////////swicth flash
{
digitalWrite(LED, HIGH); // flash = on
}
if (swff == LOW)
{
// flash = off
}
//delay(200);//////////////////////////////SOIT ICI
fb = esp_camera_fb_get();
//delay(200);//////////////////////////////SOIT ICI***********
digitalWrite(LED, LOW); // flash = off
if (!fb) {
Serial.println(“Camera capture failed”);
return;
}
// Photo file name
Serial.printf(“Picture file name: %s\n”, FILE_PHOTO);
File file = SPIFFS.open(FILE_PHOTO, FILE_WRITE);
// Insert the data in the photo file
if (!file) {
Serial.println(“Failed to open file in writing mode”);
}
else {
file.write(fb->buf, fb->len); // payload (image), payload length
Serial.print(“The picture has been saved in “);
Serial.print(FILE_PHOTO);
Serial.print(” – Size: “);
Serial.print(file.size());
Serial.println(” bytes”);
}
// Close the file
file.close();
esp_camera_fb_return(fb);
// check if file has been correctly saved in SPIFFS
ok = checkPhoto(SPIFFS);
} while ( !ok );
delay(100);
digitalWrite(LED, LOW); // flash = off
}
void sendPhoto( void ) {
// Preparing email
Serial.println(“Sending email…”);
// Set the SMTP Server Email host, port, account and password
smtpData.setLogin(smtpServer, smtpServerPort, emailSenderAccount, emailSenderPassword);
// Set the sender name and Email
smtpData.setSender(“ESP32-CAM”, emailSenderAccount);
// Set Email priority or importance High, Normal, Low or 1 to 5 (1 is highest)
smtpData.setPriority(“High”);
// Set the subject
smtpData.setSubject(emailSubject);
// Set the email message in HTML format
smtpData.setMessage(“<h2>Photo captured with ESP32-CAM and attached in this email.</h2>”, true);
// Set the email message in text format
//smtpData.setMessage(“Photo captured with ESP32-CAM and attached in this email.”, false);
// Add recipients, can add more than one recipient
smtpData.addRecipient(emailRecipient);
//smtpData.addRecipient(emailRecipient2);
// Add attach files from SPIFFS
smtpData.addAttachFile(FILE_PHOTO, “image/jpg”);
// Set the storage type to attach files in your email (SPIFFS)
smtpData.setFileStorageType(MailClientStorageType::SPIFFS);
smtpData.setSendCallback(sendCallback);
// Start sending Email, can be set callback function to track the status
if (!MailClient.sendMail(smtpData))
Serial.println(“Error sending Email, ” + MailClient.smtpErrorReason());
// Clear all data from Email object to free memory
smtpData.empty();
}
// Callback function to get the Email sending status
void sendCallback(SendStatus msg) {
//Print the current status
Serial.println(msg.info());
}
Hi.
First of all, you need to use the following link in the Preferences:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
Then, you need to go to Boards > Boards Manager, search for ESP32, and update to the latest version.
After that, the problem with LittlFS and the GRAB_LATEST not defined will be solved.
Let me know if this helps.
Regards,
Sara
Thank you so much Sara !!
i finaly found the bugs that i was searching for since so long…
1= i was trying on 2 computer(1 is 32bits and 2 is 64bits ..then i found out that esp32cam libraries doesn’t support anymore the 32bits window computer ..dam…
2= i had to get as you said the latest version on arduino IDE with the right preference link that you sent to me
3= i change to littleFS instead of spiff…
4= i had to buy another programmer (the one with the boot button on the side ) i was using only the ftdi programmer and it was working only half time …i had so many problems with that ..
but now with the latest version and the right preference with the right programmer it is ok …
it’s the first time i had so many troubles that i coudn’t find any solutions but buying your book and having the possibility to talk with you made a great score!!
now i want to try to find a way to send ( sms ) with the esp32 or esp8266… if you have any book to recommand me for that let me know !!
thank you so much again for your time Sara !!
Hi.
Thank you for sharing the solution. I’m glad everything is working as expected now.
There are different methods to send SMS with the ESP32 and ESP8266. At the time, we have this tutorial for the ESP32:
I hope this helps.
Regards,
Sara
Hi sara !!
maybe you can help me one this one ….
i tried your tutorial on how to send email with esp8266 and everything works fine ,,
,but i’am tring to use a button to send the email everytime i need to press the button….
but didn’t worked so far and not so good …hihihi
i’ve tried to modify the basic code….i think i have to put the code into the void loop so i can send
anytime i want to
instead of in the void set up loop (only 1 time )
is their any examples available from your books or videos ???
i want to do this project and any help is welcome i am not a professionnal but hobby
but a big fan of your tutorial with Rui ….hihihi
thanks again !!!
Hi.
Yes.
You have to read the button in the loop or add an interrupt to the button to detect when it was pressed.
How are you checking the button?
What changes did you make to the code and what errors do you get?
Regards,
Sara
Oh (interrups),,,I’ve never used it in one of my sketches before…I have no idea how to use this (interrups)…..I tried to just copy the entire sketch into the void setup apart from some line like (serial.begin…) and a few other lines of code but nothing worked…..I had to use a relay to activate the entire board… laugh……I would like to learn how to use (interrups) do you have some examples???
I just bought your book (micropython with esp32) with the other books on promotion….wow there is a lot to learn in your work it’s great!!….I’m at the stage to install the (cp2101 driver)….I had deaj visual studio to install on my computer so I tried to make it compatible with esp32….but I only have the esp8266..hummm.. .I installed the (mu editor) but I haven’t finished the first installation pages of the book….I’m going to continue this (weekend)…it’s been a project of mine for a long time. start to deepen the language (python) with all its possibilities…but I have to learn a lot of new things…. Thank you for making this learning possible for me with your book!!.. 🙂
Hi.
To learn how to use interrupts, we have the following tutorial (it uses a PIR motion sensor, but if you understand the logic, you can use it for a button):
Alternatively, you can use a debounce button sketch:
I’m glad you’re enjoying our eBooks. Let me know if you need help with anything else.
Regards,
Sara
Hi Sara !!
thank you for those links for ( interrupts ) codes …..now Mu_editor has been installed on my computer i am at the 39 page of your esp32 book… but i can’t see the boot.py and main.py when i click the file button ??? that’ s about where i am stuck …….should i start a new title for this question ??? because it is not link to the esp32cam ????/ ….let me know …………………..here’s the message i got when i click on ( file )
//
there was a problem getting the list of files on the device.Please check Mu_logs for technical information..etc…
//
i tried all the solutions that’s in the book but didn’t worked…
–silicone lab CP 210x …. is on the right com and i can upload code from arduino IDE to the esp8266 board
i did the ESP firmware flasher correctly
THIS IS THE FOLDER LOCATION FOR THE .BIN FILE
C:\Users\use\AppData\Local\Programs\Mu Editor
HERE’S MY SAVE FOLDER LOCATION OF THE MAIN.py FILE
C:\Users\use\mu_code\blink2
EVERYTHING ‘S FINE FOR ERASE AND WRITE FIRMWARE .. with Mu_editor
but can’t see the boot.py and main.py …?????
thanks again for your Help !!
ps: i tried to install on visual studio the esp8266 as in your pymkr tutorial ,, i have the com port number but can’t upload the code ??
Hi.
Please open a new thread for this question.
Can you add a screenshot of your issue too? To share a picture, upload it to google drive or dropbox and then share a link to the file.
Alternatively, you may want to use Thonny IDE instead. Lately, that’s the IDE for micropython that’s been working better for me,
Regards,
Sara
Hello Sara !!
everything has been working fine for a long time and now I come across a new bug..??? inside the void setup() loop i have this bug with this part of the code now (( WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector ))) this is the error i have (( Compilation error: ‘RTC_CNTL_BROWN_OUT_REG’ was not declared in this scope )))
here’s my void setup loop
void setup() {
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
Serial.begin(115200);
Serial.println();
digitalWrite(LED, LOW);
digitalWrite(swf, INPUT);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
Serial.print(“Connecting to WiFi…”);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
}
Serial.println();
if (!LittleFS.begin(true)) {
Serial.println(“An Error has occurred while mounting LittleFS”);
ESP.restart();
}
else {
delay(500);
Serial.println(“LittleFS mounted successfully”);
}
// Print ESP32 Local IP Address
Serial.print(“IP Address: http://”);
Serial.println(WiFi.localIP());
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 = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
config.grab_mode = CAMERA_GRAB_LATEST;
if(psramFound()){
config.frame_size = FRAMESIZE_UXGA;
config.jpeg_quality = 40;
config.fb_count = 1;
} else {
config.frame_size = FRAMESIZE_SVGA;
config.jpeg_quality = 42;
config.fb_count = 1;
}
// Initialize camera
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf(“Camera init failed with error 0x%x”, err);
return;
}
capturePhotoSaveLittleFS();
sendPhoto();
}
esp32 by expressif is up to date ( 3.0.5) with arduino IDe 2.3.2…I NEVER HAD This BUG BEFORE ???
i tried to look on the web but didn’t found any help
can you help me o this one ???
thanks for your time again !!
Hi.
You can remove that line of code.
I think that is probably not suppprted on the most recent version of the ESP32 boards.
Regards,
Sara
Hi Sara !!
I tried to delete the line of code as you advised me to do. I was able to upload my code however I can no longer take pictures in the code I use. I can take pictures only when I reset the esp32 cam board…hummm I’m confused..I read on the Github site that (expressif/arduino-esp-32) was updated 2 days ago…I updated my Arduin (I.D.E) 2.3.3 but that doesn’t change anything….my original code seems to need this line of code ( WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector )…in short the goal of my code is to activate the esp-32 cam and take and send pictures by activating a button normally at (LOW) and activated when it is set to (HIGH)
can you help me on this bug ???
Can you provide more details about the issue?
Do you get any errors on the serial monitor?
What code are you using as a reference?
Regards,
Sara
Hi Sara !!
I finally found some time to look for what is bugging…but after multiple tries, I can’t find what is causing this problem….yet my sketch worked on all my other esp32cams ….but since this piece of code is giving an error ( WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector ….it’s starting to stop working …to be able to upload the code with ( WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector ) I had to add this part (( #include “soc/rtc_cntl_reg.h” //Include for RTC_CNTL_BROWN_OUT_REG
#include “soc/soc.h” // Include for WRITE_PERI_REG )) at the beginning of the code to be able to upload my original code…….but now
I can take a picture only when I plug in the esp32cam pcb (external power) or when I plug it in and open the monitor directly with IDE arduino…it seems it takes longer to send the photo by email….but I can’t take a picture by pressing a button (with the external power) even if I have 3.3 volts going to the (pin 13)…( 12K resistor to the ground)…impossible to take a picture by pressing a button….
this is the basic code that i have to use (( press a button and take a picture to send by email )) everytime i press the button it send a picture….
once again my code worked before but now it no longer works since this last update (or modification on the part of arduino environment)
here’s what follows
1= code…
2= uploading text…
3 = serial monitor text (when is taking a picture )
i select
ESP32 Wrover Module
COM5
—————————– code
/*********
Rui Santos
Complete instructions at https://RandomNerdTutorials.com/esp32-cam-projects-ebook/
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*********/
#include “esp_camera.h”
#include “SPI.h”
#include “driver/rtc_io.h”
#include <ESP_Mail_Client.h>
#include “soc/rtc_cntl_reg.h” // Include for RTC_CNTL_BROWN_OUT_REG
#include “soc/soc.h” // Include for WRITE_PERI_REG
#include <FS.h>
#include <LittleFS.h>
#include <WiFi.h>
#include <Arduino.h>
//#include “soc/rtc_cntl_reg.h” // Include for RTC_CNTL_BROWN_OUT_REG
//#include “soc/soc.h” // Include for WRITE_PERI_REG
// REPLACE WITH YOUR NETWORK CREDENTIALS
const char* ssid = “***********”;
const char* password = “***********”;
// To send Email using Gmail use port 465 (SSL) and SMTP Server smtp.gmail.com
// You need to create an email app password
#define emailSenderAccount “************@gmail.com”
#define emailSenderPassword “******************”
#define smtpServer “smtp.gmail.com”
#define smtpServerPort 465
#define emailSubject “ESP32_CAM_1”
#define emailRecipient “*************@gmail.com”
#define CAMERA_MODEL_AI_THINKER
#if defined(CAMERA_MODEL_AI_THINKER)
#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
#else
#error “Camera model not selected”
#endif
int photoo = 0;
int detec = 13;
int detecc = 0;
int d = 0;
int dd = 0;
int swf = 12;
int swff = 0;
#define LED 4 // flash
/* The SMTP Session object used for Email sending */
SMTPSession smtp;
/* Callback function to get the Email sending status */
void smtpCallback(SMTP_Status status);
// Photo File Name to save in LittleFS
#define FILE_PHOTO “photo.jpg”
#define FILE_PHOTO_PATH “/photo.jpg”
void setup() {
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
// Disable brownout detection
//esp_sleep_disable_brownout();
// Serial.begin(115200);
Serial.begin(921600);
Serial.println();
digitalWrite(LED, LOW);
digitalWrite(swf, INPUT);
digitalWrite(detec, INPUT);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
Serial.print(“Connecting to WiFi…”);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
}
Serial.println();
if (!LittleFS.begin(true)) {
Serial.println(“An Error has occurred while mounting LittleFS”);
ESP.restart();
}
else {
delay(500);
Serial.println(“LittleFS mounted successfully”);
}
// Print ESP32 Local IP Address
Serial.print(“IP Address: http://”);
Serial.println(WiFi.localIP());
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 = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
config.grab_mode = CAMERA_GRAB_LATEST;
if(psramFound()){
config.frame_size = FRAMESIZE_UXGA;
config.jpeg_quality = 40;
config.fb_count = 1;
} else {
config.frame_size = FRAMESIZE_SVGA;
config.jpeg_quality = 42;
config.fb_count = 1;
}
// Initialize camera
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf(“Camera init failed with error 0x%x”, err);
return;
}
capturePhotoSaveLittleFS();
sendPhoto();
}
void loop() {
detecc = digitalRead(detec);
if (detecc == HIGH)
{
//ESP.restart();
d++;
if (d == 1)
{
capturePhotoSaveLittleFS();
sendPhoto();
//delay(5000);
photoo++;
Serial.print(“photo == “);
Serial.println(photoo);
//delay(1000);
}// if d
Serial.print(“d == “);
Serial.println(d);
if (d > 7)
{
d = 0;
}
}// if detecc
if (detecc == LOW)
{
// Serial.print(“photo == off “);
d = 0;
}
}
// Check if photo capture was successful
bool checkPhoto( fs::FS &fs ) {
File f_pic = fs.open( FILE_PHOTO_PATH );
unsigned int pic_sz = f_pic.size();
return ( pic_sz > 100 );
}
// Capture Photo and Save it to LittleFS
void capturePhotoSaveLittleFS( void ) {
camera_fb_t * fb = NULL; // pointer
bool ok = 0; // Boolean indicating if the picture has been taken correctly
do {
// Take a photo with the camera
Serial.println(“Taking a photo…”);
swff = digitalRead(swf);
if (swff == HIGH) //////////////swicth flash
{
digitalWrite(LED, HIGH); // flash = on
}
if (swff == LOW)
{
// flash = off
}
//delay(200);//////////////////////////////SOIT ICI
// Clean previous buffer
camera_fb_t * fb = NULL;
fb = esp_camera_fb_get();
//delay(200);//////////////////////////////SOIT ICI
esp_camera_fb_return(fb); // dispose the buffered image
fb = NULL; // reset to capture errors
// Get fresh image
fb = esp_camera_fb_get();
digitalWrite(LED, LOW); // flash = off
if(!fb) {
Serial.println(“Camera capture failed”);
delay(1000);
ESP.restart();
}
// Photo file name
Serial.printf(“Picture file name: %s\n”, FILE_PHOTO_PATH);
File file = LittleFS.open(FILE_PHOTO_PATH, FILE_WRITE);
// Insert the data in the photo file
if (!file) {
Serial.println(“Failed to open file in writing mode”);
}
else {
file.write(fb->buf, fb->len); // payload (image), payload length
Serial.print(“The picture has been saved in “);
Serial.print(FILE_PHOTO_PATH);
Serial.print(” – Size: “);
Serial.print(fb->len);
Serial.println(” bytes”);
}
// Close the file
file.close();
esp_camera_fb_return(fb);
// check if file has been correctly saved in LittleFS
ok = checkPhoto(LittleFS);
} while ( !ok );
digitalWrite(LED, LOW); // flash = off
}
void sendPhoto( void ) {
/** Enable the debug via Serial port
* none debug or 0
* basic debug or 1
*/
smtp.debug(1);
/* Set the callback function to get the sending results */
smtp.callback(smtpCallback);
/* Declare the session config data */
ESP_Mail_Session session;
/* Set the session config */
session.server.host_name = smtpServer;
session.server.port = smtpServerPort;
session.login.email = emailSenderAccount;
session.login.password = emailSenderPassword;
session.login.user_domain = “”;
/* Declare the message class */
SMTP_Message message;
/* Enable the chunked data transfer with pipelining for large message if server supported */
message.enable.chunking = true;
/* Set the message headers */
message.sender.name = “ESP32-CAM”;
message.sender.email = emailSenderAccount;
message.subject = emailSubject;
message.addRecipient(“Sara”, emailRecipient);
String htmlMsg = “<h2>Photo captured with ESP32-CAM and attached in this email.</h2>”;
message.html.content = htmlMsg.c_str();
message.html.charSet = “utf-8”;
message.html.transfer_encoding = Content_Transfer_Encoding::enc_qp;
message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_normal;
message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay;
/* The attachment data item */
SMTP_Attachment att;
/** Set the attachment info e.g.
* file name, MIME type, file path, file storage type,
* transfer encoding and content encoding
*/
att.descr.filename = FILE_PHOTO;
att.descr.mime = “image/png”;
att.file.path = FILE_PHOTO_PATH;
att.file.storage_type = esp_mail_file_storage_type_flash;
att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64;
/* Add attachment to the message */
message.addAttachment(att);
/* Connect to server with the session config */
if (!smtp.connect(&session))
return;
/* Start sending the Email and close the session */
if (!MailClient.sendMail(&smtp, &message, true))
Serial.println(“Error sending Email, ” + smtp.errorReason());
}
// Callback function to get the Email sending status
void smtpCallback(SMTP_Status status){
/* Print the current status */
Serial.println(status.info());
/* Print the sending result */
if (status.success())
{
Serial.println(“—————-“);
Serial.printf(“Message sent success: %d\n”, status.completedCount());
Serial.printf(“Message sent failled: %d\n”, status.failedCount());
Serial.println(“—————-\n”);
struct tm dt;
for (size_t i = 0; i < smtp.sendingResult.size(); i++)
{
/* Get the result item */
SMTP_Result result = smtp.sendingResult.getItem(i);
time_t ts = (time_t)result.timestamp;
Serial.printf(“Message No: %d\n”, i + 1);
Serial.printf(“Status: %s\n”, result.completed ? “success” : “failed”);
Serial.printf(“Date/Time: %d/%d/%d %d:%d:%d\n”, dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec);
Serial.printf(“Recipient: %s\n”, result.recipients);
Serial.printf(“Subject: %s\n”, result.subject);
}
Serial.println(“—————-\n”);
// You need to clear sending result as the memory usage will grow up.
smtp.sendingResult.clear();
}
}
————————– uploading
Sketch uses 1300837 bytes (99%) of program storage space. Maximum is 1310720 bytes.
Global variables use 54164 bytes (16%) of dynamic memory, leaving 273516 bytes for local variables. Maximum is 327680 bytes.
“C:\Users\user\AppData\Local\Arduino15\packages\esp32\tools\esptool_py\4.6/esptool.exe” –chip esp32 –port “COM5” –baud 921600 –before default_reset –after hard_reset write_flash -z –flash_mode keep –flash_freq keep –flash_size keep 0x1000 “C:\Users\user\AppData\Local\Temp\arduino\sketches\D4D7929C09E69B3A12EFB773B32E47C0/ESP_32_Sarah_send_email_SWF_restart.ino.bootloader.bin” 0x8000 “C:\Users\user\AppData\Local\Temp\arduino\sketches\D4D7929C09E69B3A12EFB773B32E47C0/ESP_32_Sarah_send_email_SWF_restart.ino.partitions.bin” 0xe000 “C:\Users\user\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7/tools/partitions/boot_app0.bin” 0x10000 “C:\Users\user\AppData\Local\Temp\arduino\sketches\D4D7929C09E69B3A12EFB773B32E47C0/ESP_32_Sarah_send_email_SWF_restart.ino.bin”
esptool.py v4.6
Serial port COM5
Connecting….
Chip is ESP32-D0WD-V3 (revision v3.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: a8:42:e3:4a:1d:e0
Uploading stub…
Running stub…
Stub running…
Changing baud rate to 921600
Changed.
Configuring flash size…
Flash will be erased from 0x00001000 to 0x00007fff…
Flash will be erased from 0x00008000 to 0x00008fff…
Flash will be erased from 0x0000e000 to 0x0000ffff…
Flash will be erased from 0x00010000 to 0x0014ffff…
Compressed 24896 bytes to 16262…
Writing at 0x00001000… (100 %)
Wrote 24896 bytes (16262 compressed) at 0x00001000 in 0.4 seconds (effective 531.8 kbit/s)…
Hash of data verified.
Compressed 3072 bytes to 146…
Writing at 0x00008000… (100 %)
Wrote 3072 bytes (146 compressed) at 0x00008000 in 0.0 seconds (effective 1134.9 kbit/s)…
Hash of data verified.
Compressed 8192 bytes to 47…
Writing at 0x0000e000… (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.0 seconds (effective 1611.3 kbit/s)…
Hash of data verified.
Compressed 1307408 bytes to 854192…
Writing at 0x00010000… (1 %)
Writing at 0x00016ca9… (3 %)
Writing at 0x000229b3… (5 %)
Writing at 0x0002ca99… (7 %)
Writing at 0x00032ddf… (9 %)
Writing at 0x000384d2… (11 %)
Writing at 0x00043364… (13 %)
Writing at 0x00052520… (15 %)
Writing at 0x00057cc2… (16 %)
Writing at 0x0005da52… (18 %)
Writing at 0x000638f5… (20 %)
Writing at 0x000695b8… (22 %)
Writing at 0x0006e5a4… (24 %)
Writing at 0x000738e6… (26 %)
Writing at 0x0007912e… (28 %)
Writing at 0x0007ec61… (30 %)
Writing at 0x0008467b… (32 %)
Writing at 0x0008a0d4… (33 %)
Writing at 0x0008f74d… (35 %)
Writing at 0x00094c59… (37 %)
Writing at 0x00099d02… (39 %)
Writing at 0x0009f0fc… (41 %)
Writing at 0x000a4323… (43 %)
Writing at 0x000a9ba5… (45 %)
Writing at 0x000af16f… (47 %)
Writing at 0x000b429e… (49 %)
Writing at 0x000b9356… (50 %)
Writing at 0x000be884… (52 %)
Writing at 0x000c3bc2… (54 %)
Writing at 0x000caab9… (56 %)
Writing at 0x000cfac4… (58 %)
Writing at 0x000d4ee8… (60 %)
Writing at 0x000da9c1… (62 %)
Writing at 0x000dfe6f… (64 %)
Writing at 0x000e5587… (66 %)
Writing at 0x000eab15… (67 %)
Writing at 0x000efde6… (69 %)
Writing at 0x000f534e… (71 %)
Writing at 0x000fa55a… (73 %)
Writing at 0x000ffc2a… (75 %)
Writing at 0x00105369… (77 %)
Writing at 0x0010ad12… (79 %)
Writing at 0x00110732… (81 %)
Writing at 0x001160fb… (83 %)
Writing at 0x0011eb11… (84 %)
Writing at 0x001271aa… (86 %)
Writing at 0x0012d060… (88 %)
Writing at 0x001321e1… (90 %)
Writing at 0x00138bda… (92 %)
Writing at 0x0013e2b9… (94 %)
Writing at 0x001438d5… (96 %)
Writing at 0x00148c75… (98 %)
Writing at 0x0014e561… (100 %)
Wrote 1307408 bytes (854192 compressed) at 0x00010000 in 11.6 seconds (effective 898.1 kbit/s)…
Hash of data verified.
Leaving…
Hard resetting via RTS pin…
——————————-lopen serial monitor take a picture
04:44:09.510 -> ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
04:44:10.523 -> Connecting to WiFi……………………………
04:44:26.005 -> LittleFS mounted successfully
04:44:26.005 -> IP Address: http://192.168.0.100
04:44:26.203 -> Taking a photo…
04:44:26.644 -> Picture file name: /photo.jpg
04:44:26.892 -> The picture has been saved in /photo.jpg – Size: 55443 bytes
04:44:26.925 -> #### Connecting to SMTP server…
04:44:26.925 -> > C: ESP Mail Client v3.4.21
04:44:46.947 -> #### Error, library or device time was not set, see examples/SMTP/Set_Time.ino for manually time setting
04:44:46.947 -> ! E: library or device time was not set, see examples/SMTP/Set_Time.ino for manually time setting
04:44:46.947 -> > C: connecting to SMTP server
04:44:46.947 -> > C: Host > smtp.gmail.com
04:44:46.947 -> > C: Port > 465
04:44:50.398 ->
04:44:50.398 -> #### SMTP server connected
04:44:50.398 -> > C: SMTP server connected, wait for greeting…
04:44:50.398 -> < S: 220 smtp.gmail.com ESMTP a640c23a62f3a-a9e566843b0sm41317966b.212 – gsmtp
04:44:50.398 ->
04:44:50.398 -> #### Sending greeting response…
04:44:50.398 -> > C: send SMTP command, EHLO
04:44:50.925 -> < S: 250-smtp.gmail.com at your service, [77.240.240.234]
04:44:50.925 -> < S: 250-SIZE 35882577
04:44:50.925 -> < S: 250-8BITMIME
04:44:50.925 -> < S: 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
04:44:50.925 -> < S: 250-ENHANCEDSTATUSCODES
04:44:50.925 -> < S: 250-PIPELINING
04:44:50.925 -> < S: 250-CHUNKING
04:44:50.925 -> < S: 250 SMTPUTF8
04:44:50.925 ->
04:44:50.925 -> #### Logging in…
04:44:50.925 -> > C: send SMTP command, AUTH PLAIN
04:44:50.925 -> > C: xxxxxxxxx@gmail.com
04:44:50.925 -> > C: ****************
04:44:51.503 -> < S: 235 2.7.0 Accepted
04:45:11.505 -> #### Error, library or device time was not set, see examples/SMTP/Set_Time.ino for manually time setting
04:45:11.570 -> ! E: library or device time was not set, see examples/SMTP/Set_Time.ino for manually time setting
04:45:11.570 ->
04:45:11.570 -> #### Sending Email…
04:45:11.570 -> > C: send Email
04:45:11.570 ->
04:45:11.570 -> #### Sending message header…
04:45:11.570 -> > C: send message header
04:45:11.970 -> < S: 250 2.1.0 OK a640c23a62f3a-a9e566843b0sm41317966b.212 – gsmtp
04:45:12.467 -> < S: 250 2.1.5 OK a640c23a62f3a-a9e566843b0sm41317966b.212 – gsmtp
04:45:12.467 ->
04:45:12.467 -> #### Sending message body…
04:45:12.467 -> > C: send message body
04:45:12.966 -> < S: 354 Go ahead a640c23a62f3a-a9e566843b0sm41317966b.212 – gsmtp
04:45:18.019 ->
04:45:18.019 -> #### Sending attachments…
04:45:18.019 -> > C: send attachments
04:45:18.019 ->
04:45:18.019 -> #### photo.jpg
04:45:18.019 -> > C: photo.jpg
04:45:18.019 -> > C: [ ] 0 %
04:45:18.597 -> > C: [# ] 10 %
04:45:18.957 -> > C: [## ] 15 %
04:45:19.272 -> > C: [### ] 20 %
04:45:19.674 -> > C: [#### ] 25 %
04:45:20.309 -> > C: [##### ] 35 %
04:45:20.583 -> > C: [###### ] 40 %
04:45:20.884 -> > C: [####### ] 45 %
04:45:21.253 -> > C: [######## ] 50 %
04:45:21.810 -> > C: [######### ] 60 %
04:45:22.109 -> > C: [########## ] 65 %
04:45:22.450 -> > C: [########### ] 70 %
04:45:22.750 -> > C: [############ ] 75 %
04:45:23.343 -> > C: [############# ] 85 %
04:45:23.691 -> > C: [############## ] 90 %
04:45:23.957 -> > C: [############### ] 95 %
04:45:24.282 -> > C: [################] 100 %
04:45:24.545 ->
04:45:24.545 -> #### Finishing the message sending…
04:45:24.545 -> > C: finishing the message sending
04:45:26.361 -> < S: 250 2.0.0 OK 1730364325 a640c23a62f3a-a9e566843b0sm41317966b.212 – gsmtp
04:45:26.361 ->
04:45:26.361 -> #### Closing the session…
04:45:26.361 -> > C: terminate the SMTP session
04:45:26.791 -> < S: 221 2.0.0 closing connection a640c23a62f3a-a9e566843b0sm41317966b.212 – gsmtp
04:45:26.791 ->
04:45:26.791 -> #### Message sent successfully
04:45:26.791 -> > C: message sent successfully
04:45:26.791 ->
04:45:26.791 -> —————-
04:45:26.791 -> Message sent success: 1
04:45:26.791 -> Message sent failled: 0
04:45:26.791 -> —————-
04:45:26.791 ->
04:45:26.791 -> Message No: 1
04:45:26.791 -> Status: success
04:45:26.791 -> Date/Time: -2146575282/1/1061164771 1073421488:-2146602688:0
04:45:26.791 -> Recipient: �?
04:45:26.791 -> Subject: �?
04:45:26.791 -> —————-
04:45:26.791 ->
can your help me on this one ????
thanks for your time again !!
Hi.
Please send me your code using pastebin or gihub.
I’ll test it myself.
Also tell me the circuit you’re wiring.
Regards,
Sara
humm I’ve never used “pastebin” before and I haven’t created a github account yet…I know I should have…laugh…ok I’ll try to find out how “pastebin” works this week end but if you want to try the code here it is anyway….the circuit is very simple 1 press button pin (13) with a 12k resistor connected to ground and 3.3 volts to the second pin of the button…very simple basic…you may have to hold down the button until the photo can be taken and sent (I forgot to mention it in the previous text)..however all the texts during (uploading) are present (in the previous text)….here is the code down here if you wanna try anyway !!!
—————————– code
/*********
Rui Santos
Complete instructions at https://RandomNerdTutorials.com/esp32-cam-projects-ebook/
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*********/
#include “esp_camera.h”
#include “SPI.h”
#include “driver/rtc_io.h”
#include <ESP_Mail_Client.h>
#include “soc/rtc_cntl_reg.h” // Include for RTC_CNTL_BROWN_OUT_REG
#include “soc/soc.h” // Include for WRITE_PERI_REG
#include <FS.h>
#include <LittleFS.h>
#include <WiFi.h>
#include <Arduino.h>
//#include “soc/rtc_cntl_reg.h” // Include for RTC_CNTL_BROWN_OUT_REG
//#include “soc/soc.h” // Include for WRITE_PERI_REG
// REPLACE WITH YOUR NETWORK CREDENTIALS
const char* ssid = “***********”;
const char* password = “***********”;
// To send Email using Gmail use port 465 (SSL) and SMTP Server smtp.gmail.com
// You need to create an email app password
#define emailSenderAccount “************@gmail.com”
#define emailSenderPassword “******************”
#define smtpServer “smtp.gmail.com”
#define smtpServerPort 465
#define emailSubject “ESP32_CAM_1”
#define emailRecipient “*************@gmail.com”
#define CAMERA_MODEL_AI_THINKER
#if defined(CAMERA_MODEL_AI_THINKER)
#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
#else
#error “Camera model not selected”
#endif
int photoo = 0;
int detec = 13;
int detecc = 0;
int d = 0;
int dd = 0;
int swf = 12;
int swff = 0;
#define LED 4 // flash
/* The SMTP Session object used for Email sending */
SMTPSession smtp;
/* Callback function to get the Email sending status */
void smtpCallback(SMTP_Status status);
// Photo File Name to save in LittleFS
#define FILE_PHOTO “photo.jpg”
#define FILE_PHOTO_PATH “/photo.jpg”
void setup() {
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
// Disable brownout detection
//esp_sleep_disable_brownout();
// Serial.begin(115200);
Serial.begin(921600);
Serial.println();
digitalWrite(LED, LOW);
digitalWrite(swf, INPUT);
digitalWrite(detec, INPUT);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
Serial.print(“Connecting to WiFi…”);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
}
Serial.println();
if (!LittleFS.begin(true)) {
Serial.println(“An Error has occurred while mounting LittleFS”);
ESP.restart();
}
else {
delay(500);
Serial.println(“LittleFS mounted successfully”);
}
// Print ESP32 Local IP Address
Serial.print(“IP Address: http://”);
Serial.println(WiFi.localIP());
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 = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
config.grab_mode = CAMERA_GRAB_LATEST;
if(psramFound()){
config.frame_size = FRAMESIZE_UXGA;
config.jpeg_quality = 40;
config.fb_count = 1;
} else {
config.frame_size = FRAMESIZE_SVGA;
config.jpeg_quality = 42;
config.fb_count = 1;
}
// Initialize camera
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf(“Camera init failed with error 0x%x”, err);
return;
}
capturePhotoSaveLittleFS();
sendPhoto();
}
void loop() {
detecc = digitalRead(detec);
if (detecc == HIGH)
{
//ESP.restart();
d++;
if (d == 1)
{
capturePhotoSaveLittleFS();
sendPhoto();
//delay(5000);
photoo++;
Serial.print(“photo == “);
Serial.println(photoo);
//delay(1000);
}// if d
Serial.print(“d == “);
Serial.println(d);
if (d > 7)
{
d = 0;
}
}// if detecc
if (detecc == LOW)
{
// Serial.print(“photo == off “);
d = 0;
}
}
// Check if photo capture was successful
bool checkPhoto( fs::FS &fs ) {
File f_pic = fs.open( FILE_PHOTO_PATH );
unsigned int pic_sz = f_pic.size();
return ( pic_sz > 100 );
}
// Capture Photo and Save it to LittleFS
void capturePhotoSaveLittleFS( void ) {
camera_fb_t * fb = NULL; // pointer
bool ok = 0; // Boolean indicating if the picture has been taken correctly
do {
// Take a photo with the camera
Serial.println(“Taking a photo…”);
swff = digitalRead(swf);
if (swff == HIGH) //////////////swicth flash
{
digitalWrite(LED, HIGH); // flash = on
}
if (swff == LOW)
{
// flash = off
}
//delay(200);//////////////////////////////SOIT ICI
// Clean previous buffer
camera_fb_t * fb = NULL;
fb = esp_camera_fb_get();
//delay(200);//////////////////////////////SOIT ICI
esp_camera_fb_return(fb); // dispose the buffered image
fb = NULL; // reset to capture errors
// Get fresh image
fb = esp_camera_fb_get();
digitalWrite(LED, LOW); // flash = off
if(!fb) {
Serial.println(“Camera capture failed”);
delay(1000);
ESP.restart();
}
// Photo file name
Serial.printf(“Picture file name: %s\n”, FILE_PHOTO_PATH);
File file = LittleFS.open(FILE_PHOTO_PATH, FILE_WRITE);
// Insert the data in the photo file
if (!file) {
Serial.println(“Failed to open file in writing mode”);
}
else {
file.write(fb->buf, fb->len); // payload (image), payload length
Serial.print(“The picture has been saved in “);
Serial.print(FILE_PHOTO_PATH);
Serial.print(” – Size: “);
Serial.print(fb->len);
Serial.println(” bytes”);
}
// Close the file
file.close();
esp_camera_fb_return(fb);
// check if file has been correctly saved in LittleFS
ok = checkPhoto(LittleFS);
} while ( !ok );
digitalWrite(LED, LOW); // flash = off
}
void sendPhoto( void ) {
/** Enable the debug via Serial port
* none debug or 0
* basic debug or 1
*/
smtp.debug(1);
/* Set the callback function to get the sending results */
smtp.callback(smtpCallback);
/* Declare the session config data */
ESP_Mail_Session session;
/* Set the session config */
session.server.host_name = smtpServer;
session.server.port = smtpServerPort;
session.login.email = emailSenderAccount;
session.login.password = emailSenderPassword;
session.login.user_domain = “”;
/* Declare the message class */
SMTP_Message message;
/* Enable the chunked data transfer with pipelining for large message if server supported */
message.enable.chunking = true;
/* Set the message headers */
message.sender.name = “ESP32-CAM”;
message.sender.email = emailSenderAccount;
message.subject = emailSubject;
message.addRecipient(“Sara”, emailRecipient);
String htmlMsg = “<h2>Photo captured with ESP32-CAM and attached in this email.</h2>”;
message.html.content = htmlMsg.c_str();
message.html.charSet = “utf-8”;
message.html.transfer_encoding = Content_Transfer_Encoding::enc_qp;
message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_normal;
message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay;
/* The attachment data item */
SMTP_Attachment att;
/** Set the attachment info e.g.
* file name, MIME type, file path, file storage type,
* transfer encoding and content encoding
*/
att.descr.filename = FILE_PHOTO;
att.descr.mime = “image/png”;
att.file.path = FILE_PHOTO_PATH;
att.file.storage_type = esp_mail_file_storage_type_flash;
att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64;
/* Add attachment to the message */
message.addAttachment(att);
/* Connect to server with the session config */
if (!smtp.connect(&session))
return;
/* Start sending the Email and close the session */
if (!MailClient.sendMail(&smtp, &message, true))
Serial.println(“Error sending Email, ” + smtp.errorReason());
}
// Callback function to get the Email sending status
void smtpCallback(SMTP_Status status){
/* Print the current status */
Serial.println(status.info());
/* Print the sending result */
if (status.success())
{
Serial.println(“—————-“);
Serial.printf(“Message sent success: %d\n”, status.completedCount());
Serial.printf(“Message sent failled: %d\n”, status.failedCount());
Serial.println(“—————-\n”);
struct tm dt;
for (size_t i = 0; i < smtp.sendingResult.size(); i++)
{
/* Get the result item */
SMTP_Result result = smtp.sendingResult.getItem(i);
time_t ts = (time_t)result.timestamp;
Serial.printf(“Message No: %d\n”, i + 1);
Serial.printf(“Status: %s\n”, result.completed ? “success” : “failed”);
Serial.printf(“Date/Time: %d/%d/%d %d:%d:%d\n”, dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec);
Serial.printf(“Recipient: %s\n”, result.recipients);
Serial.printf(“Subject: %s\n”, result.subject);
}
Serial.println(“—————-\n”);
// You need to clear sending result as the memory usage will grow up.
smtp.sendingResult.clear();
}
}
Hi.
What is exactly your problem?
Can you be more specific?
I tested your code, it sends pictures just fine… (I tested with a wire instead of a pushbutton.)
What ESP32 board do you have?
Regards,
Sara
Hi Sara !!
thanks for letting me know about (pastebin) however before publishing my code I was wondering about the (copyright)
I would like to know what to add and remove from the code that you gave me (from RUI) can i use your code and modify certain things in the original code and then publish it ??? at the very beginning of your code it has the copyright text of (RUI with the https://internet address) …… my question is “” if I modify a part of this code, can I still keep the text (from RUI) yes or no ??? I would not want to harm your work for anything in the world …. what do you advise me to do about this … ??? (I have never published code before) …
regarding the esp32cam bug…i must admit that i made a mistake and reversed (pinMode) in the void setup and mistakenly wrote (digitalWrite)….it was late at night…laugh…
“”””” BUT “”””” the real bug seems to be on a long term usage problem…
The real problem is that “”” after working for quite a long time, the esp32cam suddenly stops working and does not send any more photos by email….(I have to reuse the PCB to upload with the usb wire) and when I try to access the “”COM4″”, I am unable to connect to the “”COM4″” (even after pressing the reset button)…. it seems that I have to (press the “boot” button + reset “”sequence””) to upload the code again…but sometimes I am not able to upload the code at all and my (esp32cam) becomes scrap…
I am using an aluminum cooling block and some paste to try to cool the (esp32cam) because it gets quite hot after a full day of non-stop operation…..
in your previous answer about the (rtc)””” ( WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector ) “”” you answered me “”” You can remove that line of code.
I think that is probably not suppprted on the most recent version of the ESP32 boards. “”” … but i had to add this part
#include “soc/rtc_cntl_reg.h” // Include for RTC_CNTL_BROWN_OUT_REG
#include “soc/soc.h” // Include for WRITE_PERI_REG
in the begining of the code to compile the code successfuly. is it possible that the problem is at this level (since the last update of Arduino IDE)…???
I am trying to solve this problem by trying to find an example of code that would test if the (esp32cam) stops working properly and using a code like (ESP.restart or ESP.reset) could detect the malfunction (esp32cam “”bug””) and could start again to execute the code without any “”bug”” again now…but I have not managed to find any example of this kind yet…..have you ever seen code that works this way???
what was the longest period managed to stay “”ON”” an esp32cam board ???…
thak you so much Sara for your time it realy helps me ……!!!!!!!!!!!!!!!!!…:)
Hi.
I’m not sure about the maximum time the ESP32-CAM “can run”. I haven’t tried it before. If it gets too hot, it will at some point crash, or if the power supply is not stable.
You can connect the board to the serial monitor and let it run for a while, and then try to see what it printed when it crashed to try to figure out what might have been the issue.
I think this code about watchdog reset can be useful to try to figure out the issue: https://gist.github.com/Tech500/e406653d2e459a5affb2c9157df350c8
I’m not sure exactly how it works because I haven’t put it into practice yet.
You can modify our original codes without any problem. Just make sure you have a reference to our original code at the beginning of yours. Something like: “Based on the RNT example: “URL of the code or project.””
Regards,
Sara
Hi Sara !!
thank you for your answer because curiously since 3 days I was trying to make the (WDT) that I saw in other code examples work… I finally managed to find a code that (compiles) with the (WDT) because several examples do not (compile) at all even with help of (AI) the code that I tried seems to (reboot) periodically and I cannot control the (reboot) but now I will try with your link and give you news on this subject.
about the power supply ..must be stable because I use a 5 volts 1.5 A (ac/dc)and now I wonder if I should not add a fan to blow on the aluminum part directly it could help in the long term on this point
I noticed in your code the use of (ESP.restart) can be used against (crash)
I would like to ask you if the (ESP.reset) or (ESP.restart) could replace the (WDT) watchdog timer?? is there a way to achieve using this command instead of the (WDT) if the (WDT)does not work in the code
when you said “” You can connect the board to the serial monitor and let it run for a while, and then try to see what it printed when it crashed to try to figure out what might have been the issue. “”
I can’t connect with the usb wire because the esp32cam is on another board. So I have to remove it from the (uploading board) because I have to plug the button and other inputs. That’s why I can’t access the (serial monitor) and see what is written when the (bug) occurs. I thought about saving in a .txt file using (coolterm) software but I can’t connect the usb wire to the esp32cam board and have a reading. Maybe there is a way to cut and strip the wires of the usb wire that is connected to the computer and plug it into the breadboard (for test) to have a reading on the (serial monitor) but I don’t know actualy how to do that for now..(any ideas??)
ok I understand now I will add a reference mentioning that the code to be published is based on your code with your link at the beginning of the code page
Thank you for your help and time
Hi.
Do you have an FTDI programmer?
With that, you can have the board connected to your computer and still have the pins available to connect the button.
Alternatively, you can let it connected to the Serial monitor with the programmer board, and use a wire to set the pin state to HIGH by touching the wire on the 3V3 and the pin (this mimics the button)
Regards,
Sara