1 2 Previous Next 15 Replies Latest reply on Feb 13, 2015 11:59 AM by dgdosen

    ADXL345 via i2C

    Banq

      So I started tinkering around with trying to get the Edison to get a reading from my ADXL345 via i2c. I dropped some headers into the min breakout and wired it up the 3v3 (J20,2), GND(J19,3), i2C1_SDA, (J17,8) and i2C_SCL(J18,6). I ran "i2cdetect -y -r 1" but have yet to get anything to come up. I tried the other i2c ports on the header but same issue. I checked the voltage going into the ADXL345 and it is 3.4V. Any suggestions on what I might be doing wrong? If I can't get this to work I will probably just be waiting for the Sparkfun 9dof board to be released.

        • 1. Re: ADXL345 via i2C
          mikemoy

          You said "min breakout" just to be clear are you using the intel mini breakout board?

          If so, did you level shift the I2C lines up to 3.3v from the 1.8v  ?

          • 2. Re: ADXL345 via i2C
            Banq

            I did not. Guess I'll have to wait for the SparkFun boards.

            • 3. Re: ADXL345 via i2C
              Taimoor

              Hey @Banq,

               

              Did you ever get that ADXL to work? I've spent a frustrating past few days trying to figure the issue out. I am using python (but whatever works would do for me) and trying to write the power register.... Its returning 0.. ALWAYS! I am expecting the output console to print a number (I am getting a 0)

               

              Here's my code for the most basic test:

              #!/usr/bin/python

              import time

              import mraa

               

              USED_I2C = 6

              DEV_ADDR = 0x1D

               

              x = mraa.I2c(USED_I2C)

              byte = 0

              m = "      "

              while byte != 0x28:

                      print("I read: ")

                      x.address(DEV_ADDR)

                      x.writeReg(0x2D, 0x28)

                      time.sleep(1)

                      print(x.readReg(0x2D))

               

              Any idea on how I can test my code?

               

              My connections are as follows:

              GND==GND

              VCC==IOREF (IOREF is set to 5V)

              SDA==SDA (J2B1-9)

              SCL==SCL (J2B1-10)

              • 4. Re: ADXL345 via i2C
                Banq

                I made a little bit of progress. I got the sparkfun breakout board on monday so now I have a correctly level shifted i2c connection. I can detect the sensor with "i2cdetect -r 1" but the code I am using relies on python-smbus, so I haven't gotten much beyond that.

                • 5. Re: ADXL345 via i2C
                  Taimoor

                  Hello Banq

                   

                  I was able to make things work early morning today

                   

                   

                   

                  I'll post my code etc when I get back home. It turns out that things were pretty trivial... The documentation for beginners sucks at the moment. I don't say that it's bad, but I've found it easier to navigate through beaglebone and RPi stuff. Perhaps it's due to the overwhelming number of discussions taking place across the internet for ARM. I can't be sure.remind me if I forget to post my code.

                  • 6. Re: ADXL345 via i2C
                    Taimoor

                    Btw, if it's the Adafruit library that you were talking about, then I'm in your league. I couldn't get SMBUS to install even when I got pip working. They're were just too many dependencies missing.

                    • 7. Re: ADXL345 via i2C
                      Taimoor

                      So basically, here are the steps that I followed:

                      • Open up "Intel Edison Kit for Arduno Hardware Guide" and follow along the steps on page 30 (section 11.6). Intel® Edison Arduino Board Hardware Guide
                      • For my testing, I
                        • Wrote the Power register and wait until I can read the value back...
                      USED_I2C = 6
                      DEV_ADDR = 0x53
                      
                      x = mraa.I2c(USED_I2C)
                      byte = 0
                      m = "      "
                      while byte != 0x28:
                              print("I read: ")
                              x.address(DEV_ADDR)
                              x.writeReg(0x2D, 0x28)
                              time.sleep(1)
                              byte = x.readReg(0x2D)
                              print(byte)
                      
                      print("write to power register was successful")
                      
                      
                        • Played around with other register settings (I'm not posting that code here since I'm ashamed of how bad the code is written currently: no comments, literals everywhere). The i2c routines seem to work fine from here. Basically we can copy and adapt any code from the internet from here onwards. It would be useful if someone made/ported a library though. I would try to find time to do so if people are interested.

                       

                      General Suggestion to the Linux Dev Team

                      It would be GREAT (!!!!) if you guys could make a folder with these scripts for configuring the MUXes. In fact I think this would ease the adoption of the board as a whole for newbies. I always knew there was a Hardware guide but I didn't care going to section 11.6 until after many frustrating hours of the code not working. I can imagine how relieved I would've been if there was a script (in e.g. /local/scripts/) which I could simply execute to change the MUXes to output I2C on the pinouts.

                      • 8. Re: ADXL345 via i2C
                        Banq

                        edouardrosset/Edison · GitHub

                         

                        This script sets everything up for you. It's also nicely commented and easy to follow so you can understand what's happening. To be clear, I now have my setup working with an ADXL345 and the sparkfun i2c breakout.

                         

                        Thanks to edouardrosset

                        • 9. Re: ADXL345 via i2C
                          Taimoor

                          Thanks Banq!!

                           

                          I'll look into this. I got my setup running with the Arduino breakout too earlier. Can I ask you what you're working on?

                          • 10. Re: ADXL345 via i2C
                            mglass21

                            Thanks Taimoor, this helps a lot.  Can you share your code that reads the different axes?  thanks

                            • 11. Re: ADXL345 via i2C
                              Taimoor

                              Hello mglass21,

                               

                              I can do that only after 2nd of Feb.

                               

                              If you can wait that long, send me a reminder then...

                               

                              Thanks

                              • 12. Re: ADXL345 via i2C
                                Banq

                                I've got the Edison hooked up to the ADXL345 and a USB webcam. A python script triggers the camera at discrete angles.

                                 

                                Right now my setup is still a bit bulky but I have a 9DOF, battery and base sparkfun boards on order. Those 3 things should bring the overall  size down by a lot.

                                • 13. Re: ADXL345 via i2C
                                  Jacen

                                  could you send me the working code for ADXL345 running on Mini Edison

                                  • 14. Re: ADXL345 via i2C
                                    Banq

                                    Start with this script:

                                     

                                    edouardrosset/Edison · GitHub

                                     

                                     

                                    Then I simply followed this guide:

                                     

                                     

                                    <Stuff about="code" />: Raspberry Pi - ADXL345 Accelerometer & Python

                                    1 2 Previous Next