XIAO ESP32S3 Sense
XIAO ESP32S3 Sense
The Seeed Studio XIAO ESP32S3 Sense combines the XIAO ESP32S3 module with the Sense expansion board, which adds an OV2640 camera, a PDM microphone, and a microSD card slot.
The espp::XiaoEsp32S3Sense component provides a singleton hardware abstraction for the board’s documented camera, microphone, user-LED, and microSD pin mappings, as well as helpers for building the default ESP-IDF PDM RX microphone configuration, mounting the onboard microSD card over SDSPI, and controlling the onboard LED with a Gaussian breathing effect.
API Reference
Header File
Classes
-
class XiaoEsp32S3Sense : public espp::BaseComponent
The XiaoEsp32S3Sense class provides an interface to the Seeed Studio XIAO ESP32S3 Sense board.
The class provides access to the following features:
OV2640 camera pin mapping
PDM microphone pin mapping
User LED control / gaussian breathing helpers
User LED pin
microSD SPI pin mapping
Default ESP-IDF PDM RX microphone configuration helpers
The class is a singleton and can be accessed using the get() method.
Example
auto &sense = espp::XiaoEsp32S3Sense::get(); auto microphone = sense.microphone_pins(); auto sd_card = sense.sd_card_pins(); logger.info("Using XIAO ESP32S3 Sense camera + microphone"); logger.info("User LED pin: {}", static_cast<int>(sense.user_led_pin())); logger.info("Microphone pins: clk={}, data={}", static_cast<int>(microphone.clk), static_cast<int>(microphone.data)); logger.info("microSD pins: clk={}, mosi={}, miso={}, cs={}", static_cast<int>(sd_card.clk), static_cast<int>(sd_card.mosi), static_cast<int>(sd_card.miso), static_cast<int>(sd_card.cs)); if (!sense.initialize_led(disconnected_led_breathing_period)) { logger.error("Could not initialize user LED"); return; } sense.start_led_breathing(); initialize_and_test_sdcard(); logger.info("Initializing camera"); auto err = initialize_camera(); if (err != ESP_OK) { logger.error("Could not initialize camera: {} '{}'", err, esp_err_to_name(err)); return; } logger.info("Initializing microphone"); err = initialize_microphone(); if (err != ESP_OK) { logger.error("Could not initialize microphone: {} '{}'", err, esp_err_to_name(err)); deinitialize_microphone(); return; }
Public Functions
-
CameraPins camera_pins() const
Get the documented camera pin mapping.
- Returns:
The camera pin mapping for the XIAO ESP32S3 Sense.
-
MicrophonePins microphone_pins() const
Get the documented PDM microphone pin mapping.
- Returns:
The microphone pin mapping for the XIAO ESP32S3 Sense.
-
SdCardPins sd_card_pins() const
Get the documented SPI microSD pin mapping.
- Returns:
The microSD pin mapping for the XIAO ESP32S3 Sense.
-
bool initialize_sdcard()
Initialize the microSD card and mount it at mount_point.
- Returns:
True if the card was initialized and mounted successfully; false otherwise.
-
bool initialize_sdcard(const SdCardConfig &config)
Initialize the microSD card and mount it at mount_point.
- Parameters:
config – Mount configuration for the card.
- Returns:
True if the card was initialized and mounted successfully; false otherwise.
-
inline sdmmc_card_t *sdcard() const
Get the mounted microSD card handle.
- Returns:
Pointer to the mounted card, or `nullptr` if the card has not been initialized successfully.
-
bool initialize_led(float breathing_period = 3.5f)
Initialize the user LED.
- Parameters:
breathing_period – The period of the LED breathing effect in seconds.
- Returns:
True if the LED was successfully initialized, false otherwise.
-
void start_led_breathing()
Start the user-LED breathing effect.
Logs an error and does nothing if the LED helper has not been initialized yet.
-
void stop_led_breathing()
Stop the user-LED breathing effect.
Logs an error and does nothing if the LED helper has not been initialized yet.
-
bool set_led_brightness(float brightness)
Set the user-LED brightness.
Note
The LED brightness can only be set while the breathing task is stopped.
- Parameters:
brightness – The brightness of the LED, in the range [0, 1].
- Returns:
True if the LED brightness was successfully set, false otherwise.
-
float get_led_brightness()
Get the user-LED brightness.
- Returns:
The brightness of the LED, in the range [0, 1].
-
bool set_led_breathing_period(float period)
Set the user-LED breathing period.
- Parameters:
period – The period of the LED breathing effect in seconds.
- Returns:
True if the LED breathing period was successfully set, false otherwise.
-
float get_led_breathing_period()
Get the user-LED breathing period.
- Returns:
The period of the LED breathing effect in seconds.
-
espp::Gaussian &gaussian()
Get the Gaussian waveform used for the LED breathing effect.
- Returns:
A reference to the Gaussian waveform.
-
i2s_pdm_rx_clk_config_t microphone_clock_config(uint32_t sample_rate_hz = microphone_default_sample_rate_hz()) const
Get a default PDM RX clock configuration for the onboard microphone.
- Parameters:
sample_rate_hz – The desired microphone sample rate in Hz.
- Returns:
The default ESP-IDF PDM RX clock configuration.
-
i2s_pdm_rx_slot_config_t microphone_slot_config(i2s_slot_mode_t slot_mode = I2S_SLOT_MODE_MONO) const
Get a default PDM RX slot configuration for the onboard microphone.
- Parameters:
slot_mode – The microphone slot mode.
- Returns:
The default ESP-IDF PDM RX slot configuration.
-
i2s_pdm_rx_gpio_config_t microphone_gpio_config(bool clock_inverted = false) const
Get a default PDM RX GPIO configuration for the onboard microphone.
- Parameters:
clock_inverted – Whether to invert the generated PDM clock.
- Returns:
The default ESP-IDF PDM RX GPIO configuration.
-
i2s_pdm_rx_config_t microphone_config(uint32_t sample_rate_hz = microphone_default_sample_rate_hz(), i2s_slot_mode_t slot_mode = I2S_SLOT_MODE_MONO, bool clock_inverted = false) const
Get a complete default PDM RX configuration for the onboard microphone.
- Parameters:
sample_rate_hz – The desired microphone sample rate in Hz.
slot_mode – The microphone slot mode.
clock_inverted – Whether to invert the generated PDM clock.
- Returns:
The default ESP-IDF PDM RX configuration.
-
inline const std::string &get_name() const
Get the name of the component
Note
This is the tag of the logger
- Returns:
A const reference to the name of the component
-
inline void set_log_tag(const std::string_view &tag)
Set the tag for the logger
- Parameters:
tag – The tag to use for the logger
-
inline espp::Logger::Verbosity get_log_level() const
Get the log level for the logger
See also
See also
- Returns:
The verbosity level of the logger
-
inline void set_log_level(espp::Logger::Verbosity level)
Set the log level for the logger
See also
See also
- Parameters:
level – The verbosity level to use for the logger
-
inline void set_log_verbosity(espp::Logger::Verbosity level)
Set the log verbosity for the logger
See also
See also
See also
Note
This is a convenience method that calls set_log_level
- Parameters:
level – The verbosity level to use for the logger
-
inline espp::Logger::Verbosity get_log_verbosity() const
Get the log verbosity for the logger
See also
See also
See also
Note
This is a convenience method that calls get_log_level
- Returns:
The verbosity level of the logger
-
inline void set_log_rate_limit(std::chrono::duration<float> rate_limit)
Set the rate limit for the logger
See also
Note
Only calls to the logger that have _rate_limit suffix will be rate limited
- Parameters:
rate_limit – The rate limit to use for the logger
Public Static Functions
-
static inline XiaoEsp32S3Sense &get()
Access the singleton instance of the XiaoEsp32S3Sense class.
- Returns:
Reference to the singleton instance of the XiaoEsp32S3Sense class.
-
static inline constexpr int camera_xclk_freq_hz()
Get the recommended camera XCLK frequency in Hz.
- Returns:
The camera XCLK frequency in Hz.
-
static inline constexpr uint32_t microphone_default_sample_rate_hz()
Get the default microphone sample rate in Hz.
- Returns:
The default microphone sample rate in Hz.
-
static inline constexpr gpio_num_t user_led_pin()
Get the user LED pin on the XIAO ESP32S3 module.
- Returns:
The user LED GPIO.
-
static inline constexpr gpio_num_t sd_card_clk_pin()
Get the microSD SPI clock pin on the Sense expansion board.
- Returns:
The microSD SPI clock GPIO.
-
static inline constexpr gpio_num_t sd_card_mosi_pin()
Get the microSD SPI MOSI pin on the Sense expansion board.
- Returns:
The microSD SPI MOSI GPIO.
-
static inline constexpr gpio_num_t sd_card_miso_pin()
Get the microSD SPI MISO pin on the Sense expansion board.
- Returns:
The microSD SPI MISO GPIO.
-
static inline constexpr gpio_num_t sd_card_cs_pin()
Get the default microSD card CS pin on the Sense expansion board.
- Returns:
The microSD card chip select pin.
-
static inline constexpr gpio_num_t camera_pwdn_pin()
Get the camera power down pin.
-
static inline constexpr gpio_num_t camera_reset_pin()
Get the camera reset pin.
-
static inline constexpr gpio_num_t camera_xclk_pin()
Get the camera XCLK pin.
-
static inline constexpr gpio_num_t camera_sccb_sda_pin()
Get the camera SCCB SDA pin.
-
static inline constexpr gpio_num_t camera_sccb_scl_pin()
Get the camera SCCB SCL pin.
-
static inline constexpr gpio_num_t camera_d7_pin()
Get the camera D7 / Y9 pin.
-
static inline constexpr gpio_num_t camera_d6_pin()
Get the camera D6 / Y8 pin.
-
static inline constexpr gpio_num_t camera_d5_pin()
Get the camera D5 / Y7 pin.
-
static inline constexpr gpio_num_t camera_d4_pin()
Get the camera D4 / Y6 pin.
-
static inline constexpr gpio_num_t camera_d3_pin()
Get the camera D3 / Y5 pin.
-
static inline constexpr gpio_num_t camera_d2_pin()
Get the camera D2 / Y4 pin.
-
static inline constexpr gpio_num_t camera_d1_pin()
Get the camera D1 / Y3 pin.
-
static inline constexpr gpio_num_t camera_d0_pin()
Get the camera D0 / Y2 pin.
-
static inline constexpr gpio_num_t camera_vsync_pin()
Get the camera VSYNC pin.
-
static inline constexpr gpio_num_t camera_href_pin()
Get the camera HREF pin.
-
static inline constexpr gpio_num_t camera_pclk_pin()
Get the camera PCLK pin.
-
static inline constexpr gpio_num_t microphone_clk_pin()
Get the microphone PDM clock pin.
-
static inline constexpr gpio_num_t microphone_data_pin()
Get the microphone PDM data pin.
Public Static Attributes
-
static constexpr char mount_point[] = "/sdcard"
Mount point for the microSD card.
-
struct CameraPins
Camera pin mapping for the Sense expansion board.
Public Members
-
gpio_num_t pwdn = {GPIO_NUM_NC}
Camera power down pin.
-
gpio_num_t reset = {GPIO_NUM_NC}
Camera reset pin.
-
gpio_num_t xclk = {GPIO_NUM_NC}
Camera external clock pin.
-
gpio_num_t sccb_sda = {GPIO_NUM_NC}
Camera SCCB SDA pin.
-
gpio_num_t sccb_scl = {GPIO_NUM_NC}
Camera SCCB SCL pin.
-
gpio_num_t d7 = {GPIO_NUM_NC}
Camera D7 / Y9 pin.
-
gpio_num_t d6 = {GPIO_NUM_NC}
Camera D6 / Y8 pin.
-
gpio_num_t d5 = {GPIO_NUM_NC}
Camera D5 / Y7 pin.
-
gpio_num_t d4 = {GPIO_NUM_NC}
Camera D4 / Y6 pin.
-
gpio_num_t d3 = {GPIO_NUM_NC}
Camera D3 / Y5 pin.
-
gpio_num_t d2 = {GPIO_NUM_NC}
Camera D2 / Y4 pin.
-
gpio_num_t d1 = {GPIO_NUM_NC}
Camera D1 / Y3 pin.
-
gpio_num_t d0 = {GPIO_NUM_NC}
Camera D0 / Y2 pin.
-
gpio_num_t vsync = {GPIO_NUM_NC}
Camera VSYNC pin.
-
gpio_num_t href = {GPIO_NUM_NC}
Camera HREF pin.
-
gpio_num_t pclk = {GPIO_NUM_NC}
Camera pixel clock pin.
-
gpio_num_t pwdn = {GPIO_NUM_NC}
-
struct MicrophonePins
PDM microphone pin mapping for the Sense expansion board.
-
struct SdCardConfig
Configuration for the microSD card.
-
struct SdCardPins
SPI microSD pin mapping for the Sense expansion board.