le mie informazioni di contatto
Posta[email protected]
2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
- #include <Wire.h>
- #include <ArduCAM.h>
- #include <SPI.h>
- #include <WiFi.h>
- #include <ESPAsyncWebServer.h>
-
- #define CAM_CS 32 // modify according to your own wiring
- #define OV2640_CHIPID_HIGH 0x0A
- #define OV2640_CHIPID_LOW 0x0B
-
- ArduCAM myCAM(OV2640, CAM_CS);
-
- // Set your access point's SSID and password
- const char* ssid = "..."; //wifi名
- const char* password = "....."; // 密码
- AsyncWebServer server(80); // Create an instance of the server
-
- // This function sends the live video frames to the client
- void serverStream(AsyncWebServerRequest *request){
- AsyncWebServerResponse *response = request->beginResponse("multipart/x-mixed-replace;boundary=frame", HTTP_ANY, [](uint8_t *buffer, size_t maxLen, size_t alreadySent) -> size_t {
- if(myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK)){
- size_t len = myCAM.read_fifo_length();
- uint8_t * buf = (uint8_t *)malloc(len);
- myCAM.CS_LOW();
- myCAM.set_fifo_burst();
- myCAM.spi_trans(0xFF);
- myCAM.transferBytes(myCAM.camera_model,BUF,buf,len);
- myCAM.CS_HIGH();
- size_t available_len = len - (alreadySent ? 32 : 0);
- size_t will_send =(available_len > maxLen) ? maxLen : available_len;
- if (!alreadySent){ // First chunk
- memcpy_P(buffer, buf, will_send);
- } else { // Consequent chunks
- buffer = buf + 32;
- }
- free(buf);
- if (!alreadySent) {
- return will_send;
- } else if (alreadySent + will_send < len) {
- return will_send;
- } else {
- myCAM.clear_fifo_flag();
- return 0; // Last chunk sent, signaling end of response by returning 0 bytes left
- }
- }
- return 0; // If there's nothing in the buffer, return 0 bytes left
- });
- response->addHeader("Connection", "close");
- request->send(response);
- }
-
- void setup() {
- Wire.begin(21, 22); // SDA, SCL
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(1000);
- }
-
- myCAM.set_format(JPEG);
- myCAM.InitCAM();
- myCAM.write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK); // VSYNC is active HIGH
- myCAM.clear_fifo_flag();
- myCAM.write_reg(ARDUCHIP_FRAMES, 0x00);
-
- server.on("/stream", HTTP_GET, serverStream); // Route for live video stream
- server.begin();
- }
-
- void loop() {
- // You can put other code here
- }
OV2640 VCC (alimentazione) --> ESP32 3,3 V
OV2640 GND (terra) --> ESP32 GND
OV2640 SDA (linea dati) --> ESP32 IO21 (linea dati I2C SDA)
OV2640 SCL (linea orologio) --> ESP32 IO22 (linea orologio I2C SCL)
OV2640 VSNC (sincronizzazione frame) --> ESP32 IO25
OV2640 HREF (sincronizzazione delle righe) --> ESP32 IO23
OV2640 PCLK (orologio pixel) --> ESP32 IO19
OV2640 XCLK (orologio di sistema) --> ESP32 IO18
OV2640 D0~D7 (linea dati) --> ESP32 IO5~IO13 (linea dati parallela a 8 bit)
In questo momento, alcuni amici attenti potrebbero aver scoperto che una scheda di sviluppo ESP-WROOM-32 costa 25 yuan, un modulo OV2640 costa 23 yuan, un totale di 48 yuan e una scheda di sviluppo ESP-WROOM-32 con la propria fotocamera lo è; 23 yuan.ESP32CAM La scheda di sviluppo costa solo 41 yuan. In altre parole, la soluzione "modulo ESP-WROOM-32+" non solo è difficile da regolare ma costa anche 7 yuan, quindi perché non acquistare semplicemente una scheda di sviluppo ESP32CAM? Non chiedetelo a me, perché l'ho appena scoperto anch'io...