To edit the file, I had to go through the file path on the command line and use sudo nano qwiic_kx13x.py to give myself edit permissions.
I went back to the comment above line 334, removed both of the “”", and commented out lines 328 - 334 with # .
Then I ran the code again and got a new error shown below:
SparkFun KX13X Accelerometer Example 1
Ready.
Traceback (most recent call last):
File "/home/pi/Documents/Acceleremoter Module/Accelerometer Code.py", line 36, in <module>
runExample()
File "/home/pi/Documents/Acceleremoter Module/Accelerometer Code.py", line 23, in runExample
myKx.initialize(myKx.BASIC_SETTINGS) # Load basic settings
AttributeError: 'QwiicKX132' object has no attribute 'BASIC_SETTINGS'
I then went back and replaced all “”" with # as you suggested, but received the same exact error.
Then I went back and put a # on each unused line, but still received the same error.
The new error posted above is now referencing the lines on the example program itself: https://github.com/sparkfun/Qwiic_KX13X … 13x_ex1.py
(I did not include the comments when I copied the code, so my line 36 is line 77 from the example, and my line 23 is line 64 from the example.)
I did not alter the code after pasting it.
After looking online, usually when people get an attribute error, the cause is a result of a minor formatting issue in the code such as an indentation, spelling error, or an extra comma. Although I do not see that here.
Here is the code:
from __future__ import print_function
import qwiic_kx13x
import time
import sys
def runExample():
print("\nSparkFun KX13X Accelerometer Example 1\n")
# myKx = qwiic_kx13x.QwiicKX134() # If using the KX134 un-comment this line and replace other instances of "kx132" with "kx134"
myKx = qwiic_kx13x.QwiicKX132()
if myKx.connected == False:
print("The Qwiic KX13X Accelerometer device isn't connected to the system. Please check your connection", \
file=sys.stderr)
return
if myKx.begin():
print("Ready.")
else:
print("Make sure you're using the KX132 and not the KX134")
# myKx.set_range(myKx.KX132_RANGE8G) # Update the range of the data output.
myKx.initialize(myKx.BASIC_SETTINGS) # Load basic settings
while True:
myKx.get_accel_data()
print("X: {0}g Y: {1}g Z: {2}g".format(myKx.kx132_accel.x,
myKx.kx132_accel.y,
myKx.kx132_accel.z))
time.sleep(.02) #Set delay to 1/Output Data Rate which is by default 50Hz 1/50 = .02
if __name__ == '__main__':
try:
runExample()
except (KeyboardInterrupt, SystemExit) as exErr:
print("\nEnding Example 1")
sys.exit(0)
I also searched for “BASIC_SETTINGS” on the qwiic_kx13x.py file but did not get any results.
I am not sure if it supposed to be on that file.