Luc Paquin
Published © CC BY-NC

Project #15: Environment – Serial Camera – Mk29

Project #15: Environment – Serial Camera – Mk29

BeginnerFull instructions provided1 hour43
Project #15: Environment – Serial Camera – Mk29

Things used in this project

Hardware components

Elecrow Crowduino Uno - SD
×1
Elecrow Crowtail - Base Shield
×1
Elecrow Crowtail - Serial Camera
×1
Elecrow Crowtail - Button 2.0
×1
Adafruit MicroSD Card 4 Gb
×1
Elecrow Crowtail - RTC 2.0
×1
Adafruit CR1220 Battery
×1
Elecrow Crowtail - I2C LCD
×1
Elecrow Crowtail - LED(Green)
×1
USB Battery Pack
×1
SparkFun USB Mini-B Cable - 6 Foot
SparkFun USB Mini-B Cable - 6 Foot
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Fritzing

Code

getRTC.ino

Arduino
// RTC (Real-Time Clock)
// Setup RTC
void isSetupRTC(){

  // RTC (Real-Time Clock)
  RTC.begin();

  // RTC Running
  if (! RTC.isrunning()) {
    
    // following line sets the RTC to the date & time
    //this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // RTC.adjust(DateTime(2014, 1, 21, 3, 0, 0))
    
  }
  
}
// RTC (Real-Time Clock)
void isRTC(){

  // RTC (Real-Time Clock)
  DateTime now = RTC.now();
  
  // Date
  dateRTC = now.year(), DEC; 
  dateRTC = dateRTC + "/";
  dateRTC = dateRTC + now.month(), DEC;
  dateRTC = dateRTC + "/";
  dateRTC = dateRTC + now.day(), DEC;
  
  // Time
  timeRTC = now.hour(), DEC;
  timeRTC = timeRTC + ":";
  timeRTC = timeRTC + now.minute(), DEC;
  timeRTC = timeRTC + ":";
  timeRTC = timeRTC + now.second(), DEC;

}

DL2503Mk02p.ino

Arduino
/****** Don Luc Electronics © ******
Software Version Information
Project #15: Environment – Serial Camera – Mk29
DL2503Mk02p.ino
DL2503Mk02
1 x Crowduino Uno - SD
1 x Crowtail - Base Shield
1 x Crowtail - Serial Camera
1 x Crowtail - Button 2.0
1 x MicroSD Card 4 Gb
1 x Crowtail - RTC 2.0
1 x CR1220 Battery
1 x Crowtail - LED(Green)
1 x USB Battery Pack
1 x USB Mini-B Cable
*/

// Include the Library Code
// EEPROM library to read and write EEPROM with unique ID for unit
#include <EEPROM.h>
// Wire
#include <Wire.h>
// Liquid Crystal
#include "LiquidCrystal.h"
// RTC (Real-Time Clock)
#include "RTClib.h"
// Secure Digital (SD Card)
#include <SD.h>
#include <SPI.h>
// Serial Camera
#include <Adafruit_VC0706.h>
// Software Serial
#include <SoftwareSerial.h>

// Camera TX connected to pin 2
// Camera RX to pin 3:
SoftwareSerial cameraconnection = SoftwareSerial(2, 3);

// Serial Camera
Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);

// Create an image with the name DLEPxxx.JPG
char filename[13];

// Secure Digital (SD Card)
const int chipSelect = 4;
String zzzzzz = "";

// Button
int iButton = 9;
// Variable for reading the Button status
int iButtonState = 0;

// RTC (Real-Time Clock)
RTC_DS1307 RTC;
String dateRTC = "";
String timeRTC = "";

// Liquid Crystal
// Connect via i2c
LiquidCrystal lcd(0);

// LED Green
int iLEDGreen = 6;

// EEPROM Unique ID Information
String uid = "";

// Software Version Information
String sver = "15-29";

void loop() {

  // RTC (Real-Time Clock)
  isRTC();

  // Display RTC
  isDisplayRTC();

  // Read the state of the Switch value
  iButtonState = digitalRead(iButton);

  // The Button is HIGH:
  if (iButtonState == HIGH) {

    // LED Green HIGH
    digitalWrite(iLEDGreen, HIGH);

    // Camera
    isCamera();
    
    // MicroSD Card
    isSD();

    // LED Green LOW
    digitalWrite(iLEDGreen, LOW);

  } else {

    // LED Green LOW
    digitalWrite(iLEDGreen, LOW);

  }

  // Delay
  delay( 500 );

}

getCamera.ino

Arduino
// Camera
// Setup Camera
void isSetupCamera(){

  // Setup Camera
  cam.begin();
  // Biggest
  cam.setImageSize(VC0706_640x480);
  
}
// is Camera
void isCamera(){

  // Camera Snap
  cam.takePicture();

  // File Name
  strcpy(filename, "DLEP000.JPG");
  for (int i = 0; i < 1000; i++) {
    
    filename[4] = '0' + i/10;
    filename[5] = '0' + i/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);

  // Get the size of the image (frame) taken  
  uint16_t jpglen = cam.frameLength();

  // Time
  int32_t time = millis();
  pinMode(8, OUTPUT);
  
  // Read all the data up to # bytes!
  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;
    
  }

  // Close
  imgFile.close();

}

getDisplay.ino

Arduino
// getDisplay
// Crowbits - OLED 128X64 UID
// Display UID
void isDisplayUID(){

  // Set up the LCD's number of rows and columns: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  // Cursor
  lcd.setCursor(0, 0);
  lcd.print("Don Luc Electron");
  // Cursor
  lcd.setCursor(0, 1);
  // Print a message to the LCD.
  lcd.print( sver );

}
// Display RTC
void isDisplayRTC(){

  // Clear
  lcd.clear();
  // Set the cursor to column 0, line 0
  lcd.setCursor(0, 0);
  lcd.print( dateRTC );
  // Set the cursor to column 0, line 1
  lcd.setCursor(0, 1);
  lcd.print( timeRTC );
  
}

getEEPROM.ino

Arduino
// EEPROM
// isUID EEPROM Unique ID
void isUID() {
  
  // Is Unit ID
  uid = "";
  for (int x = 0; x < 7; x++)
  {
    uid = uid + char(EEPROM.read(x));
  }
  
}

getSD.ino

Arduino
// MicroSD Card
// MicroSD Setup
void isSetupSD() {

    // MicroSD Card
   // See if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {

    // Don't do anything more:
    while (1);
    
  }

}
// MicroSD Card
void isSD() {

  zzzzzz = "";

  //DLE|EEPROM Unique ID|Version|Date|Time|filename|
  zzzzzz = "DLE|" + uid + "|" + sver + "|" + String( dateRTC ) + "|" 
  + String( timeRTC ) + "|" + filename + "|";

  // Open the file. Note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("dledata.txt", FILE_WRITE);

  // If the file is available, write to it:
  if (dataFile) {
    
    // Write
    dataFile.println( zzzzzz );
    dataFile.close();

  }

}

setup.ino

Arduino
// Setup
void setup()
{
 
  // Delay
  delay(100);
  
  // isUID EEPROM Unique ID
  isUID();
  
  // Delay
  delay(100);

  // Initialize the LED LED Green
  pinMode(iLEDGreen, OUTPUT);
  // LED Green
  digitalWrite(iLEDGreen, LOW);

  // Delay
  delay(100);
  
  // Setup RTC
  isSetupRTC();
  
  // Delay
  delay(100);

  // MicroSD Card
  isSetupSD();
  
  // Delay
  delay(100);

  // Button
  pinMode(iButton,INPUT);

  // Delay
  delay( 100 );

  // Setup Camera
  isSetupCamera();

  // Delay
  delay( 100 );

  // Display UID
  isDisplayUID();
  
  // Delay 5 Second
  delay( 5000 );

}

Credits

Luc Paquin
32 projects • 3 followers
Teacher, Instructor, E-Mentor, R&D and Consulting -Programming Language -Microcontrollers -IoT -Robotics -Machine Learning -AI -Sensors
Contact

Comments

Please log in or sign up to comment.