NodeMcuEsp12 Lolin self resetting only when i knock once on my Piezo sensor Help

Hello, i have a NodeMcu V3 Lolin i will attach the code (the code is based on a secret Knock by Steve Hoefer, modified by Patduino and now it can work with 3 different secret knocks and also theres other code included for IFTTT requests)

Im only facing one problem. When i knock only once it resets and i get this error:

Exception (0):
epc1=0x40106889 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

ctx: cont 
sp: 3ffef760 end: 3ffef9b0 offset: 01a0

>>>stack>>>
3ffef900:  4022fa50 00000004 00000000 40228ba1  
3ffef910:  40228c05 60000a00 00000000 40201ddf  
3ffef920:  00000006 00000001 00050007 00050005  
3ffef930:  00000000 00000050 40219ea4 3ffee8c8  
3ffef940:  40201126 00000096 00000096 00001036  
3ffef950:  00000000 00000001 3ffee8c8 4020229c  
3ffef960:  00000000 0000000a 40219ea4 3ffee97c  
3ffef970:  40201126 3ffee7d8 3ffee8c8 3ffee984  
3ffef980:  3fffdad0 00000000 3ffee784 40202345  
3ffef990:  3fffdad0 00000000 3ffee97c 402036d0  
3ffef9a0:  feefeffe feefeffe 3ffee990 40100718  
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld

everything else from the code works (the 2 knocks turns on my lights and the 3 knocks turns off my lights) and it never crashes. Any ideas? Please help i tried a lot of things that i read about capacitors etc.

Best Regards

New_KNOCK2.0.ino (13.5 KB)

ORIGINAL_Knock.ino (11.9 KB)

ESP8266_IFTTT.ino (2.9 KB)

Install the "ESP exception decoder" in your Arduino IDE.

Reset cause 2: reset pin.
Possible power supply issue.

Which of the three sketches you actually use? Please post it inline.

wvmarle:
Install the "ESP exception decoder" in your Arduino IDE.

Reset cause 2: reset pin.
Possible power supply issue.

Which of the three sketches you actually use? Please post it inline.

thanks for your reply, i use the one called newKnock2.0 but i get the error with original knock too. As a power supply im using the usb cable and the mb102 breadboard power supply. I added a 100uf capacitor in the vin and ground. I will try powering up the nodemcu with a battery. When i get home i'll post the code inline. Thanks

I tried with 2 AAA batteries in parallel + Usb and i tried a 70 Amps 5 volt power supply. Now it seems like im getting exception (0) and it restarts. I downloaded the esp decoder but i cant make it appear in my arduino IDE Tools section. Do you think that its compatible with the newest IDE?

I'm using the decoder on IDE 1.8.1. Works fine.

ok so i decoded and this is what i get

Exception 0: Illegal instruction
Decoding 13 results
0x40106889: __divsi3 at d:\ivan\projects\arduinoesp\toolchain\dl\gcc-xtensa\build-2\xtensa-lx106-elf\libgcc/../../../libgcc/config/xtensa/lib1funcs.S line 638
0x4022f9e8: pm_wakeup_init at ?? line ?
0x40228b39: test_tout at ?? line ?
0x40228b9d: test_tout at ?? line ?
0x40201e84: validateKnock() at C:\Users\FedX\Dropbox\esp8266\New_KNOCK2.0/New_KNOCK2.0.ino line 371 (discriminator 2)
0x40219e3c: system_adc_read at ?? line ?
0x40201126: __analogRead at C:\Users\FedX\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_wiring_analog.c line 33
0x40202216: listenToSecretKnock() at C:\Users\FedX\Dropbox\esp8266\New_KNOCK2.0/New_KNOCK2.0.ino line 173
0x40219e3c: system_adc_read at ?? line ?
0x40201126: __analogRead at C:\Users\FedX\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_wiring_analog.c line 33
0x40202345: loop at C:\Users\FedX\Dropbox\esp8266\New_KNOCK2.0/New_KNOCK2.0.ino line 113
0x40203668: loop_wrapper at C:\Users\FedX\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_main.cpp line 56
0x40100718: cont_norm at C:\Users\FedX\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/cont.S line 109

I can see that the first error shows the path of someone called ivan on line 613 Maybe im missing a library or something?

If you're missing a library it wouldn't have compiled, so it's from something you installed.

From the name I'm guessing it's some kind of division, and it's an illegal instruction. Are you by any chance trying to divide something by zero?

Ivan is the first name of one of the lead developers of the ESP8266 core for Arduino, igrr. I wonder if that path is coming from a pre-compiled file in the ESP8266 toolchain?

pert:
Ivan is the first name of one of the lead developers of the ESP8266 core for Arduino, igrr. I wonder if that path is coming from a pre-compiled file in the ESP8266 toolchain?

Hey!, any clues on how i could fix that?

wvmarle:
If you're missing a library it wouldn't have compiled, so it's from something you installed.

From the name I'm guessing it's some kind of division, and it's an illegal instruction. Are you by any chance trying to divide something by zero?

i tried to post the code inline but it says it exceeds the maximum characters allowed. Idk if the code is trying to devide something by zero. the esp decoder shows an error at Validatedknock() in line 375. i can see this

 // normalize knocks
  for (i = 0; i < maximumKnocks; i++) { // Normalize the times
    knockReadings[i] = map(knockReadings[i], 0, maxKnockInterval, 0, 100);
  }

I just removed that part of the code and it stops crashing but the multiple knocks stops working too perhaps theres something wrong in there?

FedxE:
Hey!, any clues on how i could fix that?

I was saying that the strange path may not actually indicate a problem.

Hi Fedx,

I'll look over the code, but it takes 2 knocks to define a time interval. Maybe there is a problem with the logic in that case. It might be as simple as checking to see that you've got at least 2 knocks before checking the pattern.

Hello! The reason why its important that with one knock it doesn't restart is because the piezo sensor will be attached to my bed stand or to my bed's headboard. If by accident i hit once that surface, i lay down a glass or water or anything else it will automaitcally restart :confused: i really hope there's fix for this and that you could help me out. Thanks a lot for your help! :slight_smile:

Cheers.
-FedX

Hi FedxE,

So I looked at the code and things look ok to me. But just to be safe I counted the number of knocks in the validate function and return a "no knock pattern detected" indication if there is only a single knock.

I only tried it with an Uno -- I don't have an ESP, so I can't completely reconstruct your setup. Give this a try. Hopefully, it'll work!

Patduino.

New_KNOCK2.1.ino (13.9 KB)

patduino:
Hi FedxE,

So I looked at the code and things look ok to me. But just to be safe I counted the number of knocks in the validate function and return a "no knock pattern detected" indication if there is only a single knock.

I only tried it with an Uno -- I don't have an ESP, so I can't completely reconstruct your setup. Give this a try. Hopefully, it'll work!

Patduino.

Everything is running perfectly. THANK YOU!!!