Compare commits

..

No commits in common. "186f090bc99b05be0d757d6fe50967a75a5e5cb4" and "54bc072e20c0738d16e6091c2958fc4aa74cd036" have entirely different histories.

3 changed files with 63 additions and 195 deletions

View File

@ -18,45 +18,23 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <list> #include <list>
#include <DHT.h>
#include <DHT_U.h>
#include <ArduinoJson.h>
#include "display.hpp"
#define INPUT_PIN 10 //VIN PIN FOR GEIGER COUNTER #define INPUT_PIN 10 //VIN PIN FOR GEIGER COUNTER
#define MEASUREMENT_TIME_MS 60000 //MINUTE #define MEASUREMENT_TIME_MS 60000 //MINUTE
#define SEND_TIME_MS 1000 //HOW OFTEN TO SEND DATA
#define CALIBRATION_FACTOR 0.00332 //CONSTANT FOR CONVERTING J305 CPM TO uSv/h
std::list<unsigned long> counts; //COUNTS IN LAST MINUTE (OR MEASUREMENT_TIME_MS IF MODIFIED) std::list<unsigned long> counts; //COUNTS IN LAST MINUTE (OR MEASUREMENT_TIME_MS IF MODIFIED)
unsigned long last_send_time = 0;
//CALLBACK WHEN RADIATION PARTICLE IS DETECTED //CALLBACK WHEN RADIATION PARTICLE IS DETECTED
void IRAM_ATTR increment_counts() //TODO: Possible noise void IRAM_ATTR increment_counts()
{ {
counts.push_back(millis()); //APPEND CURRENT TIME TO LIST counts counts.push_back(millis()); //APPEND CURRENT TIME TO LIST counts
} }
//DHT11 STUFF
DHT_Unified dht(9, DHT11);
JsonDocument doc;
sensors_event_t event;
void setup() void setup()
{ {
//SERIAL COMMUNICATION INIT
Serial.begin(9600); Serial.begin(9600);
//INIT DHT11
dht.begin();
sensor_t sensor;
dht.temperature().getSensor(&sensor);
dht.humidity().getSensor(&sensor);
//INIT LCD
display::begin();
//INIT PINS //INIT PINS
pinMode(INPUT_PIN, INPUT); pinMode(INPUT_PIN, INPUT);
attachInterrupt(digitalPinToInterrupt(INPUT_PIN), increment_counts, FALLING); attachInterrupt(digitalPinToInterrupt(INPUT_PIN), increment_counts, FALLING);
@ -80,30 +58,6 @@ void loop()
if (last_counts != current_counts) //PRINT CPM IF CHANGED if (last_counts != current_counts) //PRINT CPM IF CHANGED
{ {
last_counts = current_counts; last_counts = current_counts;
display::print(String(current_counts) + " CPM", String(current_counts * CALIBRATION_FACTOR) + " uSv/h"); //TODO: Replace with OLED Serial.println(String(current_counts) + " CPM");
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;
} }
} }

View File

@ -1,24 +0,0 @@
/*
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
}

View File

@ -1,62 +0,0 @@
/*
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);
}
}
}