Skip to content

Instantly share code, notes, and snippets.

@dwblair
Created December 13, 2015 20:44
Show Gist options
  • Save dwblair/50319e4dc38aa4bfd0e6 to your computer and use it in GitHub Desktop.
Save dwblair/50319e4dc38aa4bfd0e6 to your computer and use it in GitHub Desktop.
#include <Wire.h>
#include <SPI.h>
#include <RTClib.h>
#include <RTC_DS3231.h>
#include<stdlib.h>
#include <SD.h>
// This code requires that the following library be installed:
// Mizraith's RTC library: https://github.com/mizraith/RTClib
// it also requires:
// -- that a microSD card be placed in the microSD card holder
// -- that a coin cell be placed on the board
//RTC stuff
RTC_DS3231 RTC;
//led for output
#define led 9
// working flag: 0: not working; 1: working;
int workingFlag = 1; //
//SD card variables
const int chipSelect = 7;
int SDpower = 6;
void setup() {
digitalWrite(led,LOW); // begin in state of 'not working'
pinMode(SDpower,OUTPUT);
digitalWrite(SDpower,LOW);
if (!SD.begin(chipSelect)) {
// SD failed or not present
workingFlag=0;
}
// begin I2C protocol (necessary for RTC)
Wire.begin();
RTC.begin();
//broadcast that we're working
if (workingFlag==1) {
for (int j=0;j<200;j++) {
digitalWrite(led,HIGH);
delay(10);
digitalWrite(led,LOW);
}
}
}
void loop() {}
@dwblair
Copy link
Author

dwblair commented Dec 13, 2015

Diagnostic

Requirements

  • Mizraith's RTC library must be installed in the /Libraries folder: https://github.com/mizraith/RTClib
  • a microSD card be placed in the microSD card holder
  • a coin cell be placed on the board

Procedure:

  1. Place a coin cell battery into the holder
  2. Place a microSD card into the microSD card holder
  3. Load the above code.

Diagnostic:

  • If the code begins at all, then the onboard LED D1 should be on, steadily (no blink)
  • If the microSD card can be accessed, and the RTC can be accessed, the onboard LED D1 should blink fast (with a period of 10ms).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment