Compare commits

...

10 Commits

Author SHA1 Message Date
186f090bc9
re-implemented LCD in main 2025-01-20 19:59:19 +01:00
253ed59793
implemented overloaded print & allowing blank lines 2025-01-20 19:58:07 +01:00
73d3b6f9c1
declared overloaded print fn
you can print from end now
2025-01-20 19:57:26 +01:00
e73f6f5e6e
serializing data in json 2025-01-01 14:11:29 +01:00
0a762ade5d
fixed display declaration typo 2025-01-01 14:11:06 +01:00
ff89a6ce7b
replaced serial communication with LCD 2024-11-15 21:29:35 +01:00
019cf950bb
added code to begin and print to display 2024-11-15 21:28:39 +01:00
b993bfb9bf
created display header file
only begin and print for now
2024-11-15 21:28:18 +01:00
d7db9de7a2
added noise todo 2024-11-15 20:16:31 +01:00
a9afecb20b
converting CPM to uSv/h 2024-11-15 19:56:08 +01:00
3 changed files with 195 additions and 63 deletions

View File

@ -1,63 +1,109 @@
/* /*
This is part of RadiationMapping This is part of RadiationMapping
Copyright (C) 2024 Václav Šmejkal Copyright (C) 2024 Václav Šmejkal
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <list> #include <list>
#include <DHT.h>
#define INPUT_PIN 10 //VIN PIN FOR GEIGER COUNTER #include <DHT_U.h>
#define MEASUREMENT_TIME_MS 60000 //MINUTE
#include <ArduinoJson.h>
std::list<unsigned long> counts; //COUNTS IN LAST MINUTE (OR MEASUREMENT_TIME_MS IF MODIFIED)
#include "display.hpp"
//CALLBACK WHEN RADIATION PARTICLE IS DETECTED
void IRAM_ATTR increment_counts() #define INPUT_PIN 10 //VIN PIN FOR GEIGER COUNTER
{ #define MEASUREMENT_TIME_MS 60000 //MINUTE
counts.push_back(millis()); //APPEND CURRENT TIME TO LIST counts #define SEND_TIME_MS 1000 //HOW OFTEN TO SEND DATA
} #define CALIBRATION_FACTOR 0.00332 //CONSTANT FOR CONVERTING J305 CPM TO uSv/h
void setup() std::list<unsigned long> counts; //COUNTS IN LAST MINUTE (OR MEASUREMENT_TIME_MS IF MODIFIED)
{ unsigned long last_send_time = 0;
//SERIAL COMMUNICATION INIT
Serial.begin(9600); //CALLBACK WHEN RADIATION PARTICLE IS DETECTED
void IRAM_ATTR increment_counts() //TODO: Possible noise
//INIT PINS {
pinMode(INPUT_PIN, INPUT); counts.push_back(millis()); //APPEND CURRENT TIME TO LIST counts
attachInterrupt(digitalPinToInterrupt(INPUT_PIN), increment_counts, FALLING); }
}
//DHT11 STUFF
int last_counts = -1; DHT_Unified dht(9, DHT11);
void loop() JsonDocument doc;
{ sensors_event_t event;
unsigned long current_millis = millis(); //CURRENT TIME
int current_counts = 0; void setup()
{
//REMOVE COUNTS OLDER THAN MEASUREMENT_TIME_MS Serial.begin(9600);
counts.remove_if([current_millis](unsigned long particle) //haha, *lambda* (cries in pure-C)
{ //INIT DHT11
return (current_millis - particle >= MEASUREMENT_TIME_MS); dht.begin();
}); sensor_t sensor;
dht.temperature().getSensor(&sensor);
//COUNT RECENT dht.humidity().getSensor(&sensor);
current_counts = counts.size();
//INIT LCD
if (last_counts != current_counts) //PRINT CPM IF CHANGED display::begin();
{
last_counts = current_counts; //INIT PINS
Serial.println(String(current_counts) + " CPM"); pinMode(INPUT_PIN, INPUT);
} attachInterrupt(digitalPinToInterrupt(INPUT_PIN), increment_counts, FALLING);
} }
int last_counts = -1;
void loop()
{
unsigned long current_millis = millis(); //CURRENT TIME
int current_counts = 0;
//REMOVE COUNTS OLDER THAN MEASUREMENT_TIME_MS
counts.remove_if([current_millis](unsigned long particle) //haha, *lambda* (cries in pure-C)
{
return (current_millis - particle >= MEASUREMENT_TIME_MS);
});
//COUNT RECENT
current_counts = counts.size();
if (last_counts != current_counts) //PRINT CPM IF CHANGED
{
last_counts = current_counts;
display::print(String(current_counts) + " CPM", String(current_counts * CALIBRATION_FACTOR) + " uSv/h"); //TODO: Replace with OLED
dht.temperature().getEvent(&event);
display::print(String((int) event.temperature) + "C", "", true);
dht.humidity().getEvent(&event);
display::print("", String((int) event.relative_humidity) + "%", true);
}
//SEND CURRENT STATE IN JSON
if (current_millis - last_send_time >= SEND_TIME_MS)
{
//SERIALIZE
doc["cpm"] = counts.size();
dht.temperature().getEvent(&event);
doc["temperature"] = event.temperature;
dht.humidity().getEvent(&event);
doc["humidity"] = event.relative_humidity;
serializeJson(doc, Serial); //SEND
Serial.println(); //TODO: Implement WiFi
last_send_time = current_millis;
}
}

24
display.hpp Normal file
View File

@ -0,0 +1,24 @@
/*
This is part of RadiationMapping
Copyright (C) 2024 Václav Šmejkal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace display
{
void begin(void); //INIT LCD DISPLAY
void print(String line_1, String line_2); //PRINT INTO LCD (OVERWRITING)
void print(String line_1, String line_2, bool end); //PRINT INTO LCD WITH OPTION TO PRINT FROM END
}

62
display.ino Normal file
View File

@ -0,0 +1,62 @@
/*
This is part of RadiationMapping
Copyright (C) 2024 Václav Šmejkal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "display.hpp"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 16);
namespace display
{
void begin(void)
{
//INIT THE LCD ITSELF
Wire.begin(6, 7);
lcd.init();
//TURN ON THE BACKLIGHT
lcd.backlight();
}
void print(String line_1, String line_2)
{
print(line_1, line_2, false);
}
void print(String line_1, String line_2, bool end)
{
//CLEAR
if (!end) lcd.clear();
//LINE 1
if (line_1 != "")
{
lcd.setCursor(end ? 16 - line_1.length() : 0, 0);
lcd.print(line_1);
}
//LINE 2
if (line_2 != "")
{
lcd.setCursor(end ? 16 - line_2.length() : 0, 1);
lcd.print(line_2);
}
}
}