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.
11 years, 5 months ago.
How do I read both the x,y,z axis and tilt registers using MMA7660 library
I can read and use the x,y,z registers of the MMA7660 with the library with out issue.
When I try to use the x,y,z axis and the side, orientation registers as well the side and orientation return as unknown.
When I remove the read of the x,y,z axis registers then the side and orientation registers are able to be read fine
My code is as follows: - Its a work in progress to log the registers to USB for suitablity testing the hardware is the application board
include "mbed.h" #include "MMA7660.h" #include "C12832_lcd.h" #include "MSCFileSystem.h" C12832_LCD lcd; //On board LCD display MMA7660 MMA(p28, p27); //I2C Accelerometer DigitalOut connectionLed(LED1); //Accel OK LED MSCFileSystem fs("fs"); int main() { char *Orientation, *Side *temp[4]; float x=0,y=0,z=0; int r=0,s=0; FILE *fp = fopen("/fs/test.csv","w"); // Setup Heading row fprintf(fp,"x-axis,y-axis,z-axis,Orientaion,Side \n"); lcd.cls(); //clear LCD screen if (MMA.testConnection()) connectionLed = 1; //Accelerometer init OK while(1) { r = MMA.getOrientation(); // Read the orientation s = MMA.getSide(); // Read the side // Read in the axis values x = MMA.x(); y = MMA.y(); z = MMA.z(); lcd.locate(0,3); lcd.printf("x-axis: %f \n",x); lcd.printf("y-axis: %f \n",y); lcd.printf("z-axis: %f \n",z); lcd.locate(90,3); switch (r) //MMA.getOrientation()) { case MMA7660::Up: lcd.printf("Up "); Orientation = "Up"; break; case MMA7660::Down: lcd.printf("Down "); Orientation = "Down"; break; case MMA7660::Left: lcd.printf("Left "); Orientation = "Left"; break; case MMA7660::Right: lcd.printf("Right "); Orientation = "Right"; break; default: lcd.printf("Unsure"); Orientation = "Unsure"; break; } lcd.locate(90,15); switch (s) //MMA.getSide()) { case MMA7660::Front: lcd.printf("Front "); Side = "Front"; break; case MMA7660::Back: lcd.printf("Back "); Side = "Back"; break; default: lcd.printf("Unsure"); Side = "Unsure"; break; } fprintf(fp,"%f,%f,%f,%s,%s\n",x,y,z,Orientation,Side); fclose(fp); wait(0.5); FILE *fp = fopen("/fs/test.csv","a"); // Append the data to the file }
1 Answer
11 years, 5 months ago.
Hey,
Good find, my bad :P.
Issue summarized: The sensor has an active state, and the library tracks in which state it is. This was faulty, so by default it put it enabled, but its internal tracker was initialized to its default: inactive. When just reading the side this is ignored, and it worked fine. But as soon as you read an axis, it checked the internal tracker, saw it was inactive, made it active for one measurement, retrieved the measurement, and set it back to inactive. So now it didn't do updates anymore, and the orientations went to unknown. It should be fixed now.
Click on the lib, at the right side there is an update button. That should solve your issues.
Erik