Skip to content

Commit 99ef796

Browse files
committed
ESP32 S3-Camera Test Sketches
1 parent 5873189 commit 99ef796

File tree

12 files changed

+800
-0
lines changed

12 files changed

+800
-0
lines changed
327 KB
Loading
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
## ESP32S3 Camera Baord
3+
4+
Here are the sketches which test the functionality of this ESP32 S3 camera board
5+
6+
![ESP32S3 Camera Board](Overview.jpg)
7+
8+
9+
Here is a summary of the limitations/issues that I have found:
10+
11+
- I could not make the 4 pin SDMMC to work.
12+
- The microphone just provides noise
13+
- The board has no Boot button, so you can not set the board easily into upload mode. Here is the work around:
14+
- connect GND with Pin 0
15+
- press and release the SWT2 (Reset/EN button)
16+
- disconnect Pin 0
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
/// If button is pressed it is pulled low
3+
4+
const int BUTTON = 38;
5+
6+
void setup() {
7+
Serial.begin(115200);
8+
pinMode(BUTTON, INPUT);
9+
}
10+
11+
void loop() {
12+
Serial.println(digitalRead(BUTTON));
13+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#pragma once
2+
3+
#include <memory>
4+
#include "esp_camera.h"
5+
6+
class Camera;
7+
8+
/***
9+
* @brief A simple Arduino C++ API over the ESP32 camera functionality.
10+
* @author Phil Schatzmann
11+
*/
12+
13+
class Camera {
14+
// esp_camera_fb_return
15+
struct Deleter {
16+
void operator()(camera_fb_t *ptr) const {
17+
if (ptr) {
18+
esp_camera_fb_return(ptr);
19+
}
20+
}
21+
};
22+
23+
public:
24+
Camera() = default;
25+
/**
26+
* @brief Initialize the camera driver
27+
*
28+
* @note call camera_probe before calling this function
29+
*
30+
* This function detects and configures camera over I2C interface,
31+
* allocates framebuffer and DMA buffers,
32+
* initializes parallel I2S input, and sets up DMA descriptors.
33+
*
34+
* Currently this function can only be called once and there is
35+
* no way to de-initialize this module.
36+
*
37+
* @param config Camera configuration parameters
38+
*
39+
* @return RESULT_OK on success
40+
*/
41+
bool begin(const camera_config_t &config) {
42+
return esp_camera_init(&config) == ESP_OK;
43+
}
44+
45+
/**
46+
* @brief Deinitialize the camera driver
47+
*
48+
* @return
49+
* - RESULT_OK on success
50+
* - ERR_INVALID_STATE if the driver hasn't been initialized yet
51+
*/
52+
bool end(void) { return esp_camera_deinit() == ESP_OK; }
53+
54+
/**
55+
* @brief Obtain unique_ptr to a frame buffer.
56+
*
57+
* @return pointer to the frame buffer
58+
*/
59+
auto frameBuffer(void) {
60+
return std::unique_ptr<camera_fb_t, Deleter>(esp_camera_fb_get());
61+
}
62+
63+
/**
64+
* @brief Save camera settings to non-volatile-storage (NVS)
65+
*
66+
* @param key A unique nvs key name for the camera settings
67+
*/
68+
bool settingsSave(const char *key) {
69+
return esp_camera_save_to_nvs(key) == ESP_OK;
70+
}
71+
72+
/**
73+
* @brief Load camera settings from non-volatile-storage (NVS)
74+
*
75+
* @param key A unique nvs key name for the camera settings
76+
*/
77+
bool settingsLoad(const char *key) {
78+
return esp_camera_load_from_nvs(key) == ESP_OK;
79+
}
80+
81+
/**
82+
* @brief Return the frame buffer to be reused again.
83+
*
84+
* @param fb Pointer to the frame buffer
85+
*/
86+
void returnFrameBuffer(camera_fb_t &fb) { return esp_camera_fb_return(&fb); }
87+
};
88+
89+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
// important settings:
3+
// - USB CDC on Boot: Enabled (to see the Serial.print)
4+
// - PSRAM: QSPI PSRAM (to have enough memory for the framebuffer)
5+
6+
#include "Camera.h"
7+
8+
#define XCLK_GPIO_NUM 10
9+
#define SIOD_GPIO_NUM 21
10+
#define SIOC_GPIO_NUM 14
11+
#define Y9_GPIO_NUM 11
12+
#define Y8_GPIO_NUM 9
13+
#define Y7_GPIO_NUM 8
14+
#define Y6_GPIO_NUM 6
15+
#define Y5_GPIO_NUM 4
16+
#define Y4_GPIO_NUM 2
17+
#define Y3_GPIO_NUM 3
18+
#define Y2_GPIO_NUM 5
19+
#define VSYNC_GPIO_NUM 13
20+
#define HREF_GPIO_NUM 12
21+
#define PCLK_GPIO_NUM 7
22+
#define LED_GPIO_NUM 34
23+
24+
Camera camera;
25+
camera_config_t config;
26+
27+
void setup() {
28+
Serial.begin(115200);
29+
while(!Serial);
30+
31+
config.ledc_timer = LEDC_TIMER_0;
32+
config.pin_d0 = Y2_GPIO_NUM;
33+
config.pin_d1 = Y3_GPIO_NUM;
34+
config.pin_d2 = Y4_GPIO_NUM;
35+
config.pin_d3 = Y5_GPIO_NUM;
36+
config.pin_d4 = Y6_GPIO_NUM;
37+
config.pin_d5 = Y7_GPIO_NUM;
38+
config.pin_d6 = Y8_GPIO_NUM;
39+
config.pin_d7 = Y9_GPIO_NUM;
40+
config.pin_xclk = XCLK_GPIO_NUM;
41+
config.pin_pclk = PCLK_GPIO_NUM;
42+
config.pin_vsync = VSYNC_GPIO_NUM;
43+
config.pin_href = HREF_GPIO_NUM;
44+
config.pin_sccb_sda = SIOD_GPIO_NUM;
45+
config.pin_sccb_scl = SIOC_GPIO_NUM;
46+
config.xclk_freq_hz = 20000000;
47+
config.pixel_format = PIXFORMAT_JPEG; // YUV422,GRAYSCALE,RGB565,JPEG
48+
config.frame_size = FRAMESIZE_HD; //
49+
config.jpeg_quality = 16;
50+
config.fb_count = 2; // 8
51+
config.fb_location = CAMERA_FB_IN_PSRAM; /*!< The location where the frame
52+
buffer will be allocated */
53+
config.grab_mode = CAMERA_GRAB_LATEST; /*!< When buffers should be filled */
54+
55+
56+
if (!camera.begin(config)){
57+
Serial.println("Camera failed");
58+
while(true);
59+
}
60+
Serial.print("Recording...");
61+
}
62+
63+
void loop() {
64+
65+
auto fb = camera.frameBuffer();
66+
Serial.println(fb->len);
67+
68+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Demo for the color LED (SK6812)
2+
3+
#include <FastLED.h>
4+
5+
const int NUM_LEDS = 1;
6+
const int DATA_PIN = 33;
7+
CRGB led;
8+
9+
void setup() {
10+
FastLED.addLeds<NEOPIXEL, DATA_PIN>(&led, NUM_LEDS);
11+
}
12+
void loop() {
13+
led = CRGB::Red;
14+
FastLED.show();
15+
delay(1000);
16+
led = CRGB::Black;
17+
FastLED.show();
18+
delay(1000);
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Demo for the LED
2+
3+
const int LED=34;
4+
5+
// the setup function runs once when you press reset or power the board
6+
void setup() {
7+
// initialize digital pin as an output.
8+
pinMode(LED, OUTPUT);
9+
}
10+
11+
// the loop function runs over and over again forever
12+
void loop() {
13+
digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)
14+
delay(1000); // wait for a second
15+
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
16+
delay(1000); // wait for a second
17+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// The module comes with a MSM261 I2S Microphone
2+
// Make sure that USB CDC on Boot is enabled
3+
4+
5+
const int I2S_WS = 37;
6+
const int I2S_SCK = 36;
7+
const int I2S_SD = 35;
8+
const AudioInfo info(8000, 1, 16);
9+
I2SStream i2sStream; // Access I2S as stream
10+
CsvOutput<int16_t> csvStream(Serial);
11+
StreamCopy copier(csvStream, i2sStream); // copy i2sStream to csvStream
12+
13+
// Arduino Setup
14+
void setup(void) {
15+
Serial.begin(115200);
16+
AudioLogger::instance().begin(Serial, AudioLogger::Info);
17+
18+
auto cfg = i2sStream.defaultConfig(RX_MODE);
19+
cfg.copyFrom(info);
20+
cfg.i2s_format = I2S_STD_FORMAT; // or try with I2S_LSB_FORMAT
21+
cfg.use_apll = false;
22+
cfg.pin_data = I2S_SD;
23+
cfg.pin_mck = I2S_SCK;
24+
cfg.pin_ws = I2S_WS;
25+
i2sStream.begin(cfg);
26+
27+
// make sure that we have the correct channels set up
28+
csvStream.begin(info);
29+
30+
Serial.println("starting...");
31+
32+
}
33+
34+
// Arduino loop - copy data
35+
void loop() {
36+
copier.copy();
37+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
3+
/// set
4+
/// - USB CDC on Boot: enabled
5+
/// - PSRAM: QSPI RAM
6+
7+
#include <Arduino.h>
8+
9+
void setup() {
10+
Serial.begin(115200);
11+
12+
Serial.printf("Total heap: %d\n", ESP.getHeapSize());
13+
Serial.printf("Free heap: %d\n", ESP.getFreeHeap());
14+
Serial.printf("Total PSRAM: %d\n", ESP.getPsramSize());
15+
Serial.printf("Free PSRAM: %d\n", ESP.getFreePsram());
16+
}
17+
18+
void loop() {
19+
20+
}

0 commit comments

Comments
 (0)