Accelerometer SMB380

I have a Fez Mini with the SMB380 accelerometer, but when i lunch the program with the genuine driver the result is :
‘System.InvalidOperationException’ in Microsoft.SPOT.Hardware.dll

the error occurs in this source code :
static private void WriteRegister(byte address, byte value)
{
write[0] = address;
write[1] = value;
_spi.WriteRead(write, read); <===ERROR
}

mine parameters are :
HalSystemInfo.halVersion:
HalSystemInfo.halVendorInfo:
HalSystemInfo.oemCode: 0
HalSystemInfo.modelCode: 0
HalSystemInfo.skuCode: 0
HalSystemInfo.moduleSerialNumber:
HalSystemInfo.systemSerialNumber:
ClrInfo.clrVersion: 4.0.1681.0
ClrInfo.clrVendorInfo: Microsoft Copyright © Microsoft Corporation. All rig
ClrInfo.targetFrameworkVersion: 4.0.1681.0
SolutionReleaseInfo.solutionVersion: 4.0.3.0
SolutionReleaseInfo.solutionVendorInfo: GHI Electronics, LLC
SoftwareVersion.BuildDate: May 21 2010
SoftwareVersion.CompilerVersion: 310739
FloatingPoint: True
SourceLevelDebugging: True
ThreadCreateEx: True
LCD.Width: 0
LCD.Height: 0
LCD.BitsPerPixel: 0
AppDomains: True
ExceptionFilters: True
IncrementalDeployment: True
SoftReboot: True
Profiling: False
ProfilingAllocations: False
ProfilingCalls: False
IsUnknown: False

do you have an idea ?

NB : the fez module is correct, i can blink LED, manage interruption with a switch

The code you showed i s fine. The problem is somewhere else. Did you use the cod efrom here?
http://www.tinyclr.com/downloads/Extension/Broch_AccelerometerExtension.pdf

hello,
sorry, i was on holidays…
i found the error, the correct code for the bus initilisation is :

SPI.Configuration config = new SPI.Configuration((Cpu.Pin)FEZ_Pin.Digital.UEXT10 , false, 0, 0, true , true,200, SPI.SPI_module.SPI1);
200 is the correct value instead 100

the driver code is false, when we try to obtain x, y and z values, ther are not well compute :
wrong code :


static public void GetXYZ(out sbyte x, out sbyte y, out sbyte z)

            {

                x = (sbyte)ReadRegister(0x02);

                x = (sbyte)ReadRegister(0x03);
......

correct code would be (i hope) :

                static public void GetXYZ(out int x, out int y, out int z)
            {
                int x1, x2, y1,y2,z1,z2;

                x2 = (sbyte)ReadRegister(0x02); //LSB 6 7
               
                x1 = (sbyte)ReadRegister(0x03); //MSB 0 7
                
                x = (x1 << 2) | (x2 >> 6);

It is not easy to read your code if you do not mark it as “code” so we can see it. I will edit your post so you can see what I mean. Thanks :slight_smile:

thank’s for the modification.

one question :
with smb380, is it possble to know the direction (right, left, up, down, …) ?
the acceleration value is not enough to obtain this information.

my project : to track the position of an object without GPS, only with accelerometer and gyro.

I am not expert in robotics but I think they usually use gyros with accelerometer.

[quote]with smb380, is it possble to know the direction (right, left, up, down, …) ?
the acceleration value is not enough to obtain this information.[/quote]

The smb380 is a good 3 axis acceleration sensor you can tell how fast you are going and what not in a certain direction. To know true direction and orientation you will want a gyro. The real thing you get to know with a gyro is what is truly down and up. Combining the out put from both a acceleration sensor and a heading hold gyro you can almost get dead reckoning. of course that really depends on how close to dead reckoning you need to get to you can use a cheaper gyro that just shows rate. i have used a couple of these http://store.diydrones.com/ProductDetails.asp?ProductCode=BR-0005-10 before not in the .net world. builtin a previous quad copter based on arduino. With both combined you can be sure that you know the direction you are going from the position you started and how fast and if any terrain caused tilt needing compensation.

i found this reference : http://invensense.com/mems/gyro/documents/EB-ITG-3200-00-01.1.pdf for the gyro.
if you have a pure translational motion, the information gave by the gyro cannot be used, is it true ?

right thats why you use both a gyro and a acceleration sensor.

edited to expand on that.

An acceleration sensor is a sensor that measures acceleration or translational motion. A gyroscope is an angular rate sensor - it measures the rate of angular rotation. While angular acceleration sensors do exist, they are rarely used and freaking expensive. A gyro’s angular rate output is integrated to determine angular heading which in turn is used to determine if you have been turning and by how much. When combined with displacement information from your acceleration sensor you can figure out your position.

Both devices can come as something that does both. They just get much more expensive then using 2 of the cheaper devices together.

hi,
i don’t known how it’s possible to obtain the direction with the measured values.
an idea for me ?

      X
      |
      |

Y------±-*—Y
|
|
X

depending on orientation you can get direction by which axis has a higher or lower number depending on where it is on the grid above.

Let’s assume you have a range of 512.

Then this will be the direction:

____512Y
-512X___512X
____-512Y

Note: This can be different

The problem is not so simple, because if the values of the SMB380 are between -512 and +512, they represente an acceleration, and not a position.
An example : you are on a your zero point, you accelerate (the value is positive), you brake (the value is negative), but your direction is the same in the 2 cases.

Ah I see, could you provide us the measurements you are getting?

You can add a compass module for measure the direction.

What you want to do? Is it for a robot?

my project :
i’m a diver, and one of the diver’s problems is to be able to find the boat after one hour under the sea.
I’m looking for an inertial navigation unit to reach the zero point when i finish my dive.
something a underwater GPS, but GPS is unavailable in water…

Hmm,

some kind of dead reckoning :wink:

So you need a compass module and precision timer and the accelerometer.

So timer is no problem , it is integrated. the accelerometer is also no problem.

But compass module is very expensive.For your application you must use a tilt compensated compass module. And this is very expensive.

Your xyz acceleration add in time = distance and direction traveled from you starting position. The way you do it is determine how far you can go at a certain acceleration an time. If you need to know your turning you can use the x and y to determine at which rate you are turning. you can also add in the z to determine level of accent and decent at the same time. Just be sure to measure time to travel at multiple speeds and directions including ramp up time if you are using some form of PID control. With enough measurements and coming up with a good algorithm you can determine exactly how far you are from your starting position and where. GPS on land or water is very inaccurate for small devices where you can be off by 1.5 meter to 3 meters. I never use it on a dead reckoning robot even with 2-3 GPS modules feeding coordinates. You will never be where it says you are due to the distance it can be off. I have used what i described before to end up .5 inches where i started after a weaving 600 ft course. It will just take time to measure and tune.