完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
教大家获取图片之后以当前时间为文件名保存到我们的SD卡里面,然后大家就可以用读卡器看到里面的图片了(ESP32_CAM好像对SD卡大小有要求,不能太大)
OK,直接上代码,已经跑过了的,大家自己看看吧 #include "esp_camera.h" #include "FS.h" #include #include #include "SD_MMC.h" #include #include #include "string.h" -- 这个是时区的详情 const char* ntpServer = "cn.pool.ntp.org"; //pool.ntp.org为获取时间得接口,可以尝试更多得接口。比如微软的time.windows.com,美国国家标准与技术研究院的time.nist.gov const long gmtOffset_sec = 8*60*60;//这里采用UTC计时,中国为东八区,就是 8*60*60 const int daylightOffset_sec = 0*60*60; struct tm timeinfo; //创建一个结构体用于存储时间 char * path = "/2020_6_18_TIME_19_0_47.jpg"; char timr_str[40] = "test.jpg"; //以下是WIFI的链接用户名和密码 #define ssid "b123" #define password "cx123456" //*********************************************************************************************************************** wifi连接 String translateEncryptionType(wifi_auth_mode_t encryptionType) { //获取wifi的特性 switch (encryptionType){ case (WIFI_AUTH_OPEN): return "Open"; case (WIFI_AUTH_WEP): return "WEP"; case (WIFI_AUTH_WPA_PSK): return "WPA_PSK"; case (WIFI_AUTH_WPA2_PSK): return "WPA2_PSK"; case (WIFI_AUTH_WPA_WPA2_PSK): return "WPA_WPA2_PSK"; case (WIFI_AUTH_WPA2_ENTERPRISE): return "WPA2_ENTERPRISE"; } } void scanNetworks(){ //搜索附近的WIFI源并打印出来 int numberOfNetworks= WiFi.scanNetworks(); Serial.print("Numberof networks found: "); Serial.println(numberOfNetworks); for (int i = 0; i< numberOfNetworks; i++) { Serial.print("Networkname: "); Serial.println(WiFi.SSID(i)); Serial.print("Signalstrength: "); Serial.println(WiFi.RSSI(i)); Serial.print("MACaddress: "); Serial.println(WiFi.BSSIDstr(i)); Serial.print("Encryptiontype: "); String encryptionTypeDescription = translateEncryptionType(WiFi.encryptionType(i)); Serial.println(encryptionTypeDescription); Serial.println("-----------------------"); } } void connectToNetwork(){ WiFi.begin(ssid,password); while (WiFi.status()!= WL_CONNECTED) { delay(1000); Serial.println("try to connecting ..."); } Serial.println("Connectedto network"); } void wifi_connect(){ scanNetworks(); //搜索附近的wifi信号并且打印出来 connectToNetwork(); //链接到wifi Serial.println(WiFi.macAddress()); //打印出mac地址 Serial.println(WiFi.localIP()); //打印出本地ip地址 Serial.println("wifi连接成功"); //打印出本地ip地址 //WiFi.disconnect(true); //断开wifi //Serial.println(WiFi.localIP()); } //************************************************************************************************************************************** 摄像头初始化参数 static camera_config_t camera_config = { .pin_pwdn = 32, .pin_reset = -1, .pin_xclk = 0, .pin_sscb_sda = 26, .pin_sscb_scl = 27, .pin_d7 = 35, .pin_d6 = 34, .pin_d5 = 39, .pin_d4 = 36, .pin_d3 = 21, .pin_d2 = 19, .pin_d1 = 18, .pin_d0 = 5, .pin_vsync = 25, .pin_href = 23, .pin_pclk = 22, .xclk_freq_hz = 20000000, .ledc_timer = LEDC_TIMER_0, .ledc_channel = LEDC_CHANNEL_0, .pixel_format = PIXFORMAT_JPEG, .frame_size = FRAMESIZE_XGA, .jpeg_quality = 12, .fb_count = 1, }; esp_err_t camera_init() { //initialize the camera esp_err_t err = esp_camera_init(&camera_config); if (err != ESP_OK) { Serial.print("Camera Init Failed"); return err; } sensor_t * s = esp_camera_sensor_get(); //initial sensors are flipped vertically and colors are a bit saturated if (s->id.PID == OV2640_PID) { // s->set_vflip(s, 1);//flip it back // s->set_brightness(s, 1);//up the blightness just a bit // s->set_contrast(s, 1); } Serial.print("Camera Init OK"); return ESP_OK; } //************************************************************************************************************************************** SD卡初始化参数 void sd_init() { if(!SD_MMC.begin()){ Serial.println("Card Mount Failed"); return; } uint8_t cardType = SD_MMC.cardType(); if(cardType == CARD_NONE){ Serial.println("No SD card attached"); return; } Serial.print("SD Card Type: "); if(cardType == CARD_MMC){ Serial.println("MMC"); } else if(cardType == CARD_SD){ Serial.println("SDSC"); } else if(cardType == CARD_SDHC){ Serial.println("SDHC"); } else { Serial.println("UNKNOWN"); } uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024); //获取SD卡大小,大小单位是MB Serial.printf("SD 卡容量大小: %lluMBn", cardSize); } //************************************************************************************************************************************** 获取当前时间作为返回的函数部分 void get_time_path() //获取目前时间返回字符串 { memset(timr_str, 0, sizeof(timr_str)); configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); if(!getLocalTime(&timeinfo)) { Serial.println("Failed to obtain time"); sprintf(timr_str, "/TIME_get_failed.jpg"); } else { //Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S"); Serial.print("现在时间是:"); Serial.print("年份是:");Serial.println(timeinfo.tm_year + 1900); Serial.print("月份是:");Serial.println(timeinfo.tm_mon + 1); Serial.print("号数是:");Serial.println(timeinfo.tm_mday); Serial.print("小时数是:");Serial.println(timeinfo.tm_hour ); //中国区 Serial.print("分钟数是:");Serial.println(timeinfo.tm_min); Serial.print("分钟数是:");Serial.println(timeinfo.tm_sec); sprintf(timr_str, "/%d_%d_%d_TIME_%d_%d_%d.jpg",timeinfo.tm_year+1900,timeinfo.tm_mon + 1,timeinfo.tm_mday,timeinfo.tm_hour,timeinfo.tm_min,timeinfo.tm_sec); } } //************************************************************************************************************************************** 主函数部分 void setup() { Serial.begin(115200); wifi_connect(); camera_init(); //摄像头初始化 sd_init(); //SD卡初始化 pinMode(16, INPUT_PULLUP); //设置按键管脚输入上拉模式 Serial.println("16号IO拉低将会进行拍照!!!"); } void loop() { if(digitalRead(16) == 0) { delay(60); //延时消抖 if(digitalRead(16) == 0) { //这里面的舵机就代表确认拉低IO16之后,我们将要拍照并且把图片保存到SD卡当中,而照片名字就保存为目前的时间 Serial.println("即将进行拍照!!!"); camera_fb_t * fb = esp_camera_fb_get(); get_time_path(); Serial.print("存入的图片名称为:");Serial.println(timr_str); path = timr_str; if(fb == NULL) { Serial.println( "get picture failed"); //代表获取图片失败 } else { //char * path = time_str; //以下就是上一篇文章讲到的写入文件得到过程,但是一点点小区别 fs::FS &fs = SD_MMC; Serial.printf("Writing file: %sn", path); File file = fs.open(path, FILE_WRITE); if (!file) { Serial.println("文件创建失败"); } else { file.write(fb->buf , fb->len); //payload , lengte vd payload Serial.println("成功写入照片"); } //return the frame buffer back to the driver for reuse esp_camera_fb_return(fb); } } } } |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1924 浏览 1 评论
synopsys 的design ware:DW_fpv_div,浮点数除法器,默认32位下,想提升覆盖率(TMAX),如果用功能case去提升覆盖率呢?
2406 浏览 1 评论
RK3588 GStreamer调试四路鱼眼摄像头四宫格显示报错
5193 浏览 1 评论
【飞凌嵌入式OK3576-C开发板体验】RKNN神经网络-YOLO图像识别
254 浏览 0 评论
【飞凌嵌入式OK3576-C开发板体验】SSH远程登录网络配置及CAN通讯
1336 浏览 0 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 11:53 , Processed in 0.523827 second(s), Total 43, Slave 34 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号