I hooked up my Arduino to a LIS3LV02DQ - a nice little 3-axis accelerometer that can operate over an SPI interface. Thought I'd put the little howto on my blog, here:
http://research.techkwondo.com/blog/julian/259
Julian
I hooked up my Arduino to a LIS3LV02DQ - a nice little 3-axis accelerometer that can operate over an SPI interface. Thought I'd put the little howto on my blog, here:
http://research.techkwondo.com/blog/julian/259
Julian
just got this sensor working. I did modify R13 as mentioned in this thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1163734586. I thought the SPI wasn't working but it was because of the "while(1==1)" in line 67. Is there any specific reason for this line?
Another thing. I see some functions that I don't see in the arduino manual, are you just mixing in C? Or are there some undocumented functions? Functions like "write_register", "#define" or "spi_transfer".
If it wasn't clear yet: I am a total newbie with the arduino. Only able to blink some LED's and made some simple programs with processing to learn the language.
Dirk
Huh — that while(1==1) is clearly a typo. It shouldn't be there. I've uploaded a fixed version of the code.
As for the write_register, and spi_transfer functions, those aren't Arduino features, those are functions I created. They're definitions are right there in the code — line 89 defines the function write_register. See the Arduino manual on Function Declarations. It might also help you to grab a basic C tutorial somewhere online and go over some of the fundamentals. That will explain to you the #define operator — it's a C idiom for declaring a pre-processor variable.
Wiring, the language used for the Arduino, is basically C, with a number of aspects abstracted to simplify the process of programming a Atmel microcontroller. When you click "Verify" (the button that looks like "play" — the rightward arrow), you're actually just creating a C program and compiling it. Look in the folder "applet" generated under your Sketchbook folder. It's all C code (and C++), and uses the avr-libc libraries for a bunch of functionality. So, pretty much anything you can do in C you can do in Arduino, including having #define and creating your own functions.
Finally, the resistor shouldn't be a concern — I believe it's there to control current to the LED attached to pin 13. That resistor is there only as a convenience for users so they don't have to connect their own resistor if they just need a simple LED for debugging or whatever.
I feel so stupid. I just overlooked these function delcarations. I found the same ones in the eeprom tutorial, but still didn't see that they were defined in the program it self.
If I understand correctly I can just use C in the arduino language? That's nice.
The resistor thing is explained in the thread I mentioned. I have got a second arduino board so I can check if it makes a difference. But in the picture of your board I can see the I have a newer version.
I hooked up my Arduino to a LIS3LV02DQ
Read WHO_AM_I =0x3A, it is ok.
x_h=0,x_l=8; y_h=255, y_l=174; z_h=4, z_l=63
x_h=0,x_l=8; y_h=255, y_l=174; z_h=4, z_l=63
x_h=0,x_l=9; y_h=255, y_l=174; z_h=4, z_l=64
How to caculate the right acceleration?
The values are two's complement signed numbers; if the most significant bit is a one, then the value is a negative number.
Taking your values:
x_h=0,x_l=8; y_h=255, y_l=174; z_h=4, z_l=63
(x_h << 8) | x_l = 8, which is pretty close to zero.
(y_h << 8) | y_l = 0xFFAE = -82
(z_h << 8) | z_l = 0x043f = 1087
What is the orientation of your board?
When you tilt the board, do the values change?
Don't forget the acceleration due to gravity.
If you have a scale of 1g = 1024, these look to be pretty good figures.