Skip to content

Instantly share code, notes, and snippets.

@tlrobinson
Last active September 12, 2019 20:11
Show Gist options
  • Select an option

  • Save tlrobinson/f911f206e777e1af0e76a220f9c77bec to your computer and use it in GitHub Desktop.

Select an option

Save tlrobinson/f911f206e777e1af0e76a220f9c77bec to your computer and use it in GitHub Desktop.

Revisions

  1. tlrobinson revised this gist Sep 12, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions geiger.ino
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    // get config.h from Adafruit IO example sketch and fill in your details
    #include "config.h"

    #include <Pins_Arduino.h>
  2. tlrobinson revised this gist Sep 12, 2019. No changes.
  3. tlrobinson created this gist Sep 12, 2019.
    55 changes: 55 additions & 0 deletions geiger.ino
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    #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);
    }
    }