I'm trying to develop a radiation data logger with an RTC for an upcoming trip to Chernobyl. I'm hoping to use it in conjunction with a GPS datalogger to map radiation hotspots.
Equipment:
UNO
Adafruit Data Logger Shield Data-Logger Shield for Arduino
GM-10 geiger counter GM-10 Geiger Counter Radiation Detector and Software
Using this code from an earlier post by Radioactive: http://arduino.cc/forum/index.php/topic,54367.0.html
I'm able to log CPM but I can't figure out how to get the csv to include a field of RTC time.
I'm really new at this and any help would be greatly appreciated!
Code:
// Geiger Counter example
/* Adapted by Tracy Albert from programing for a frequecy counter by,
Martin Nawrath KHM LAB3
Kunsthochschule f¸r Medien Kˆln
Academy of Media Arts
http://www.khm.de
http://interface.khm.de/index.php/labor/experimente/
*/
#include <FreqCounter.h>
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"
#define LOG_INTERVAL 1000 // mills between entries
#define CS 10
#define MOSI 11
#define MISO 12
#define SCK 13
#define redLEDpin 2
#define greenLEDpin 3
RTC_DS1307 RTC; // define the Real Time Clock object
///////////////////////////////////////////////////
//
// VARAIABLES
//
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;
char name[] = "GEIGER.CSV";
unsigned long frq = 0;
unsigned long cnt = 0;
///////////////////////////////////////////////////
//
// FUNCTIONS
//
// store error strings in flash to save RAM
#define error(s) error_P(PSTR(s))
void error_P(const char *str)
{
PgmPrint("error: ");
SerialPrintln_P(str);
if (card.errorCode()) {
PgmPrint("SD error: ");
Serial.print(card.errorCode(), HEX);
Serial.print(',');
Serial.println(card.errorData(), HEX);
// red LED indicates error
digitalWrite(redLEDpin, HIGH);
}
while(1); // effectively STOP the sketch
}
void writeToFile(char *fileName, char *str)
{
if (file.open(root, fileName, O_CREAT | O_APPEND | O_WRITE))
{
file.write((uint8_t *)str, strlen(str));
file.close();
}
}
unsigned long getFrequency()
{
unsigned long freq = 0;
FreqCounter::f_comp=10; // Cal Value / Calibrate with professional Freq Counter
FreqCounter::start(1000L); // 1 sec Gate Time L to force long.
while (FreqCounter::f_ready == 0)
{
freq = FreqCounter::f_freq;
}
return freq;
}
///////////////////////////////////////////////////
//
// SETUP
//
void setup(void)
{
Serial.begin(9600);
Serial.println("Geiger Counter 0.1");
// SD card error 1,ff fix.
pinMode(CS, OUTPUT);
pinMode(MOSI, OUTPUT);
pinMode(MISO, INPUT);
pinMode(SCK, OUTPUT);
pinMode(10, OUTPUT);
pinMode(redLEDpin, OUTPUT);
pinMode(greenLEDpin, OUTPUT);
// init all for SD access.
if (!card.init(true)) error("card.init");
if (!volume.init(card)) error("volume.init");
if (!root.openRoot(volume)) error("openRoot");
Serial.println("Setup ready");
}
///////////////////////////////////////////////////
//
// LOOP - FOREVER
//
void loop()
{
DateTime now;
// delay for the amount of time we want between readings
delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
digitalWrite(greenLEDpin, HIGH);
// GET MEASUREMENT
frq = getFrequency();
// DISPLAY IT ON SERIAL
Serial.print(cnt++);
Serial.print(" cpm: ");
Serial.println(frq);
// fetch the time
now = RTC.now();
Serial.print(", ");
Serial.print(now.year(), DEC);
Serial.print("/");
Serial.print(now.month(), DEC);
Serial.print("/");
Serial.print(now.day(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(":");
Serial.print(now.minute(), DEC);
Serial.print(":");
Serial.print(now.second(), DEC);
// WRITE TO FILE
char buffer[32];
// all fields comma separated so Excel can make a graph
sprintf(buffer, "%ld, cpm, %ld, Hz \r\n", cnt, frq, now);
writeToFile(name, buffer);
}