HUZZAH Feather "EspSoftSerialRx.cpp" compile error

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
keli
 
Posts: 77
Joined: Mon Jul 07, 2008 9:53 am

HUZZAH Feather "EspSoftSerialRx.cpp" compile error

Post by keli »

I'm using a mightyohm Geiger Counter Kit, along with a HUZZAH 8266 Feather, and Feather wing OLED in a mod to it. I'm having problems compiling the code. I keep on getting an error that "EspSoftSerialRx.cpp" does not exist. I've looked and it is in "/home/pi/Arduino1.8.19/Arduino/libraries/EspSoftSerial-master" along with "EspSoftSerialRx.h". I'm confused. Things seem to be in the right place, so I am not sure what is going on; HUZZAH ESP8266 is the selected board. Any ideas? Thanks Keli

Code: Select all

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <CircularBuffer.h>
#include <EspSoftSerialRx.h>
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
/home/pi/Arduino1.8.19/Arduino/libraries/EspSoftSerial-master/EspSoftSerialRx.cpp:8:10: fatal error: arduino.h: No such file or directory
Multiple libraries were found for "Adafruit_MQTT.h"
8 | #include <arduino.h>
Used: /home/pi/Desktop/geiger/libraries/Adafruit_MQTT_Library-master
| ^~~~~~~~~~~
Not used: /home/pi/Desktop/geiger/libraries/Adafruit_MQTT_Library
compilation terminated.
exit status 1
Error compiling for board Adafruit Feather HUZZAH ESP8266.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: HUZZAH Feather "EspSoftSerialRx.cpp" compile error

Post by mikeysklar »

Keli,

It looks like your Arduino IDE installation is also failing to find the "arduino.h" header and multiple "Adafruit_MQTT.h" headers.

Is this an older Arduino IDE installation with a mixture of libraries? It might help to move your Arduino folder and start a fresh install with the current release and installing the libraries you need.

User avatar
keli
 
Posts: 77
Joined: Mon Jul 07, 2008 9:53 am

Re: HUZZAH Feather "EspSoftSerialRx.cpp" compile error

Post by keli »

Thanks for your help. My Arduino is Arduino IDE 1.8.19; latest version I think. I did have an earlier version of Arduino on the Pi. I'm to lazy to get rid of the old, and depended on
the installer to do the right thing. I usually don't have a problem with code, but includes drive me nuts. Its like a fight to get past them. But I learn a lot by figuring it out. I will think about your suggestion to clean things up, thanks K.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: HUZZAH Feather "EspSoftSerialRx.cpp" compile error

Post by mikeysklar »

I often move the Arduino folder (on my Mac it is Documents/Arduino) to a different name and start a fresh install to see if I can get things going with less library conflicts.

User avatar
keli
 
Posts: 77
Joined: Mon Jul 07, 2008 9:53 am

Re: HUZZAH Feather "EspSoftSerialRx.cpp" compile error

Post by keli »

Still haven't resolved my problem, I can't seem to include "EspSoftSerialRx.cpp". I can see when I look in the "library" directory that it is there. Problem has progressed from not being able to find "EspSoftSerialRx.h" to .cpp. Clean uninstalled Arduino, reinstalled Arduino 1.8.19, made no difference. "EspSoftSerial-master" has both files, they are in the library. Actually have the sketch on two different Pis, does basically the same on both. Tried ESP8266 "examples" and things compile on the examples I tried.

Arduino: 1.8.19 (Linux), Board: "Adafruit Feather HUZZAH ESP8266, 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 4MB (FS:2MB OTA:~1019KB), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

/home/pi/Arduino/libraries/EspSoftSerial-master/EspSoftSerialRx.cpp:8:10: fatal error: arduino.h: No such file or directory
8 | #include <arduino.h>
| ^~~~~~~~~~~
compilation terminated.
Multiple libraries were found for "ESP8266WiFi.h"
Used: /home/pi/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/libraries/ESP8266WiFi
Not used: /home/pi/Arduino-1.8.19/arduino-1.8.19/libraries/ESP8266WiFi
Multiple libraries were found for "CircularBuffer.h"
Used: /home/pi/Arduino/libraries/CircularBuffer
Not used: /home/pi/Arduino/libraries/EspSoftSerial-master
exit status 1
Error compiling for board Adafruit Feather HUZZAH ESP8266.


This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Code: Select all

// Example Program for MightyOhm Geiger Counter FeatherWing + OLED Upgrade
// This example is specifically for use with Adafruit Feather HUZZAH (ESP8266)
// It will also work with other Feather boards with modifications
//
// By: Dan Watson
// syncchannel.blogspot.com
// 1/31/2016

// This program makes use of the EspSoftSerial library to receive data from the Geiger counter.
// EspSoftwareSerial: https://github.com/scottwday/EspSoftSerial
// Thank you scottwday for this useful library!

// The Adafruit MQTT, MQTT_Client, GFX, and SSD1306 libraries are also used. Official documentation:
// https://learn.adafruit.com/adafruit-feather-huzzah-esp8266/overview
// https://learn.adafruit.com/adafruit-io/mqtt-api
// https://learn.adafruit.com/monochrome-oled-breakouts
// All of the MQTT code below is borrowed from Adafruit's example programs. Thank you!

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <CircularBuffer.h>
#include <EspSoftSerialRx.h>
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"

#define WLAN_SSID       "your ssid here"
#define WLAN_PASS       "your password here"
#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883
#define AIO_USERNAME    "your Adafruit IO user name here"
#define AIO_KEY         "your Adafruit IO private key here"

/************ Global State (you don't need to change this!) ******************/

// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;

// Store the MQTT server, username, and password in flash memory.
// This is required for using the Adafruit MQTT library.
const char MQTT_SERVER[] PROGMEM    = AIO_SERVER;
const char MQTT_USERNAME[] PROGMEM  = AIO_USERNAME;
const char MQTT_PASSWORD[] PROGMEM  = AIO_KEY;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);

/****************************** Feeds ***************************************/

// Modify these feed names to match what you created on Adafruit IO

const char CPS_FEED[] PROGMEM = AIO_USERNAME "/feeds/GeigerCPS";
Adafruit_MQTT_Publish cpsfeed = Adafruit_MQTT_Publish(&mqtt, CPS_FEED);

const char CPM_FEED[] PROGMEM = AIO_USERNAME "/feeds/GeigerCPM";
Adafruit_MQTT_Publish cpmfeed = Adafruit_MQTT_Publish(&mqtt, CPM_FEED);

const char SIEVERTS_FEED[] PROGMEM = AIO_USERNAME "/feeds/GeigerSieverts";
Adafruit_MQTT_Publish sievertsfeed = Adafruit_MQTT_Publish(&mqtt, SIEVERTS_FEED);

/****************************************************************************/

#define buttonA 0
#define buttonB 16
#define buttonC 2
#define rxPin 13

Adafruit_SSD1306 display;
EspSoftSerialRx SerialGeiger;

#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

// Used to store strings arriving from geiger counter
String geigerSerial;

// Storage for stats
int cps = 0;
int cpm = 0;
float sieverts = 0;

// Misc variables for mode and monitoring
uint8_t mode = 1;
unsigned long geigerTimeout = 0;
bool geigerConnected = false;
uint8_t publishCounter = 0;
bool publishStatus = false;

void setup()
{
  // String from geiger counter will be echoed on USB Serial
  // Software serial Rx-only is used to receive the string from the geiger counter
  Serial.begin(9600);
  SerialGeiger.begin(9600, rxPin);
  
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);

  // All three buttons on the OLED FeatherWing are used in this example
  pinMode(buttonA, INPUT_PULLUP);
  pinMode(buttonC, INPUT_PULLUP);
  pinMode(buttonC, INPUT_PULLUP);
  
  display.clearDisplay();

  // Connect to WiFi access point.
  Serial.println(); Serial.println();
  Serial.print("Connecting to ");
  Serial.println(WLAN_SSID);

  WiFi.begin(WLAN_SSID, WLAN_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println();

  Serial.println("WiFi connected");
  Serial.println("IP address: "); Serial.println(WiFi.localIP());
}

void loop()
{
  // Check if a button is pressed and change mode accordingly
  
  bool gotButton = false;
  
  if (!digitalRead(buttonA))
  {
    mode = 1;
    gotButton = true;
  }

  else if (!digitalRead(buttonB))
  {
    mode = 2;
    gotButton = true;
  }

  else if (!digitalRead(buttonC))
  {
    mode = 3;
    gotButton = true;
  }

  if (gotButton)
    delay(50); // Debounce

  // End of button checking

  // Monitor the serial connection from the geiger counter.
  // If it is absent for > 3 seconds, display a warning to the user
  if (millis() > (geigerTimeout + 3000) && geigerConnected == true)
  {
    geigerConnected = false;
    display.setTextColor(WHITE);
    display.clearDisplay();
    display.setTextSize(1);
    display.setCursor(0,8);
    display.println("GEIGER COUNTER");
    display.println("NOT CONNECTED!");
    display.display();
  }

  // End of serial connection monitoring

  // Attempt to receive a serial character from the geiger counter
  // If we got one, append it to the string
  // If we got a new line character, parse the string and update the display
  // The strings arrive about once a second, so this loop is also used for timing of publish events
    
  unsigned char b;
  if(SerialGeiger.read(b))
  {
    geigerSerial += char(b);

    if (b == 0x0A) // New line, end of string. We need to parse.
    {
      Serial.print(geigerSerial); // Echo the string to USB serial for potential PC monitoring
      geigerConnected = true; // Record that serial connection health is ok
      geigerTimeout = millis();
      publishCounter++; // When this gets to five (five seconds passed) we will publish
      SerialGeiger.service(); // Periodic service routine required for this library

      // Parse CPS, CPM, and uS/hr from the string
      int comma1Index = geigerSerial.indexOf(',');
      int comma2Index = geigerSerial.indexOf(',', comma1Index + 1);
      int comma3Index = geigerSerial.indexOf(',', comma2Index + 1);
      int comma4Index = geigerSerial.indexOf(',', comma3Index + 1);
      int comma5Index = geigerSerial.indexOf(',', comma4Index + 1);
      int comma6Index = geigerSerial.indexOf(',', comma5Index + 1);

      String cpsString = geigerSerial.substring(comma1Index+1,comma2Index);
      String cpmString = geigerSerial.substring(comma3Index+1,comma4Index);
      String sievertsString = geigerSerial.substring(comma5Index+1,comma6Index);

      cps = cpsString.toInt();
      cpm = cpmString.toInt();
      sieverts = sievertsString.toFloat();

      geigerSerial = ""; // Clear the string for next time

      // Update the display depending on what mode we are in
      // Lots of potential to modify/improve this. You could do cool stuff like graphing!
      switch (mode) {
        case 1: // Stats
          display.setTextColor(WHITE);
          display.setTextSize(1);
          display.clearDisplay();
          display.setCursor(4,8);
          display.print("CPS:");
          display.print(cps);
          display.print(" | CPM:");
          display.print(cpm);
          display.setCursor(4,20);
          display.print("uSv/hr: ");
          display.println(sieverts);
          display.display();
          break;
        case 2: // CPM only in large text for greater visibility
          display.setTextColor(WHITE);
          display.clearDisplay();
          display.setTextSize(1);
          display.setCursor(2,19);
          display.print("CPM:");
          display.setTextSize(3);
          display.setCursor(30,4);
          display.print(cpm);
          display.display();
          break;
        case 3: // Status of Wi-Fi, publishing, and IP address
          display.setTextSize(1);
          display.setTextColor(WHITE);
          display.clearDisplay();
          display.setCursor(2,8);
          display.print("Wi-FI: ");
          if (WiFi.status() != WL_CONNECTED)
            display.println("Not Connected");
          else if (!publishStatus)
            display.println("Can't Publish");
          else
            display.println("Connected");
          display.setCursor(2,20);
          display.print("IP: ");
          display.println(WiFi.localIP());
          display.display();
          break;
      }
    }
  }

  MQTT_connect();

  // We publish every five seconds to Adafruit IO
  // If any publish attempt fails, the user will be notified on the Mode 3 screen
  if (publishCounter >= 5)
  {
    publishCounter = 0;
    bool publishResults = true;
    if (!cpsfeed.publish(cps))
      publishResults = false;
    delay(10);
    if (!cpmfeed.publish(cpm))
      publishResults = false;
    delay(10);
    if (!sievertsfeed.publish(sieverts))
      publishResults = false;
    publishStatus = publishResults;
  }
}

// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect() {
  int8_t ret;

  // Stop if already connected.
  if (mqtt.connected()) {
    return;
  }

  Serial.print("Connecting to MQTT... ");

  while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
       Serial.println(mqtt.connectErrorString(ret));
       Serial.println("Retrying MQTT connection in 5 seconds...");
       mqtt.disconnect();
       delay(5000);  // wait 5 seconds
  }
  Serial.println("MQTT Connected!");
}

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: HUZZAH Feather "EspSoftSerialRx.cpp" compile error

Post by mikeysklar »

Which EspSoftwareSerial are you running?

There is the arduino package one available, but the code you have provided references the github one that was last updated six years ago. Are you downloading installing that library?


https://github.com/scottwday/EspSoftSerial

User avatar
keli
 
Posts: 77
Joined: Mon Jul 07, 2008 9:53 am

Re: HUZZAH Feather "EspSoftSerialRx.cpp" compile error

Post by keli »

Thanks for your help. I have both EspSoftwareSerial (coming from the Library Manager), and EspSoftSerial-master (from GitHub) in both Arduino libraries (/home/pi/Arduino-1.8.19/arduino-1.8.19/libraries, and /home/pi/Arduino/libraries). EspSoftSerial-master has both EspSoftSerialRx.h, and EspSoftSerialRx.cpp, EspSoftwareSerial has neither file. Looks like when you use the "Add .ZIP Library..." command it puts the libraries in /home/pi/Arduino/libraries. My "/home/pi/Arduino-1.8.19/arduino-1.8.19/libraries path looks a little odd", but since the compiler pulls libraries from "home/pi/Arduino/libraries"; that should not be a problem. When I did a clean install (wiped out IDE installation folder, Sketchbook, and Data folders); the Arduino 1.8.19 installer made both Arduino Library paths, wanted to see if I had problems with the old Arduino. I have another Pi running Arduino 1.8.19 under Bullseye (main work machine runs under Buster) both machines have the same "compile error", I installed both so if I screwed up I did it twice. I don't know why the installer made two Library folders, but I assume it knew what it was doing. EspSoftwareSerial does not have the Rx.h, or Rx.cpp files, thats why I went looking at GitHub and found "EspSoftSerial-master". I would be happy if some one could point me the "right" library to use to fix the compile error. I've run other ESP8266 EXAMPLE files and they all compile properly so Arduino seems OK. I would think if any one just put the following include calls in a otherwise bare sketch, they would have a similiar compile error, if not they would have solved my problem. Thanks K

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <CircularBuffer.h>
#include <EspSoftSerialRx.h>
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: HUZZAH Feather "EspSoftSerialRx.cpp" compile error

Post by mikeysklar »

Our page suggests a rather old ESPSoftSerial release of 2.5.1 was tested and last working. You could go back to a much earlier release, but I think the issue could also be resolved by going back on the ESP32 or Arduino IDE to earlier versions.

Maybe the best place to start is going back to releases from 2 years ago for all three and see if you can find a starting point where everything works then start upgrading each one at a time?

User avatar
keli
 
Posts: 77
Joined: Mon Jul 07, 2008 9:53 am

Re: HUZZAH Feather "EspSoftSerialRx.cpp" compile error

Post by keli »

Given up on the "Geiger_WiFi_OLED_Example.ino" project by Dan Watson. There is a problem (out of date Arduino, or includes?) with the includes that I don't have the time, or motivation to work out. I found another Geiger project by "dmainmon", "Geiger Counter IoT" that is almost identical; doesnt use Adafruit IO, but does use a local Webserver to graph the data. Uses the pulse from the LED as the count source, not "serial" data, and uses an interrupt. Have already compiled the code successfully, yahoo. Main difference is that it uses a NodeMCU 8266, not a Feather HUZZAH; doesn't make much difference they are both ESP8266. Does not have a board display, but I can add the Feather OLED code for that from "Geiger_WiFi_OLED_Example.ino" (usefull after all). I also want to monitor the Geiger voltage, found the code/HW for that from "another" Geiger project, uses a AD8244 buffer and a volgtage divider. The "Geiger Counter IoT" code already as examples for graphing data over time, and graphical meters for analog voltages, perfect. I learned a lot from the failed project, more about the Arduino app file structure, and includes so the time spent was not wasted. K

Code: Select all

/* ESP8266 Geiger Counter
   This sketch uses an ESP8266 to read the LED signal from the Mighty OHM Geiger counter. The data is then displayed
   using the serial console or a web browser.

     Viewing the data via web browser by going to the ip address. In this sketch the address is
     http://192.168.1.220


   ///////////////////////////////////////
   Arduino IDE Setup
   File:
      Preferences
        Add the following link to the "Additional Boards Manager URLs" field:
        http://arduino.esp8266.com/stable/package_esp8266com_index.json
   Tools:
      board: NodeMCU 1.0 (ESP-12 Module)
      programmer: USBtinyISP


  ///////////////////////////////
*/
#include <ESP8266WiFi.h>
#include "FS.h" // FOR SPIFFS


// if testing over 1000 cpm turn off debugging or the serial buffer will overload
boolean debugmode = false;

// MaxChartElements is the number of elements to display on the graph. Setting this too high
// will cause the page to take a long time to load and possibly time out

const int MaxChartElements = 60;
const char* ssid = "WiFiSSID";
const char* password = "WiFiPassword";
const int interruptPin = 4; // ~D2 // connected to + LED
const int MAXFILELINES = 1440; // approximately 24 hours
const int MAXFILES = 45; // 45 days of data


int hitCount = 0;
double startMillis;
double seconds;
double minutes;
double CPM = 0.0;
double uSv = 0.0;
double lastcSv = 0.0;
int webRefresh = 60; // how often the webpage refereshes
int WiFiStrength = 0;
int minHolder = 0;
int minuteHits = 0;
int lineCount = 0;
int fileCount = 0;
String fName = "/geiger/gdata";

boolean WiFiConnected = true;


WiFiServer server(80);

//////////////////////////////////////////////////////////////////////////////////////
// this function executes everytime there is hit to the Geiger counter             ///
//////////////////////////////////////////////////////////////////////////////////////
void pinChanged()
{

  detachInterrupt(interruptPin);


  seconds = (millis() - startMillis) / 1000;
  minutes = seconds / 60;
  hitCount++;
  minuteHits++;

  CPM = (hitCount) / minutes;
  uSv = CPM * 0.0057;

  if (debugmode)
  {
    //  Good for debugging
    Serial.print(" Hit Count: "); Serial.println(hitCount);
    Serial.print(" Time seconds: "); Serial.println(seconds);
    Serial.print(" Time minutes: "); Serial.println(minutes);
    Serial.print(" CPM: "); Serial.println(CPM);
    Serial.print(" uSv/hr: "); Serial.println(uSv);

    Serial.println(" ");
  }

  attachInterrupt(interruptPin, pinChanged, RISING);

}

//////////////////////////////////////////////////////////////////
// function used to reset variables: used for data clearing    ///
// session reset                                               ///
//////////////////////////////////////////////////////////////////

void resetVariables()
{

  //reset varialbles
  hitCount = 0;
  startMillis = millis();
  seconds = 0.0;
  minutes = 0.0;
  CPM = 0.0;
  uSv = 0.0;
  minHolder = 0;
  minuteHits = 0;
  lastcSv = 0;
  //
}

//////////////////////////////////
//    main setup function      ///
//////////////////////////////////

void setup() {

  pinMode(interruptPin, INPUT);
  startMillis = millis();
  attachInterrupt(interruptPin, pinChanged, RISING); // start counting Geiger hits

  if (debugmode)
  {
    Serial.begin(115200);
    delay(10);
  }
  SPIFFS.begin();

  ///////////////////

  Dir dir = SPIFFS.openDir("/geiger");
  while (dir.next()) {
    fileCount ++;
    if (debugmode)
    {
      Serial.print(dir.fileName());
      File f = dir.openFile("r");
      Serial.println(f.size());
    }
  }

  //////////////////


  fName += fileCount;
  fName += ".txt";
  File f = SPIFFS.open(fName, "r");
  if (!f) {
    if (debugmode)
      Serial.println("Please wait 30 secs for SPIFFS to be formatted");

    SPIFFS.format();
    if (debugmode)
      Serial.println("Spiffs formatted");

    f = SPIFFS.open(fName, "w");

    if (debugmode)
      Serial.println("Data file created");
  }
  else
  {


    if (debugmode)
      Serial.println("Data file exists");

    while (f.available()) {

      //Lets read line by line from the file
      String str = f.readStringUntil('\n');

      lineCount++;

    }

    f.close();
  }


  // Connect to WiFi network
  if (debugmode)
  {
    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);
  }

  WiFi.begin(ssid, password);

  // Set the ip address of the webserver
  // WiFi.config(WebServerIP, Gatway, Subnet)
  // or comment out the line below and DHCP will be used to obtain an IP address
  // which will be displayed via the serial console

  WiFi.config(IPAddress(192, 168, 1, 220), IPAddress(192, 168, 1, 1), IPAddress(255, 255, 255, 0));

  // connect to WiFi router
  int waitCount = 0;
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    if (debugmode)
      Serial.print(".");

    waitCount++;

    if (waitCount > 30)
    {
      WiFiConnected = false;
      break;
    }
  }


  if (WiFiConnected)
  {

    if (debugmode)
    {
      Serial.println("");
      Serial.println("WiFi connected");
    }
    // Start the server
    server.begin();

    if (debugmode)
    {
      Serial.println("Server started");

      // Print the IP address
      Serial.print("Use this URL to connect: ");
      Serial.print("http://");
      Serial.print(WiFi.localIP());
      Serial.println("/");
    }

  } else
  {
    if (debugmode)
      Serial.println("WiFi NOT connected");
  }

}

////////////////////////////////////
//       main loop function      ///
////////////////////////////////////

void loop() {

  /////// create new file every x lines of data

  if (lineCount == MAXFILELINES)
  {
    fileCount++;
    fName = "/geiger/gdata";
    fName += fileCount;
    fName += ".txt";
    lineCount = 0;

  }
  //////
  if (fileCount <= MAXFILES)
  {
    if (minutes > minHolder + 1)
    {

      minHolder++; // every minute

      File f = SPIFFS.open(fName, "a");
      if (!f) {

        if (debugmode)
          Serial.println("file open for append failed");
      }
      else
      {

        lastcSv = minuteHits * 0.0057;
        if (debugmode)
          Serial.println("====== Writing to SPIFFS file =========");

        f.print(",['"); f.print( minHolder); f.print("'"); f.print(",");
        f.print(minuteHits); f.print(",");
        f.print(lastcSv);  f.println("]");

        // the following lines will use the session averages for data
        //  f.print(CPM); f.print(",");
        //  f.print(uSv);  f.println("]");

        lineCount++;

      }
      f.close();
      minuteHits = 0; //reset per minute counter

    }
  }

  ////////////////////////////

  // check to for any web server requests. ie - browser requesting a page from the webserver
  WiFiClient client = server.available();
  if (!client) {
    return;
  }


  // Wait until the client sends some data
  WiFiStrength = WiFi.RSSI();
  if (debugmode)
    Serial.println("new client");

  // Read the first line of the request
  String request = client.readStringUntil('\r');

  if (debugmode)
    Serial.println(request);

  if (request.indexOf("/REFRESH") != -1) {
    webRefresh = 60;
  }

  if (request.indexOf("/RESET") != -1) {  // Reset Session
    resetVariables();
    webRefresh = 0;
  }

  client.flush();

  /////////////////////////////// Return the response

  client.println("HTTP/1.1 200 OK");


  if (request.indexOf("/CLEAR") != -1) {  // Clear file contents
    //    detachInterrupt(interruptPin);
    webRefresh = 0;
    if (debugmode)
      Serial.println("Clearing Data");


    Dir dir = SPIFFS.openDir("/geiger");
    while (dir.next()) {

      SPIFFS.remove(dir.fileName());

    }

    client.println("Content-Type: text/html");
    client.println(""); //  do not forget this one
    client.println("<!DOCTYPE HTML>");

    client.println("<html>");
    client.println(" <head>");

    client.println("</head><body>");
    client.println("<h1>Data Files</h1>");
    client.println("<a href=\"/\">Back</a><br><br>");
    client.println("<br><br><div style\"color:red\">Files Cleared</div>");

    client.println("<br><a href=\"/CLEAR\"\"><button>Clear Data</button></a>");
    client.println(" WARNING! This will delete all data.");

    client.println("</body></html>");

    resetVariables();
    lineCount = 0;
    fileCount = 1;
    fName = "/geiger/gdata1.txt";

    return;

  }



  ////////////////// download file
  if (request.indexOf("/gdata") != -1) {

    String fileDownloadName = request.substring(request.indexOf("/geiger"), request.indexOf("HTTP") - 1) ;
  
    client.println("Content-Type: text/plain");

    client.print("Content-Disposition: attachment;filename=");
    client.println(fileDownloadName);

    client.println("");

    File fi = SPIFFS.open(fileDownloadName, "r");
    if (!fi) {
      client.println("file open for download failed ");
      client.println(fileDownloadName.substring(1));
    }
    else
    {
      if (debugmode)
        Serial.println("====== Reading from SPIFFS file =======");

      while (fi.available()) {

        //Lets read line by line from the file
        String line = fi.readStringUntil('\n');

        client.println(line);
      }

    }
    fi.close();

    return;
  }

  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");

  client.println("<html>");
  client.println(" <head>");

  if (request.indexOf("/DATA") != -1)
  {
    client.println("</head><body>");
    client.println("<h1>Data Files</h1>");
    client.println("<a href=\"/\">Back</a><br><br>");
    if (fileCount >= MAXFILES)
    {
      client.println("<div style=\"color:red\">File limit reached. Clear data to restart data logging.</div>");
    }
    client.println("<a href=\"/CLEAR\"\"><button>Clear Data</button></a>");
    client.println(" WARNING! This will delete all data files.<br><br>");

    Dir dir = SPIFFS.openDir("/geiger");
    while (dir.next()) {

      client.print("<a href=\"");
      client.print(dir.fileName());
      client.print("\">");
      client.print(dir.fileName());
      client.println("</a><br>");
      //  File f = dir.openFile("r");
      //  client.println(f.size());
      //  client.println("<br>");
    }


    client.println("</body></html>");
    return;
  }



  if (webRefresh != 0)
  {
    client.print("<meta http-equiv=\"refresh\" content=\"");
    client.print(webRefresh);
    client.println("\">");
  }

  double CPMholder = CPM;
  double uSvholder = uSv;
  int hitHolder = hitCount;
  double minutesHolder = minutes;

  client.println("<script type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"></script> ");
  client.println("   <script type=\"text/javascript\"> ");
  client.println("    google.charts.load('current', {'packages':['corechart','gauge']}); ");
  client.println("    google.charts.setOnLoadCallback(drawChart); ");
  client.println("    google.charts.setOnLoadCallback(drawChartG); ");
  client.println("    google.charts.setOnLoadCallback(drawChartGM); ");
  client.println("    google.charts.setOnLoadCallback(drawChartGH); ");
 
  /////////

  // draw low emission uSv guage
  client.println("   function drawChartG() {");

  client.println("      var data = google.visualization.arrayToDataTable([ ");
  client.println("        ['Label', 'Value'], ");
  client.print("        ['\xB5Sv/hr',  ");
  //
  if (lastcSv != 0)
    client.print(lastcSv); // minute by minute
  else
    client.print(uSvholder);  // shows the average

  client.println(" ], ");
  client.println("       ]); ");
  // setup the google chart options here
  client.println("    var options = {");
  client.println("      width: 250, height: 150,");
  client.println("      min: 0, max: 1,");
  client.println("      greenFrom: 0, greenTo: .25,");
  client.println("      yellowFrom: .25, yellowTo: .75,");
  client.println("      redFrom: .75, redTo: 1,");
  client.println("       minorTicks: 5");
  client.println("    };");
  client.println("   var chart = new google.visualization.Gauge(document.getElementById('chart_div'));");
  client.println("  chart.draw(data, options);");
  client.println("  }");

  //////////////

  // draw medium emission uSv guage
  client.println("   function drawChartGM() {");

  client.println("      var data = google.visualization.arrayToDataTable([ ");
  client.println("        ['Label', 'Value'], ");
  client.print("        ['\xB5Sv/hr',  ");
  //
  if (lastcSv != 0)
    client.print(lastcSv); // minute by minute
  else
    client.print(uSvholder);  // shows the average

  client.println(" ], ");
  client.println("       ]); ");
  // setup the google chart options here
  client.println("    var options = {");
  client.println("      width: 250, height: 150,");
  client.println("      min: 0, max: 10,");
  client.println("      greenFrom: 0, greenTo: 2.5,");
  client.println("      yellowFrom: 2.5, yellowTo: 7.5,");
  client.println("      redFrom: 7.5, redTo: 10,");
  client.println("       minorTicks: 5");
  client.println("    };");
  client.println("   var chart = new google.visualization.Gauge(document.getElementById('chart_divGM'));");
  client.println("  chart.draw(data, options);");
  client.println("  }");

  //////////////

  // draw high emission uSv guage
  client.println("   function drawChartGH() {");

  client.println("      var data = google.visualization.arrayToDataTable([ ");
  client.println("        ['Label', 'Value'], ");
  client.print("        ['\xB5Sv/hr',  ");
  //
  if (lastcSv != 0)
    client.print(lastcSv); // minute by minute
  else
    client.print(uSvholder);  // shows the average

  client.println(" ], ");
  client.println("       ]); ");
  // setup the google chart options here
  client.println("    var options = {");
  client.println("      width: 250, height: 150,");
  client.println("      min: 0, max: 100,");
  client.println("      greenFrom: 0, greenTo: 25,");
  client.println("      yellowFrom: 25, yellowTo: 75,");
  client.println("      redFrom: 75, redTo: 100,");
  client.println("       minorTicks: 5");
  client.println("    };");
  client.println("   var chart = new google.visualization.Gauge(document.getElementById('chart_divGH'));");
  client.println("  chart.draw(data, options);");
  client.println("  }");

 ///////////////////

  double analogValue = analogRead(A0); // read the analog signal

  // convert the analog signal to voltage
  // the ESP2866 A0 reads between 0 and ~3 volts, producing a corresponding value
  // between 0 and 1024. The equation below will convert the value to a voltage value.

  double analogVolts = (analogValue * 3.12) / 1024;

  ///////
  client.println("    function drawChart() { ");

  client.println("     var data = google.visualization.arrayToDataTable([ ");
  client.println("       ['Hit', 'CPM', '\xB5Sv / hr'] ");

  // open file for reading
  int fileSize = 0;

  if (lineCount > 0)
  {
    File fi = SPIFFS.open(fName, "r");
    if (!fi) {
      client.println("<br>file open for read failed");
    }
    else
    {

      if (debugmode)
        Serial.println("====== Reading from SPIFFS file =======");

      fileSize = fi.size();
      int loopCount = 1;
      while (fi.available()) {

        //Lets read line by line from the file
        String line = fi.readStringUntil('\n');

        if (loopCount >= (lineCount - MaxChartElements))
          client.println(line);

        loopCount++;

      }
    }
    fi.close();

  } else // no data lines
  {
    client.print(",['No Data - click Refresh in ");
    client.print(60 - seconds);
    client.println(" seconds',0,0]");
  }

  client.println("     ]); ");
  client.println("     var options = { ");
  client.println("        title: 'Geiger Activity', ");
  client.println("        curveType: 'function', ");

  client.println("  series: {");
  client.println("         0: {targetAxisIndex: 0},");
  client.println("         1: {targetAxisIndex: 1}");
  client.println("       },");

  client.println("  vAxes: { ");
  client.println("         // Adds titles to each axis. ");
  client.println("         0: {title: 'CPM'}, ");
  client.println("         1: {title: '\xB5Sv / hr'} ");
  client.println("       }, ");

  client.println("  hAxes: { ");
  client.println("         // Adds titles to each axis. ");
  client.println("         0: {title: 'time elapsed (minutes)'}, ");
  client.println("         1: {title: ''} ");
  client.println("       }, ");

  client.println("         legend: { position: 'bottom' } ");
  client.println("       }; ");

  client.println("       var chart = new google.visualization.LineChart(document.getElementById('curve_chart')); ");

  client.println("       chart.draw(data, options); ");
  client.println("      } ");
  client.println("    </script> ");



  client.println("  </head>");
  client.println("  <body>");
  client.println("  <h1>Geiger Counter IoT</h1>");
  if (webRefresh != 0) {
    client.print("<table><tr><td>This page will referesh every ");
    client.print(webRefresh);
    client.print(" seconds ");
  }
  else
  {
    client.print("<div><b style=\"color:red;\">REFRESH NOW</b> ");
  }
  client.println("<a href=\"/REFRESH\"\"><button>Refresh</button></a></td>");

  client.print("<td style=\"text-align:center; width:650px;\">");
  if (fileCount >= MAXFILES)
  {
    client.print("<div style=\"color:red\">File limit reached. Data logging stopped.<br>Click Data Files and Clear Data to restart data logging.</div>");
  }

  client.println("<a href=\"/DATA\"\">Data Files</a></td></tr></table>");

  client.println("<table><tr><td style=\"width:190px; vertical-align:top;\">");


  client.print("<b>Session Details</b>");


  client.println("<br>Hit Count: ");
  client.println(hitHolder);
  client.print("<br>Total Minutes: ");
  client.println(minutesHolder);
  client.print("<br>Avg CPM: <b>");
  client.println(CPMholder);
  client.print("</b><br>Avg µSv/hr: <b>");
  client.println(uSvholder);
  client.print("</b><br>Avg millirems/hr: <b>");
  client.println(uSvholder * .1);
  client.println("</b><br><a href=\"/RESET\"\"><button>Reset Session</button></a>");

  client.println("</td><td>");
  client.println("<div id=\"chart_div\" style=\"width: 250px;\"></div>");
  client.println("</td><td>");
  client.println("<div id=\"chart_divGM\" style=\"width: 250px;\"></div>");
  client.println("</td><td>");
  client.println("<div id=\"chart_divGH\" style=\"width: 250px;\"></div>");
  client.println("</td></tr></table>");

  client.println("<div id=\"curve_chart\" style=\"width: 1000px; height: 500px\"></div>");

  client.println("<br>WiFi Signal Strength: ");
  client.println(WiFiStrength);
  client.print("dBm <br>Geiger Power: "); client.print(analogVolts);  client.println("volts");


  /*
    // some usefull debugging information
    // check remaining data
    FSInfo fs_info;
    SPIFFS.info(fs_info);

    int fileTotalKB = (int)fs_info.totalBytes;
    int fileUsedKB = (int)fs_info.usedBytes;

    client.print("<div>fileTotalBytes: ");

    client.print(fileTotalKB);
    client.print("<br>fileUsedBytes: ");
    client.print(fileUsedKB);


    float flashChipSize = (float)ESP.getFlashChipSize() / 1024.0 / 1024.0;
    client.print("<br>chipSize: ");
    client.print(flashChipSize);
  */

  ///////////////////////////

  client.println("</body>");
  client.println("</html>");


  if (debugmode)
  {
    Serial.println("Client disonnected");
    Serial.println("");
  }


}

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: HUZZAH Feather "EspSoftSerialRx.cpp" compile error

Post by mikeysklar »

Nice find. It looks like you were able to get everything going with the exception of AIO and can add in the OLED.

User avatar
keli
 
Posts: 77
Joined: Mon Jul 07, 2008 9:53 am

Re: HUZZAH Feather "EspSoftSerialRx.cpp" compile error

Post by keli »

Have been going through the "Geiger_Counter_IoT" sketch and found two things I really like; a nice code example on how to "draw colored analog meters (guages)" on a website page! Another example shows you how to use the SPIFFS (SPI Flash File System) to log "data" in this case "uSv - Microsieverts" for up to a 2 week period. Checkout the "whole" sketch posted earlier. A warning is given that SPIFFS is currently deprecated, "The actual File and Dir objects returned from either filesystem behave in the same manner and documentation is applicable to both. To convert most applications from SPIFFS to LittleFS simply requires changing the SPIFFS.begin() to LittleFS.begin() and SPIFFS.open() to LittleFS.open() with the rest of the code remaining untouched.". Two links to SPIFFS documentation below. The examples open up all kinds of avenues to other things I might do. K

https://arduino-esp8266.readthedocs.io/ ... ystem.html
https://thebigpotatoe.github.io/Effortless-SPIFFS/

Code: Select all

  
// draw medium emission uSv guage
  client.println("   function drawChartGM() {");

  client.println("      var data = google.visualization.arrayToDataTable([ ");
  client.println("        ['Label', 'Value'], ");
  client.print("        ['\xB5Sv/hr',  ");
  //
  if (lastcSv != 0)
    client.print(lastcSv); // minute by minute
  else
    client.print(uSvholder);  // shows the average

  client.println(" ], ");
  client.println("       ]); ");
  // setup the google chart options here
  client.println("    var options = {");
  client.println("      width: 250, height: 150,");
  client.println("      min: 0, max: 10,");
  client.println("      greenFrom: 0, greenTo: 2.5,");
  client.println("      yellowFrom: 2.5, yellowTo: 7.5,");
  client.println("      redFrom: 7.5, redTo: 10,");
  client.println("       minorTicks: 5");
  client.println("    };");
  client.println("   var chart = new google.visualization.Gauge(document.getElementById('chart_divGM'));");
  client.println("  chart.draw(data, options);");
  client.println("  }");

// SPIFF example
if (fileCount <= MAXFILES)
  {
    if (minutes > minHolder + 1)
    {

      minHolder++; // every minute

      File f = SPIFFS.open(fName, "a");
      if (!f) {

        if (debugmode)
          Serial.println("file open for append failed");
      }
      else
      {

        lastcSv = minuteHits * 0.0057;
        if (debugmode)
          Serial.println("====== Writing to SPIFFS file =========");

        f.print(",['"); f.print( minHolder); f.print("'"); f.print(",");
        f.print(minuteHits); f.print(",");
        f.print(lastcSv);  f.println("]");

        // the following lines will use the session averages for data
        //  f.print(CPM); f.print(",");
        //  f.print(uSv);  f.println("]");

        lineCount++;

      }
      f.close();
      minuteHits = 0; //reset per minute counter

    }
  } // End if

User avatar
keli
 
Posts: 77
Joined: Mon Jul 07, 2008 9:53 am

Re: HUZZAH Feather "EspSoftSerialRx.cpp" compile error

Post by keli »

I wanted to run the Geiger code before I got my Feather ESP8266 Huzzah to see if I could get it to compile, no problem, yahoo! Got the Huzzah and decided to upload the code to the microcontroller and see if it would work even without the Geiger connected (or built yet). What I got was not what I expected. The "basint_picture.jpg" shows a nightmare, nothing worked, and I didn't understand what was going on in the Arduino "Serial Monitor". All I could think of doing was to go through the code ripping out lines till I could get just a "println" to work. The code has some really nice debug statements to help, but they were not working at all, after I turned them on. I even ran some example ESP82266 programs to see what happened, they worked. By accident I noticed some thing. Interrupts! I looked at "attachInterrupt(interruptPin, pinChanged, RISING)" and it occurred to me what probably (?) was happening. I had "nothing" attached to to the Huzzah, just USB power. The interrupt was seeing a floating rising edge on the unconnected pin ("const int interruptPin = 4; // ~D2 // connected to + LED") and interrupting "over and over" again. That's the crazy stuff I was seeing on the Serial Monitor. Found an appropriate place to comment out the interrupt and things worked, see "geigerweb.jpg" below. Have a working "Geiger_Counter_IoT.ino" now, just have to add the input from the Geiger counter. Have to still add an OLED Feather, analog inputs for battery and Geiger tube voltages, and temperature. But the base is working. Keli

attachInterrupt(interruptPin, pinChanged, RISING);

//attachInterrupt(interruptPin, pinChanged, RISING);

Code: Select all

//////////////////////////////////
//    main setup function      ///
//////////////////////////////////

void setup() {

  pinMode(interruptPin, INPUT);
  startMillis = millis();
  
  // interruptPin = ?; Name of interrupt func pinChanged; Trig on RISING edge
  // Start counting Geiger hits
  // *** Turn interrupt back on here ***
  // attachInterrupt(interruptPin, pinChanged, RISING);

  if (debugmode)
  {
    Serial.begin(115200);
    delay(10);
  }
Attachments
What happens when you comment out the interrupt.
What happens when you comment out the interrupt.
delint_picture.jpg (79.06 KiB) Viewed 219 times
What happens when you include the interrupt
What happens when you include the interrupt
basint_picture.jpg (105.38 KiB) Viewed 219 times
What the Geiger web site should look like
What the Geiger web site should look like
geigerweb.jpg (90.14 KiB) Viewed 219 times

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: HUZZAH Feather "EspSoftSerialRx.cpp" compile error

Post by mikeysklar »

Good work. Nice job debugging the issue down to the interrupt being enabled.

User avatar
keli
 
Posts: 77
Joined: Mon Jul 07, 2008 9:53 am

Re: HUZZAH Feather "EspSoftSerialRx.cpp" compile error

Post by keli »

Thought I had every thing figured out about what was causing my crash on the Huzzah when I enabled the interrupt, not so fast. As soon as I included the line "attachInterrupt(interruptPin, pinChanged, RISING);" the Huzzah would go into "panic" mode, whether the interrupt was connected to GND, or not. So my idea that the interrupt panic was caused by a "floating" interrupt pin was wrong. I went searching for some "good" interrupt code to see if it would work on the Huzzah. Found this site for the good code.

https://daniellethurow.com/blog/2021/9/ ... ah-esp8266

His explanation helped me understand what was going on.

"The ESP8266 has a slightly different setup than the standard chips used in Arduinos, which results in an extra step. When declaring the interrupt function, you have to "prepend" ICACHE_RAM_ATTR to the function definition. This tells the linker to put this function in RAM instead of flash, where the rest of the program goes. The exact reasons why seem a bit murky. Different posts and forum questions online give no reason beyond “you gotta put this here”, or give different reasons why. But the basics as I understand it is that the interrupt handler (aka the code that runs during the interrupt) needs to be stored in RAM on the ESP8266, not flash, where it would normally be stored without that ICACHE_RAM_ATTR. This is because the interrupt code can run at any time, and if the chip is in the middle of writing or reading to flash, trying to also run the interrupt handler code in flash at the same time will cause the chip to crash. Crashing is bad, so the ESP8266 Arduino code has a built-in check to make sure all interrupt handlers are in the RAM. If it’s not, the code will pre-emptively crash with an error that says “ISR not in IRAM!”."

"you have to prepend ICACHE_RAM_ATTR to the interrupt function definition."

This has to be the way to "call" the interrupt function: "ICACHE_RAM_ATTR void detectsButton()"

This causes a crash of the interrupt function: "void pinChanged()"

Good interrupt function call in code:
attachInterrupt(digitalPinToInterrupt(GPIO_INTERRUPT_PIN), detectsButton, RISING);

Bad interrupt function call in code:
attachInterrupt(interruptPin, pinChanged, RISING);

Why the original code did not crash for the author, I don't understand. Both code examples are for the ESP82266's. As a note I can unhook the interrupt pin and the Huzzah does not panic, keeps on trucking.

Plan now is to move the good interrupt code over to the Geiger code. Nice part since I added the Push Button Switch (PBS), and LED to the Huzzah proto board for the intgerrupt testing, I don't have to hook up the Geiger counter yet to see if every thing works, I can just bang on the PBS. Keli

Code: Select all

#define GPIO_INTERRUPT_PIN 4
#define LED_PIN 14
#define WAIT_TIME 250
#define DEBOUNCE_TIME 10


volatile bool buttonPressed = false;
volatile unsigned long lastTrigger = millis();
volatile int bounce = 0;
int prevBounceCount = 0;

ICACHE_RAM_ATTR void detectsButton() {
  //NOTE because in ISR, millis() call will return the same value every time
  
  //only trigger if I didn't just trigger DEBOUNCE_TIME ago
  //lastTrigger > millis() means millis has overflowed
  if (lastTrigger > millis() || lastTrigger+DEBOUNCE_TIME < millis())
  {
    lastTrigger = millis(); 
    buttonPressed = true;
  }
  else{
    bounce++;
  }
 
}

void setup() {
  Serial.begin(115200);
  Serial.println("Starting sketch");
  pinMode(LED_PIN, OUTPUT);
  pinMode(GPIO_INTERRUPT_PIN, INPUT_PULLUP);

  attachInterrupt(digitalPinToInterrupt(GPIO_INTERRUPT_PIN), detectsButton, RISING);

}

void loop() {

  //lastTrigger > millis() means millis has overflowed
  if (buttonPressed && (lastTrigger > millis() || lastTrigger+WAIT_TIME <= millis())){
     Serial.println("button was pressed, time to turn off LED");
     digitalWrite(LED_PIN, LOW);
     buttonPressed = false;
  }
  else if (buttonPressed){
    digitalWrite(LED_PIN, HIGH);
  }
  if (bounce != prevBounceCount){
    Serial.println("Debounced");
    prevBounceCount = bounce;
  }
  
  //Other functionality goes here...
  delay(250);

}
Attachments
Pic of the interrupt driven serial monitor output.
Pic of the interrupt driven serial monitor output.
interupt_picture.jpg (106.44 KiB) Viewed 178 times
Pic of simple HW to check the interrupt.
Pic of simple HW to check the interrupt.
proto_picture.jpg (128.25 KiB) Viewed 178 times

User avatar
keli
 
Posts: 77
Joined: Mon Jul 07, 2008 9:53 am

Re: HUZZAH Feather "EspSoftSerialRx.cpp" compile error

Post by keli »

Found out some thing interesting, if I prepend "ICACHE_RAM_ATTR" to the interrupt call in the original Geiger code that caused the Huzzah to "panic", i.e. "ICACHE_RAM_ATTR void pinChanged()" the panic for the included interrupt goes away. All I can figure out is that at some time in the past (?), Arduino must have "automatically" and transparently did that call "prepend" for you, for the original code to have worked. Have another problem going on (refresh without re-displaying the gauges at a 60 second cycle rate), but now things are working more as I think they should (SPIFFS writing data out to flash, interrupt picking up what would be pulses from the Geiger counter, data displayed on the Feather OLED, web page graphics working). Some of the global variable "typing" used in the interrupt call might be wrong causing the bug, have to experiment to find out, more likely some thing else is causing the it. Keli

Code: Select all

////////////////////////////////////////////////////////////////////////////
// This function executes everytime there is hit on the Geiger counter /////
////////////////////////////////////////////////////////////////////////////
ICACHE_RAM_ATTR void pinChanged()
{
  detachInterrupt(interruptPin);
  
  seconds = (millis() - startMillis) / 1000;
  minutes = seconds / 60;
  hitCount++;
  minuteHits++;

  CPM = (hitCount) / minutes;

  // The standard unit of radiation dosing in an area is the micro-Sievert/hour (uSv/hr).
  // For this tube, multiply its CPM by 0.0057 to get the equivalent uSv/hr radiation level.
  uSv = CPM * 0.0057;

  if (debugmode)
  {
    //  Good for debugging
    Serial.print(" Hit Count: "); Serial.println(hitCount);
    Serial.print(" Time seconds: "); Serial.println(seconds);
    Serial.print(" Time minutes: "); Serial.println(minutes);
    Serial.print(" CPM: "); Serial.println(CPM);
    Serial.print(" uSv/hr: "); Serial.println(uSv);

    Serial.println(" ");
  }

  attachInterrupt(interruptPin, pinChanged, RISING);
}
Attachments
Shows data being read out to the SPIFFS.
Shows data being read out to the SPIFFS.
datapg.jpg (88.07 KiB) Viewed 157 times
Shows graphing of a little data going on.
Shows graphing of a little data going on.
graph.jpg (116.07 KiB) Viewed 157 times

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”