Я использую камеру, контроллер реального времени, плату для карт памяти microSD и SD-карту.Предполагается, что камера сделает снимок и сохранит его на SD-карте с введенной меткой времени.Тем не менее, код не может быть проверен, и я продолжаю получать сообщение об ошибке SdFat.h: Нет такого файла или каталога.Я запустил код на Arduino 1.8.5 с помощью платы микроконтроллера ESP8266.
Это мой программный код:
#include <Arduino.h>
#include <Adafruit_VC0706.h>
#include <SPI.h>
#include<JPEGDecoder.h>
#include <SoftwareSerial.h>
#include <RTClib.h>
#include <Wire.h>
#include <SD.h>
#define SD_CS D8
#define DS3231_ADDRESS 0x68 ///< I2C address for DS3231
SoftwareSerial mySerial (D4,D3); //D4-RX, D3-TX
Adafruit_VC0706 cam = Adafruit_VC0706(&mySerial);
File myFile; // test file
RTC_DS3231 RTC; // define the Real Time Clock object
char timestamp[30];
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup()
{
pinMode(SD_CS, OUTPUT);
Serial.begin(9600);
Wire.begin ( D1, D2); //D1=SDA D2=SCL
if(!SD.begin(SD_CS))
{
Serial.println("SD card is not inserted");
return;
}
Serial.println("SD Card Present");
// Try to locate the camera
if (cam.begin()) {
Serial.println("Camera Found:");
} else {
Serial.println("No camera found?");
return;
}
if (!RTC.begin()) {
Serial.println("RTC failed");
while(1);
};
}
void loop() {
snapshot();
ESP.deepSleep(0); //deep sleep mode until RESET pin is connected to a HIGH signal
}
//------------------------------------------------------------------------------
void snapshot(){
// Set the picture size - you can choose one of 640x480, 320x240 or 160x120
//cam.setImageSize(VC0706_640x480);
cam.setImageSize(VC0706_320x240); // medium
//cam.setImageSize(VC0706_160x120); // small
// You can read the size back from the camera (optional, but maybe useful?)
uint8_t imgsize = cam.getImageSize();
Serial.print("Image size: ");
// Serial.println("640x480");
Serial.println("320x240");
// Serial.println("160x120");
Serial.println("Snap");
delay(30);
if(!cam.takePicture())
{
Serial.println("Failed to snap!");
}
else
{
Serial.println("Picture taken!");
}
// Create an image with the name IMGxxxx.JPG
char filename[13];
strcpy(filename, "IMG0001.JPG");
for (int i = 1; i < 10000; i++) {
filename[3] = '0' + i/1000;
filename[4] = '0' + i/100;
filename[5] = '0' + i%100/10;
filename[6] = '0' + i%10;
// create if does not exist, do not open existing, write, sync after write
if (! SD.exists(filename)) {
break;
}
}
// Open the file for writing
File imgFile = SD.open(filename, FILE_WRITE);
SdFile::dateTimeCallback(dateTime); //Timestamp for file
// Get the size of the image (frame) taken
uint16_t jpglen = cam.frameLength();
Serial.print("Storing ");
Serial.print(jpglen, DEC);
Serial.print(" byte image.");
int32_t time = millis();
//pinMode(D8, OUTPUT);
byte wCount = 0; // For counting # of writes
while (jpglen > 0) {
// read 32 bytes at a time;
uint8_t *buffer;
uint8_t bytesToRead = min(32, jpglen); // change 32 to 64 for a speedup but may not work with all setups!
buffer = cam.readPicture(bytesToRead);
imgFile.write(buffer, bytesToRead);
if(++wCount >= 64) { // Every 2K, give a little feedback so it doesn't appear locked up
Serial.print('.');
wCount = 0;
}
//Serial.print("Read "); Serial.print(bytesToRead, DEC); Serial.println(" bytes");
jpglen -= bytesToRead;
}
imgFile.close();
time = millis() - time;
Serial.println("done!");
Serial.print(time); Serial.println(" ms elapsed");
Serial.println("Storing Time in Textfile");
myFile = SD.open("DATES.txt", FILE_WRITE);
DateTime now = RTC.now();
myFile.print(filename);
myFile.print(' ');
myFile.print(now.year(), DEC);
myFile.print('/');
myFile.print(now.month(), DEC);
myFile.print('/');
myFile.print(now.day(), DEC);
myFile.print(" (");
myFile.print(daysOfTheWeek[now.dayOfTheWeek()]);
myFile.print(") ");
myFile.print(now.hour(), DEC);
myFile.print(':');
myFile.print(now.minute(), DEC);
myFile.print(':');
myFile.print(now.second(), DEC);
myFile.println();
myFile.close();
Serial.println("Done");
}
//------------------------------------------------------------------------------
// call back for file timestamps
void dateTime(uint16_t* date, uint16_t* time) {
DateTime now = RTC.now();
sprintf(timestamp, "%02d:%02d:%02d %2d/%2d/%2d \n", now.hour(),now.minute(),now.second(),now.month(),now.day(),now.year()-2000);
// return date using FAT_DATE macro to format fields
*date = FAT_DATE(now.year(), now.month(), now.day());
// return time using FAT_TIME macro to format fields
*time = FAT_TIME(now.hour(), now.minute(), now.second());
}
//------------------------------------------------------------------------------
Это сообщение об ошибке:
In file included from C:\Users\ACER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SD\src/SD.h:28:0,
from C:\Program Files (x86)\Arduino\libraries\JPEGDecoder-master\src/JPEGDecoder.h:53,
from C:\Users\ACER\Documents\Arduino\sketch_sep19a\sketch_sep19a.ino:4:
C:\Users\ACER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SDFS\src/SDFS.h:36:19: fatal error: SdFat.h: No such file or directory
#include <SdFat.h>
^
compilation terminated.
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).
После поиска в Интернете я попытался установить библиотеку SdFat здесь , чтобы посмотреть, поможет ли это.После установки у меня появилось больше ошибок, поэтому я удалил библиотеку и попробовал другой метод.
Я попытался this , но я не уверен, что делаю это правильно, так как я получил больше ошибок, так какхорошо.