Skip to content
This repository has been archived by the owner on Feb 9, 2022. It is now read-only.

Commit

Permalink
v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
khoih-prog authored Jan 27, 2020
1 parent dbf0d1e commit 26f4f2a
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 130 deletions.
58 changes: 36 additions & 22 deletions examples/Geiger_Counter/Geiger_Counter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases
* Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager
* Licensed under MIT license
* Version: 1.0.0
* Version: 1.0.1
*
* Based on orignal code by Crosswalkersam (https://community.blynk.cc/u/Crosswalkersam)
* posted in https://community.blynk.cc/t/select-connection-type-via-switch/43176
Expand All @@ -16,6 +16,7 @@
* Version Modified By Date Comments
* ------- ----------- ---------- -----------
* 1.0.0 K Hoang 25/01/2020 Initial coding
* 1.0.1 K Hoang 27/01/2020 Enable simultaneously running BT/BLE and WiFi
*****************************************************************************************************************************/

#define BLYNK_PRINT Serial
Expand Down Expand Up @@ -51,7 +52,6 @@ bool USE_BT = true;
#define VOLTAGE_FACTOR ( ( 4.2 * (3667 / 3300) ) / 4096 )

float voltage = 0;
long count = 0;
long countPerMinute = 0;
long timePrevious = 0;
long timePreviousMeassure = 0;
Expand All @@ -62,23 +62,19 @@ float radiationDose = 0;

void IRAM_ATTR countPulse();
volatile unsigned long last_micros;
volatile long count = 0;

BlynkTimer timer;

void IRAM_ATTR countPulse()
{
if ((long)(micros() - last_micros) >= DEBOUNCE_TIME_MICRO_SEC)
{
Pulse();
count++;
last_micros = micros();
}
}

void Pulse()
{
count++;
}

void sendDatatoBlynk()
{
if (USE_BT)
Expand All @@ -97,14 +93,34 @@ void sendDatatoBlynk()
}
}

void Serial_Display()
{
Serial.print(F("cpm = "));
Serial.printf("%4d", countPerMinute);
Serial.print(F(" - "));
Serial.print(F("RadiationValue = "));
Serial.printf("%5.3f", radiationValue);
Serial.print(F(" uSv/h"));
Serial.print(F(" - "));
Serial.print(F("Equivalent RadiationDose = "));
Serial.printf("%6.4f", radiationDose);
Serial.println(F(" uSv"));
}

#define USE_SIMULATION false

void checkStatus()
{
static float voltage;

if (millis() - timePreviousMeassure > MEASURE_INTERVAL_MS)
{
timePreviousMeassure = millis();

noInterrupts();
countPerMinute = COUNT_PER_MIN_CONVERSION * count;
interrupts();

radiationValue = countPerMinute * CONV_FACTOR;
radiationDose = radiationDose + (radiationValue / float(240.0));

Expand All @@ -116,26 +132,24 @@ void checkStatus()
radiationDose = 0;
}

Serial.print("cpm = ");
Serial.print(countPerMinute, DEC);
Serial.print(" - ");
Serial.print("RadiationValue = ");
Serial.print(radiationValue, 2);
Serial.print("uSv/h");
Serial.print(" - ");
Serial.print("Equivalent RadiationDose = ");
Serial.print(radiationDose, 4);
Serial.println("uSv");

count = 0;
Serial_Display();

#if USE_SIMULATION
count += 10;
if (count >= 1000)
count = 0;
#else
count = 0;
#endif
}
}

void setup()
{
pinMode(GEIGER_INPUT_PIN, INPUT);

Serial.begin(115200);
Serial.println(F("\nStarting Geiger-Counter"));

pinMode(GEIGER_INPUT_PIN, INPUT);
attachInterrupt(GEIGER_INPUT_PIN, countPulse, HIGH);

#if BLYNK_USE_BT_ONLY
Expand Down
110 changes: 62 additions & 48 deletions examples/Geiger_Counter_OLED/Geiger_Counter_OLED.ino
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
/****************************************************************************************************************************
Geiger_Counter_OLED.ino
For ESP32 using WiFi along with BlueTooth
Library for inclusion of both ESP32 Blynk BT and WiFi libraries. Then select one at runtime.
Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases
Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager
Licensed under MIT license
Version: 1.0.0
Based on orignal code by Crosswalkersam (https://community.blynk.cc/u/Crosswalkersam)
posted in https://community.blynk.cc/t/select-connection-type-via-switch/43176
Purpose: Use WiFi when posible by GPIO14 => HIGH or floating when reset.
Use Bluetooth when WiFi not available (such as in the field) by by GPIO14 => LOW when reset.
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 25/01/2020 Initial coding
* Geiger_Counter_OLED.ino
* For ESP32 using WiFi and BlueTooth simultaneously
*
* Library for inclusion of both ESP32 Blynk BT or BLE and WiFi libraries and run WiFi and BT/BLE simultaneously
* Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases
* Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager
* Licensed under MIT license
* Version: 1.0.1
*
* Based on orignal code by Crosswalkersam (https://community.blynk.cc/u/Crosswalkersam)
* posted in https://community.blynk.cc/t/select-connection-type-via-switch/43176
* Purpose: Use WiFi when posible by GPIO14 => HIGH or floating when reset.
* Use Bluetooth when WiFi not available (such as in the field) by by GPIO14 => LOW when reset.
*
* Version Modified By Date Comments
* ------- ----------- ---------- -----------
* 1.0.0 K Hoang 25/01/2020 Initial coding
* 1.0.1 K Hoang 27/01/2020 Enable simultaneously running BT/BLE and WiFi
*****************************************************************************************************************************/


#define BLYNK_PRINT Serial

#include <SPI.h>
Expand All @@ -33,25 +35,28 @@
#include <BlynkSimpleEsp32_BT_WF.h>
#include <BlynkSimpleEsp32_WF.h>

#define WIFI_BT_SELECTION_PIN 14 //Pin D14 mapped to pin GPIO14/HSPI_SCK/ADC16/TOUCH6/TMS of ESP32
#define GEIGER_INPUT_PIN 18 // Pin D18 mapped to pin GPIO18/VSPI_SCK of ESP32
#define VOLTAGER_INPUT_PIN 36 // Pin D36 mapped to pin GPIO36/ADC0/SVP of ESP32

// OLED SSD1306 128x32
#define OLED_RESET_PIN 4 // Pin D4 mapped to pin GPIO4/ADC10/TOUCH0 of ESP32
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32


char ssid[] = "SSID";
char pass[] = "PASS";
#endif

String cloudBlynkServer = "account.duckdns.org";
//String cloudBlynkServer = "192.168.2.110";
#define BLYNK_SERVER_HARDWARE_PORT 8080

// Blynk token shared between BT and WiFi
char auth[] = "****";

bool USE_BT = true;

#define WIFI_BT_SELECTION_PIN 14 //Pin D14 mapped to pin GPIO14/HSPI_SCK/ADC16/TOUCH6/TMS of ESP32
#define GEIGER_INPUT_PIN 18 // Pin D18 mapped to pin GPIO18/VSPI_SCK of ESP32
#define VOLTAGER_INPUT_PIN 36 // Pin D36 mapped to pin GPIO36/ADC0/SVP of ESP32

// OLED SSD1306 128x32
#define OLED_RESET_PIN 4 // Pin D4 mapped to pin GPIO4/ADC10/TOUCH0 of ESP32
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32

#define CONV_FACTOR 0.00658

#define DEBOUNCE_TIME_MICRO_SEC 4200L
Expand All @@ -60,7 +65,6 @@ bool USE_BT = true;
#define VOLTAGE_FACTOR ( ( 4.2 * (3667 / 3300) ) / 4096 )

float voltage = 0;
long count = 0;
long countPerMinute = 0;
long timePrevious = 0;
long timePreviousMeassure = 0;
Expand All @@ -71,6 +75,7 @@ float radiationDose = 0;

void IRAM_ATTR countPulse();
volatile unsigned long last_micros;
volatile long count = 0;

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET_PIN);
BlynkTimer timer;
Expand All @@ -79,16 +84,11 @@ void IRAM_ATTR countPulse()
{
if ((long)(micros() - last_micros) >= DEBOUNCE_TIME_MICRO_SEC)
{
Pulse();
count++;
last_micros = micros();
}
}

void Pulse()
{
count++;
}

void sendDatatoBlynk()
{
if (USE_BT)
Expand All @@ -109,16 +109,16 @@ void sendDatatoBlynk()

void Serial_Display()
{
Serial.print("cpm = ");
Serial.print(countPerMinute, DEC);
Serial.print(" - ");
Serial.print("RadiationValue = ");
Serial.print(radiationValue, 2);
Serial.print("uSv/h");
Serial.print(" - ");
Serial.print("Equivalent RadiationDose = ");
Serial.print(radiationDose, 4);
Serial.println("uSv");
Serial.print(F("cpm = "));
Serial.printf("%4d", countPerMinute);
Serial.print(F(" - "));
Serial.print(F("RadiationValue = "));
Serial.printf("%5.3f", radiationValue);
Serial.print(F(" uSv/h"));
Serial.print(F(" - "));
Serial.print(F("Equivalent RadiationDose = "));
Serial.printf("%6.4f", radiationDose);
Serial.println(F(" uSv"));
}

void OLED_Display()
Expand Down Expand Up @@ -156,14 +156,20 @@ void OLED_Display()
display.display();
}

#define USE_SIMULATION false

void checkStatus()
{
static float voltage;

if (millis() - timePreviousMeassure > MEASURE_INTERVAL_MS)
{
timePreviousMeassure = millis();

noInterrupts();
countPerMinute = COUNT_PER_MIN_CONVERSION * count;
interrupts();

radiationValue = countPerMinute * CONV_FACTOR;
radiationDose = radiationDose + (radiationValue / float(240.0));

Expand All @@ -178,15 +184,22 @@ void checkStatus()
Serial_Display();
OLED_Display();

count = 0;
#if USE_SIMULATION
count += 10;
if (count >= 1000)
count = 0;
#else
count = 0;
#endif
}
}

void setup()
{
pinMode(GEIGER_INPUT_PIN, INPUT);

Serial.begin(115200);
Serial.println(F("\nStarting Geiger-Counter-OLED"));

pinMode(GEIGER_INPUT_PIN, INPUT);
attachInterrupt(GEIGER_INPUT_PIN, countPulse, HIGH);

if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Expand All @@ -204,7 +217,8 @@ void setup()
if (digitalRead(WIFI_BT_SELECTION_PIN) == HIGH)
{
Serial.println(F("GPIO14 HIGH, Use WiFi"));
Blynk_WF.begin(auth, ssid, pass);
//Blynk_WF.begin(auth, ssid, pass);
Blynk_WF.begin(auth, ssid, pass, cloudBlynkServer.c_str(), BLYNK_SERVER_HARDWARE_PORT);
USE_BT = false;
}
else
Expand Down
Loading

0 comments on commit 26f4f2a

Please sign in to comment.