Skip to content

Sensor Accelerometer

HTTYDKing edited this page Oct 31, 2022 · 2 revisions

I2C communications with accelerometer

A quick guide on how you would be able to manually get values from the accelerometer.

1 - Wiring the accelerometer sensor to the BeagleBone

For this step just follow the image below to connect the pins to the right slots. Make sure that it is the P9 slots.

Black wire - ground

Red wire - 3.3V

Green wire - I2C Clock

Blue wire - I2C

Purple wire - Configures each sensor to a different register (should not be connected to the beagle board)

2 - Going into the BeagleBone

Once you connect the BeagleBone to your laptop then open ubuntu and type in the command

ssh debain@192.168.7.2

If it gives out nothing then just wait for a minute and then try again

It will then request a password from you which is temppwd

3 - Getting values with I2C

Now use the below commands to get the required information from the board

i2cdetect -l -- lists all the different busses on the beaglebone

i2cdetect -r 2 -- connect to the i2c 2nd bus, a table to registries will appear and the relevant register names would appear e.g. 18 19

The next step is to set the modes for the addresses on the beaglebone so that you would be receiving the information from the sensors.

i2cset -y 2 0x18 0x20 0x64 -- Setting it to High Power mode

i2cset -y 2 0x18 0x21 0x0c -- Enabling BDU

i2cset -y 2 0x18 0x25 0x30 -- Setting full scale selection to +-16 gs

i2cget -y 2 0x18 0x27 -- Reading this bit will tell you whether the sensor is ready to be read from. If it is then it is ready to be read if it is 0 either you made a mistake or would have to wait and try again in another second.

Repeat these steps with the 0x19 registry for the other sensor.

Reading information from the registers

As for this breadboard, there are 2 sensors we will have 2 registries (being 0x19, 0x18)

Next, you will get the information from the sensor, this can be done by typing these commands into the command line in ubuntu:

i2cget -y 2 0x18 0x28 -- This is getting the Low x-axis which is the smaller insignificant value for the x-axis acceleration

i2cget -y 2 0x18 0x29 -- This is getting the High x-axis which would be the larger more significant value for x-axis acceleration

Repeat this with 0x2a 0x2b for the y-axis low and high and 0x2c 0x2d for the z-axis high and low.

Repeat all the previous steps but with 0x19 to get the reading from the other sensor

###This is an example of how it looks in a command line

Conversion

Then once you get your values go to the datasheet (Page 57 onwards) and concatenate the values together to get the acceleration. e.g. if you get 0x00 (being your high value), and 0xec (the low value) then to concatenate it would be 0x00ec. Perform hexadecimal to decimal (base 10) conversion and multiply that value by 0.01 to get your acceleration. If the sensor is stationary the x-axis and y-axis acceleration should be 0 but the z-axis acceleration will be 1.