How Can i use ADXL345?


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

Maybe this old tutorial is a good reference:

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

1 Like

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

1 Like

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

1 Like

I found this github example

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;

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 ?

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 :smile:


All done:

1 Like

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

hi Guys!

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

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 along with kennethlimcp’s modified .h file, but it drops error continuously :frowning:

Your help would be appreciated, thank you in advance!


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!


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… :frowning:

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!



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 :smile:

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

1 Like

hey Kenneth!

Thanks for your continuous help :slight_smile: 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:

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.

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

Also, the library repo is this:

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



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

and THANK YOU for compiling the firmware for me!

@Noten you can try this binary file:

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. :wink:

Kenneth, you ROCK!

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

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

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. :wink:

Have fun!

1 Like

Thank you Kenneth! Appreciate it!

1 Like