The program is supposed to take photo and store the picture into the SD card with the timestamp.
My Program Code:
#include <SdFat.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 //For NodeMCU Kit Set version 1
#define DS3231_ADDRESS 0x68 ///< I2C address for DS3231
SoftwareSerial mySerial (D4, D3); //D4-RX, D3 TX For NodeMCU Kit Set version 1
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(115200);
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);
}
snapshot();
// ESP.deepSleep(0); //deep sleep mode until RESET pin is connected to a LOW signal
}
void loop() {
}
//------------------------------------------------------------------------------
void snapshot() {
// Set the picture size - you can choose one of 640x480, 320x240 or 160x120
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(imgsize);
// Serial.println("640x480");
Serial.println("320x240");
// Serial.println("160x120");
Serial.println("Snap");
delay(2500);
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 % 1000 / 10;
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());
}
//------------------------------------------------------------------------------
The error message is too long so I can only copy paste some parts which I think might be relevant:
In file included from C:\Users\ACER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SD\src/SD.h:25:0,
from C:\Users\ACER\Documents\Arduino\libraries\JPEGDecoder-master\src/JPEGDecoder.h:56,
from C:\Users\ACER\Desktop\Arduino IDE\Snapshot NodeMCU with RTC\Snapshot_NodeMCU___RTC\Snapshot_NodeMCU___RTC.ino:4:
C:\Users\ACER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SDFS\src/SDFS.h:190:5: error: 'sdfat' does not name a type
sdfat::SdFat* getFs()
^
C:\Users\ACER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SDFS\src/SDFS.h:215:5: error: 'sdfat' does not name a type
sdfat::SdFat _fs;
^
C:\Users\ACER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SDFS\src/SDFS.h: In member function 'virtual bool sdfs::SDFSImpl::exists(const char*)':
C:\Users\ACER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SDFS\src/SDFS.h:98:27: error: '_fs' was not declared in this scope
return _mounted ? _fs.exists(path) : false;
^
C:\Users\ACER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SDFS\src/SDFS.h: In member function 'virtual bool sdfs::SDFSImpl::rename(const char*, const char*)':
C:\Users\ACER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SDFS\src/SDFS.h:104:27: error: '_fs' was not declared in this scope
return _mounted ? _fs.rename(pathFrom, pathTo) : false;
^
C:\Users\ACER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SDFS\src/SDFS.h: In member function 'virtual bool sdfs::SDFSImpl::info(fs::FSInfo&)':
C:\Users\ACER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SDFS\src/SDFS.h:113:26: error: '_fs' was not declared in this scope
info.blockSize = _fs.vol()->blocksPerCluster() * 512;
reference to 'File' is ambiguous
//There are a lot of '???' not declared in this scope and 'sdfat' does not name a type error.
At first, there was a different error that states that SdFile::dateTimeCallback(dateTime); is not declared. After doing some research online, I tried to install SdFat library here to see if it helps and after installing I got more error as shown above. How can I solve these errors?