Intel® Makers
Intel® Edison, Intel® Joule™, Intel® Curie™, Intel® Galileo
Announcements
Welcome - This is a Peer-to-Peer Forum only. Intel has discontinued these products but you may find support from other customers on this Forum
9868 Discussions

ADXL345 via i2C

ABanq
New Contributor I
1,222 Views

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.

0 Kudos
1 Solution
ABanq
New Contributor I
265 Views

https://github.com/edouardrosset/Edison 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 https://github.com/edouardrosset edouardrosset

View solution in original post

15 Replies
MMoy
New Contributor II
265 Views

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 ?

ABanq
New Contributor I
265 Views

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

idata
Community Manager
265 Views

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)

ABanq
New Contributor I
265 Views

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.

idata
Community Manager
265 Views

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.

idata
Community Manager
265 Views

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.

idata
Community Manager
265 Views

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).
  • 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.

MWilh1
Beginner
265 Views

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

idata
Community Manager
265 Views

Hello mglass21,

I can do that only after 2nd of Feb.

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

Thanks

ABanq
New Contributor I
266 Views

https://github.com/edouardrosset/Edison 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 https://github.com/edouardrosset edouardrosset

idata
Community Manager
265 Views

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?

ABanq
New Contributor I
265 Views

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.

jlee166
New Contributor II
265 Views

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

ABanq
New Contributor I
265 Views

Start with this script:

https://github.com/edouardrosset/Edison edouardrosset/Edison · GitHub

Then I simply followed this guide:

http://www.stuffaboutcode.com/2014/06/raspberry-pi-adxl345-accelerometer.html : Raspberry Pi - ADXL345 Accelerometer & Python

DDose1
Beginner
265 Views

I'm also having problems running an ADXL345 accelerometer (Grove - 3-Axis Digital Accelerometer(±16g)) on an Edison.

I'm using the accelerometer attached to the Grove base shield. If I run a sketch (using Edison specific Arduino 1.5.3) - I can see results in my serial port, but all values are 0'd out.

As a test, I put the same shield on an Arduino Uno - and it runs fine with any version of the Arduino IDE.

I've tried the post flash suggestion above, but my Edison still doesn't seem to properly recognize the accelerometer. Any ideas?

Reply