So I,m trying to read a Current Sensor (AC current).
To get rid of interference (caused by wifi activity) I take 10 measurements within a second.
Get the peak to peak value of each and keep the 8 smallest measurements (works well enough).
Then average them and print out the result.
Either disable the watchdog or pat it once in a while As the last thing in the loop "while((millis()-start_time) < 100)" try to call "yield()" or put in a small delay.
Danois90:
Either disable the watchdog or pat it once in a while As the last thing in the loop "while((millis()-start_time) < 100)" try to call "yield()" or put in a small delay.
hmmm.. very interesting, read up on that... I had no clue.
So correct me if I'm wrong but for loops that take a long time to finish and prevent background processes to execute you need to add yield(). (not sure exactly what that does though...
Thanks Danois90!!!
I edited the code and after a long while running smoothly I got this....
.
.
.
.
.
23.00 - - - - - - - - volt ->0.02246
23.00 - - - - - - - - volt ->0.02344
24.00 - - - - - - - - volt ->0.02246
24.00 - - - - - - - - volt ->0.02246
23.00 - - - - - - - - volt ->0.02441
24.00 - - - - - - - - volt ->0.0
Exception (0):
epc1=0x402026a2 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
ctx: cont
sp: 3ffef750 end: 3ffef970 offset: 01a0
Decoding stack results
0x40202692: Print::printFloat(double, unsigned char) at C:\Users\Nisteri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1\cores\esp8266\Print.cpp line 287
0x402026d8: Print::print(double, int) at C:\Users\Nisteri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1\cores\esp8266\Print.cpp line 149
0x402026f5: Print::println(double, int) at C:\Users\Nisteri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1\cores\esp8266\Print.cpp line 214
0x402021c8: loop() at C:\Users\Nisteri\Documents\Arduino\LIGHTS.v.0.1/LIGHTS.v.0.1.ino line 13
0x40202888: loop_wrapper() at C:\Users\Nisteri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1\cores\esp8266\core_esp8266_main.cpp line 121
its actually a ESP-12e, with a range of 0-1v
I use a voltage divider from 3.3v with 5.6k-1k to supply the A0 with ~0.5v and read the voltage across the burden resistor of the CT.
I'm just testing the stability right now so no current passes through the CT.
AWOL: while((millis()-start_time) < 100)Don't block for such a ridiculously long time.
Look at blink without delay example for clues.
"ridiculously long time" :o I have a lot to learn... but I get what you mean. Will have a look!
Danois90:
Either disable the watchdog or pat it once in a while As the last thing in the loop "while((millis()-start_time) < 100)" try to call "yield()" or put in a small delay.
What exactly is this "watchdog" good for besides being one more thing that the programmer has to keep track of?
In your loop method you are calling "AvgPeak2Peak()" twice (one time should be enough), and each call takes at least 1 second and this causes the loop method to take at least 2 seconds to complete - this is really not a good idea. You should modify your code to take one reading for each loop and when you have enough readings, they should be processed.
#define READING_DELAY 10 //millis
#define NUM_READINGS 10 //10 readings with 10 millis delay = 100ms per reading
//lastMillis is initialized to a value which will force a reading during first loop execution
unsigned long lastMillis = 0xFFFF;
int maxValue = 0, minValue = 1024;
byte numReadings = 0;
void loop()
{
unsigned long ms = millis();
if (ms - lastMillis >= READING_DELAY)
{
lastMillis = ms;
int value = analogRead(A0);
if (value < minValue) minValue = value;
else if (value > maxValue) maxValue = value;
numReadings++;
if (numReadings >= NUM_READINGS)
{
//Here Peak2Peak would be a non-blocking reading similar to your "Peak2Peak()"
//but without any watchdog insidents
int Peak2Peak = maxValue - minValue;
//Reset for next reading
maxValue = 0;
minValue = 1024;
numReadings = 0;
}
}
}
Next step would be to extend the code in order to implement a non-blocking representation of "AvgPeak2Peak()"
I'm not sure why you get an exception while printing a float. It may be another watchdog insident or it may be caused by an invalid float value (NaN).
Greece, Kanivaloss means cannibal.
Although it's spelled wrong.
Correctly it would be more like kannivalos, which is too often taken. So I stick with the wrong version
But I'm intrigued about that Finish meaning now....