Lately, I have become interested in doing some more science experiments with the Raspberry Pi. I decided to start with physics, and some basic pendulum experiments.
Connect the Sensor to the Raspberry Pi
The connections are pretty straightforward. First, you will need to solder the pins onto the sensor. There are seven pins, and you will use 4 of them. Once soldered, make these connections:
|3v||3v – Pin 1|
|SDA||SDA – Pin 3|
|SCL||SCL – Pin 5|
|GND||Ground – Pin 6|
Next we will work on the Pi to get it to recognize the sensor.
Preparing the Pi
You will need to change a couple files on the Pi so it can work with the sensor.
sudo nano /etc/modules
In that file add the following lines
Then you need to open another file, and remove I2C from the blacklist. If you already have I2C enabled for the Pi, you might not have to do this, but it is good to check.
Comment out this line
it will look like
Reboot the Pi to make the changes.
Install the software
In the command line, type:
sudo apt-get install python-smbus i2c-tools git-core
The Pi will go through some installation. After that you can check to see that your sensor is connected.
sudo i2cdetect -y 1
If everything works, you should get something like this:
If you see all dashes, something is probably not connected right. You will want to go back and check it again.
Get a Measurement
To get a measurement, you will need to download some software from pimoroni. Make sure you are in home directory and use the command below.
sudo git clone https://github.com/pimoroni/adxl345-python.git
This creates a folder called adxl345-python. In that folder there are a few files, one of which is an example file.
sudo python example.py
That is pretty much it. Everything else is just getting a program set up to collect the data you want, in the way you want it. Have fun!