Last active
September 12, 2019 20:11
-
-
Save tlrobinson/f911f206e777e1af0e76a220f9c77bec to your computer and use it in GitHub Desktop.
MightyOhm Geiger Counter Kit + ESP8266 (WEMOS D1 mini) https://mightyohm.com/blog/products/geiger-counter/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get config.h from Adafruit IO example sketch and fill in your details | |
#include "config.h" | |
#include <Pins_Arduino.h> | |
#include <SoftwareSerial.h> | |
#include <Regexp.h> | |
AdafruitIO_Feed *cpm_feed = io.feed("Geiger CPM"); | |
AdafruitIO_Feed *cps_feed = io.feed("Geiger CPS"); | |
AdafruitIO_Feed *usv_feed = io.feed("Geiger uSv/hr"); | |
SoftwareSerial geiger(D2, D3); | |
void setup() { | |
Serial.begin(115200); | |
while (! Serial); | |
Serial.print("Connecting to Adafruit IO"); | |
io.connect(); | |
while (io.status() < AIO_CONNECTED) { | |
Serial.print("."); | |
delay(500); | |
} | |
Serial.println(); | |
Serial.println(io.statusText()); | |
geiger.begin(9600); | |
geiger.setTimeout(10); | |
} | |
void loop() { | |
io.run(); | |
String line = geiger.readStringUntil('\n'); | |
char buf[line.length()]; | |
line.toCharArray(buf, line.length()); | |
MatchState ms; | |
ms.Target(buf); | |
char result = ms.Match ("CPS, (%d+), CPM, (%d+), uSv/hr, (%d+.%d+)"); | |
if (result == REGEXP_MATCHED) { | |
Serial.println(line); | |
int cps = atoi(ms.GetCapture(buf, 0)); | |
int cpm = atoi(ms.GetCapture(buf, 1)); | |
float usv = atof(ms.GetCapture(buf, 2)); | |
cps_feed->save(cps); | |
cpm_feed->save(cpm); | |
usv_feed->save(usv); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Brown = ground
Red = 3.3V
Orange = RX (pin D2 in above sketch)