I'm trying to find the simplest way to make a not too much accurate pedometer (20% error) with MMA8451.
To achieve that goal I have understand that first of all I have to configure MMA8451 properly to obtain the right data (not too few neither too much) from accelerometer.
Then I have to pull out steps from data !!
I'm looking for any kind of suggestion ...
Tnx
Hello Federico,
Thank you for writing.
In your case, I highly recommend you to use the MMA9553. The MMA9553 is an intelligent motion sensing pedometer, and is much more easy to make a pedometer with this IC than with the MMA8451.
This is how you can configure the MMA9553.
void MMA9553L_Init(void){
pedometer_config(); // Write all the Pedometer configuration
pedometer_enable(); // Enable the Pedometer application
pedometer_active();
pedometer_wakeup(); // Disable Sleep Mode and enable Wake-up Mode
}
The pedometer_config function, is the following.
void pedometer_config(void){
unsigned char MBx[20]= {0x15, 0x20, 0x00, 0x10,
SLEEP_MIN_MSB, SLEEP_MIN_LSB,
SLEEP_MAX_MSB, SLEEP_MAX_LSB,
SLEEP_COUNT_THR_MSB, SLEEP_COUNT_THR_LSB,
CONFIG, STEP_LENGTH,
HEIGHT, WEIGHT, FILTER_STEP,
MALE_FILTER_TIME, STEP_PERIOD,
STEP_COALESCE, ACT_COUNT_THR_MSB,
ACT_COUNT_THR_LSB};
I2C_WriteMultiRegisters(MMA9553L_ADDRESS, MMA9553_SUB_ADDR, sizeof(MBx), MBx);
}
The pedometer_enable function, is the following.
void pedometer_enable(void){
unsigned char MBx[5]={0x17, 0x20, 0x05, 0x01, 0x00};
I2C_WriteMultiRegisters(MMA9553L_ADDRESS, MMA9553_SUB_ADDR, sizeof(MBx), MBx);
}
The pedometer_active function, is the following.
void pedometer_active(void){
unsigned char MBx[5]={0x15, 0x20, 0x06, 0x01, 0x80};
I2C_WriteMultiRegisters(MMA9553L_ADDRESS, MMA9553_SUB_ADDR, sizeof(MBx), MBx);
}
The pedometer_wakeup function, is the following.
void pedometer_wakeup(void){
unsigned char MBx[5]={0x12, 0x20, 0x06, 0x01, 0x00};
I2C_WriteMultiRegisters(MMA9553L_ADDRESS, MMA9553_SUB_ADDR, sizeof(MBx), MBx);
}
This is how you could read the steps.
void Read_Step(void)
{
pedometer_cmd_readstatus();
I2C_ReadMultiRegisters(MMA9553L_ADDRESS, MMA9553_SUB_ADDR, 2, MBx);
if (MBx[1]==0x80){ // Is COCO flag set?
I2C_ReadMultiRegisters(MMA9553L_ADDRESS, MMA9553_SUB_ADDR, sizeof(MBx), MBx); // 12 bytes status data + 4 bytes frame start
StepCount = ((short) (MBx[6]<<8 | MBx[7]));
// Send the step count to the terminal
//Hex_to_Dec(StepCount);
}
}
The pedometer_cmd_readstatus function is the following.
void pedometer_cmd_readstatus(void){
unsigned char MBx[4]={0x15, 0x30, 0x00, 0x0C};
I2C_WriteMultiRegisters(MMA9553L_ADDRESS, MMA9553_SUB_ADDR, sizeof(MBx), MBx);
}
Finally, these are the macros that you are going to need.
#define MMA9553L_ADDRESS 0x4C
#define MMA9553_SUB_ADDR 0x00
#define SLEEP_MIN_MSB 0x0C
#define SLEEP_MIN_LSB 0xE0
#define SLEEP_MAX_MSB 0x13
#define SLEEP_MAX_LSB 0x20
#define SLEEP_COUNT_THR_MSB 0x00
#define SLEEP_COUNT_THR_LSB 0x96
#define CONFIG 0x60
#define STEP_LENGTH 0x50
#define HEIGHT 0xAA // Height in centimeters, 170 (0xAA)
#define WEIGHT 0x44 // Weight in kilograms, 68 (0x44)
#define FILTER_STEP 0x04
#define MALE_FILTER_TIME 0x03 // Male
#define STEP_PERIOD 0x05
#define STEP_COALESCE 0x01
#define ACT_COUNT_THR_MSB 0x00
#define ACT_COUNT_THR_LSB 0x00
I hope this information will be useful for you.
Best Regards,
Diego