-
Notifications
You must be signed in to change notification settings - Fork 0
/
IoT-devices-GGreg20_V3_DisplaySSD1306-Demo-sketch.ino
162 lines (138 loc) · 4.19 KB
/
IoT-devices-GGreg20_V3_DisplaySSD1306-Demo-sketch.ino
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
/*
IoT-devices GGreg20_V3 with Display SSD1306 Demo sketch
Filename: IoT-devices-GGreg20_V3_DisplaySSD1306-Demo-sketch.ino
This is a demonstration sketch that clearly shows how
the GGreg20_V3 radiation detector connects and works with
the Arduino UNO controller.
This example shows a valid code that can be used with a real controller
and module GGreg20_V3 manufactured by IoT-devices LLC.
In addition to the Arduino controllers, the GGreg20_V3 can work with any
other controller that can handle GPIO events, or even those that can measure
logic through an ADC (if needed).
For example, such controllers are ESP32, ESP8266, STM32, Raspberry Pi and many others.
The circuit:
* GGreg20_V3 Ionizing Radiation Detector's pulse output is emulated via simple pushbutton
* Arduino UNO
* OLED Display SSD1306, I2C
* LED blinks with pulses
Created 13-01-2022
By IoT-devices LLC, Kyiv, Ukraine
Modified 13-01-2022
By IoT-devices LLC
Product page: https://iot-devices.com.ua/en/product/ggreg20_v3-ionizing-radiation-detector-with-geiger-tube-sbm-20/
Hackaday Project: https://hackaday.io/project/183103-ggreg20v3-ionizing-radiation-detector
Licensed under Apache-2.0 License
License record: IoT-devices, LLC : EO/zaD7NcdSfHLgB/OlzLx/6De/N5thMJ1PCZSsxhxqd3J4OoHK84QQgNlKVSh5X1lrEp0a0/8fRyTThM649FZNcQPydSrHadjHNH3pMPb6q4sDRHzsmt4vE18M3cfG+Rd7cMNqqlTl2IUu5J7mLiclji8di0FSBIB7UOnf14JxJ71oruGPkEiqK9yLAw4or
*/
//
#include <Wire.h>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiWire.h"
// 0X3C+SA0 - 0x3C or 0x3D
#define I2C_ADDRESS 0x3C
// Define proper RST_PIN if required.
#define RST_PIN -1
int pin = 13;
byte interruptPin = 2;
int cpm = 0;
volatile byte state = LOW;
volatile unsigned long now = millis ();
const int debounceTime = 5; // debounce in milliseconds
volatile unsigned long measure_time = 60000;
unsigned long meas_start = millis ();
int ma5_pointer = 0;
float ma5_arr[5] = {};
float ma5_val = 0;
int ma5_arr_elements = 0;
SSD1306AsciiWire oled;
void setup() {
ma5_arr[0] = 0;
ma5_arr[1] = 0;
ma5_arr[2] = 0;
ma5_arr[3] = 0;
ma5_arr[4] = 0;
ma5_arr[5] = 0;
ma5_pointer = 0;
ma5_val = 0;
ma5_arr_elements = 0;
Serial.begin(115200);
Wire.begin();
Wire.setClock(400000L);
pinMode(pin, OUTPUT);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), counter, LOW);
#if RST_PIN >= 0
oled.begin(&Adafruit128x64, I2C_ADDRESS, RST_PIN);
#else // RST_PIN >= 0
oled.begin(&Adafruit128x64, I2C_ADDRESS);
#endif // RST_PIN >= 0
Serial.println(meas_start);
}
void loop() {
digitalWrite(pin, state);
state = LOW;
// Main 1-pass measure 60 seconds timer
if (millis() - meas_start >= measure_time) {
calc();
cpm = 0;
meas_start = millis();
}
Serial.println(millis() - meas_start);
Serial.println(ma5_pointer);
Serial.println(ma5_val);
Serial.println(ma5_arr_elements);
Serial.println(ma5_arr[0]);
Serial.println(ma5_arr[1]);
Serial.println(ma5_arr[2]);
Serial.println(ma5_arr[3]);
Serial.println(ma5_arr[4]);
Serial.println(cpm);
delay(1000);
disp();
}
void counter() {
// Pin deBounce conditioning
if (digitalRead(interruptPin) == LOW && (millis() - now) >= debounceTime) {
cpm = cpm + 1;
now = millis ();
blink();
}
}
void blink() {
state = HIGH;
Serial.println(state);
delay(30);
}
void disp() {
oled.clear();
oled.setFont(lcdnums14x24);
oled.setCursor(0,0);
oled.print(cpm);
oled.setFont(Verdana12);
oled.println(" CPM");
oled.setCursor(0,4);
oled.setFont(lcdnums14x24);
oled.print(ma5_val);
oled.setFont(Verdana12);
oled.print(" uSv/h MA5");
oled.setCursor(92,0);
oled.print((measure_time - (millis() - meas_start))/1000);
oled.print(" sec");
delay(500);
}
void calc() {
ma5_val = 0;
ma5_arr[ma5_pointer] = cpm * 0.0054; // 0.0054 conversion factor for SBM-20 GM tube
byte i = 0;
while(i < 5 && ma5_arr[i] != 0){
ma5_arr_elements = (i + 1);
i++;
}
byte j = 0;
while(j < ma5_arr_elements && ma5_arr[j] != 0){
ma5_val += ma5_arr[j];
j++;
}
if(ma5_arr_elements != 0){ma5_val /= ma5_arr_elements;}
if (ma5_pointer < 4){ma5_pointer++;} else {ma5_pointer = 0;}
}