# How Can i use ADXL345?

**URL:** <https://community.particle.io/t/how-can-i-use-adxl345/3991>\
**Category:** Troubleshooting\
**Created:** [April 21, 2014, 2:26pm UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991 "2014-04-21T14:26:57Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yasin](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/yasin/32/69_2.png) [@Yasin](https://community.particle.io/u/Yasin)\
**Post date:** [April 21, 2014, 2:26pm UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991/1 "2014-04-21T14:26:57Z")

</div>

Hello,

I just bought ADXL345 3-Axis sensor. Can someone tell me how can i use it with spark core?

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [April 21, 2014, 2:29pm UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991/2 "2014-04-21T14:29:32Z")

</div>

Maybe this old tutorial is a good reference:

[https://www.sparkfun.com/tutorials/240](https://www.sparkfun.com/tutorials/240)

---

<div class="post-metadata">

**Author:** ![Yasin](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/yasin/32/69_2.png) [@Yasin](https://community.particle.io/u/Yasin)\
**Post date:** [April 21, 2014, 2:32pm UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991/3 "2014-04-21T14:32:00Z")

</div>

@kennethlimcp i saw this page but , i don’t know exactly spark core pinout diagram. Which pin is SCL, SDA, SDO on spark core?

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [April 21, 2014, 2:41pm UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991/4 "2014-04-21T14:41:17Z")

</div>

The :spark: docs is always a good place to look

[http://docs.spark.io/#/hardware/pins-and-i-o-i2c](http://docs.spark.io/#/hardware/pins-and-i-o-i2c)

---

<div class="post-metadata">

**Author:** ![Yasin](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/yasin/32/69_2.png) [@Yasin](https://community.particle.io/u/Yasin)\
**Post date:** [April 21, 2014, 3:06pm UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991/5 "2014-04-21T15:06:14Z")

</div>

Thanks 🙂 but code is still complex. . Did someone worked with ADXL345 ? i need help 🙂

---

<div class="post-metadata">

**Author:** ![Yasin](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/yasin/32/69_2.png) [@Yasin](https://community.particle.io/u/Yasin)\
**Post date:** [April 25, 2014, 8:32am UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991/6 "2014-04-25T08:32:11Z")

</div>

I found this github example [https://github.com/jenschr/Arduino-libraries/tree/master/ADXL345](https://github.com/jenschr/Arduino-libraries/tree/master/ADXL345)

i think it is work with no library but i want to use it detailed so can any one edit for library ?

No library results;

![](https://community.particle.io/uploads/particle/1188/5a72ebec1f62d724.png)

---

<div class="post-metadata">

**Author:** ![Yasin](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/yasin/32/69_2.png) [@Yasin](https://community.particle.io/u/Yasin)\
**Post date:** [April 25, 2014, 11:39am UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991/7 "2014-04-25T11:39:33Z")

</div>

I am working with library files. But no success. I have tried lot of time and have problem.

```
    In file included from ../inc/spark_wiring.h:30:0,
from ../inc/application.h:31,
from ADXL345.h:15,
from ADXL345.cpp:16:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
ADXL345.cpp: In member function 'void ADXL345::getRangeSetting(byte*)':
ADXL345.cpp:96:23: error: 'B00000011' was not declared in this scope
ADXL345.cpp: In member function 'void ADXL345::setRangeSetting(int)':
ADXL345.cpp:106:9: error: 'B00000000' was not declared in this scope
ADXL345.cpp:109:9: error: 'B00000001' was not declared in this scope
ADXL345.cpp:112:9: error: 'B00000010' was not declared in this scope
ADXL345.cpp:115:9: error: 'B00000011' was not declared in this scope
ADXL345.cpp:121:14: error: 'B11101100' was not declared in this scope
ADXL345.cpp: In member function 'double ADXL345::getRate()':
ADXL345.cpp:493:8: error: 'B00001111' was not declared in this scope
ADXL345.cpp:494:28: error: 'pow' was not declared in this scope
ADXL345.cpp: In member function 'void ADXL345::setRate(double)':
ADXL345.cpp:507:31: error: 'B11110000' was not declared in this scope
ADXL345.cpp: In member function 'double ADXL345::getRate()':
ADXL345.cpp:495:1: warning: control reaches end of non-void function [-Wreturn-type]
make: *** [ADXL345.o] Error 1

```

Anyone help me ?

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [April 25, 2014, 11:58am UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991/8 "2014-04-25T11:58:55Z")

</div>

Will take a look now.

@Yasin, I have ported the library and testing the examples to make sure they compile. Do check back when i update here again 😄

**UPDATE**

All done: [https://github.com/kennethlimcp/SparkCoreLibraries/tree/master/ADXL345](https://github.com/kennethlimcp/SparkCoreLibraries/tree/master/ADXL345)

---

<div class="post-metadata">

**Author:** ![Yasin](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/yasin/32/69_2.png) [@Yasin](https://community.particle.io/u/Yasin)\
**Post date:** [April 25, 2014, 4:40pm UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991/9 "2014-04-25T16:40:39Z")

</div>

Hey ! Thanks dude. It is working well :)) you are hero :))

---

<div class="post-metadata">

**Author:** ![Noten](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/noten/32/354_2.png) [@Noten](https://community.particle.io/u/Noten)\
**Post date:** [October 18, 2014, 11:47am UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991/10 "2014-10-18T11:47:09Z")

</div>

hi Guys!

I’m also trying to wire this chip with the spark core, but had no luck ☹

Can somebody post the entire code how you were able to get it work?

I connected it like this:  
// Gnd - GND  
// 3.3v - VCC  
// 3.3v - CS  
// Analog 4 - SDA  
// Analog 5 - SLC

And used the demo code from [https://github.com/jenschr/Arduino-libraries/tree/master/ADXL345](https://github.com/jenschr/Arduino-libraries/tree/master/ADXL345) along with kennethlimcp’s modified .h file, but it drops error continuously ☹

Your help would be appreciated, thank you in advance!

Noten

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [October 18, 2014, 11:52am UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991/11 "2014-10-18T11:52:37Z")

</div>

Hey @Noten, it seems like it’s I2C based?

The current firmware in the buildfarm has issues with I2C and a fix it on it’s way.

Sorry about that!

---

<div class="post-metadata">

**Author:** ![Noten](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/noten/32/354_2.png) [@Noten](https://community.particle.io/u/Noten)\
**Post date:** [October 18, 2014, 12:02pm UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991/12 "2014-10-18T12:02:14Z")

</div>

hey!

Oh, i didn’t know that. So what is the next step? Should i wait for the fix and start compiling it again? Or should i start downloading the firmware from the web-ide and upload to the core manually?

Problem is i’m afraid i don’t even have a working code sample, so i cannot say for sure this is related to i2c or code, etc… ☹

If you have a working and available source-code for this, i could try with that, so at least i could see that this is i2c related for sure.

Thanks for your fast reply kenneth!

Noten

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [October 18, 2014, 12:31pm UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991/13 "2014-10-18T12:31:31Z")

</div>

@Noten,

I’m afraid using the Web IDE doesn’t resolve the issue as it’s compiling against the broken firmware.

The only short term solution right now is to compile it using the commit which fixes the issue locally.

That might be a little painful to work with for a start…

I think the demo code on the repo i published works fine since it was requested by someone and he probably used it already…

If i compiled it locally with the I2C fix, i’ll drop the binary file here so that you can test it out 😄

One thing missing in terms of hardware might be the **pull-up resistors** for I2C lines unless the board came with it already.

---

<div class="post-metadata">

**Author:** ![Noten](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/noten/32/354_2.png) [@Noten](https://community.particle.io/u/Noten)\
**Post date:** [October 18, 2014, 3:27pm UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991/14 "2014-10-18T15:27:13Z")

</div>

hey Kenneth!

Thanks for your continuous help 🙂 I’m not really a technical person, so not really sure how these things should be connected (especially with the pull-up resistor), i just connected the pins and that’s it.

Here is my sensor: ![](https://sea2.discourse-cdn.com/flex026/uploads/particle/3336/040fe14ed2510cf9.JPG)

Not sure if i have to use any pull-up resistors and if yes where (and how).

Your test code would be brilliant! If you could that ,that would be awesome!!!

Thanks a bunch Kenneth for all your help again, really appreciate it.

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [October 18, 2014, 3:29pm UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991/15 "2014-10-18T15:29:09Z")

</div>

Do you have the link for the product? I’ll look up the datasheet.

Also, the library repo is this: [https://github.com/kennethlimcp/spark-lib-adxl345](https://github.com/kennethlimcp/spark-lib-adxl345)

Currently compiling it against an older firmware and will post the link for the binary file in a moment

---

<div class="post-metadata">

**Author:** ![Noten](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/noten/32/354_2.png) [@Noten](https://community.particle.io/u/Noten)\
**Post date:** [October 18, 2014, 3:32pm UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991/16 "2014-10-18T15:32:29Z")

</div>

hey!

Sure. The model number is GY-291, with the ADXL345, you can find more info about it here:

[http://hobbycomponents.com/index.php/gy-291-adxl345-triple-axis-accelerometer.html](http://hobbycomponents.com/index.php/gy-291-adxl345-triple-axis-accelerometer.html)  
or

> **[GY-291 ADXL345 3-axis Acceleration Gravity Tilt Sensor Module](http://www.dx.com/p/gy-291-adxl345-digital-3-axis-acceleration-of-gravity-tilt-module-for-arduino-148921#.VEKHwYcl5bw)**
>
> I like this from DX. Find the cool gadgets at a incredibly low price with worldwide free shipping here.

and THANK YOU for compiling the firmware for me!

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [October 18, 2014, 3:45pm UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991/17 "2014-10-18T15:45:59Z")

</div>

@Noten you can try this binary file: [https://dl.dropboxusercontent.com/u/36134145/adxl345.bin](https://dl.dropboxusercontent.com/u/36134145/adxl345.bin)

Seems like the library is broken as i haven’t maintained it in a while but i compiled using a test code that did not require the library for while.

You will need to open up a Serial terminal with 115200 to test out. 😉

---

<div class="post-metadata">

**Author:** ![Noten](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/noten/32/354_2.png) [@Noten](https://community.particle.io/u/Noten)\
**Post date:** [October 18, 2014, 4:08pm UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991/18 "2014-10-18T16:08:38Z")

</div>

Kenneth, you ROCK!

So as the “Yosemite” issue is resolved as well, i was able to install your firmware, it is AWESOME!

[https://www.dropbox.com/s/g2yohtt7byia4ml/Screenshot%202014-10-18%2018.06.32.jpg?dl=0](https://www.dropbox.com/s/g2yohtt7byia4ml/Screenshot%202014-10-18%2018.06.32.jpg?dl=0) 😉

So once the i2c is fixed on the webIDE, i will be able to compile the code from your github repo and done?

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [October 18, 2014, 4:10pm UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991/19 "2014-10-18T16:10:43Z")

</div>

I think the library is a little broken but from the repo link i pasted above, there’s an example that works like how you just tested without the library!

If i don’t fix it before the I2C issue is resolved, simply use that example as a temporary solution. I’ll ask @peekay123 for some help with the library errors.

Doesn’t look complicated to fix but i’ll probably tackle it few hours later. 😉

Have fun!

---

<div class="post-metadata">

**Author:** ![Noten](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/noten/32/354_2.png) [@Noten](https://community.particle.io/u/Noten)\
**Post date:** [October 18, 2014, 4:12pm UTC](https://community.particle.io/t/how-can-i-use-adxl345/3991/20 "2014-10-18T16:12:13Z")

</div>

Thank you Kenneth! Appreciate it!

[Next page](https://community.particle.io/t/how-can-i-use-adxl345/3991.md?page=2)
