HELP with Arduino and Parallax MMA7455

Hello,

I would like to first make out that I am not very experienced with the Arduino platform nor am I very experienced with electronics but I am a competent learner. My problem is that I am having trouble understanding how to use the Arduino board with the Parallax MMA7455 Accelerometer. Has anybody else tried to use this with the Arduino. If so your help will be most appreciated.

Thank You
Tomas

I've looked at the datasheet for the MMA7455, and it is quite a complex device.

Have you ever used I2C or SPI interfaces?

There are libraries to talk to I2C or SPI, but there is quite a lot to understand about the MMA7455.

Have far have you got?

GB

If you haven't already done so, you should carefully read the Parallax documentation:

http://www.parallax.com/Portals/0/Downloads/docs/prod/sens/28526-MMA7455-3axisAccel-v1.1.pdf

There's some important stuff there about how to hook the thing up, and how to read the device output. You will separately need to read the datasheet to understand how the registers work. For example, the mode control register ($16) will need to be set to the measurement mode and g-level. Notice that it defaults to +/-8G, and standby mode (that is, all 0 for the 4 LSB). If you want +/-2G (for example), and measurement mode, you'd have to set the lower four bits to

1001

so the register would have to contain $x9 (where x represents the upper four bits, which determine the SPI mode and whether or not a value is sent out an interrupt line: you can probably leave those bits all 0, so you'd have reg $16 contain $09).

The I2C or SPI Arduino library you use should show you how to output values to registers, and how to read registers on the MMA.

Thanks a lot. This will be a great help. ;D

I think that my main problem arises when trying to hook up the accelerometer. I want to hoop it up via an SPI connection. I know how to wire up the ground and the voltage pins but i dont really understand how to wire up the CLK, DATA and CS pins coming from the accelerometer module. Any help with this would be great and will hopefully enable me to greatly progress with my project

On page 5 of http://www.parallax.com/Portals/0/Downloads/docs/prod/sens/28526-MMA7455-3axisAccel-v1.1.pdf
It explains which pins to wire up.
Looking at it, it looks like it connects ATmega SCK to SPC on the board.
It wants the MOSI and MISO of the ATmega joined together and fed into DATA (I've never seen that before, I'd need to think about this)
and, I think CS can be tied high with a resistor (e.g. 1K), or to an Arduino digital out pin, which can switch it on with a HIGH.

You can see what MISO, MOSI and SCK correspond to by looking at a pin map or schematic, e.g. ATmega168/328.

HTH
GB

Thanks thats great. The link you posted describing the pin layout of the microprocessor was a great help

Can anybody just confirm how to hook up the data line of the Accelerometer to the arduino board. Thanks a lot gbulmer for your help, i just wish to confirm your suspicions.

:slight_smile:

Not trying to persuade you against using this device but if electronics is not your forte you might want to consider using an analog accelerometer like this one Triple Axis Accelerometer Breakout - MMA7260Q - SEN-00252 - SparkFun Electronics instead of the digital one. THe analog ones are much easier to connect and use (depending on what you're doing).

If you aren't confident about wiring up SPI, use I2C.

The ATmega pin map shows which pins are I2C, and there are only two. You'll need a couple of resistors (the Parallax data sheet recommends 4.7k[ch937]). There is an I2C/TWI library.

THe analog ones are much easier to connect and use (depending on what you're doing).

A few of my micromouse colleagues have a strong opposite view. They say the digital accelerometers are easier to use.
The analogue accelerometers usually need signal processing, whereas the digital ones do enough of it that the values are okay 'raw'.
Having said that, there is a bit of filtering on that sparkfun board which should help.

GB

Thanks again gbulmer

You have been a great help. I feel now I can wire this thing up

Cheers :smiley:

Seriously need help. I think I have hooked up my accelerometer correctly to the arduino and I have come up with some software to run it, however I have run into problems. I have noticed that every time the Wire.endTransmission() function is called the program hangs. Do you think this is because it has been wired up incorrectly?

#include <Wire.h>

#define ACCELEROMETER 0x1D //Address for Accelerometer

//REGISTERS
#define MODE_CONTROL  0x16 //Mode control register
#define PULSE_DET     0x1B //Pulse detection threshold limit value
#define X_OUT         0x06 //8 bit register containing value for X
#define Y_OUT         0x07 //8 bit register containing value for Y
#define Z_OUT         0x08 //8 bit register containing value for Z
#define DETECTION     0x0A //Detection source register

//VALUES
#define Z_PULSE       0x4  //Pulse detected on Z-axis
#define SENSITIVITY   0x25 //Default sensitivity level

//required setup function
void setup() {
    Wire.begin();
    Serial.begin(9600);
    accWrite(MODE_CONTROL, SENSITIVITY);
}

//required loop function
void loop() {
    Serial.println("Begin");
    accRead(MODE_CONTROL);
    delay(100);
    Serial.println("Done");
}

//function to write byte data into a register
void accWrite(byte address, byte data) {
    Wire.beginTransmission(ACCELEROMETER);
    Wire.send(address);
    Wire.send(data);
    Wire.endTransmission();
}

//function to read byte data from a register
byte accRead(byte address){
    byte val = 0x00;
    Wire.beginTransmission(ACCELEROMETER);
    Wire.send(address);
    Wire.requestFrom(ACCELEROMETER, 1);
    val = Wire.receive();
    Serial.println(val);
    Wire.endTransmission();
    return val;
}

Thanks again

So it never gets past the first Wire.endTransmission(); in accWrite

void accWrite(byte address, byte data) {
    Wire.beginTransmission(ACCELEROMETER);
    Wire.send(address);
    Wire.send(data);
    Wire.endTransmission();
}

first called from

void setup() {
    Wire.begin();
    Serial.begin(9600);
    accWrite(MODE_CONTROL, SENSITIVITY);
}

Yes?
If you put LEDs onto the two I2C wires, can you see them flicker?

Right, I have it working now, but the registers that should contain numbers for the X Y Z coordinates out put funny ASCII characters.

/*
  Accelerometer
  
  A Program which takes input from an accelerometer and outputs the
  data to the serial port
  
  Hardware:      Parallax MMA7455
  Concept Usage: Games controller
*/

#include <Wire.h>

#define ACCELEROMETER 0x1D //Address for Accelerometer

//REGISTERS
#define MODE_CONTROL  0x16 //Mode control register
#define PULSE_DET     0x1B //Pulse detection threshold limit value
#define X_OUT         0x06 //8 bit register containing value for X
#define Y_OUT         0x07 //8 bit register containing value for Y
#define Z_OUT         0x08 //8 bit register containing value for Z
#define DETECTION     0x0A //Detection source register

//VALUES
#define Z_PULSE       0x40 //Pulse detected on Z-axis
#define SENSEVALUE    0x25 //Default sensitivity level

//required setup function
void setup() {
    Wire.begin();
    Serial.begin(9600);
    accWrite(MODE_CONTROL, SENSEVALUE);
}

//required loop function
void loop() {
    Serial.print("X: ");
    Serial.print(accRead(X_OUT));
    Serial.print("   Y: ");
    Serial.print(accRead(Y_OUT));
    Serial.print("   Z: ");
    Serial.println(accRead(Z_OUT));
    delay(100);
}

//function to write byte data into a register
void accWrite(byte address, byte data) {
    Wire.beginTransmission(ACCELEROMETER);
    Wire.send(address);
    Wire.send(data);
    Wire.endTransmission();
}

//function to read byte data from a register
byte accRead(byte address){
    byte val = 0x00;
    Wire.beginTransmission(ACCELEROMETER);
    Wire.send(address);
    Wire.endTransmission();
    Wire.requestFrom(ACCELEROMETER, 1);
    if(Wire.available() > 0) {
        val = Wire.receive();
    }
    Wire.endTransmission();
    return val;
}

The output I get is like this:
X: ú Y: å Z: P
X: ü Y: æ Z: O
X: û Y: å Z: P
Ill keep hacking away to try fix it, but I have had no luck so far

No worries, I fixed it. I stupidly forgot to cast the byte value, returned by the receive() function, to an integer before returning from the accRead() function

Thank you all for your help, especially gbulmer, you have been great help

When you do Serial.print(accRead(X_OUT));

The compiler thinks it should be printing a single character, hence the weird character.

Change byte accRead(byte address){
to

unsigned int accRead(byte address){

or Serial.print((unsigned int)accRead(X_OUT));
and it should print something more useful.
[edit]Ooops - our posts crossed over. You got it[/edit]

Thanks anyway, in fact ill probably change my casting technique over to using a return type of Unsigned int

Cheers

This was really cool - I had one on the board already with no doco on how to use it?

I am guessing (speculating) that it needs calibration? I notice that the X/Y values are consistently high (around 250) and the Z value is consistently low (65) while the board is at rest on the table. :-/

That may sound a little bit odd, but is understandable.

If the sensor is to show both + acceleration, and - acceleration, no acceleration (0g) should be a ‘mid value’. If the z axis is small, flip the board over, and put it flat on the table. Hopefully the z axis is now significantly bigger.

Experiment with testing each axis for minimum, maximum and mid (0g) values.

keep one edge (lets call that A) ‘flat’ on the table, and gently lift the opposite edge (call that C) towards vertical. One of the sensor values (X or Y) should change a lot. Now put C flat, and lift A. The same sensor value should change, but in the opposite direction.

Now put it flat, and repeat the process with the other two edges (B and D) of the board, and see one sensor change a lot.

That should show you the range of values from + and - 1g.

HTH - GB

Hi,
I need help with the MMA 7455 accelerometer module. I found your arduino progarmme useful but unfortunately I could not get it to work. I am using Hercules to read the serial out put data from the arduino once it has been connected to a accelerometer module, I only find zeros in the out put from the xyz accelerometer out put data streams. Please help me.