Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Can't get right value from accelerometer MMA7361


  • Please log in to reply
10 replies to this topic

#1 JacopoMTK

JacopoMTK

    Member

  • Members
  • PipPip
  • 26 posts

Posted 03 December 2012 - 09:33 PM

Hi everyone,

first of all i found and tried the solution in thistopic but it doesn't seems to work.

I'm trying to read the value of x,y,z axis from and MMA7361 accelerometer,the problem is that i keep reading nearly-equal values even if i move the accelerometer in any position.

How i connected it:
Vcc = netduino 3v3 port;
Aref = Vcc;
Gnd= Gnd
X=AnalogInput 5
Y=AnalogInput 4
Z=AnalogInput 3

Here's my code:

SecretLabs.NETMF.Hardware.AnalogInput XPort = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A5);
SecretLabs.NETMF.Hardware.AnalogInput YPort = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A4);
SecretLabs.NETMF.Hardware.AnalogInput ZPort = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A3);

while (true)
{
     //read from input ports
     float X = XPort.Read();
     float Y = YPort.Read();
     float Z = ZPort.Read();
      
     //convert to degrees [360*(analogValue/ADCresolution)]
     X= 360*(X/1024);
     Y= 360*(Y/1024);
     Z= 360*(Z/1025);
  
     Debug.Print("X: " + X+ "; Y: " + Y+ "; Z: " + Z);
}

Now,i keep getting outputs aroud 130-200 no matter how i rotate the accelerometer.
Any idea on why it should be happening?

Thanks.

#2 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 03 December 2012 - 09:55 PM

Are you using a specific breakout board? Sparkfun perhaps?

#3 pounce

pounce

    Member

  • Members
  • PipPip
  • 12 posts

Posted 03 December 2012 - 10:09 PM


Now,i keep getting outputs aroud 130-200 no matter how i rotate the accelerometer.


Sorry if this sounds silly, but are you moving it quickly or are you just tipping it? I read what you wrote and the first thing that came to mind was whether you were treating it like a gyro instead of an accelerometer.

#4 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 03 December 2012 - 11:04 PM

i also dont think your calculations are correct. maybe it works and you just dont convert it correctly into degrees, thats normally include a little more math. so your values are between 130 and 200 //edit that was stupid also, its an accelerometer and you dont need/cant convert that into degrees. it tell you how much acceleration you have on each axis. is 800mV at 1.5g setting

#5 JacopoMTK

JacopoMTK

    Member

  • Members
  • PipPip
  • 26 posts

Posted 04 December 2012 - 09:17 AM

I'm using this board.
I'd like to attach the acceleromeyet to my hand in ordet to get the rotation.

@poumce:i've tried both but no luck.

@NooM:that's probably true but I can't figure out how to tranlate the
results I get in another way :\

Also a question:using an accelerometer,will I be able to get the hand rotation
even if the arm is moving?I probably should use a gyro for that but they cost twice as much :\

Thanks

#6 Lunddahl

Lunddahl

    Advanced Member

  • Members
  • PipPipPip
  • 152 posts
  • LocationEurope, Denmark

Posted 04 December 2012 - 10:36 AM

Also a question:using an accelerometer,will I be able to get the hand rotation even if the arm is moving?I probably should use a gyro for that but they cost twice as much :\


This is very good reading:
https://www.sparkfun...ccel_gyro_guide

You might actually be looking for an IMU, and probably one with a micro on it to decode the data from the sensors in real time, and give you something more useful back.

Processing the data from the sensors requires real time processing, something you do not have on the Netduino or any other NETMF platform, that's where an IMU shines, is has a processor just for that. The backside, is that they are expensive compared to the actual sensors.

#7 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 04 December 2012 - 11:58 AM

I'm using this board.
I'd like to attach the acceleromeyet to my hand in ordet to get the rotation.

@poumce:i've tried both but no luck.

@NooM:that's probably true but I can't figure out how to tranlate the
results I get in another way :\

Also a question:using an accelerometer,will I be able to get the hand rotation
even if the arm is moving?I probably should use a gyro for that but they cost twice as much :\

Thanks


It sounds like you need several different sensors for your project depending on what you are trying to accomplish. I will assume you are trying to build a device to detect the motions of your hand and use it to control something. If I were to build such a device I would likely use 3 sensors for this. This includes an 3 axis Accelerometer, 3 axis Magnetometer (compass) and a 3 axis Gyroscope. The reason being is that they give you very different readings but used in conjunction and give you all the data you need.

For instance, an accelerometer can certainly detect that there was motion on the X, Y or Z axis and what the force of that motion was. You will not however determine Roll or Pitch from the Accelerometer. That is where a Magnetometer comes in. It's basically a compass and measures it's location based on the earths magnetic field and it can calculate Roll, Pitch and Yaw. The third part is knowing the speed of the rotation. We now know your hand moved up/down, left/right, forward/backwards and how fast. We also know how your hand rotated (Roll, Pitch, Yaw). Now lets assume in your project that you need to know not only that your hand "Rolled" but how fast. The Gyroscope does just that. It measures angular velocity or RPM (rotations per minute) and can tell you how fast your hand rolled.

These days most smart phones, nav systems and safety systems in cars, planes and boats use a Gyro in conjunction with a Compass (Magnetometer) to accurately measure Roll, Pitch and Yaw and the Magnitude of those movements.

You may need something like this MinIMU-9 v2 Gyro, Accelerometer, and Compass (L3GD20 and LSM303DLHC Carrier)

or this IMU Digital Combo Board - 6 Degrees of Freedom ITG3200/ADXL345

It really comes down to how many degrees of freedom you need (3, 6, 9)

Another good read: Magnetometers and Accelerometers and Gyros (oh my?)

#8 JacopoMTK

JacopoMTK

    Member

  • Members
  • PipPip
  • 26 posts

Posted 05 December 2012 - 08:33 AM

Hi,thanks to everyone for the links and explanations.
Currently i got the angles from the accelerometer using this code.X and Y rotation are accurate but the Z value keep changing with a range of 40 degrees :\ (even using multiple readings to get an average value).
Today i'll try again to get a more stable value on Z axis.

Anyway,unfortunately the IMU boards are way too expensive for me,but i was thinking to the magnetometer only since the price is similar to the accelerometer i got.
I will not be able to get the acceleration from it directly but i think i should be able to get some clues about it.
For example if at time T1 the rotation in 20 degrees and at the second reading at time T2 the rotation is 30 degrees,i should be able to tell
how fast the magnetometer is rotation doing 30-20/(t2-t1).

[quote name='"Dave VanderWekke"]It's basically a compass and measures it's location based on the earths magnetic field and it can calculate Roll' date=' Pitch and Yaw. [/quote']

But,i really don't understand what magnetometer gives as result,i mean reading some articles,it seems it gives as result the megnetic strength based on his position not a x,y,z rotation.

Thanks.

#9 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 05 December 2012 - 11:35 AM

Hi,thanks to everyone for the links and explanations.
Currently i got the angles from the accelerometer using this code.X and Y rotation are accurate but the Z value keep changing with a range of 40 degrees :\ (even using multiple readings to get an average value).
Today i'll try again to get a more stable value on Z axis.

Anyway,unfortunately the IMU boards are way too expensive for me,but i was thinking to the magnetometer only since the price is similar to the accelerometer i got.
I will not be able to get the acceleration from it directly but i think i should be able to get some clues about it.
For example if at time T1 the rotation in 20 degrees and at the second reading at time T2 the rotation is 30 degrees,i should be able to tell
how fast the magnetometer is rotation doing 30-20/(t2-t1).



But,i really don't understand what magnetometer gives as result,i mean reading some articles,it seems it gives as result the megnetic strength based on his position not a x,y,z rotation.

Thanks.


With the magnetometer and most other sensors you have to remember you can't simply use it to get a number that will tell you which way your hand it pointing. You need to write your software to measure the delta (change) and that is how you know the rotation.

If you stick with the HMC5883L Compass there is code available. I can send you the class I am using too. This will save you a ton of work.

#10 JacopoMTK

JacopoMTK

    Member

  • Members
  • PipPip
  • 26 posts

Posted 13 December 2012 - 03:35 PM

With the magnetometer and most other sensors you have to remember you can't simply use it to get a number that will tell you which way your hand it pointing. You need to write your software to measure the delta (change) and that is how you know the rotation.

If you stick with the HMC5883L Compass there is code available. I can send you the class I am using too. This will save you a ton of work.


Sorry for the late reply,again i didn't get the notification :\
Anyway,tomorrow i'll make an order to get some components but it seems that the shop ran
out of HMC5883L so i'll have to make another order for it at the end of january.

Thanks for the code offer!I'll try to work it out by myself at first but
in case i'll appreciate it.

Thanks.

#11 wnieuw

wnieuw

    New Member

  • Members
  • Pip
  • 1 posts

Posted 10 October 2014 - 07:25 PM

I encountered the same problem that I got always nearly the same values on all 3 axes of the MMA7361 (sensor board).

Then I found that the "sleep" pin needs to be high in order for the accelerometer to function. So simply connect the "sleep" pin to the positive power lead . I used a 10K resistor.

Now it works!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.