DEV Community

El Bruno for Microsoft Azure

Posted on • Originally published at elbruno.com on

6 1

#ESP32CAM – WebServer taking photos 📸 every N seconds #Arduino

Hi !

Still learning with the ESP32 CAM board.

In today’s post the scenario is simple:

  • Init the camera
  • Init the local File System
  • Take a photo every 5 seconds and store it in memory
  • Creates an endpoint named [/photo] to return the last saved photo

As the previous sample, I’ll write this using Visual Studio Code and PlatformIO project, using the AI Thinker ESP-32CAM board.

Demo here is tricky, but hey, a selfie is always a good excuse.

selfie with the esp32 cam

As usual, the full sample code is in the demo repository.

Let’s review some noted from the code:

  • The setup and loop are the key codes for this demo.
  • In the setup, init wifi, fs, and camera
  • As a visual clue, I turn on the flash 1 second after each one
  • In the loop, the camera takes a photo every 5 seconds

void setup()
{
  // Serial port for debugging purposes
  Serial.begin(9600);

  // initialize digital pin ledPin as an output
  pinMode(FLASH_GPIO_NUM, OUTPUT);

  // connect to wifi
  initAndConnectWifi();
  flashOnForNSeconds(1);

  // init fs and camera
  initFS();
  initCamera();
  flashOnForNSeconds(1);

  // init and start server
  server.on("/photo", HTTP_GET, [](AsyncWebServerRequest *request)
            { request->send(SPIFFS, FILE_PHOTO, "image/jpg", false); });
  server.begin();
}

void loop()
{
  capturePhotoSaveSpiffs();
  delay(5000);
}

Enter fullscreen mode Exit fullscreen mode

Next steps will include learning Edge Impulse and Computer Vision in this device !

Full code available in my ESP32 Cam Demo repository.

Happy coding!

Greetings

El Bruno

More posts in my blog ElBruno.com.


Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay