Skip to content

Commit d0f3fa0

Browse files
authored
Merge pull request #36 from S-Gol/master
Added use of the built-in DLPF filter
2 parents 199af07 + 7f59bb5 commit d0f3fa0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

mpu6050/mpu6050.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ class mpu6050:
3636
GYRO_RANGE_1000DEG = 0x10
3737
GYRO_RANGE_2000DEG = 0x18
3838

39+
FILTER_BW_256=0x00
40+
FILTER_BW_188=0x01
41+
FILTER_BW_98=0x02
42+
FILTER_BW_42=0x03
43+
FILTER_BW_20=0x04
44+
FILTER_BW_10=0x05
45+
FILTER_BW_5=0x06
46+
3947
# MPU-6050 Registers
4048
PWR_MGMT_1 = 0x6B
4149
PWR_MGMT_2 = 0x6C
@@ -52,6 +60,7 @@ class mpu6050:
5260

5361
ACCEL_CONFIG = 0x1C
5462
GYRO_CONFIG = 0x1B
63+
MPU_CONFIG = 0x1A
5564

5665
def __init__(self, address, bus=1):
5766
self.address = address
@@ -179,6 +188,13 @@ def set_gyro_range(self, gyro_range):
179188
# Write the new range to the ACCEL_CONFIG register
180189
self.bus.write_byte_data(self.address, self.GYRO_CONFIG, gyro_range)
181190

191+
def set_filter_range(self, filter_range=FILTER_BW_256):
192+
"""Sets the low-pass bandpass filter frequency"""
193+
# Keep the current EXT_SYNC_SET configuration in bits 3, 4, 5 in the MPU_CONFIG register
194+
EXT_SYNC_SET = self.bus.read_byte_data(self.address, self.MPU_CONFIG) & 0b00111000
195+
return self.bus.write_byte_data(self.address, self.MPU_CONFIG, EXT_SYNC_SET | filter_range)
196+
197+
182198
def read_gyro_range(self, raw = False):
183199
"""Reads the range the gyroscope is set to.
184200

0 commit comments

Comments
 (0)