Hello guys I need help, I am working on this project conencting an ESP32 with an ADXL345, and then getting data and then calculating steps, jump height and stride length. I am communicating through the I2C, I am having some problems and I need help, here is what I get when I run my code:
Guru Meditation Error: Core 1 panic'ed (IllegalInstruction). Exception was unhandled.
Memory dump at 0x400d163c: fa87811a 000008a9 a5004136
Core 1 register dump:
PC : 0x400d1642 PS : 0x00060f30 A0 : 0x800d164d A1 : 0x3ffb27d0
A2 : 0x3ffc0158 A3 : 0x00000053 A4 : 0x00000001 A5 : 0x000001ff
A6 : 0x00000000 A7 : 0x3ffc015c A8 : 0x3ffc0154 A9 : 0x3ffb27c0
A10 : 0x3f260806 A11 : 0x42480000 A12 : 0x1eb851f0 A13 : 0x3f28f5c2
A14 : 0x00000000 A15 : 0x00000000 SAR : 0x0000001d EXCCAUSE: 0x00000000
EXCVADDR: 0x00000000 LBEG : 0x4008578c LEND : 0x400857a2 LCOUNT : 0x00000000
Backtrace:0x400d163f:0x3ffb27d00x400d164a:0x3ffb2800 0x400d387f:0x3ffb2820
and Here is my code, please someone help:
#include <Wire.h>
float xavg = 0, yavg = 0, zavg = 0;
float xcur = 0, ycur = 0, zcur = 0;
float xnxt = 0, ynxt = 0, znxt = 0;
int steps = 0;
void setup() {
adxl345_init();
read_av_acc();
}
void loop() {
for (int i = 0; i < 50; i++) {
Wire.beginTransmission(0x53);
Wire.write(0x32);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte x0 = Wire.read();
Wire.beginTransmission(0x53);
Wire.write(0x33);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte x1 = Wire.read();
x1 = x1 & 0x03;
uint16_t x = (x1 << 8) + x0;
int16_t xf = x;
if (xf > 511)
{
xf = xf - 1024;
}
float xa = xf * 0.004;
xcur = xcur + xa;
Wire.beginTransmission(0x53);
Wire.write(0x34);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte y0 = Wire.read();
Wire.beginTransmission(0x53);
Wire.write(0x35);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte y1 = Wire.read();
y1 = y1 & 0x03;
uint16_t y = (y1 << 8) + y0;
int16_t yf = y;
if (yf > 511)
{
yf = yf - 1024;
}
float ya = yf * 0.004;
ycur = ycur + ya;
Wire.beginTransmission(0x53);
Wire.write(0x36);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte z0 = Wire.read();
Wire.beginTransmission(0x53);
Wire.write(0x37);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte z1 = Wire.read();
z1 = z1 & 0x03;
uint16_t z = (z1 << 8) + z0;
int16_t zf = z;
if (zf > 511)
{
zf = zf - 1024;
}
float za = zf * 0.004;
zcur = zcur + za;
}
xcur = xcur / 50;
ycur = ycur / 50;
zcur = zcur / 50;
float acc = sqrt(((xcur - xavg) * (xcur - xavg)) +
((ycur - yavg) * (ycur - yavg)) +
((zcur - zavg) * (zcur - zavg)));
delay(250);
//Next Acceleration
for (int i = 0; i < 50; i++) {
Wire.beginTransmission(0x53);
Wire.write(0x32);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte x0 = Wire.read();
Wire.beginTransmission(0x53);
Wire.write(0x33);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte x1 = Wire.read();
x1 = x1 & 0x03;
uint16_t x = (x1 << 8) + x0;
int16_t xf = x;
if (xf > 511)
{
xf = xf - 1024;
}
float xa = xf * 0.004;
xnxt = xnxt + xa;
Wire.beginTransmission(0x53);
Wire.write(0x34);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte y0 = Wire.read();
Wire.beginTransmission(0x53);
Wire.write(0x35);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte y1 = Wire.read();
y1 = y1 & 0x03;
uint16_t y = (y1 << 8) + y0;
int16_t yf = y;
if (yf > 511)
{
yf = yf - 1024;
}
float ya = yf * 0.004;
ynxt = ynxt + ya;
Wire.beginTransmission(0x53);
Wire.write(0x36);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte z0 = Wire.read();
Wire.beginTransmission(0x53);
Wire.write(0x37);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte z1 = Wire.read();
z1 = z1 & 0x03;
uint16_t z = (z1 << 8) + z0;
int16_t zf = z;
if (zf > 511)
{
zf = zf - 1024;
}
float za = zf * 0.004;
znxt = znxt + za;
}
xnxt = xnxt / 50;
ynxt = ynxt / 50;
znxt = znxt / 50;
float acc2 = sqrt(((xnxt - xavg) * (xnxt - xavg)) +
((ynxt - yavg) * (ynxt - yavg)) +
((znxt - zavg) * (znxt - zavg)));
if (acc2 - acc > 0.05)
{
steps = steps + 1;
}
// Constants for stride length calculation
const float stepLengthMeters = 0.75; // Assuming an average step length of 0.75 meters
float strideLength = steps * stepLengthMeters; // Calculate the total distance covered in meters
// Constants for jump height calculation
const float gravity = 9.81; // Acceleration due to gravity in m/s^2
float maxAcceleration = 0.0; // Variable to store the maximum acceleration observed
// Inside the loop where acceleration is calculated, update the maximum acceleration
if (acc > maxAcceleration) {
maxAcceleration = acc; // Update the maximum acceleration if a higher value is found
}
float jumpHeight = (maxAcceleration * maxAcceleration) / (2 * gravity); // Using kinematic equations to
//estimate jump height
Serial.print("steps: ");
Serial.print(steps);
Serial.print("\t");
Serial.print("Stride Length: ");
Serial.print(strideLength);
Serial.print(" meters\t");
Serial.print("Estimated Jump Height: ");
Serial.print(jumpHeight);
Serial.print(" meters");
Serial.println();
delay(400);
}
void adxl345_init() {
Serial.begin(115200);
Wire.begin();
Wire.beginTransmission(0x53);
Wire.write(0x2C);
Wire.write(0x08);
Wire.endTransmission();
Wire.beginTransmission(0x53);
Wire.write(0x31);
Wire.write(0x08);
Wire.endTransmission();
Wire.beginTransmission(0x53);
Wire.write(0x2D);
Wire.write(0x08);
Wire.endTransmission();
}
float read_av_acc() {
for (int i = 0; i < 50; i++) {
Wire.beginTransmission(0x53);
Wire.write(0x32);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte x0 = Wire.read();
Wire.beginTransmission(0x53);
Wire.write(0x33);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte x1 = Wire.read();
x1 = x1 & 0x03;
uint16_t x = (x1 << 8) + x0;
int16_t xf = x;
if (xf > 511)
{
xf = xf - 1024;
}
float xa = xf * 0.004;
xavg = xavg + xa;
Wire.beginTransmission(0x53);
Wire.write(0x34);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte y0 = Wire.read();
Wire.beginTransmission(0x53);
Wire.write(0x35);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte y1 = Wire.read();
y1 = y1 & 0x03;
uint16_t y = (y1 << 8) + y0;
int16_t yf = y;
if (yf > 511)
{
yf = yf - 1024;
}
float ya = yf * 0.004;
yavg = yavg + ya;
Wire.beginTransmission(0x53);
Wire.write(0x36);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte z0 = Wire.read();
Wire.beginTransmission(0x53);
Wire.write(0x37);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte z1 = Wire.read();
z1 = z1 & 0x03;
uint16_t z = (z1 << 8) + z0;
int16_t zf = z;
if (zf > 511)
{
zf = zf - 1024;
}
float za = zf * 0.004;
zavg = zavg + za;
}
xavg = xavg / 50;
yavg = yavg / 50;
zavg = zavg / 50;
}
Guru Meditation Error: Core 1 panic'ed
Re: Guru Meditation Error: Core 1 panic'ed
float read_av_acc() has no return statement. So function returns nothing and crashes.
Who is online
Users browsing this forum: Baidu [Spider] and 117 guests