8 Replies Latest reply on Jul 30, 2015 5:28 AM by ivansky

    ADXL345 only returns 0,0,0 using SPI

    ivansky

      I have been doing a lot of research on this but haven't gotten anywhere so far.  I would love some help if anyone knows how to fix this.

       

      I have an Intel Galileo Gen 2 board.  I have it connected to an ADXL345 accelerometer as per the Sparkfun guide at ADXL345 Quickstart Guide - SparkFun Electronics.

       

      In other words, I have the following pins connected:

       

      Pin 10 to CS

      Pin 11 to SDA

      Pin 12 to SDO

      Pin 13 to SCL

      3V to VCC

      GND to GND

       

      I am just using the Basic code as shown on that page. However, all I ever get returned from the device is a bunch of zeroes.  I actually have two of the ADXL345 boards and they both give the same results.  I didn't actually buy these boards direct from Sparkfun, I ordered them from a local supplier, so I guess it's possible they're not identical.

       

      I note that the code provided on Sparkfun seems to be using an older version of the SPI library.  Although I have 1.6.4 of the Arduino IDE, if I try to use calls like "beginTransaction" I get errors about that not being declared and I am not sure how to upgrade the libraries.  Note: I am working on OS X Mavericks.

       

      Does anyone have any suggestions?

       

      Many thanks.

      Ivan

        • 1. Re: ADXL345 only returns 0,0,0 using SPI
          DiegoV_Intel

          Hi ivansky,

           

          I've tested the same accelerometer with my Galileo Gen2 and it worked. I used the Arduino 1.6.4 as you did. I followed the same guide of Sparkfun and the sample code provided by them. I faced the same issue as you when I first tried it, I got only 0,0,0 but it was due to a connection issue in the power lines (VCC/GND). Once I made sure everything was properly connected I got the expected results from the ADXL345. My suggestion would be to check the hardware connections. Make sure the ADXL345 breakout board is properly connected and the pins are properly soldered.

           

          Regards,

          Diego.

          • 2. Re: ADXL345 only returns 0,0,0 using SPI
            ivansky

            Thanks Diego.  I am working through your suggestion now.  I haven't been successful so far, I have confirmed that there is 3.3V applied at the board, so my Vcc and GND seem OK.  My breakout also has a 5V input so I think I will wire that up instead and see if it makes a difference.  My accelerometer was already soldered and it looks OK - I didn't do it myself so it is more likely to be properly done!  :-)

             

            Hmmm, I tried the 5V input, confirmed the 5V (actually 4.98V according to my multimeter) on the accelerometer, but still reading all zeroes from the registers.  I even replaced all the jumper wires I am using, although I haven't completely ruled out a problem with the breadboard.

             

            I assume since you didn't mention it that the pinout for SPI is definitely correct - i.e. the pins for SPI on the Galileo are as described in that Sparkfun tutorial?

             

            I think I will try next on an Arduino board - I hadn't tried this earlier because I didn't realise my board could take 5V, I thought the ADXL345 was 3.3V only.

             

            If I figure this out I will post back.

            Ivan

            • 3. Re: ADXL345 only returns 0,0,0 using SPI
              DiegoV_Intel

              Hello ivansky,

               

              Yes, I used the same pins for SPI described in the Sparkfun tutorial. I didn't change anything actually.

               

              One thing you could try is measuring the SPI signals sent by the Galileo. Make sure that the board is actually sending data. Then you can measure the SPI signals sent by the breakout board. That way you will know if there is a flow of data between both devices.

               

              I hope you can make it work.

               

              Regards,

              Diego.

              • 4. Re: ADXL345 only returns 0,0,0 using SPI
                ivansky

                Thanks again Diego.  I haven't gotten back to this project yet but I will in the next few days.  Can I measure the SPI signals just with a multimeter though?  I don't have any fancy tools like an oscilloscope or whatever they're called nowadays.

                 

                Ivan

                • 5. Re: ADXL345 only returns 0,0,0 using SPI
                  DiegoV_Intel

                  Hi ivansky,

                   

                  Unfortunately a multimeter is not a good tool for measuring SPI signals; you need a logic analyzer or an oscilloscope. You can try to make the breakout board work without any additional tool, but it would be harder because you wouldn't be able to "see" what data is flowing through the SPI bus.

                   

                  Regards,

                  Diego.

                  • 6. Re: ADXL345 only returns 0,0,0 using SPI
                    ivansky

                    OK, in order to try another option I attempted to access the information via I2C, using the ADXL345 library.  However, even this was unsuccessful.  I am guessing I am doing something wrong as I have now tried it with both the Galileo and a Uno, but nothing works.  Unfortunately an oscilloscope is a bit out of my price range.  At this stage I do not have an answer for this problem but I will keep experimenting.  Thank you for the suggestions so far.

                    • 7. Re: ADXL345 only returns 0,0,0 using SPI
                      DiegoV_Intel

                      Hello ivansky,

                       

                      I suggest you to test the breakout board with your Arduino UNO using SPI. If you are using the same code provided in the Sparkfun guide, and the connections are wired correctly, I'd think that it might be a problem with the breakout board itself and not with the code or the host board (Galileo or Arduino).

                       

                      Regards,

                      Diego.

                      • 8. Re: ADXL345 only returns 0,0,0 using SPI
                        ivansky

                        Diego, thank you very much for your patient assistance.  I am sorry it has taken me so long to revisit this issue - I have been working on other projects.  Tonight I was able to read data from my ADXL345, proving it is definitely working!  I am currently using an Arduino Pro Mini, but will try it on a Galileo soon to confirm it on that board.  The fix for me was to use a different set of code, in particular I loaded the Adafruit Sensor and ADXL345 libraries, then used their example code from the ADXL345 library, and it worked fine, connected via I2C.

                         

                        I don't know what was not working with the code from Sparkfun, which is normally a great site - it could have been the jumper wires, breadboard, or anything.  I don't have the expertise (or oscilloscope) to find out why the previous approach was faulty.  I just want to say for the record that the Adafruit code worked for me immediately, without modification.  Which makes me happy!