-->
Page 1 of 2

External Interrupt RISING and FALLING example

PostPosted: Mon Apr 06, 2015 10:50 pm
by swilson
I can get everything compiled and uploaded fine onto the ESP-12. No problems as far as that goes. Example scripts I have tried work great. I am having problems with the following script and I have tried everything I know of to get it to work. When I power the esp it boots up, connects to wifi and shows correct IP. It then proceeds to run a randomly the HIGH or LOW detection until it gets to the end and then loops right back to the wificlient and says connecting again and just sits there. I only want the program to run and sit there until the pin goes HIGH (3.3V) or LOW (GRD) and runs whichever pertains to HIGh or LOW. I don't know why it is connecting and then nothing when it hasn't even detected a trigger. I even added more delays to see if it was just outrunning the server. Don't know what I am doing wrong and hopefully you can spot it. Also if you have any suggestions on how to make my sketch smaller and more efficient please let me know.

UPDATE: see post #5 for my working example.

Re: Having trouble with input HIGH LOW detection

PostPosted: Tue Apr 07, 2015 2:02 am
by gerardwr
From your description i gather you want to take action when the level on the GPIO changes from LOW to HIGH.

In your code you do not check for such a transition, but merely look at the current pin level.

Hope this helps.

Re: Having trouble with input HIGH LOW detection

PostPosted: Tue Apr 07, 2015 9:07 am
by Dennis
Wow, this surely must result in a massive amount of mails - you are sending them as fast as the arduino, eh, the esp8266 is looping over its main loop... each loop equals one new email being sent.... tststs. The only limiting factor is the googlemail API responsiveness. :lol:

Hint: you want to attach an interrupt to the pin in question, and use it to trigger "send mail" event...

regards

Re: Having trouble with input HIGH LOW detection

PostPosted: Tue Apr 07, 2015 3:34 pm
by swilson
Lol. Well yes it would send a massive amount of emails if that part completely worked. I will figure that out later.

I did decide on using an interrupt and have it somewhat working. Since I need to be alerted when it comes on and goes off I set 2 pins as interrupts. One is for RISING and the other for FALLING. I then tie the 2 pins together. When the 2 pins see voltage (rising) then the one interrupt is triggered. When they see ground (falling) then the other is triggered. My interrupt functions have state = 1 for rising or high and state = 0 for falling or low. My loop function has if (state == 1) and if (state == 0) for each thing I want to do with state = 2 at the end of each thing. I declare state volatile = 2 at the beginning of the sketch.

Does that sound about right? Or could I use a CHANGE interrupt and check for high and low for each thing to do?

Server and esp8266 seem to be having a falling out about halfway through the commands.

I will try to do some led testing to get the interrupts just right before I worry with the server problem.

I will try to post some code this evening.

Thanks everyone.