Pages: [1]   Go Down
Author Topic: Code examples for ADXL345 accelerometer?  (Read 6674 times)
0 Members and 1 Guest are viewing this topic.
The Holy Land
Offline Offline
Jr. Member
**
Karma: 1
Posts: 60
Arduino stones
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi' I've recently purchased the ADXL345 accelerometer. But I can't find any code examples of it being used with the arduino, or with anything else for that matter. Please let me know if you have used it or know of an open project where I can see a wiring scheme and/or some Arduino code.
Thanks!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Erm, the data sheet  smiley-wink

Looks like you can use it with either SPI or I2C, I2C is probably easiest. Read up about the wire library. Once you know how to address an I2C slave, look at the register map on page 14 of the data sheet. Then you can pull whatever information you want out of the chip. smiley
Logged

The Holy Land
Offline Offline
Jr. Member
**
Karma: 1
Posts: 60
Arduino stones
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Looks like you can use it with either SPI or I2C, I2C is probably easiest.

That sounded a bit Chinese, but let's see if I got it straight. I need to use the Wire library in order to communicate with the sensor, and using I2C umm protocol? would be the easiest option (still have to figure out the slave thing). After I can communicate I just take the values from the registers I need using the table on page 14.
Correct?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Correct, or you can write to the registers that need to be written to (looks like a lot of thresholds in the datasheet  smiley )

Basically both the arduino and the adxl345 are both on the same BUS, the arduino is the master and the adxl345 is the slave.

1. The arduino activates the BUS, all the slaves listen in

2.The arduino writes a slave address and whether it wants to read or write to the BUS

3.All the slaves listen for the address, compare it to their own address and if it's not equal they stop listening, this means that now only the slave you want is listening to the arduino. The slave then looks at whether you want to read or write and gets into the correct mode

4.The arduino then writes a register address to the BUS, the selected slave reads it and notes down the register address.

5.If the arduino wanted to write it would send the byte and the slave would write it into the noted register, if the arduino wanted to read the slave would send the data from the noted register to the arduino.

edit:Fix'd for being basically unreadable
« Last Edit: October 15, 2009, 07:45:16 am by Merve » Logged

Seattle, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 248
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Woo one sentence record

Classic advice from editor/writing teacher to writers:

The period is your friend!
 ;D
Logged

.andy

The Holy Land
Offline Offline
Jr. Member
**
Karma: 1
Posts: 60
Arduino stones
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, read about the Wire library and also read the datasheet. The address of the device is 0xA6 for reading and 0xA7 for writing. Now all I have to do is wire the thing correctly and hit run? I'm kinda stuck at that phase.

On page 10 of the datasheet there's a simple wiring scheme. I'm connecting the CS pin to the arduino 3V out, and the SDO to ground (to get the addresses they mention). Now where do I stick the chip SDA and SDCL is beyond me. The Wire library page says that the arduino SDA is analog in 4, and clock is analog 5. But I'm not sure are they used that way when arduino is the master or the slave.
I'm asking lots of questions before the actual plugging because I don't wanna fry the 30$ chip smiley-grin
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ha, yeah I know that feeling

You are correct about CS and SDO, also remember you have to connect Vdd and Vss to 3v (isn't it 3.3V?) and the GND pins to GND (page 19 has the power circuit).

It may seem weird that the pins are analog 4 and 5 but that is just where atmel decided to put the hardware for the I2C. SDA and SCL are just one the pins alternate functions.
Logged

The Holy Land
Offline Offline
Jr. Member
**
Karma: 1
Posts: 60
Arduino stones
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanx a lot for the help! I'll try it as soon as I get back home (in a week smiley-sad) and I hope I'll get the other chip issues figured out till then, if not, will revive this post smiley-grin
Logged

The Holy Land
Offline Offline
Jr. Member
**
Karma: 1
Posts: 60
Arduino stones
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, and welcome back to the adxl345 accelerometer saga.

I've plugged the chip according to the datasheet, the schematic of the breakout board and the Wire library reference.

The wiring looks like this:


I discovered very soon that this wiring shorts the arduino! After some experimenting I've narrowed down the shorting wires to this:



Now I'm assuming one of two things:
A. The breakout board (or the chip) is defective
B. My wiring is awful wrong

Please advise
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi MeLight,
did you check the sparkfun-board SEN-09364
They present the source code with it, take a look into the file ADXL345.c.

(I still do not have neither ADXL nor Arduino, so no knowledge of my own)
Good luck!
Georg
Logged

The Holy Land
Offline Offline
Jr. Member
**
Karma: 1
Posts: 60
Arduino stones
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've finally managed to do it, and wrote a matching application for Processing. Here're the details adxl345 + arduino + Processing
Logged

Pages: [1]   Go Up
Jump to: