Since a few months I’m kind of interested in research topics related to displacement calculation based on time series acceleration. This basically shows that when something starts moving it displacement depends on the velocity and the time that it has been moving, but due to the fact that the velocity changes continuously we take this variation as the object acceleration (meters per second per second). In this case we will use the accelerometer to estimate the relative position to a point p, which is derived using the double integration of the acceleration metrics.
Until now we have no speed, time or acceleration metrics so we are going to start from the very beginning.
Total budged for this project: 105.73 Eur.
First let’s connect our ADXL345 accelerometer to the Raspberry by connecting the jumpers as follow:
|Raspberry GPIO pin||ADXL345 pin|
This will lead to something like:
Or a wider view:
Once having the Raspberry wired, let’s configure it by the following steps.
- From our Raspberry Pi, install:
sudo apt-get install python-smbus i2c-tools
- Enable the I2C kernel module in the Raspberry Pi:
Now, enable I2C kernel module in: Advanced Options -> I2C -> Would you like the ARM module.. -> Would you like it enabled by default..
- Edit the modules file (sudo vim /etc/modules) and make sure it contains the following lines:
- Remove I2C from the blacklist file (/etc/modprobe.d/raspi-blacklist.conf) commenting the following line if it appears:
- After all these previous steps, reboot the Raspberry Pi
- Test the connection to the I2C module:
sudo i2cdetect -y 1
The command should print the following output:
Now, when having the module working properly, we need to get and use the python ADXL345 library to have access to the time based data.
- Clone the library repository and execute the example code:
git clone https://github.com/pimoroni/adxl345-python cd adxl345-python sudo python example.py
The command’s output should be:
Showing the G forces in each axis.
This is it for the first part of the tutorial. Next posts will dig into the real-time data processing.