Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added use of the built-in DLPF filter #36

Merged
merged 2 commits into from
Nov 26, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions mpu6050/mpu6050.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ class mpu6050:
GYRO_RANGE_1000DEG = 0x10
GYRO_RANGE_2000DEG = 0x18

FILTER_BW_256=0x00
FILTER_BW_188=0x01
FILTER_BW_98=0x02
FILTER_BW_42=0x03
FILTER_BW_20=0x04
FILTER_BW_10=0x05
FILTER_BW_5=0x06

# MPU-6050 Registers
PWR_MGMT_1 = 0x6B
PWR_MGMT_2 = 0x6C
Expand All @@ -52,6 +60,7 @@ class mpu6050:

ACCEL_CONFIG = 0x1C
GYRO_CONFIG = 0x1B
MPU_CONFIG = 0x1A

def __init__(self, address, bus=1):
self.address = address
Expand Down Expand Up @@ -179,6 +188,12 @@ def set_gyro_range(self, gyro_range):
# Write the new range to the ACCEL_CONFIG register
self.bus.write_byte_data(self.address, self.GYRO_CONFIG, gyro_range)

def set_filter_range(self, filter_range=FILTER_BW_256):
"""Sets the low-pass bandpass filter frequency"""
#TODO - Currently overwrites bits 3,4,5 used for FSYNC pin. Change implementation to fix this.
return self.bus.write_byte_data(self.address, self.MPU_CONFIG,filter_range)
S-Gol marked this conversation as resolved.
Show resolved Hide resolved


def read_gyro_range(self, raw = False):
"""Reads the range the gyroscope is set to.

Expand Down