mpu 6050 accelerometer question

Hey guys,
Thank you to all of you who helped me with my last post. It took a little while but I have a working bluetooth accelerometer running on an Arduino nano! Not a bad start for a first Arduino project. Anyway, part 2 is resetting the values of the accelerometer and the gyro when the I stop moving it around in the air. I have no idea where to start on that one. I went through the code line by line and I couldn't find out where to change it. My goal is this, when I stop moving the unit around for at least half a second, I want the accelerometer values and the gyro values, x,y, and z, to reset to 0. The idea is that each time I stop moving the MPU 6050, it will get a new starting point in the x,y,z plane and I can start measuring the distance it moves from a new starting point. I hope that makes sense. Thanks in advance for the help guys!
Sincerely,
Steve

Anyway, part 2 is resetting the values of the accelerometer and the gyro when the I stop moving it around in the air. I have no idea where to start on that one.

I'm having trouble finding the right place in your code, too. It's very faint. almost like the background. Could you brighten or darken it a bit?

SteveRogers:
...
The idea is that each time I stop moving the MPU 6050, it will get a new starting point in the x,y,z plane and I can start measuring the distance it moves from a new starting point.
...

if (MPU6050.state = "stopped")
{
  MPU.readings = 0;
}
else
{
  MPU.readings = (whateverPinMPU6050is_connected_to);
}

Thanks for the reply. I will try that code and let u know how it works.

The I am using pins a4 and a5 on the nano. How do I specify those two? Also, is there a reference for more commands like .state? Thanks.

Hey Retro, thanks again for the code sample. I couldn't get it to work though. How do I declare mpu6050 as a register? I think I need to do that some how.

I couldn't get it to work though.

if (MPU6050.state = "stopped")
I wonder why.

I appreciate the mockery. I wonder why too. I am a beginner and any real help is worth it even if I have to take a little teasing here and there.

Well "=" is an assignment, and unless "MPU6050.state" is an instance of a String, the assignment isn't going to work.
If it is an instance of a String, the assignment is going to be true, so the "if" is superfluous.

SteveRogers, please forget all the other replies.

lar3ry wrote that your code is very faint. He ment that you didn't upload your sketch, so we don't know if you even tried to make something. Upload your sketch between code tags (use the '#'-button). Also add links to where you found that code or library, you can copy the url in the text.

AWOL wrote : "I wonder why". He wanted you to see that it is wrong and nonsense-code.

So you have a MPU-6050 ?
Does it work ? Can you get values out of it ? Do the values change if you rotate and move the MPU-6050 ?
You wrote that you went through the code. What code ? Where did it come from ?

Hi, sorry about leaving out the code. I made the original post while traveling and I couldn't upload code. Here is a link to the code I am using. Arduino Playground - MPU-6050

Yes, I am using an gy-521 MPU-6050. I am getting the raw data just fine. I just don't know how to do anything with it yet. Eventually I want to send the raw data out to a Java program I will write, but that is later. Right now, I just want to reset the accelerometer and gyro values to 0 when I have stopped moving the MPU, and have them start up again as soon as I start moving again. Eventually I will want to reset the values each time the MPU is powered on as well. Thanks again for all the help. This is a pretty cool forum.
Sincerely,
SR

i should've mentioned that was pseudo-code and not to be taken literally.
(and an attempt that probably was incorrect as i have no idea what MPU 6050 code looks like)

i'm a newbie and the MPU6050 is on my "To Do list" but i already have some general ideas.

SteveRogers:
Hi, sorry about leaving out the code. I made the original post while traveling and I couldn't upload code. Here is a link to the code I am using. Arduino Playground - HomePage
...
...

so you've pasted that whole code and now want to change it without understanding what it does ?

from what i can gather, the key* section is in the void loop() - specifically lines 751-759;

    • what i would know to manipulate, there are probably more basic variables that can be read but i haven't taken in the code fully.
 // Print the raw acceleration values
 
  Serial.print(F("accel x,y,z: "));
  Serial.print(accel_t_gyro.value.x_accel, DEC);
  Serial.print(F(", "));
  Serial.print(accel_t_gyro.value.y_accel, DEC);
  Serial.print(F(", "));
  Serial.print(accel_t_gyro.value.z_accel, DEC);
  Serial.println(F(""));

you need to see what those values are when the MPU6050 or the unit it is on/sensing has stopped.

then use a conditional statement, if the values (when stopped) are met - reset the readings.

Thanks retronet_RIMBA1ZO, I didn't recognize it as pseude-code.

SteveRogers, The values of the gyro are near zero, and the accelerometer measures the earth gravity when not moving.
You can store those values, and if one of them changes a lot, the sensor is in motion.
So you need 6 integers that store the offset when the sensor is not moving.

To use the gyro and accelerometer, you have to know something about filtering.
This is a good guide : Guide to gyro and accelerometer with Arduino including Kalman filtering - Sensors - Arduino Forum
Try to understand that, it is important.

To get real 3D data from the sensor, you can use the i2cdevlib.
http://www.i2cdevlib.com/
The 'dmp' example requires that the INT signal is connected, and it shows a number of values on the serial monitor. Also the quaternions.