« Arduinoで作ろう(40) CW Decoder | トップページ | Arduinoで作ろう(41) WeMos D1で温度・湿度のWebサーバ »

2020年3月29日 (日)

ガイガーカウンタ GC10(5)放射線量データロガー(2)

20200329_

 たくさん持ってるArduinoのシールドを整理してたらRTC DS1307の付いたSDカードシールドを発見しました。そういえば,以前 この中華製パチもんシールドを買った記憶があるわ。んで,このシールド向けにGC10用放射線量データロガーを組み直してみました。

Sdcardshieldrtcgc10_2

// ガイガーカウンタGC10+DS1307,SD Cardシールド+Arduino で放射線量データロガー


#include <SPI.h>
#include <SD.h>
#include "RTClib.h" //https://github.com/adafruit/RTClib
RTC_DS1307 rtc;
const int chipSelect = 10;

void setup() {
  Serial.begin(9600);
  Serial.print("Initializing SD card...");
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    while (1);
  }
  Serial.println("card initialized.");
  rtc.begin() ;
  //following line sets the RTC to the date & time this sketch was compiled
  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}

void loop() {
  String cpm = "" ;
  String dataString = "";
  char buff[12] ;
  if (Serial.available()) {
    cpm="";
    cpm = Serial.readStringUntil('\r');
    Serial.flush();
    cpm.trim(); // 改行コードを取り除く
    delay(1000);
  }
  if (int(millis()/1000%600) == 0){ //10分(600秒)ごとに記録
    DateTime now = rtc.now();
    sprintf(buff, "%04u/%02u/%02u", now.year(), now.month(), now.day()) ;
    dataString += String(buff);
    dataString += ",";
    sprintf(buff, "%02u:%02u:%02u", now.hour(), now.minute(), now.second()) ;
    dataString += String(buff);
    dataString += ",";
    dataString += String(cpm);
    dataString += ",";
    dataString += String(cpm.toFloat()/165); //gms=165として,μSv/hに換算
    File dataFile = SD.open("datalog.csv", FILE_WRITE);
      if (dataFile) {
        dataFile.println(dataString);
        dataFile.close();
        Serial.println(dataString);
      }
  }
}

| |

« Arduinoで作ろう(40) CW Decoder | トップページ | Arduinoで作ろう(41) WeMos D1で温度・湿度のWebサーバ »

Arduino」カテゴリの記事

高校物理」カテゴリの記事

コメント

コメントを書く



(ウェブ上には掲載しません)


コメントは記事投稿者が公開するまで表示されません。



« Arduinoで作ろう(40) CW Decoder | トップページ | Arduinoで作ろう(41) WeMos D1で温度・湿度のWebサーバ »