This PowerShell module is to interact with ADXL345 accelerometer for reading acceleration on 3 axis.
Several vendors have breakout boards with ADXL345 sensor. In this example we'll use SparkFun Triple Axis Accelerometer Breakout.
ADXL345 sensor supports both I2C and SPI interfaces; here we'll use I2C.
Wiring diagram with Raspberry Pi 3 looks like this:
Installation instructions can be found here.
sudo raspi-config
5 Interfacing options
P5 I2C
Would you like ARM I2C interface to be enabled -> Yes
Don't forget to start PowerShell with sudo or you'll be unable to access I2C bus.
sudo pwsh
Install-Module -Name Microsoft.PowerShell.IoT
git clone https://github.com/PowerShell/PowerShell-IoT.git
Import-Module ./PowerShell-IoT/Examples/Microsoft.PowerShell.IoT.ADXL345
To simply collect acceleration values in g:
PS /home/pi> $accelerometer = Get-ADXL345Device
PS /home/pi> Get-ADXL345Data -Device $accelerometer
Name Value
---- -----
y -0.03008072
x 0.0828058
z 0.86966985
To represent current acceleration on the 3 axis with bargraphs:
PS /home/pi> $accelerometer = Get-ADXL345Device
PS /home/pi> while ($true) {
$data = Get-ADXL345Data -Device $accelerometer -Limit 1
Write-Progress -id 1 -Activity 'X axis' -Status 'Acceleration' -PercentComplete ($data.x * 50 + 50)
Write-Progress -id 2 -Activity 'Y axis' -Status 'Acceleration' -PercentComplete ($data.y * 50 + 50)
Write-Progress -id 3 -Activity 'Z axis' -Status 'Acceleration' -PercentComplete ($data.z * 50 + 50)
}
X axis
Acceleration
[ooooooooooooooooooooooooooooooooooooooooooooooooooo ]
Y axis
Acceleration
[ooooooooooooooooooooooooooooooooooooooooooooooooo ]
Z axis
Acceleration
[ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ]