rudy0912
Posts: 20
Joined: Wed Dec 24, 2014 9:29 pm

ADXL345 only returning -2.048

Fri Jan 09, 2015 10:44 pm

I'm using i2c to connect to the ADXL345 and it only returns -2.048 for all axes. Any ideas?
Both the exmaple.py and adxl345.py return -2.048: https://github.com/pimoroni/adxl345-python

rgrbic
Posts: 128
Joined: Thu Jun 12, 2014 1:07 pm
Contact: Website

Re: ADXL345 only returning -2.048

Sat Jan 10, 2015 9:31 am

I didn't check the examples. These accelerometers have +-2g by default which you get as 2048 or -2048 so you are getting constantly maximal value. Maybe the programs are written for different resolutions?
At 127.0.0.1
Twitter: @rgrbic
IoT-projects.com

Mark_T
Posts: 149
Joined: Sat Dec 27, 2014 10:54 am

Re: ADXL345 only returning -2.048

Sat Jan 10, 2015 12:18 pm

I would check all the connections, saturated values like this could indicate the Pi is seeing all LOW or all HIGH
on the interface?

rudy0912
Posts: 20
Joined: Wed Dec 24, 2014 9:29 pm

Re: ADXL345 only returning -2.048

Sat Jan 10, 2015 2:31 pm

rgrbic wrote:I didn't check the examples. These accelerometers have +-2g by default which you get as 2048 or -2048 so you are getting constantly maximal value. Maybe the programs are written for different resolutions?
The program has a way of changing it from detecting +-2g to +-16g. After i change it to +-16 it starts to only return -16.
Mark_T wrote:I would check all the connections, saturated values like this could indicate the Pi is seeing all LOW or all HIGH
on the interface?
Running i2cdetect -y 1 shows the adxl345 at address 53 so I think it is connected correctly.
Here are the connections I'm using:
Pi - ADXL345
GND - GND
3.3V - VCC
SDA - SDA
SCL - SCL

And this is the adxl345 i bought: http://www.amazon.com/RioRand-ADXL345-D ... ds=adxl345

Thanks for the replies and suggestions but I still haven't been able to get it working.

User avatar
joan
Posts: 14668
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: ADXL345 only returning -2.048

Sat Jan 10, 2015 2:38 pm

Try this C code for the ADXL345 http://abyz.co.uk/rpi/pigpio/examples.html#Misc_code

Compile with

gcc -o adxl345 adxl345.c

Run with

./adxl345 1

to use bus 1.

rgrbic
Posts: 128
Joined: Thu Jun 12, 2014 1:07 pm
Contact: Website

Re: ADXL345 only returning -2.048

Sat Jan 10, 2015 2:42 pm

Maybe is accelerometer in standby mode. Check the datasheet.
At 127.0.0.1
Twitter: @rgrbic
IoT-projects.com

rudy0912
Posts: 20
Joined: Wed Dec 24, 2014 9:29 pm

Re: ADXL345 only returning -2.048

Sun Jan 11, 2015 2:01 am

joan wrote:Try this C code for the ADXL345 http://abyz.co.uk/rpi/pigpio/examples.html#Misc_code

Compile with

gcc -o adxl345 adxl345.c

Run with

./adxl345 1

to use bus 1.
I ran the above code and it does the same thing as before. One interesting difference is that the first 3 readings differ a little bit and then the rest are all -1440.

-1440 -1440 -1440
-1368 -1368 -1368
-1437 -1437 -1437
then the rest is all: -1440 -1440 -1440

User avatar
joan
Posts: 14668
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: ADXL345 only returning -2.048

Sun Jan 11, 2015 8:55 am

These chips are usually embedded in a little board as the chips themselves are tiny. Could you photograph the side of the board with the pin labels. Also make sure your connections are secure.

rudy0912
Posts: 20
Joined: Wed Dec 24, 2014 9:29 pm

Re: ADXL345 only returning -2.048

Sun Jan 11, 2015 1:11 pm

http://i.imgur.com/TUCIQh8.jpg
http://i.imgur.com/kXjuTHr.jpg

Initially there wasn't this much solder on the pins but I added more (way too much...first time soldering) when rgrbic suggested to check the connections. I know it looks like VCC is touching GND and CS but the second picture should show that it isn't. The readings remained the same before and after I added the extra solder.

User avatar
joan
Posts: 14668
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: ADXL345 only returning -2.048

Sun Jan 11, 2015 1:21 pm

Much better than my soldering.

It is probably in SPI mode rather than I2C mode.

To select I2C mode connect SDO to GND and CS to VCC.

rudy0912
Posts: 20
Joined: Wed Dec 24, 2014 9:29 pm

Re: ADXL345 only returning -2.048

Sun Jan 11, 2015 3:05 pm

It still isn't working. I've attached a picture of my breadboard in hopes that someone points out an amateur mistake since I'm new to making circuits.

http://i.imgur.com/CVlVnzQ.jpg

GND + SDO go to the right power strip which is connected to GND on the pi
VCC + CS go to the left power strip which is connected to 3.3V on the pi
SDA and SCL go to their respective pins on the pi

User avatar
DougieLawson
Posts: 37083
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: ADXL345 only returning -2.048

Sun Jan 11, 2015 3:30 pm

Looks like you're off by one on GND & Vcc

You've got the power rail connected to CS.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

rudy0912
Posts: 20
Joined: Wed Dec 24, 2014 9:29 pm

Re: ADXL345 only returning -2.048

Sun Jan 11, 2015 4:23 pm

I'm not sure I understand you.
Do you mean that I'm off by one row on my connections for GND and VCC? If so I think that's just the angle for the picture because they are definitely in the correct row. And to make the connection for CS to VCC, I should run a wire from CS to the VCC row and then another wire from VCC to the power rail?

User avatar
joan
Posts: 14668
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: ADXL345 only returning -2.048

Sun Jan 11, 2015 4:36 pm

That should now work on I2C.

If you have a resistance meter it would be worth checking that adjacent pins aren't incorrectly connected.

rudy0912
Posts: 20
Joined: Wed Dec 24, 2014 9:29 pm

Re: ADXL345 only returning -2.048

Sun Jan 11, 2015 5:12 pm

joan wrote:That should now work on I2C.

If you have a resistance meter it would be worth checking that adjacent pins aren't incorrectly connected.
Were you referring to this picture saying it should work? http://i.imgur.com/CVlVnzQ.jpg
Unfortunately it doesn't work and I don't have a resistance meter.

User avatar
joan
Posts: 14668
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: ADXL345 only returning -2.048

Sun Jan 11, 2015 5:20 pm

rudy0912 wrote:
joan wrote:That should now work on I2C.

If you have a resistance meter it would be worth checking that adjacent pins aren't incorrectly connected.
Were you referring to this picture saying it should work? http://i.imgur.com/CVlVnzQ.jpg
Unfortunately it doesn't work and I don't have a resistance meter.
Yes, the following connections should work as I2C.

Code: Select all

SCL  - SCL
SDA  - SDA
SDO  - Ground
INT2 - N/C
INT1 - N/C
CS   - 3V3
VCC  - 3V3
GND  - Ground

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12585
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: ADXL345 only returning -2.048

Sun Jan 11, 2015 5:20 pm

why do you have sdo (an output) shorted to GND?

User avatar
joan
Posts: 14668
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: ADXL345 only returning -2.048

Sun Jan 11, 2015 5:32 pm

mahjongg wrote:why do you have sdo (an output) shorted to GND?
My understanding is that tying CS to 3V3 sets I2C mode, tying SDO to ground sets the I2C address as 0x53 rather than the alternative 0x1D.

ADXL345 spec page 10.

rudy0912
Posts: 20
Joined: Wed Dec 24, 2014 9:29 pm

Re: ADXL345 only returning -2.048

Sun Jan 11, 2015 8:20 pm

joan wrote:
mahjongg wrote:why do you have sdo (an output) shorted to GND?
My understanding is that tying CS to 3V3 sets I2C mode, tying SDO to ground sets the I2C address as 0x53 rather than the alternative 0x1D.

ADXL345 spec page 10.
I looked through the spec sheet and that seems correct. They also had this picture in the i2c section: http://imgur.com/yjuXMtf

It looks like you don't have to have any other connections than those 4(ALT ADDRESS is SDO). I tried it this way but it also didn't work :(
I'm beginning to think that I might have just bought a broken adxl345.

User avatar
joan
Posts: 14668
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: ADXL345 only returning -2.048

Sun Jan 11, 2015 8:34 pm

rudy0912 wrote: ...
I'm beginning to think that I might have just bought a broken adxl345.
Possibly. I suppose you could try SPI mode.

rudy0912
Posts: 20
Joined: Wed Dec 24, 2014 9:29 pm

Re: ADXL345 only returning -2.048

Mon Jan 12, 2015 2:11 am

Are there any guides for setting up the adxl345 and raspberry pi via SPI? Searching the internet is only returning guides for i2c and I'm not familiar enough with SPI to write my own code.

Thanks for all the help.

rgrbic
Posts: 128
Joined: Thu Jun 12, 2014 1:07 pm
Contact: Website

Re: ADXL345 only returning -2.048

Mon Jan 12, 2015 11:01 am

Just to be sure, there is pull up resistor on i2c line?
At 127.0.0.1
Twitter: @rgrbic
IoT-projects.com

User avatar
joan
Posts: 14668
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: ADXL345 only returning -2.048

Mon Jan 12, 2015 11:26 am

rudy0912 wrote:Are there any guides for setting up the adxl345 and raspberry pi via SPI? Searching the internet is only returning guides for i2c and I'm not familiar enough with SPI to write my own code.

Thanks for all the help.
For SPI.

Make the following connections.

Code: Select all

GND Ground (pin 6)
VCC 3V3    (pin 1)
CS  CE1    (pin 26)
SDO MISO   (pin 21)
SDA MOSI   (pin 19)
SCL SCLK   (pin 23)
I suggest you test with my pigs utility. If it works you should be able to use the SPI of your choice.

Download and install.

Code: Select all

wget abyz.co.uk/rpi/pigpio/pigpio.zip
unzip pigpio.zip
cd PIGPIO
make
make install
Start the daemon

Code: Select all

sudo pigpiod
Open, initialise, and read from the device

Code: Select all

pigs spio 1 40000 3          # open SPI channel 1, 40 kbps, mode 3
pigs spiw 0 0x6d 0           # write 0 to 0x2D
pigs spiw 0 0x6d 8           # write 8 to 0x2D
pigs spiw 0 0x71 0           # write 0 to 0x31
pigs spiw 0 0x71 11          # write 11 to 0x31
pigs spix 0 0xf2 0 0 0 0 0 0 # read 6 bytes from 0x32
pigs spix 0 0xf2 0 0 0 0 0 0
pigs spix 0 0xf2 0 0 0 0 0 0
pigs spix 0 0xf2 0 0 0 0 0 0
Results similar to

Code: Select all

harry ~ $ pigs spio 1 40000 3          # open SPI channel 1, 40 kbps, mode 3
0
harry ~ $ pigs spiw 0 0x6d 0           # write 0 to 0x2D
harry ~ $ pigs spiw 0 0x6d 8           # write 8 to 0x2D
harry ~ $ pigs spiw 0 0x71 0           # write 0 to 0x31
harry ~ $ pigs spiw 0 0x71 11          # write 11 to 0x31
harry ~ $ pigs spix 0 0xf2 0 0 0 0 0 0 # read 6 bytes from 0x32
7 0 2 0 52 255 141 0
harry ~ $ pigs spix 0 0xf2 0 0 0 0 0 0
7 0 3 0 52 255 139 0
harry ~ $ pigs spix 0 0xf2 0 0 0 0 0 0
7 0 3 0 52 255 141 0
harry ~ $ pigs spix 0 0xf2 0 0 0 0 0 0
7 0 2 0 52 255 141 0
harry ~ $ pigs spix 0 0xf2 0 0 0 0 0 0
7 0 2 0 52 255 140 0
harry ~ $ pigs spix 0 0xf2 0 0 0 0 0 0
7 0 3 0 51 255 140 0
harry ~ $ pigs spix 0 0xf2 0 0 0 0 0 0
7 0 3 0 51 255 139 0
harry ~ $ pigs spix 0 0xf2 0 0 0 0 0 0
7 0 182 255 148 255 200 0
harry ~ $ pigs spix 0 0xf2 0 0 0 0 0 0
7 0 182 255 148 255 201 0
harry ~ $ pigs spix 0 0xf2 0 0 0 0 0 0
7 0 181 255 150 255 200 0
harry ~ $ pigs spix 0 0xf2 0 0 0 0 0 0
7 0 180 255 150 255 200 0

User avatar
joan
Posts: 14668
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: ADXL345 only returning -2.048

Mon Jan 12, 2015 11:47 am

rgrbic wrote:Just to be sure, there is pull up resistor on i2c line?
The Pi has hard wired pull-ups to 3V3 on SDA and SCL.

rudy0912
Posts: 20
Joined: Wed Dec 24, 2014 9:29 pm

Re: ADXL345 only returning -2.048

Mon Jan 12, 2015 4:45 pm

"pigs spix 0 0xf2 0 0 0 0 0 0" returns "7 240 0 240 0 240 0 240" every time

Return to “Automation, sensing and robotics”