Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By erniberni
#29349 Hi all,
I tried the pi calculation performance test I found here http://forum.arduino.cc/index.php?topic=138802.msg1042841#msg1042841.
I did some minor modification, but the code crashes everytime.
Code: Select all//
// Pi_2
//
// Steve Curd
// December 2012
//
// This program approximates pi utilizing the Newton's approximation.  It quickly
// converges on the first 5-6 digits of precision, but converges verrrry slowly
// after that.  For example, it takes over a million iterations to get to 7-8
// significant digits.
//
// http://forum.arduino.cc/index.php?topic=138802.0
//

#define ITERATIONS 1000000L    // number of iterations
#define FLASH 10000            // blink LED every 1000 iterations

void setup() {
  pinMode(2, OUTPUT);     // Initialize the BUILTIN_LED pin as an output
 Serial.begin(115200);
 delay(1000);
}
void loop() {
 unsigned long start, time;
 unsigned long niter=ITERATIONS;
 int LEDcounter = 0;
 boolean alternate = false;
 unsigned long i, count=0;
 float x = 1.0;
 float temp, pi=1.0;
 Serial.print("Beginning ");
 Serial.print(niter);
 Serial.println(" iterations...");
 Serial.println();
 start = millis(); 
 for ( i = 2; i < niter; i++) {
   x *= -1.0;
   pi += x / (2.0f*(float)i-1.0f);
   if (LEDcounter++ > FLASH) {
     LEDcounter = 0;
     if (alternate) {
       digitalWrite(2, HIGH);
       alternate = false;
     } else {
       digitalWrite(2, LOW);
       alternate = true;
     }
     temp = 40000000.0 * pi;
//     module.setDisplayToDecNumber( temp, 0x80);
   }
 }
 time = millis() - start;
 pi = pi * 4.0;
 Serial.print("# of trials = ");
 Serial.println(niter);
 Serial.print("Estimate of pi = ");
 Serial.println(pi, 10);
 Serial.print("Time: "); Serial.print(time); Serial.println(" ms");
 delay(2000);
}

The message on the serial interface is
Code: Select allBeginning 1000000 iterations...


ctx: cont
sp: 3ffe9b00 end: 3ffe9cf0 offset: 01b0

>>>stack>>>
3ffe9cb0:  000004c6 000016df 00000001 402010a3 
3ffe9cc0:  3fffdc20 00000000 3ffe9d14 3ffe9d1c 
3ffe9cd0:  3fffdc20 00000000 3ffe9d14 4020184a 
3ffe9ce0:  00000000 00000000 3ffe8cd0 40100118 
<<<stack<<<

 ets Jan  8 2013,rst cause:1, boot mode:(3,7)

load 0x4010f000, len 1264, room 16
tail 0
chksum 0x42
csum 0x42
~ld
Beginning 1000000 iterations...
....

After commenting out this single line with the float calculation
Code: Select all pi += x / (2.0f*(float)i-1.0f);

the program doesn't crash anymore.
The code is running fine on an Arduino Uno.

Any idea?
Reinhard
User avatar
By schufti
#29365 Hi,
chances are good it's a wd timeout.

Put the preparations in the setup() and resolve the for loop to use the main loop().

to get best timing, disable WiFi first in setup()
User avatar
By erniberni
#29396
Put the preparations in the setup() and resolve the for loop to use the main loop().
to get best timing, disable WiFi first in setup()


Could you please give me a more detailed description?
User avatar
By igrr
#29408 True, this is software watchdog reset. Try reducing the number of iterations or adding a yield(); statement inside the if (LEDcounter++ > FLASH) block.