Electronic – arduino – Getting ADXL345 accelerometer to work over SPI with Arduino Uno

arduinospi

I'm using this cheap ADXL chip with Arduino Uno. When I read the sensor with I2C – it works fine. However I have some servo motors as well which generate a lot of noise and when I turn the motors on, the sensor readings become pretty much useless.

I read that SPI is much more immune to noise, so I decided to go this way. However I just cannot get it to work with SPI.
I'm using this code, which seems to work for other people: https://www.sparkfun.com/tutorials/240

I triple checked the wirings, they seems ok to me, tried with and without level shifter, tried hooking up various pull-up resistors… and still I get just zeroes.
Yet I2C works just fine (without any pull-ups).

I'm wondering since the Sparkfun code uses a different breakout board for the ADXL chip – could it be that mine needs some specific pull-ups, that are not mentioned in that tutorial? How can I know what pull-ups need to be placed?

And any other suggestions will be much appreciated!

Best Answer

You should read the datasheet for the part to double check your connections. You should not be having any pullups for SPI communication.

Regarding being unable to communicate via I2C when motors are on - how long are your I2C wires? Trying to lower the resistance of I2C pullups might help.

In general you can try to remedy this situation by adding bigger caps near microcontroller/accelerometer power supply or even adding a small (~10 ohm or less) series resistor and a cap on Vcc that goes to noise sensitive part.

Read up on star grounding and powering techniques, it is possible you could solve your problem by just reconnecting wires in "star" manner.