diff --git a/MPU6050.py b/MPU6050.py index feb5fea..b39cc0d 100644 --- a/MPU6050.py +++ b/MPU6050.py @@ -12,7 +12,7 @@ class MPU6050: # Global Variables GRAVITIY_MS2 = 9.80665 address = None - bus = smbus.SMBus(1) + bus = None # Scale Modifiers ACCEL_SCALE_MODIFIER_2G = 16384.0 @@ -65,9 +65,11 @@ class MPU6050: ACCEL_CONFIG = 0x1C GYRO_CONFIG = 0x1B - def __init__(self, address): + def __init__(self, address, bus_index = 1): + # Set address and bus index self.address = address - + self.bus = smbus.SMBus(bus_index) + # Wake up the MPU-6050 since it starts in sleep mode self.bus.write_byte_data(self.address, self.PWR_MGMT_1, 0x00) @@ -253,9 +255,9 @@ def get_gyro_data(self): def get_all_data(self): """Reads and returns all the available data.""" - temp = get_temp() - accel = get_accel_data() - gyro = get_gyro_data() + temp = self.get_temp() + accel = self.get_accel_data() + gyro = self.get_gyro_data() return [accel, gyro, temp]