Accelerometer help

I followed the start guide for the accelerometer on my raspberry pi 4 and i have run into a problem with Thonny. When I try to run the example script I keep getting the following error:

Traceback (most recent call last):
File “/home/bjreeder/piicodev_sensors/accelerometer/acceleration.py”, line 9, in
motion = PiicoDev_LIS3DH() # Initialise the accelerometer
File “/home/bjreeder/piicodev/lib/python3.11/site-packages/PiicoDev_LIS3DH.py”, line 84, in init
self.i2c = create_unified_i2c(bus=bus, freq=freq, sda=sda, scl=scl)
File “/home/bjreeder/piicodev/lib/python3.11/site-packages/PiicoDev_Unified.py”, line 167, in create_unified_i2c
i2c = I2CUnifiedLinux(bus=bus, suppress_warnings=suppress_warnings)
File “/home/bjreeder/piicodev/lib/python3.11/site-packages/PiicoDev_Unified.py”, line 111, in init
self.i2c = SMBus(bus)
File “/home/bjreeder/piicodev/lib/python3.11/site-packages/smbus2/smbus2.py”, line 280, in init
self.open(bus)
File “/home/bjreeder/piicodev/lib/python3.11/site-packages/smbus2/smbus2.py”, line 310, in open
self.fd = os.open(filepath, os.O_RDWR)
FileNotFoundError: [Errno 2] No such file or directory: ‘/dev/i2c-1’

any help would be appreciated because I am really out of my element here.

Here is the example script I am trying to run:

“”"
PiicoDev Accelerometer LIS3DH
Simple example to read acceleration data
“”"

from PiicoDev_LIS3DH import PiicoDev_LIS3DH
from PiicoDev_Unified import sleep_ms # cross-platform compatible sleep function

motion = PiicoDev_LIS3DH() # Initialise the accelerometer
motion.range = 2 # Set the range to ±2g

while True:
x, y, z = motion.acceleration
x = round(x,2) # round data for a nicer-looking print()
y = round(y,2)
z = round(z,2)
myString = "X: " + str(x) + ", Y: " + str(y) + ", Z: " + str(z) # build a string of data
print(myString)

sleep_ms(100)
2 Likes

Hi Brandon,

It looks like the Accelerometer guide quicky skips over setting up I2C, the distance sensor here goes into depth on how to get all of that setup: PiicoDev Distance Sensor VL53L1X - Raspberry Pi Guide - Tutorial Australia

Let us know how you go!

1 Like

Thanks Liam

that solved my problem

3 Likes