Go Down

Topic: Geiger counter Data logger project. (Read 9 times) previous topic - next topic

Radioactive

Mar 05, 2011, 01:41 am Last Edit: Mar 05, 2011, 03:52 pm by Radioactive Reason: 1
I am using an Uno with the SD shield as a stand alone data collection system.

The GM-10 is the actual Geiger counter or sensor, its readings compare with Background, a Cs-137 calibration source and Ra-226.

http://www.blackcatsystems.com/GM/products/GM10GeigerCounter.html

Its spending the night in my basement sniffing for Radon gas.

Here is the sketch.

Code: [Select]
// Geiger Counter Lib 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 <SdFat.h>
#include <SdFatUtil.h>

Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;
void setup (void);
unsigned long frq;
int cnt;
int pinLed=13

// 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);
 }
 while(1);
}

void writeCRLF(SdFile &f)
{
 f.write((uint8_t *)"\r\n", 2);
}
/*
* Write an unsigned number to a file
*/
void writeNumber(SdFile &f, uint32_t n)
{
 uint8_t buf[10];
  uint8_t i = 0;do {
   i++;
   buf[sizeof(buf) - i] = n%10 + '0';
   n /= 10;
 } while (n);
 f.write(&buf[sizeof(buf) - i], i);
}
/*
* Write a string to a file
*/
void writeString(SdFile &f, char *str)
{
 uint8_t n;
 for (n = 0; str[n]; n++);
 f.write((uint8_t *)str, n);
}
void setup(void){
 pinMode(pinLed, OUTPUT);

 Serial.begin(9600);        // connect to the serial port
 Serial.println("Geiger Counter");

 // initialize the SD card
 if (!card.init()) error("card.init");
 
 // initialize a FAT volume
 if (!volume.init(card)) error("volume.init");
 
 // open the root directory
 if (!root.openRoot(volume)) error("openRoot");

 
}
 void loop(){
// create a new file
 char name[] = "WRITE00.TXT";
 // wait if any serial is going on
 FreqCounter::f_comp=10;   // Cal Value / Calibrate with professional Freq Counter
 FreqCounter::start(60000);  // 1 minuit Gate Time
 while (FreqCounter::f_ready == 0)
  frq=FreqCounter::f_freq;
 Serial.print(cnt++);
 Serial.print("  cpm: ");
 Serial.println(frq);
   delay(100);
 digitalWrite(pinLed,!digitalRead(pinLed));  // blink Led

//-----------------------------------------------------

 for (uint8_t i = 0; i< 1000; cnt++){
  name[5] = i/10 + '0';
  name[6] = i%10 + '0';
  if (file.open(root, name, O_CREAT | O_APPEND | O_WRITE)) break;
 
 if (!file.isOpen()) error ("file.create");}
 // write 100 line to file
 for (uint8_t i = 0; i < 100; i++){
   writeNumber(file, cnt);
   writeString(file, " cpm ");
   writeNumber(file, frq);
   writeCRLF(file);
 
 // close file and force write of all data to the SD

card
 file.close();}

}







A human being should be able to change a diaper, Plan an invasion, Butcher a hog, Con a ship, Design a building, Write a sonnet, Balance acc

robtillaart

Thanks for sharing,

Please modify your post using the # button to wrap the code in [ code] [ /code] tags.

A few comments:

1) The logging will be faster if you first build up a string to write to the SD card

char buffer[32];
sprintf(buffer, "%ld,  cpm,  %ld, Hz \r\n", cnt, frq);   // all fields comma separated so Excel can make a graph
f.write(file, buffer, strlen(buffer));    // just one call

2) Now all the code in within loop(), think you should try to split it up in several functions to keep the overview.

3) Use CTRL-t in the IDE to get your indentation right.

What are the results of the measurements?





 
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Radioactive

Thanks I will play with that Modification. Here are some results from the testing.

1 cpm 0
2 cpm 65547
_______I never understood why this second reading is so high since I added the SD card, it even shows up on the serial port? Below is background.
3 cpm 13
4 cpm 15
5 cpm 10
6 cpm 12
7 cpm 15
8 cpm 19
9 cpm 23
10 cpm 12
11 cpm 17
___________CS-137
12 cpm 906
13 cpm 1556
14 cpm 1553
15 cpm 1538
16 cpm 1564
17 cpm 1556
18 cpm 1605
19 cpm 1658
____________Ra-226
20 cpm 46176
21 cpm 59645
22 cpm 59445
23 cpm 59567
24 cpm 59568
25 cpm 59635
26 cpm 59442
27 cpm 59571
28 cpm 59367
29 cpm 59702
30 cpm 59676
31 cpm 59793
32 cpm 59596
33 cpm 59646
34 cpm 59574
35 cpm 59787
36 cpm 59526
37 cpm 59785
38 cpm 59736
39 cpm 23244
40 cpm 61100
41 cpm 61226
42 cpm 61106
43 cpm 61167
44 cpm 61249
45 cpm 61391
46 cpm 61335
47 cpm 61031
48 cpm 61063
49 cpm 61159
50 cpm 61209
51 cpm 61509
52 cpm 62050
53 cpm 61994
54 cpm 62242
55 cpm 62030
56 cpm 62029
57 cpm 61984
58 cpm 61961
59 cpm 62127
60 cpm 42656
________Background
61 cpm 48
cpm 60
63 cpm 24
64 cpm 15
65 cpm 18
66 cpm 16
67 cpm 10
68 cpm 12
69 cpm 15
70 cpm 16
71 cpm 13
72 cpm 18
73 cpm 11
74 cpm 8
75 cpm 19
76 cpm 17
77 cpm 12
78 cpm 13
79 cpm 16
80 cpm 22
81 cpm 14
82 cpm 9
83 cpm 20
84 cpm 16
85 cpm 12
86 cpm 9
87 cpm 14
__________Cs-137 Again
88 cpm 529
89 cpm 1608
90 cpm 1663
91 cpm 1655
92 cpm 1685
93 cpm 1608
94 cpm 1637
95 cpm 1536
96 cpm 1594
97 cpm 1733
98 cpm 1608
99 cpm 1586
100 cpm 1717
101 cpm 1568
102 cpm 1618
103 cpm 1608
104 cpm 1556
105 cpm 1588
106 cpm 1623
107 cpm 1648
108 cpm 1672
109 cpm 1638
110 cpm 1636
111 cpm 1606
112 cpm 1574
113 cpm 1584
114 cpm 1614
115 cpm 1664
116 cpm 1608
117 cpm 1688
118 cpm 1565
119 cpm 1646
120 cpm 1629
121 cpm 1600
122 cpm 1615
123 cpm 1630
124 cpm 1627
125 cpm 1609
126 cpm 1681
127 cpm 1597
128 cpm 1669
129 cpm 1671
130 cpm 1642
131 cpm 1641
132 cpm 1565
133 cpm 1543
134 cpm 1596
135 cpm 1566
136 cpm 1590
137 cpm 1609
138 cpm 1523
139 cpm 1624
140 cpm 1598
141 cpm 1623
142 cpm 1618
143 cpm 1709
144 cpm 1626
145 cpm 1670
146 cpm 1588
147 cpm 1611
148 cpm 1669
149 cpm 1541
150 cpm 1611
151 cpm 1605
152 cpm 1593
153 cpm 1631
154 cpm 1645
155 cpm 1571
156 cpm 1582
157 cpm 1607
158 cpm 1602
159 cpm 1578
160 cpm 1677
161 cpm 1644
162 cpm 1661
163 cpm 1582
164 cpm 1564
165 cpm 1642


A human being should be able to change a diaper, Plan an invasion, Butcher a hog, Con a ship, Design a building, Write a sonnet, Balance acc

robtillaart


Instead of the delay(100) in the loop() you might do some extra measurements and do some averaging, although the samples seem quite stable. The first reading when holding the sample Radon/ cesium can be lower as they approach the Geiger counter.

About averaging: - http://arduino.cc/playground/Main/RunningAverage


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Radioactive

Quote
1) The logging will be faster if you first build up a string to write to the SD card

char buffer[32];
sprintf(buffer, "%ld,  cpm,  %ld, Hz \r\n", cnt, frq);   // all fields comma separated so Excel can make a graph
f.write(file, buffer, strlen(buffer));    // just one call

2) Now all the code in within loop(), think you should try to split it up in several functions to keep the overview.

3) Use CTRL-t in the IDE to get your indentation right.

What are the results of the measurements?



I keep getting the error.

No matching function for call to 'SD file::write(SDFile&, Char&, Size_t)

I am kind of at a loss as to what to do next? Any help is appreciated.
A human being should be able to change a diaper, Plan an invasion, Butcher a hog, Con a ship, Design a building, Write a sonnet, Balance acc

Go Up