Need help with datalogger from Arduino libraries


i have code log data sensors on sd library , have code geiger counter don't know how implement geiger code datalogger code.

the datalogger code

code: [select]
/*
  sd card datalogger

 this example shows how log data 3 analog sensors
 to sd card using sd library.

 the circuit:
 * analog sensors on analog ins 0, 1, , 2
 * sd card attached spi bus follows:
 ** mosi - pin 11
 ** miso - pin 12
 ** clk - pin 13
 ** cs - pin 4 (for mkrzero sd: sdcard_ss_pin)

 created  24 nov 2010
 modified 9 apr 2012
 by tom igoe

 this example code in public domain.

 */

#include <spi.h>
#include <sd.h>

const int chipselect = 4;

void setup() {
  // open serial communications , wait port open:
  serial.begin(9600);
  while (!serial) {
    ; // wait serial port connect. needed native usb port only
  }


  serial.print("initializing sd card...");

  // see if card present , can initialized:
  if (!sd.begin(chipselect)) {
    serial.println("card failed, or not present");
    // don't more:
    return;
  }
  serial.println("card initialized.");
}

void loop() {
  // make string assembling data log:
  string datastring = "";

  // read 3 sensors , append string:
  (int analogpin = 0; analogpin < 3; analogpin++) {
    int sensor = analogread(analogpin);
    datastring += string(sensor);
    if (analogpin < 2) {
      datastring += ",";
    }
  }

  // open file. note 1 file can open @ time,
  // have close 1 before opening another.
  file datafile = sd.open("datalog.txt", file_write);

  // if file available, write it:
  if (datafile) {
    datafile.println(datastring);
    datafile.close();
    // print serial port too:
    serial.println(datastring);
  }
  // if file isn't open, pop error:
  else {
    serial.println("error opening datalog.txt");
  }
}


the geiger counter code

code: [select]
#include <sd.h>

#include <spi.h>

#define log_period 15000     //logging period in milliseconds, recommended value 15000-60000.

#define max_period 60000    //maximum logging period

unsigned long counts;             //variable gm tube events

unsigned long cpm;                 //variable cpm

unsigned int multiplier;             //variable calculation cpm in sketch

unsigned long previousmillis;      //variable time measurement

 

void tube_impulse(){               //procedure capturing events geiger kit

  counts++;

}



void setup(){                                               //setup procedure

  counts = 0;

  cpm = 0;

  multiplier = max_period / log_period;      //calculating multiplier, depend on log period

  serial.begin(9600);                                    // start serial monitor

 // uncommennt if have time-out problem connect radiation logger
 //  delay(2000);
 //  serial.write('0');                                      // sending 0 avoid connection time out radiation logger
 //  delay(2000);
 //  serial.write('0');                                     // sending 0 avoid connection time out radiation logger

  pinmode(2, input);                                   // set pin int0 input capturing gm tube events

  digitalwrite(2, high);                                 // turn on internal pullup resistors, solder c-int on pcb

  attachinterrupt(0, tube_impulse, falling);  //define external interrupts

}

 

void loop(){                                               //main cycle

  unsigned long currentmillis = millis();

  if(currentmillis - previousmillis > log_period){

    previousmillis = currentmillis;

    cpm = counts * multiplier;

        serial.print(cpm);                              // send cpm data radiation logger

        serial.write(' ');                                // send null character separate next data

    counts = 0;

  }

}


Arduino Forum > Using Arduino > Programming Questions > Need help with datalogger from Arduino libraries


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts