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

Moderator: igrr

User avatar
By Artur Gaspar
#24910 Good day.
I have a problem when trying to run the SQRT function.
The system hangs and returns the following message:

Here's the test code . note that if you uncomment the line " x = 2; " the program works normally.
It also works normally use ATAN in place of SQRT .
ATAN2 have also hangs .
Someone went through it and managed to solve ?
Thanks.

Code: Select all#include "math.h"
#include "I2Cdev.h"
#include "MPU6050.h"
#include "Wire.h"

MPU6050 accelgyro;

int16_t ax, ay, az;
int16_t gx, gy, gz;

void setup() {
  Wire.begin();
  Serial.begin(115200);
  // initialize device
  Serial.println("Initializing I2C devices...");
  accelgyro.initialize();
  // verify connection
  Serial.println("Testing device connections...");
  Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
  Serial.print("\n");
}

void loop() {
  double g;

  // read raw accel/gyro measurements from device
  accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

  //ax= 2;  //uncomment and works

  Serial.print("ax=");
  Serial.println(ax);
  g = sqrt(ax);
  Serial.print("g=");
  Serial.println(g);

  delay(200);
}
User avatar
By martinayotte
#24911 Maybe it is because the call to accelgyro.getMotion6() is returning negative numbers.
What your prints are showing ? Are they meanful values ?
You can change the variable types to uint16_t instead of int16_t. to see if it will help.
User avatar
By Artur Gaspar
#24921 Now it's worse!
I simplified to the maximum and the error remains .

Code: Select all#include "math.h"
#include "I2Cdev.h"
#include "MPU6050.h"
#include "Wire.h"

MPU6050 accelgyro;

short int ax, ay, az;
short int gx, gy, gz;

void setup() {
  Wire.begin();
  Serial.begin(115200);
  // initialize device
  Serial.println("Initializing I2C devices...");
  accelgyro.initialize();
  // verify connection
  Serial.println("Testing device connections...");
  Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
  Serial.print("\n");
}

void loop() {
  double g;
  Serial.println("Read X");
  ax = accelgyro.getAccelerationX();
  Serial.print("ax=");
  Serial.println(ax);
  g = sqrt(ax);
  Serial.print("g=");
  Serial.println(g);

  delay(200);
}


The serial output:
Code: Select allInitializing I2C devices...
Testing device connections...
MPU6050 connection successful

Read X
ax=0

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

wdt reset


Works fine with POW and ATAN.
Hang with SQRT and ATAN2.