@stefandws ALL the camera settings are the same, both you and I did a file comparison to prove that. Some of the pictures you supplied are showing that either the 'shutter' was triggered early, or something is blocking the lens.
THE ONLY WAY TO TEST THE TWO SKETCHES IS TO LAY THE CAMERA ON A FLAT SURFACE AIMED AT THE CEILING AND YOU STAND 3 FT AWAY WHEN YOU PLUG IN THE USB CABLE AND DO AN UPLOAD.
I also want to clarify some wording. You say 'reset' but in fact the sketch is set up to use GPIO pin 13 as noted in the attached pic. Please verify you have a button connected to ground on 1 side and GPIO13 on the other.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
Hello Ron,
sorry I am not that fast. I am trying to use the ESP32-cam-device first time
1) there is no error message when brown out is set to 1 or 0 ... no difference
2)
What I would like to see is just lay the camera on the table beside the PC and take a random picture then use the other sketch.
this can be seen in my tests ..
- original "loop" code
( ESP32-CAM Time-lapse camera, esp32cam-timelapse.ino,Takes time-lapse pictures with ESP32-CAM Saves images to MicroSD Card,DroneBot Workshop 2022
https://dronebotworkshop.com
br />delayTime = 10000
camera without yogurt cup housing (distance starting from approx 1m getting closer up to yogurt cup distance) - original "loop" code, camera fixed within yogurt cup housing ... (distance starting from approx 1m getting closer up to yogurt cup distance)
except it is not laying on the table Iam holding the camera in my hands
1) original "loop" code without cup housing .... result is just fine (time-lapse code) ... camera hold within my hands
2) modified loop loop code ... modified camer settings ... camera hold within my hands
the problem is:
the setting has to work within the yogurt cup housing since this exactly fits onto the water meter.
I am trying to get the setting to work in order to take a picture of the water meter once an hour and save the pictures to SD card,
Triggering the camera by rst-button in this setting is just fine!
it is just the automatism that seems to cause trouble for any reason I do not understand
Please don't waste your time with this problem ... I will order a new device and will report back in a couple of days when I have tested same settings with the new device.
If the other device is causing the same result.... (that is what I am expecting) then it has to be a software setting problem ... at least for my understanding
we will see ... I will report
Thanks for your help and get well soon!!
Stefan
I also want to clarify some wording. You say 'reset' but in fact the sketch is set up to use GPIO pin 13 as noted in the attached pic. Please verify you have a button connected to ground on 1 side and GPIO13 on the other.
I am just using the "devices":
ESP32-CAM plugged into ESP32-CAM-MB
The MB has two buttons ...
a) labeled RST
b) IO0
by pressing RST the system restarts and takes a perfect picture of the watermeter
@stefandws But you are forgetting both you and I did a file compare and the camera code is identical for both sketches.
The difference is one is done in setup, the other in the loop. This may have power implications that is why a better power supply is needed, do NOT use your PC to power the camera unless it is at least USB3.1
Also have you looked at the board errata, I glanced at it yesterday and saw some mention of issues in sleep mode.
You didn't answer my question re Reset button vs GPIO13. The sketch is using GPIO13, that is how you can take multiple shots with the sketch you call 'reset'. If that is the one working for you then connect a RTC board to pin 13 and set it to trigger the pin once an hour. Problem solved other than modifying the SD card writing to auto-increment like the elapsed timer code does. It's a simple copy and paste.
As far as ordering another board, if it comes from the same supplier/manufacturer it will be the same as what you have. We certainly have heard of these clones being flawed, but I doubt that is what is happening here.
One critical fact you are overlooking is that in the batch of what you call 'bad' pictures, I see plenty of evidence of 'normal' pictures except the lens is either blocked or the shutter is slow.
I am very sure this is a user error, not a code error.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@stefandws The code to do a reset in software is ESP.restart
For your project, simply change the delay to be 60 mins * 60 secs/min * 1,000ms/sec or 3,600,000ms
Now just copy the SD card writing code from the time lapse to the other sketch. Easy peasy!
To test, use delay(60000) for once a minute or even less if you want.
NOTE: The ESP.restart(); statement must be the last one in the setup proc.
for further details see HERE
void setup(){
Serial.begin(115200);
Serial.println("Restarting in 10 seconds");
delay(10000);
ESP.restart();
}
void loop() {}
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
ESP.restart();
I think this is the magical line.
Pictures taken are now ok ... but it generates no new pictures ... it is always overwriting same picture on the SD-card
I think this was the magic line .... I will try later and to look into how the filenames are generated.
but I must leave for now ... will try later
THANK YOU!!!!
@stefandws I modified the reset code and it compiles as the ESP object is part of the esp32 hardware library. Just add an #include "esp.h" at the top of the sketch. I will do a quick copy/paste of the SD card logic and then give this code back to you. This code is the version that takes a good picture after a reset, and writes those pictures to an SD card. Give me a few moments.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
Hi Ron @zander and @stefandws,
Ron, I hope you are feeling better ... that is the most important thing!
------------------
As I said, (Ron) you have much more experience of this device than I have. I was only trying to shed a little light on the problem .. pun intended 😀
It is sometime since I played with ESP32 CAM, but I do recall seeing the LED come on under some conditions ... albeit unfortunately, I don't remember the details, but I had a feeling it might have been related to the reset button. As I am not that familiar with all of the supporting library camera code, it occurred to me there might be some automatic LED 'flash' mode, so it might not need any explicit user code.
I am not clear what light source is available to the camera in its yogurt pot 'shed'. I recall the standard 'CAM' that comes with the ESP32 CAM needs reasonably well lit conditions to produce even a 'passable' image quality.
As the images seem to include 'over exposure' and 'under exposure', sometimes apparently acheving both in the same image, and remembering it takes a significant time to read out all of the pixels from a frame, I was left wondering if the picture was in effect the combined result of two or more frames, each frame contributing a horizontal band of the image, some with LED on, others with it off. Of course, this was all speculation, and may be total nonsense, but my approach to problems like this is to suggest a plausible explanation, and then look for evidence to support or reject the suggestion.
I merely suggested that the @stefandws tried providing adequate, constant lighting to see if it changed the problem .. which is somewhat similar to your suggestion of taking pictures into the room, as they are both ways of reducing any effect of the local LED lighting. Neither suggestion is a direct 'cure' for the problem - they are both about trying to find out how the 'weird' images are occurring.
Best wishes and take care my friend, Dave
@davee Stefan is highly resistant to following instructions. I agree with most of what you said other than the ESP32CAM LED being involved. I will try to find an example of LED usage but that is lower priority. I am giving up trying to teach and just giving him one possible solution.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@stefandws Here is the sketch I created that should have incrementing file names. If not, you can fix that part.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
Hi Ron @zander,
Good to hear from you ... hope you are taking it easy.
The LED suggestion may be a complete red herring .. I can't see his kit and I have a few of my own things to be getting on with, so I am not keen to reproduce the whole experiment. It was just a thought.
Looks like you might have found a way round the problem ... if so, well done.
Take care, Dave
@davee Yep, got lucky again. The more I read the docs, the luckier I get.
Just an FYI, here is how the onboard LED is managed. I have one camera sketch that uses the LED under web control
#ifdef CONFIG_LED_ILLUMINATOR_ENABLEDvoid enable_led(bool en){ // Turn LED On or Offint duty = en ? led_duty : 0;if (en && isStreaming && (led_duty > CONFIG_LED_MAX_INTENSITY)){duty = CONFIG_LED_MAX_INTENSITY;}ledc_set_duty(CONFIG_LED_LEDC_SPEED_MODE, CONFIG_LED_LEDC_CHANNEL, duty);ledc_update_duty(CONFIG_LED_LEDC_SPEED_MODE, CONFIG_LED_LEDC_CHANNEL);ESP_LOGI(TAG, "Set LED intensity to %d", duty);}#endif
As far as illness. I have been referred to the appropriate doctor. No idea how long I have to wait. There is a chance they are barking up the wrong tree based on what I know about my body. My Dr does not know what I know but I may not have told him.
Diet has improved me to the point I can work a little bit each day but it's a battle.
I may have not mentioned I am dealing with Iron Deficiency Anemia, and besides taking Iron supplements and some diet changes I just have to wait for a phone call. They think it's a scope and repair job so I will walk out of the hospital cured so to speak. If however, they find nothing as I suspect I am in for a bit of a rough time, abdominal surgery at 81 is a bit of a bother.
My other major health issue is AFIB and I am getting some tests done. It may only result in medication change or may not. My attacks happen about once a month and usually last a day. I can live with that.
Once the IDA is resolved (can take 3 to 6 months) I should have a lot more energy so I will be able to get more done at the bench and provide more help here.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
Hello Ron,
yes, this was the magic line!
ESP.restart();
THANK YOU VERY MUCH!!!
but ... please first look after yourself ... get well soon!
in case someone should have the same problems .... for my environment the solution of the problem was:
--> combination of both scrips
1) generation of the filename taken from script " esp32cam-microsd.inoTake picture when button pressed
2) "loop part" taken from script " esp32cam-timelapse.inoTakes time-lapse pictures with ESP32-CAM
Saves images to MicroSD Card"
3) including ESP-restert()
and voila .. perfect pictures taken triggered within the loop
the modified code that is working with on the "camera fixed into yogurt cup housing device" is working well (at least it seems like that right now) ... next step is to mount on the watermeter and test real life setting.
this brings up some other questions:
- logging additional information on the SD-CARD additional to the images stored on the SD-card .. instead of using the serial monitor while board is connected to PC
- how to reset the counter to zero
- how to reduce (set) LED-flash light (brightness)
- how to best continue in order to find optimal camera settings (... setting values of the camera parameters by changing variables over time ... "for/next loop" ... with parameters logged to SD-card
but... I first will try to solve this by myself by doing some research
most important: GET WELL SOON!
and Thanks for the great suport!!
Stefan
this is the modified code that does the job within my environment:
/* ESP32-CAM Time-lapse camera esp32cam-timelapse.ino Takes time-lapse pictures with ESP32-CAM Saves images to MicroSD Card DroneBot Workshop 2022 https://dronebotworkshop.com */ // Include Required Libraries // Camera libraries #include "esp_camera.h" #include "soc/soc.h" #include "soc/rtc_cntl_reg.h" #include "driver/rtc_io.h" // MicroSD Libraries #include "FS.h" #include "SD_MMC.h" // EEPROM Library #include "EEPROM.h" // Use 1 byte of EEPROM space #define EEPROM_SIZE 1 // Counter for picture number unsigned int pictureCount = 0; // Pin definitions for 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 // Delay time in millieconds unsigned int delayTime = 10000; void configESPCamera() { // Configure Camera parameters // Object to store the camera configuration parameters 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; // Choices are YUV422, GRAYSCALE, RGB565, JPEG // Select lower framesize if the camera doesn't support PSRAM if (psramFound()) { config.frame_size = FRAMESIZE_UXGA; // FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA config.jpeg_quality = 10; //10-63 lower number means higher quality config.fb_count = 2; } else { config.frame_size = FRAMESIZE_SVGA; config.jpeg_quality = 12; config.fb_count = 1; } // Initialize the Camera esp_err_t err = esp_camera_init(&config); if (err != ESP_OK) { Serial.printf("Camera init failed with error 0x%x", err); return; } // Camera quality adjustments sensor_t * s = esp_camera_sensor_get(); // BRIGHTNESS (-2 to 2) s->set_brightness(s, 2); // CONTRAST (-2 to 2) s->set_contrast(s, 0); // SATURATION (-2 to 2) s->set_saturation(s, 0); // SPECIAL EFFECTS (0 - No Effect, 1 - Negative, 2 - Grayscale, 3 - Red Tint, 4 - Green Tint, 5 - Blue Tint, 6 - Sepia) s->set_special_effect(s, 0); // WHITE BALANCE (0 = Disable , 1 = Enable) s->set_whitebal(s, 1); // AWB GAIN (0 = Disable , 1 = Enable) s->set_awb_gain(s, 1); // WB MODES (0 - Auto, 1 - Sunny, 2 - Cloudy, 3 - Office, 4 - Home) s->set_wb_mode(s, 0); // EXPOSURE CONTROLS (0 = Disable , 1 = Enable) s->set_exposure_ctrl(s, 0); // 1 // AEC2 (0 = Disable , 1 = Enable) s->set_aec2(s, 0); // AE LEVELS (-2 to 2) s->set_ae_level(s, 1); // AEC VALUES (0 to 1200) s->set_aec_value(s, 1200); // GAIN CONTROLS (0 = Disable , 1 = Enable) s->set_gain_ctrl(s, 1); // AGC GAIN (0 to 30) s->set_agc_gain(s, 15); // GAIN CEILING (0 to 6) s->set_gainceiling(s, (gainceiling_t)0); // BPC (0 = Disable , 1 = Enable) s->set_bpc(s, 0); // WPC (0 = Disable , 1 = Enable) s->set_wpc(s, 1); // RAW GMA (0 = Disable , 1 = Enable) s->set_raw_gma(s, 1); // LENC (0 = Disable , 1 = Enable) s->set_lenc(s, 1); // HORIZ MIRROR (0 = Disable , 1 = Enable) s->set_hmirror(s, 0); // VERT FLIP (0 = Disable , 1 = Enable) s->set_vflip(s, 0); // DCW (0 = Disable , 1 = Enable) s->set_dcw(s, 1); // COLOR BAR PATTERN (0 = Disable , 1 = Enable) s->set_colorbar(s, 0); } void initMicroSDCard() { // Start the MicroSD card Serial.println("Mounting MicroSD Card"); if (!SD_MMC.begin()) { Serial.println("MicroSD Card Mount Failed"); return; } uint8_t cardType = SD_MMC.cardType(); if (cardType == CARD_NONE) { Serial.println("No MicroSD Card found"); return; } } void takeNewPhoto(String path) { // Take Picture with Camera // Setup frame buffer camera_fb_t * fb = esp_camera_fb_get(); if (!fb) { Serial.println("Camera capture failed"); return; } // Save picture to microSD card fs::FS &fs = SD_MMC; File file = fs.open(path.c_str(), FILE_WRITE); if (!file) { Serial.println("Failed to open file in write mode"); } else { file.write(fb->buf, fb->len); // payload (image), payload length Serial.printf("Saved file to path: %s\n", path.c_str()); } // Close the file file.close(); // Return the frame buffer back to the driver for reuse esp_camera_fb_return(fb); } void setup() { // Disable brownout detector WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); // Start Serial Monitor Serial.begin(115200); // Initialize the camera Serial.print("Initializing the camera module..."); configESPCamera(); Serial.println("Camera OK!"); // Initialize the MicroSD Serial.print("Initializing the MicroSD card module... "); initMicroSDCard(); // initialize EEPROM with predefined size EEPROM.begin(EEPROM_SIZE); pictureCount = EEPROM.read(0) + 1; } void loop() { // Path where new image will be saved in MicroSD card String path = "/image" + String(pictureCount) + ".jpg"; Serial.printf("Picture file name: %s\n", path.c_str()); // Take and Save Photo takeNewPhoto(path); // Update EEPROM picture number counter EEPROM.write(0, pictureCount); EEPROM.commit(); // Delay for specified period delay(delayTime); ESP.restart(); }
@stefandws You don't need the restart in your sketch, the loop procedure accomplishes it, all you need to do is move code around so that code that is only needed once is in setup, and code needed each picture is in loop. Look at my code I sent you.
Here is my quick answers to your questions
logging additional information on the SD-CARD additional to the images stored on the SD-card .. instead of using the serial monitor while board is connected to PC
Yes, you can, but you will need to study file system concepts to determine how to do this.
how to reset the counter to zero
Just assign 0 to the counter as in myCounter = 0;
how to reduce (set) LED-flash light (brightness)
That might not be very easy, you need to know how to find things in the system, not just code, but the doc'n as well. I just had a quick look because I have looked at it before and I don't see a quick easy path. Make this low priority.
how to best continue in order to find optimal camera settings (... setting values of the camera
parameters by changing variables over time ... "for/next loop" ... with parameters logged to SD-card
I do not recommend for next, change one setting at a time.
The settings you inherited are optimal, but if you want to play, change ONE at a time, like brightness until it looks good to you, then move on to contrast etc.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@stefandws You don't need the restart in your sketch, the loop procedure accomplishes it, all you need to do is move code around so that code that is only needed once is in setup, and code needed each picture is in loop. Look at my code I sent you.
I am not sure if I do understand what you are saying
but if I move the RESTART from within the loop to the end of procedure setup() the pictures are of no use just as before.
I think I have to stay leaving restart within the loop .. this seems to work just fine
void setup() { // Disable brownout detector WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); // Start Serial Monitor Serial.begin(115200); // Initialize the camera Serial.print("Initializing the camera module..."); configESPCamera(); Serial.println("Camera OK!"); // Initialize the MicroSD Serial.print("Initializing the MicroSD card module... "); initMicroSDCard(); // initialize EEPROM with predefined size EEPROM.begin(EEPROM_SIZE); pictureCount = EEPROM.read(0) + 1; Serial.println("Restarting in 10 seconds"); delay(10000); ESP.restart(); }
Having ESP.restart() within the loop .. the result is perfect!
void loop() { // Path where new image will be saved in MicroSD card String path = "/image" + String(pictureCount) + ".jpg"; Serial.printf("Picture file name: %s\n", path.c_str()); // Take and Save Photo takeNewPhoto(path); // Update EEPROM picture number counter EEPROM.write(0, pictureCount); EEPROM.commit(); // Delay for specified period delay(delayTime); ESP.restart(); }