So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By walders
#71908 H, first post here :) , I have a project with the node ncu v1.0 esp8266 and I need some ideas on how to troubleshoot/ debug please.

I'm using arduino ide 1.8.2
board Nodemcu 1.0
board manager url: http://arduino.esp8266.com/stable/packa ... index.json

The circuit has a single sensor and my code to detect sensor change is written in an interupt. Time interval between interupts is recorded and sent to thingspeak.

The issue is that although the functionality is sound, after a day or two, The serial monitor stops reporting intervals, this is reflected in the thingspeak channel. The sensor has an oboard led which indicate changes are still being detected. No errors are seen on the serial monitor. Pressing the reset button gets it going again, for a day or two then it silently fails again.

I've tried lookin at FreeHeap which is fine, and Serial.printf to see where it stops without any solid info as to what's going in.

\here's a portion of mr code with the interupt routine and setup
Code: Select allvoid isr()
{
 float pulselength;
 float now = micros();
 pulseNow = now;


 if ( (pulseNow - pulseThen) > resolution )  //drop the very first pulse as uncertain length
 {
   Serial.print("interrupt start ..");
   Serial.println(tn++);
   ++numPulses;
   Serial.println("Pulse detected ");
   Serial.print(" ");
 
   pulselength = (pulseNow - pulseThen) /1000000;
   keeppulse += pulselength;
   Serial.print("pulselength..");
   Serial.print(pulselength);
   Serial.print(" keeppulse..");
   Serial.print(keeppulse);
   Serial.print(" numPulses ");
   Serial.println(numPulses);
   pulseThen = pulseNow;
   Serial.printf("interupt heap size: %u\n", ESP.getFreeHeap());
   Serial.println("interrupt end ..");
 }

}
 
void setup() {
  // put your setup code here, to run once:
  struct wifisettings::settings pete;
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(115200);
  Serial.println();

  wifisettings::set_wizsetting(&wiz);
  wifimanager::doWifiManagerSetup(&wiz);
  wifisettings::get_wizsetting(&wiz);

  //  display.display();
  delay(4000);
  //  display.clearDisplay();
 Serial.println("interval counter v9.2\n");
 pinMode(2, OUTPUT); //probe output on pin D4
 attachInterrupt(0, isr, RISING);    // define interrupt 0
 numPulses = 0;                                                                                                                                                                                                                                                                                                                                                                                                         
 keeppulse = 0;
   if (drd.detectDoubleReset()) {
    Serial.println("Double Reset Detected");
    doConfig();
  } else {
    Serial.println("No Double Reset Detected");
  }
  Serial.printf("Setup heap size: %u\n", ESP.getFreeHeap());
  }
User avatar
By Narfel
#71947 It is unlikely to be the reason, but the most recent version of the Arduino IDE is 1.8.5 as of writing this post. Also, a NodeMCU 1.0 board can mean a certain hardware or just the version of NodeMCU running on some hardware. If you are referring to the former my experience with the V3 of those is pretty similar, giving up without any indication after variable amount of time. After some testing i chalked it up to shoddy chinese flash, which i accepted as the truth to conserve my sanity.
You didn't write how you are powering that thing. Is it a stable source? Those things are fickle with power sources and what works for days on end suddenly can change because of the relative humidity on the moon changing :D
User avatar
By schufti
#71951 Hi,
my comments are more of a general nature and may not give even the right direction to solve your problem.

a) an ISR should be in IRAM to avoid problems with the cache controller (hw flaw)

void ICACHE_RAM_ATTR AddSec(void) {
addsec = true;
}

b) the ISR should be as minimalistic as possible.
no delays
no serial output
best to just set a flag and deal with it in loop().
User avatar
By McChubby007
#71953 Please, please spend some time researching best practice when writing an isr. Not a week goes by on this very forum, where the same mistakes are being made. It really is not a tricky subject, but you can't just grope around in the dark - it is a science and follows a set of rules. As has been said, minimal, no interrupt generation, no serial out, careful with non-atomic operations, shared data etc. Please look through the forum.