Seeed Studio XIAO ESP32S3 Sense - battery problem.

Hello, this is my first encounter with Seeed Studio XIAO ESP32S3 Sense and I don’t have much experience with these gadgets.
I programmed the Seeed Studio XIAO ESP32S3 Sense to take pictures every 3 seconds and save them to the sd card, but it only happens when the board is powered via the usb-c port. When I power the board through a battery connected to the rear pins, there is no indication of life.
When I connect the battery and usb cable to the board, the device works and indicates that the battery is charging.
When I unplug the usb cable but leave the battery connected to the board, the device continues to work and take/record photos.
When I restart the device and connect it to the battery only, there is no sign of life.
It’s like using the usb port as the start button to start the device.
Where am I going wrong and can the Seeed Studio XIAO ESP32S3 Sense run on battery only? Connecting a battery - starting to work, disconnecting the battery - stops the operation of the device.


Hi there,
You have a (While Serial) in the Startup portion of the Sketch So it’s waiting on the USB connection, Comment that out and it will work as you like.
GL :slight_smile: PJ :v:

Hi, I didn’t write the code I’m using. I used an internet tutorial with a code walkthrough.
My programming level is pretty low.
Would you please suggest what I should change or add in the source code, if of course I’m not making it difficult for you.

Тhank you!

#include “esp_camera.h”
#include “FS.h”
#include “SD.h”
#include “SPI.h”


#include “camera_pins.h”

unsigned long lastCaptureTime = 0;
int imageCount = 1;
bool camera_sign = false;
bool sd_sign = false;

void photo_save(const char * fileName) {

camera_fb_t *fb = esp_camera_fb_get();
if (!fb) {
Serial.println(“Failed to get camera frame buffer”);

writeFile(SD, fileName, fb->buf, fb->len);


Serial.println(“Photo saved to file”);

void writeFile(fs::FS &fs, const char * path, uint8_t * data, size_t len){
Serial.printf(“Writing file: %s\n”, path);

File file =, FILE_WRITE);
    Serial.println("Failed to open file for writing");
if(file.write(data, len) == len){
    Serial.println("File written");
} else {
    Serial.println("Write failed");


void setup() {

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.frame_size = FRAMESIZE_UXGA;
config.pixel_format = PIXFORMAT_JPEG; // for streaming
config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
config.fb_location = CAMERA_FB_IN_PSRAM;
config.jpeg_quality = 12;
config.fb_count = 1;

if(config.pixel_format == PIXFORMAT_JPEG){
config.jpeg_quality = 10;
config.fb_count = 2;
config.grab_mode = CAMERA_GRAB_LATEST;
} else {

  config.frame_size = FRAMESIZE_SVGA;
  config.fb_location = CAMERA_FB_IN_DRAM;

} else {
// Best option for face detection/recognition
config.frame_size = FRAMESIZE_240X240;
config.fb_count = 2;

// camera init
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf(“Camera init failed with error 0x%x”, err);

camera_sign = true;

Serial.println(“Card Mount Failed”);
uint8_t cardType = SD.cardType();

if(cardType == CARD_NONE){
Serial.println(“No SD card attached”);

Serial.print("SD Card Type: ");
if(cardType == CARD_MMC){
} else if(cardType == CARD_SD){
} else if(cardType == CARD_SDHC){
} else {

sd_sign = true;

Serial.println(“Photos will begin in one minute, please be ready.”);

void loop() {

if(camera_sign && sd_sign){
// Get the current time
unsigned long now = millis();

if ((now - lastCaptureTime) >= 3000) {
  char filename[32];
  sprintf(filename, "/image%d.jpg", imageCount);
  Serial.printf("Saved picture:%s\n", filename);
  Serial.println("Photos will begin in one minute, please be ready.");
  lastCaptureTime = now;


The problem is “while(!Serial);”. You can simply remove this line I think.

Thank you! Device is work. I’m very happy ! :wink:

I have a similar problem.
The code work, when I have added the LiPo
with the Adadfruit BFF Charger, where I have an on/off button.
When soldering the LiPo directly on the Xiao, it
does not work. Only one picture, which cannot be opened and
is always stored as picture17, although the SD card is empty before.
May anyone have any idea? Much appreciated.

Hi there,
and Welcome here,
I would check two things, one the first thing is the while serial statement, means the cable must be plugged in to run. Change that by commenting it out, and try again.
Then if it’s still an issue be sure that the PSram is turned on or enabled in the tools menu of the IDE for the S3 chip. Try that and report back. You’re not the first to have some startup issue’s, one step at a time and you’ll have success.
GL :slight_smile: PJ

Thank you so much! :grinning: Figured out, that I needed to press the Reset Button. Then it worked.

1 Like

Great!, Sometimes it is just the basic things, Good Job! :smile: :+1:
GL :slight_smile: PJ