Accelerometer MMA7361 readings pausing

Hi!

I hooked up the accelerometer to an Arduino UNO according to this tutorial.

I am using the AcceleroMMA7361 library and the sketch in the tutorial. But application needs to read the x-axis continuously so I am not using a delay anywhere.

It has been working the whole day without a problem, up until an hour ago. All of a sudden the readings are paused. I get readings for 500 milliseconds, and then nothing for 500 milliseconds, then readings for 500 milliseconds etc.

I didn’t change the physical connections. I uploaded the AnalogInSerialOut sketch to read from one of the axis pins connected to an analog pin, and I am still getting the same pause. So I guess something is broken, but I don’t understand what. I could buy a new one, but I want to be sure I’m not doing anything wrong so that I don’t break it again!

The wiring is according to this diagram.

AcceleroMMA7361 library code:

#include <AcceleroMMA7361.h>
AcceleroMMA7361 accelero;
int x;
int y;
int z;
void setup()
{
 Serial.begin(9600);
 accelero.begin(13, 12, 11, 10, A0, A1, A2);
 accelero.setARefVoltage(5); //sets the AREF voltage to 3.3V
 accelero.setSensitivity(LOW); //sets the sensitivity to +/-6G
 accelero.calibrate();
}
void loop()
{
 x = accelero.getXAccel();
 y = accelero.getYAccel();
 z = accelero.getZAccel();
 Serial.print("\nx: ");
 Serial.print(x);
 Serial.print(" \ty: ");
 Serial.print(y);
 Serial.print(" \tz: ");
 Serial.print(z);
 Serial.print("\tG*10^-2");
}

Analog reading:

const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to

int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 255);
  // change the analog out value:
  analogWrite(analogOutPin, outputValue);

  // print the results to the serial monitor:
  Serial.print("sensor = " );
  Serial.print(sensorValue);
  Serial.print("\t output = ");
  Serial.println(outputValue);

  // wait 2 milliseconds before the next loop
  // for the analog-to-digital converter to settle
  // after the last reading:
  delay(2);
}

Any help is appreciated, thank you!

Post the code, using code tags ("</>" button) and a wiring diagram.

I added the code and a link to a diagram explaining how I've connected it.

Thank you!

so I am not using a delay anywhere.

The code you posted has delays, so it could not be the code you are actually running.

Sorry, posted the wrong code. I updated it.

The code that reads the analog value only has a 2 millisecond delay. But the readings stops for 500 milliseconds at a time.

I found an old accelerometer of another kind that does the same thing. So I’m thinking it’s a hardware issue. Can it get over heated and mess something up?

The input buffers on whatever computer is reading the serial data stream may be overflowing.

Why do you think you need to read the accelerometer "continuously"?

You can't in any case, because it takes time to read out the data into the Arduino, and time to transmit the data to another computer.

jremington:
Why do you think you need to read the accelerometer “continuously”?

I need it because I need to be able to detect patterns in small pulses of movements at any time. A 500 millisecond delay makes my application useless, because half of the “pulses” don’t get detected since they happen during the delay. A 200 milliseconds delay at tops could be ok.

jremington:
The input buffers on whatever computer is reading the serial data stream may be overflowing.

If this is the problem, how can I fix it?

Thanks!

If this is the problem, how can I fix it?

One method is to reduce the amount of data sent to the other computer and have it be less busy with other tasks.

A much better method is for the Arduino to monitor the input data, recognize the patterns of interest and only then notify the host computer. That way you discard all the uninteresting data.

If timing is important, the serial baud rate is critical. It takes about 1 millisecond to send a single character to the host computer at 9600 baud.

jremington: A much better method is for the Arduino to monitor the input data, recognize the patterns of interest and only then notify the host computer. That way you discard all the uninteresting data.

I need to figure out what patterns that are of interest before I can do that. This is the reason why I am printing the readings to the serial port.

After I tried a lot of different setups, different accelerometers, different boards on different USB ports, I figured out that the problem was the same no matter what. So it is definitely a question of the serial communication. I am on a mac. I downloaded CoolTerm to monitor the readings and there are no pauses!

I really need to learn more about serial communication. Thanks for your help!