Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years ago.
MMA7455 can't do what i want
Did someone use this sensor before? This is my code
#include "mbed.h" #include "MMA7455.h" #define PI 3.14159265358979323846264 MMA7455 acc(p32,p31); Serial pc(USBTX, USBRX); int main() { int32_t x,y,z; double x1,y1,z1; double xg,yg,zg; double xd,yd,zd; acc.setMode(MMA7455::ModeMeasurement); acc.setRange(MMA7455::Range_2g); acc.calibrate(); while(1) { acc.read(x,y,z); xg=x*0.016; yg=y*0.016; zg=z*0.016; x1=xg/(sqrt(pow(yg,2.0)+pow(zg,2.0))); y1=yg/(sqrt(pow(xg,2.0)+pow(zg,2.0))); z1=(sqrt(pow(yg,2.0)+pow(xg,2.0)))/zg; xd=atan(x1); yd=atan(y1); zd=atan(z1); pc.printf("xd: %.4f ",xd*180.0/PI); pc.printf("yd: %.4f ",yd*180.0/PI); pc.printf("zd: %.4f ",zd*180.0/PI); pc.printf("\r\n\n"); wait(0.2); } }
My problem is about when MMA7455 doesn't move. The degree can't keep 0 0 0 (x,y,z degree) It's the problem of my code or the sensor ? Thx very much!!
1 Answer
8 years ago.
if you print the xg,yg and zg, you may find they are all zero....
xg = double(x) * 0.016;
I have found this issue sometimes...