MMA8451Q Breakout board - 'MMA8451Q couldn't start'


#1

I’m currently working on a project ‘Human Fall detection’ using MMA8451Q accelerometer. I’m using MMA8451Q breakout board from Adafruit and Arduino Uno. I had downloaded the Adafruit library for MMA8451Q sensor and tried to run the demo code in Arduino IDE. But, it is showing ‘Couldn’t Start’ in the serial monitor when I run this code:
#include <Wire.h>
#include <Adafruit_MMA8451.h>
#include <Adafruit_Sensor.h>

Adafruit_MMA8451 mma = Adafruit_MMA8451();

void setup(void) {
Serial.begin(9600);

Serial.println(“Adafruit MMA8451 test!”);
mma.begin();

if (! mma.begin()) {
Serial.println(“Couldnt start”);
while (1);
}
Serial.println(“MMA8451 found!”);

mma.setRange(MMA8451_RANGE_2_G);

Serial.print("Range = "); Serial.print(2 << mma.getRange());
Serial.println(“G”);

}

void loop() {
// Read the ‘raw’ data in 14-bit counts
mma.read();
Serial.print(“X:\t”); Serial.print(mma.x);
Serial.print("\tY:\t"); Serial.print(mma.y);
Serial.print("\tZ:\t"); Serial.print(mma.z);
Serial.println();

/* Get a new sensor event */
sensors_event_t event;
mma.getEvent(&event);

/* Display the results (acceleration is measured in m/s^2) */
Serial.print(“X: \t”); Serial.print(event.acceleration.x); Serial.print("\t");
Serial.print(“Y: \t”); Serial.print(event.acceleration.y); Serial.print("\t");
Serial.print(“Z: \t”); Serial.print(event.acceleration.z); Serial.print("\t");
Serial.println("m/s^2 ");

/* Get the orientation of the sensor */
uint8_t o = mma.getOrientation();

switch (o) {
case MMA8451_PL_PUF:
Serial.println(“Portrait Up Front”);
break;
case MMA8451_PL_PUB:
Serial.println(“Portrait Up Back”);
break;
case MMA8451_PL_PDF:
Serial.println(“Portrait Down Front”);
break;
case MMA8451_PL_PDB:
Serial.println(“Portrait Down Back”);
break;
case MMA8451_PL_LRF:
Serial.println(“Landscape Right Front”);
break;
case MMA8451_PL_LRB:
Serial.println(“Landscape Right Back”);
break;
case MMA8451_PL_LLF:
Serial.println(“Landscape Left Front”);
break;
case MMA8451_PL_LLB:
Serial.println(“Landscape Left Back”);
break;
}
Serial.println();
delay(500);

}

Initially, I thought the sensor is not detected because it is not soldered but I removed this part of the code
if (! mma.begin()) {
Serial.println(“Couldnt start”);
while (1);
}
and uploaded it, I could see the ‘Sensor is found’ and some X, Y,Z values but all the values are same and they hadn’t changed when I changed the orientation of the sensor.
Could anyone please help me out with this issue?


#2

Your first reaction was probably correct, it is likely you have a hardware problem as the code appears to be telling you it can’t find the sensor. I’d suggest checking the wiring to your sensor (adafruit usually has good tutorials on connecting their devices). You could also load a Fritzing sketch of your hardware layout here.

Peter


#3

Thank you. Soldering the sensor worked