Arduino IDEのサンプルスケッチ内にある、"ArduCAM_ESP8266_OV2640_Capture"というスケッチの改変を行いたいと考えております。このスケッチは、ArduCAMというシリアルカメラと、ESP8266というWiFiマイコンを用いて、Webブラウザ上にカメラで撮影した写真かストリーミング映像を表示させるものです。
今回お聞きしたいのは、ストリーミングのフレームレートを低下させる方法です。ESP8266の処理を軽減させるために、フレームレートを落としたいのですが、どうしてもやり方が分かりません。
以下に、そのサンプルスケッチを記載します(簡略化のため写真撮影の機能は削除しています)。
Arduino
1#include <ESP8266WiFi.h> 2#include <WiFiClient.h> 3#include <ESP8266WebServer.h> 4#include <ESP8266mDNS.h> 5#include <Wire.h> 6#include <ArduCAM.h> 7#include <SPI.h> 8#include "memorysaver.h" 9#if !(defined ESP8266 ) 10#error Please select the ArduCAM ESP8266 UNO board in the Tools/Board 11#endif 12 13//This demo can only work on OV2640_MINI_2MP or ARDUCAM_SHIELD_V2 platform. 14#if !(defined (OV2640_MINI_2MP)||(defined (ARDUCAM_SHIELD_V2) && defined (OV2640_CAM))) 15#error Please select the hardware platform and camera module in the ../libraries/ArduCAM/memorysaver.h file 16#endif 17// set GPIO16 as the slave select : 18const int CS = 16; 19 20//you can change the value of wifiType to select Station or AP mode. 21//Default is AP mode. 22int wifiType = 0; // 0:Station 1:AP 23 24//Station mode you should put your ssid and password 25const char *ssid = "SSID"; // Put your SSID here 26const char *password = "PASSWORD"; // Put your PASSWORD here 27 28ESP8266WebServer server(80); 29 30ArduCAM myCAM(OV2640, CS); 31 32 33void start_capture(){ 34 myCAM.clear_fifo_flag(); 35 myCAM.start_capture(); 36} 37 38void serverStream(){ 39 WiFiClient client = server.client(); 40 41 String response = "HTTP/1.1 200 OK\r\n"; 42 response += "Content-Type: multipart/x-mixed-replace; boundary=frame\r\n\r\n"; 43 server.sendContent(response); 44 45 while (1){ 46 start_capture(); 47 48 while (!myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK)); 49 50 size_t len = myCAM.read_fifo_length(); 51 if (len >= 0x07ffff){ 52 Serial.println("Over size."); 53 continue; 54 }else if (len == 0 ){ 55 Serial.println("Size is 0."); 56 continue; 57 } 58 59 myCAM.CS_LOW(); 60 myCAM.set_fifo_burst(); 61 #if !(defined (ARDUCAM_SHIELD_V2) && defined (OV2640_CAM)) 62 SPI.transfer(0xFF); 63 #endif 64 if (!client.connected()) break; 65 response = "--frame\r\n"; 66 response += "Content-Type: image/jpeg\r\n\r\n"; 67 server.sendContent(response); 68 69 static const size_t bufferSize = 4096; 70 static uint8_t buffer[bufferSize] = {0xFF}; 71 72 while (len) { 73 size_t will_copy = (len < bufferSize) ? len : bufferSize; 74 SPI.transferBytes(&buffer[0], &buffer[0], will_copy); 75 if (!client.connected()) break; 76 client.write(&buffer[0], will_copy); 77 len -= will_copy; 78 } 79 myCAM.CS_HIGH(); 80 81 if (!client.connected()) break; 82 } 83} 84 85void handleNotFound(){ 86 String message = "Server is running!\n\n"; 87 message += "URI: "; 88 message += server.uri(); 89 message += "\nMethod: "; 90 message += (server.method() == HTTP_GET)?"GET":"POST"; 91 message += "\nArguments: "; 92 message += server.args(); 93 message += "\n"; 94 server.send(200, "text/plain", message); 95 96 if (server.hasArg("ql")){ 97 int ql = server.arg("ql").toInt(); 98 myCAM.OV2640_set_JPEG_size(ql);delay(1000); 99 Serial.println("QL change to: " + server.arg("ql")); 100 } 101} 102 103void setup() { 104 uint8_t vid, pid; 105 uint8_t temp; 106#if defined(__SAM3X8E__) 107 Wire1.begin(); 108#else 109 Wire.begin(); 110#endif 111 Serial.begin(115200); 112 Serial.println("ArduCAM Start!"); 113 114 // set the CS as an output: 115 pinMode(CS, OUTPUT); 116 117 // initialize SPI: 118 SPI.begin(); 119 SPI.setFrequency(4000000); //4MHz 120 121 //Check if the ArduCAM SPI bus is OK 122 myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 123 temp = myCAM.read_reg(ARDUCHIP_TEST1); 124 if (temp != 0x55){ 125 Serial.println("SPI1 interface Error!"); 126 while(1); 127 } 128 129 //Check if the camera module type is OV2640 130 myCAM.wrSensorReg8_8(0xff, 0x01); 131 myCAM.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid); 132 myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid); 133 if ((vid != 0x26 ) && (( pid != 0x41 ) || ( pid != 0x42 ))) 134 Serial.println("Can't find OV2640 module!"); 135 else 136 Serial.println("OV2640 detected."); 137 138 139 //Change to JPEG capture mode and initialize the OV2640 module 140 myCAM.set_format(JPEG); 141 myCAM.InitCAM(); 142 myCAM.OV2640_set_JPEG_size(OV2640_320x240); 143 myCAM.clear_fifo_flag(); 144 145 if (wifiType == 0){ 146 if(!strcmp(ssid,"SSID")){ 147 Serial.println("Please set your SSID"); 148 while(1); 149 } 150 if(!strcmp(password,"PASSWORD")){ 151 Serial.println("Please set your PASSWORD"); 152 while(1); 153 } 154 // Connect to WiFi network 155 Serial.println(); 156 Serial.println(); 157 Serial.print("Connecting to "); 158 Serial.println(ssid); 159 160 WiFi.mode(WIFI_STA); 161 WiFi.begin(ssid, password); 162 while (WiFi.status() != WL_CONNECTED) { 163 delay(500); 164 Serial.print("."); 165 } 166 Serial.println("WiFi connected"); 167 Serial.println(""); 168 Serial.println(WiFi.localIP()); 169 }else if (wifiType == 1){ 170 Serial.println(); 171 Serial.println(); 172 Serial.print("Share AP: "); 173 Serial.println(AP_ssid); 174 Serial.print("The password is: "); 175 Serial.println(AP_password); 176 177 WiFi.mode(WIFI_AP); 178 WiFi.softAP(AP_ssid, AP_password); 179 Serial.println(""); 180 Serial.println(WiFi.softAPIP()); 181 } 182 183 // Start the server 184 server.on("/stream", HTTP_GET, serverStream); 185 server.onNotFound(handleNotFound); 186 server.begin(); 187 Serial.println("Server started"); 188} 189 190void loop() { 191 server.handleClient(); 192}
どなたか詳しい方、助力をお願いします。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。