Skip to content

Instantly share code, notes, and snippets.

@MOAMIndustries
Last active November 15, 2021 04:22
Show Gist options
  • Save MOAMIndustries/48ab0eb5d5d8d4656b3a789afd52f290 to your computer and use it in GitHub Desktop.
Save MOAMIndustries/48ab0eb5d5d8d4656b3a789afd52f290 to your computer and use it in GitHub Desktop.
Writing accelerometer values to JSON file
from Adafruit_BNO055 import BNO055
# Create and configure the BNO sensor connection.
# Configure based on your IO configuration
# Raspberry Pi configuration with serial UART and RST connected to GPIO 18:
bno = BNO055.BNO055(serial_port='/dev/serial0', rst=18)
web_path ="/var/www/html/"
while True:
#Get readings from accelerometers
heading, roll, pitch = bno.read_euler()
x,y,z = bno.read_accelerometer()
sys, gyro, accel, mag = bno.get_calibration_status()
#store values in dictionary
data ={'xA':x,'yA':y,'zA':z,'yaw':heading,'roll':roll,'pitch':pitch}
calibration={'sys':sys,'gyro':gyro,'accel':accel,'mag':mag}
#open file and dump data formatted as JSON
with open(os.path.join(web_path,json_file), 'w') as f:
json.dump(data, f)
with open(os.path.join(web_path,calib_file), 'w') as f:
json.dump(calibration, f)
@mahabubsikder751975
Copy link

Hi fellow,

I am getting this error to generate data from your py file:
File "c:\Software\RealtimeChart\Streaming_IMU_Logger.py", line 4, in
heading, roll, pitch = bno.read_euler()
NameError: name 'bno' is not defined

Pls help me out

@MOAMIndustries
Copy link
Author

@mahabubsikder751975
I've updated the code to include the definition and library for bno.
This is the IMU used in the example, but you could use any IMU and library with a similar result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment