-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRadiation.ino
More file actions
177 lines (153 loc) · 5.68 KB
/
Radiation.ino
File metadata and controls
177 lines (153 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//Code developed by Diego Malpica, for the Antarctica Project
#include <TFT_eSPI.h>
#include "seeed_bme680.h"
#include <SPI.h>
#include <Seeed_FS.h>
#include <Wire.h>
#include "Adafruit_VEML6075.h"
#include "SD/Seeed_SD.h"
#include "RTC_SAMD51.h"
#include "DateTime.h"
#define LOG_PERIOD 15000 //Logging period in milliseconds, recommended value 15000-60000.
#define MAX_PERIOD 60000 //Maximum logging period without modifying this sketch
unsigned long counts; //variable for GM Tube events
unsigned long cpm; //variable for CPM
unsigned int multiplier; //variable for calculation CPM in this sketch
unsigned long previousMillis; //variable for time measurement
void tube_impulse(){ //subprocedure for capturing events from Geiger Kit
counts++;
}
RTC_SAMD51 rtc;
TFT_eSPI tft;
TFT_eSprite spr = TFT_eSprite(&tft); // Sprite
Adafruit_VEML6075 uv = Adafruit_VEML6075();
File myFile;
void setup() {
// put your setup code here, to run once:
rtc.begin();
tft.begin();
tft.setRotation(3);
spr.createSprite(tft.width(),tft.height());
Serial.begin(115200);
counts = 0;
cpm = 0;
multiplier = MAX_PERIOD / LOG_PERIOD; //calculating multiplier, depend on your log period
attachInterrupt(0, tube_impulse, FALLING); //define external interrupts
Serial.println("VEML6075 Full Test");
if (! uv.begin()) {
Serial.println("Failed to communicate with VEML6075 sensor, check wiring?");
}
Serial.println("Found VEML6075 sensor");
// Set the integration constant
uv.setIntegrationTime(VEML6075_100MS);
// Get the integration constant and print it!
Serial.print("Integration time set to ");
switch (uv.getIntegrationTime()) {
case VEML6075_50MS: Serial.print("50"); break;
case VEML6075_100MS: Serial.print("100"); break;
case VEML6075_200MS: Serial.print("200"); break;
case VEML6075_400MS: Serial.print("400"); break;
case VEML6075_800MS: Serial.print("800"); break;
}
Serial.println("ms");
// Set the high dynamic mode
uv.setHighDynamic(true);
// Get the mode
if (uv.getHighDynamic()) {
Serial.println("High dynamic reading mode");
} else {
Serial.println("Normal dynamic reading mode");
}
// Set the mode
uv.setForcedMode(false);
// Get the mode
if (uv.getForcedMode()) {
Serial.println("Forced reading mode");
} else {
Serial.println("Continuous reading mode");
}
// Set the calibration coefficients
uv.setCoefficients(2.22, 1.33, // UVA_A and UVA_B coefficients
2.95, 1.74, // UVB_C and UVB_D coefficients
0.001461, 0.002591); // UVA and UVB responses
SD.begin(SDCARD_SS_PIN, SDCARD_SPI);
myFile = SD.open("RadUV.csv", FILE_WRITE);
DateTime now = DateTime(F(__DATE__), F(__TIME__));
myFile.println("Date,Time,UVA,UVB,UVI,CPM,USv_h");
//Serial.println("adjust time!");
rtc.adjust(now);
now = rtc.now();
}
void loop() {
// put your main code here, to run repeatedly:
DateTime now = rtc.now();
int val;
spr.fillSprite(TFT_BLACK);
spr.setFreeFont(&FreeSansBoldOblique18pt7b);
spr.setTextColor(TFT_RED);
spr.drawString("Radiation+UV", 60 - 15, 10 , 1);// Print the test text in the custom font
for(int8_t line_index = 0;line_index < 5 ; line_index++)
{
spr.drawLine(0, 50 + line_index, tft.width(), 50 + line_index, TFT_GREEN);
}
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > LOG_PERIOD){
previousMillis = currentMillis;
cpm = counts * multiplier;
spr.setFreeFont(&FreeSansBoldOblique9pt7b); // Select the font
Serial.print("Raw UVA reading: "); Serial.println(uv.readUVA());
Serial.print("Raw UVB reading: "); Serial.println(uv.readUVB());
Serial.print("UV Index reading: "); Serial.println(uv.readUVI());
// cpm
spr.setTextColor(TFT_WHITE);
spr.drawString("cpm:", 60 - 24, 100 -24 , 1);// Print the test text in the custom font
spr.drawRoundRect(50 - 24,100,150,40,5,TFT_WHITE);
spr.setTextColor(TFT_WHITE);
spr.drawNumber(cpm,60 - 20,100+10,1);
spr.setTextColor(TFT_GREEN);
spr.drawString("cpm", 110 + 12, 100+8, 1);
// beta and gamma radiation uSv/h (conversion factor cpm/151 or cpm/153.8)
spr.setTextColor(TFT_WHITE);
spr.drawString("Dose:", 230 -24 , 100 - 24 , 1);// Print the test text in the custom font
spr.drawRoundRect(230 - 24,100,100,40,5,TFT_WHITE);
spr.setTextColor(TFT_WHITE);
spr.drawNumber((cpm/151),230 - 20,100+10,1);
spr.setTextColor(TFT_GREEN);
spr.drawString("uSv/h", 230 + 12, 100+8, 1);
// UV Index
spr.setTextColor(TFT_WHITE);
spr.drawString("UV Index", 60 - 24, 180 -24 , 1);// Print the test text in the custom font
spr.drawRoundRect(60 - 24,180,150,40,5,TFT_WHITE);
spr.setTextColor(TFT_WHITE);
spr.drawNumber(uv.readUVI(),60 - 20,180+10,1);
spr.setTextColor(TFT_GREEN);
spr.drawString("UV-I", 110 + 12, 180+8, 1);
//SD.begin(SDCARD_SS_PIN, SDCARD_SPI);
myFile = SD.open("RadUV.csv", FILE_APPEND);
myFile.print(now.year(), DEC);
myFile.print('/');
myFile.print(now.month(), DEC);
myFile.print('/');
myFile.print(now.day(), DEC);
myFile.print(",");
myFile.print(now.hour(), DEC);
myFile.print(':');
myFile.print(now.minute(), DEC);
myFile.print(':');
myFile.print(now.second(), DEC);
myFile.print(",");
myFile.print(uv.readUVA());
myFile.print(",");
myFile.print(uv.readUVB());
myFile.print(",");
myFile.print(uv.readUVI());
myFile.print(",");
myFile.print(cpm);
myFile.print(",");
myFile.print(cpm/151);
myFile.println(",");
// myFile.close();
spr.pushSprite(0, 0);
delay(1000);
}
}