最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

arduino - Get Camera Frame Latency after Set Pins of microphone (INMP441) - Stack Overflow

programmeradmin1浏览0评论

I don't know why when I uncomment this line:

// i2s_set_pin(I2S_NUM_1, &i2s_mic_pins);

getting fb frame takes much more time. (I don't have any error.)

OUTPUT:

Without i2s_set_pin:

16:59:56.940 -> Shot!!!
16:59:57.105 -> Shot!!!
16:59:57.271 -> Shot!!!
...

With i2s_set_pin:

17:00:34.303 -> Shot!!!
17:00:35.862 -> Shot!!!
...

I want the camera to take more frames per second even while recording audio because it should stream alongside the video.

Code:

#include "esp_camera.h"
#include <stdio.h>
#include <driver/i2s.h>

// MIC SETTING
const int SAMPLE_RATE = 8000;

#define I2S_MIC_SERIAL_CLOCK GPIO_NUM_13
#define I2S_MIC_LEFT_RIGHT_CLOCK GPIO_NUM_12
#define I2S_MIC_SERIAL_DATA GPIO_NUM_14

i2s_config_t i2s_config = {
  .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
  .sample_rate = SAMPLE_RATE,
  .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
  .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
  munication_format = I2S_COMM_FORMAT_I2S,
  .intr_alloc_flags = ESP_INTR_FLAG_LEVEL2,
  .dma_buf_count = 2,
  .dma_buf_len = 128,
  .use_apll = false,
  .tx_desc_auto_clear = false,
  .fixed_mclk = 0
};

i2s_pin_config_t i2s_mic_pins = {
  .bck_io_num = I2S_MIC_SERIAL_CLOCK,
  .ws_io_num = I2S_MIC_LEFT_RIGHT_CLOCK,
  .data_out_num = I2S_PIN_NO_CHANGE,
  .data_in_num = I2S_MIC_SERIAL_DATA
};

// Camera Pin Configuration
#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


// Declare grid_brightness as a pointer
uint8_t* grid_brightness = nullptr;

// Camera initialization function
void setupCamera() {
    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_sccb_sda = SIOD_GPIO_NUM;
    config.pin_sccb_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_RGB565;  // Change to PIXFORMAT_GRAYSCALE if needed

    // Set frame size
    config.frame_size = FRAMESIZE_QVGA;  // Change this to another size if needed

    // Automatically update frame width & height
//    setFrameSize(config.frame_size);

    

    config.jpeg_quality = 10;
    config.fb_count = 1;

    // Initialize camera
    esp_err_t err = esp_camera_init(&config);
    if (err != ESP_OK) {
        Serial.println("Camera Init Failed");
        return;
    }
}




void motion_task() {
    camera_fb_t *fb = esp_camera_fb_get();
    if (!fb) {
        Serial.println("Camera capture failed");
        return;
    }

    Serial.println("Shot!!!");
    
    esp_camera_fb_return(fb);
}

void setup() {
    Serial.begin(115200);
    
    setupCamera();

    i2s_driver_install(I2S_NUM_1, &i2s_config, 0, NULL);
//    i2s_set_pin(I2S_NUM_1, &i2s_mic_pins);
    

}

void loop() {
  motion_task();
}
发布评论

评论列表(0)

  1. 暂无评论