Arduino Accelerometer

Hey guys,
I need some help regarding a project I am working on nowadays. I am stuck at a number of things and want guidance regarding them. I am working on a project which is using Arduino Due (Board Model DUE R3) connected with ADXL345 accelerometer. The board is connected with Pc with a usb cable. Right now I am using the following code to recieve the x,y and z readings from the accelerometer:

#include <Wire.h>

#include <Adafruit_Sensor.h>

#include <Adafruit_ADXL345_U.h>

Adafruit_ADXL345_Unified BSens = Adafruit_ADXL345_Unified(1);
void setup()

void loop()
sensors_event_t event;
Serial.print(" “);
Serial.print(” ");

With this code right now I am recieving the readings from the accelerometer at 310 Hz datarate. Increasing the data rate starts to give errors in the reception of the data (printing of data on the screen at once). The ADXL345 manual says that we can increase the data rate of the accelerometer to upto 3200Hz. So my plan is to increase the datarate of the accelerometer to 3200Hz(maximum value) and store it as a packet of data in the Arduino Due Board and recieve that data after every 1 or 2 seconds as a packet file.
So can you please guide me in how to increase the sampling rate of my ADXL345 Accelerometer and then how to store the data (x,y and z values) coming from accelerometer to the Arduino board for 1 or 2 seconds, in the form of packet and then how to receive that packet to Pc after every 1 or 2 seconds?
As I am new to this project so a detailed explanation will be appreciated.
Will be really grateful to people if you please help me in this project. Can also provide additional information if needed.
Thank you and have a nice day.
Daniyal Khan

I have a question about your project. Have you tried it at 9600 baud rate? If so, how fast are you getting information?

Yeah it is currently working at 9600 buad rate. And the rate is 310 Hz at this buad.

Increase the baud rate of the serial port if you want to get more data across. 9600 is bits per second, and you are transferring at least 3 bytes for each reading which at 310 Hz would be 8kbits a second.

First, the standard Arduino serial transmission on the Due is extremely slow. Glacial. Like a sloth on tarpaper. It has to wait for each character to send. This wastes millions of processor cycles waiting for the one-byte serial buffer to be cleared. If you're concerned about speed, then be very careful how you use Serial. If you can, send only one byte (virtually instantaneous) and then go away and do 50 other things before queueing the next byte for transmission. You can't packetize your serial transmissions without a lot of work in your program. Or buy an Arduino Mega and be amazed.

Second, it looks like you're talking to the ADXL345 with the I2C (Wire) interface. SPI can be faster than I2C. I'm not familiar with Adafruit's unified interface but it's probably not even using high-speed I2C. My experience with the ADXL345 is that it can handle faster data rates than the AVR Arduinos can achieve. 10MHz SPI works great.

Third, yes you can use the ADXL345's FIFO buffer to store a number of samples and read them out in a block. You don't get anything like 1 second worth of data. The buffer is quite small. You will probably end up modifying the Unified object to get this functionality the way you want it.

Fourth, if you have to keep I2C, then you can accelerate things by not sending stop bits. The ADXL345 doesn't need them. This can save up to 25% of your I2C bandwidth.

Fifth, if you are using high speed I2C, you probably need lower value pullup resistors than what's already there. You can parallel resistors to get the resistance down. 470 ohms is probably the limit. 4.7k is good for most purposes.

Hey Guys thanks for the great response and help.

MorganS: Thanks a lot for the detailed answer. I completely understood that I need to change my board and am planning to do it on your advice.

Please also advice on how should I use serial to increase the data rate of my ADXL345. And how can I use SPI for faster data rates?

Can you please also state the methods by which I can store the data by using ADXL345's FIFO buffer.

Please also state the method of not sending stop bits.

As I am a newbie in this kind of work so please recoomend me the next stage with detailed methods of the operations I should do to achieve what I want. I really thank you for the answer and help. Regards, Daniyal Khan

Not sending stop bits: don't use the Wire.endTransmission() function.

Faster SPI: SPI.setClockDivider(SPI_CLOCK_DIV2); this will transfer data at 8MHz instead of the 0.1MHz of standard I2C.

Using the FIFO: I don't know, I've never tried. It never seemed useful for my projects.

I am really confused about your conversation... I think when you guys are talking about "Arduino DUE R3" you actually mean "Arduino UNO R3".. and this post should not be in the Arduino DUE section