From b86d6672c7573e4215a49aa79704c4db64d62b8b Mon Sep 17 00:00:00 2001 From: Scott Mudge Date: Sun, 21 Apr 2019 04:34:09 -0400 Subject: [PATCH 01/13] Added acceleration module configuration functionality. --- Adafruit_BNO055/BNO055.py | 86 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/Adafruit_BNO055/BNO055.py b/Adafruit_BNO055/BNO055.py index 2d1ac82..9f4ed74 100644 --- a/Adafruit_BNO055/BNO055.py +++ b/Adafruit_BNO055/BNO055.py @@ -35,6 +35,36 @@ # Page id register definition BNO055_PAGE_ID_ADDR = 0X07 +# Accel G Range Config Value (Last 2 bits) +BNO055_ACCEL_G_RANGE_2G = 0b00000000 +BNO055_ACCEL_G_RANGE_4G = 0b00000001 +BNO055_ACCEL_G_RANGE_8G = 0b00000010 +BNO055_ACCEL_G_RANGE_16G = 0b00000011 + +# Accel Bandwidth Config Value (Middle 3 bits) +BNO055_ACCEL_BANDWIDTH_8Hz = 0b00000000 +BNO055_ACCEL_BANDWIDTH_16Hz = 0b00000001 +BNO055_ACCEL_BANDWIDTH_32Hz = 0b00000010 +BNO055_ACCEL_BANDWIDTH_64Hz = 0b00000011 +BNO055_ACCEL_BANDWIDTH_128Hz = 0b00000100 +BNO055_ACCEL_BANDWIDTH_256Hz = 0b00000101 +BNO055_ACCEL_BANDWIDTH_512Hz = 0b00000110 +BNO055_ACCEL_BANDWIDTH_1024Hz = 0b00000111 + + +# Accel Operation Mode (First 3 bits) +BNO055_ACCEL_OPERATION_MODE_NORMAL = 0b00000000 +BNO055_ACCEL_OPERATION_MODE_SUSPEND = 0b00000001 +BNO055_ACCEL_OPERATION_MODE_LOW_POWER_1 = 0b00000010 +BNO055_ACCEL_OPERATION_MODE_STANDBY = 0b00000011 +BNO055_ACCEL_OPERATION_MODE_LOW_POWER_2 = 0b00000100 +BNO055_ACCEL_OPERATION_MODE_DEEP_SUSPEND = 0b00000101 + +# Accel Config Bitshifts +BNO055_ACCEL_BANDWIDTH_BITSHIFT = 2 +BNO055_ACCEL_OPERATION_MODE_BITSHIFT = 5 +BNO055_ACCEL_G_RANGE_BITSHIFT = 0 + # PAGE0 REGISTER DEFINITION START BNO055_CHIP_ID_ADDR = 0x00 BNO055_ACCEL_REV_ID_ADDR = 0x01 @@ -122,6 +152,12 @@ BNO055_OPR_MODE_ADDR = 0X3D BNO055_PWR_MODE_ADDR = 0X3E +# Config registers +BNO055_ACCEL_CFG_ADDR = 0x08 +BNO055_MAG_CFG_ADDR = 0x09 +BNO055_GYR0_CFG_ADDR = 0x0A +BNO055_GYR1_CFG_ADDR = 0x0B + BNO055_SYS_TRIGGER_ADDR = 0X3F BNO055_TEMP_SOURCE_ADDR = 0X40 @@ -228,6 +264,11 @@ def __init__(self, rst=None, address=BNO055_ADDRESS_A, i2c=None, gpio=None, # Wait a 650 milliseconds in case setting the reset high reset the chip. time.sleep(0.65) self._serial = None + + self._accel_g_range = BNO055_ACCEL_G_RANGE_4G + self._accel_bandwidth = BNO055_ACCEL_BANDWIDTH_64Hz + self._accel_operation_mode = BNO055_ACCEL_OPERATION_MODE_NORMAL + self._i2c_device = None if serial_port is not None: # Use serial communication if serial_port name is provided. @@ -361,6 +402,11 @@ def _operation_mode(self): # Enter operation mode to read sensor data. self.set_mode(self._mode) + def _update_accel_config(self): + """Sets the acceleration config according to the datasheet (see set_mode).""" + byte = self._accel_g_range | (self._accel_bandwidth << 2) | (self._accel_operation_mode << 5) + self._write_byte(BNO055_ACCEL_CFG_ADDR, byte & 0xFF) + def begin(self, mode=OPERATION_MODE_NDOF): """Initialize the BNO055 sensor. Must be called once before any other BNO055 library functions. Will return True if the BNO055 was @@ -419,6 +465,46 @@ def set_mode(self, mode): # too). time.sleep(0.03) + def set_accel_g_range(self, g_range: int = BNO055_ACCEL_G_RANGE_4G): + """Sets the acceleration G-Range to the specified range. Available ranges: + + BNO055_ACCEL_G_RANGE_2G + BNO055_ACCEL_G_RANGE_4G + BNO055_ACCEL_G_RANGE_8G + BNO055_ACCEL_G_RANGE_16G + + """ + self._accel_g_range = g_range + self._update_accel_config() + + def set_accel_bandwidth(self, bandwidth: int = BNO055_ACCEL_BANDWIDTH_64Hz): + """Sets teh acceleration update bandwidth to the specified value. Available values: + + BNO055_ACCEL_BANDWIDTH_8Hz + BNO055_ACCEL_BANDWIDTH_16Hz + BNO055_ACCEL_BANDWIDTH_32Hz + BNO055_ACCEL_BANDWIDTH_64Hz + BNO055_ACCEL_BANDWIDTH_128Hz + BNO055_ACCEL_BANDWIDTH_256Hz + BNO055_ACCEL_BANDWIDTH_512Hz + BNO055_ACCEL_BANDWIDTH_1024Hz + """ + self._accel_bandwidth = bandwidth + self._update_accel_config() + + def set_accel_operation_mode(self, mode: int = BNO055_ACCEL_OPERATION_MODE_NORMAL): + """Sets the acceleration operation to the specified mode. Available modes: + + BNO055_ACCEL_OPERATION_MODE_NORMAL + BNO055_ACCEL_OPERATION_MODE_SUSPEND + BNO055_ACCEL_OPERATION_MODE_LOW_POWER_1 + BNO055_ACCEL_OPERATION_MODE_STANDBY + BNO055_ACCEL_OPERATION_MODE_LOW_POWER_2 + BNO055_ACCEL_OPERATION_MODE_DEEP_SUSPEND + """ + self._accel_operation_mode = mode + self._update_accel_config() + def get_revision(self): """Return a tuple with revision information about the BNO055 chip. Will return 5 values: From 58ab28bef6a9fd35d58abe97d2a4fff44ced80f1 Mon Sep 17 00:00:00 2001 From: Scott Mudge Date: Sun, 21 Apr 2019 04:34:58 -0400 Subject: [PATCH 02/13] Added acceleration module configuration functionality. --- Adafruit_BNO055/BNO055.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Adafruit_BNO055/BNO055.py b/Adafruit_BNO055/BNO055.py index 9f4ed74..66e117b 100644 --- a/Adafruit_BNO055/BNO055.py +++ b/Adafruit_BNO055/BNO055.py @@ -406,6 +406,8 @@ def _update_accel_config(self): """Sets the acceleration config according to the datasheet (see set_mode).""" byte = self._accel_g_range | (self._accel_bandwidth << 2) | (self._accel_operation_mode << 5) self._write_byte(BNO055_ACCEL_CFG_ADDR, byte & 0xFF) + # Sleep for 20 ms to allow changes time to propagate + time.sleep(0.02) def begin(self, mode=OPERATION_MODE_NDOF): """Initialize the BNO055 sensor. Must be called once before any other From c33662789c5ca6fa080b841255ce5659efa38861 Mon Sep 17 00:00:00 2001 From: Scott Mudge Date: Sun, 21 Apr 2019 11:44:01 -0400 Subject: [PATCH 03/13] Fixed for python 2, corrected endianness. --- Adafruit_BNO055/BNO055.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Adafruit_BNO055/BNO055.py b/Adafruit_BNO055/BNO055.py index 66e117b..9ac0d05 100644 --- a/Adafruit_BNO055/BNO055.py +++ b/Adafruit_BNO055/BNO055.py @@ -61,9 +61,9 @@ BNO055_ACCEL_OPERATION_MODE_DEEP_SUSPEND = 0b00000101 # Accel Config Bitshifts -BNO055_ACCEL_BANDWIDTH_BITSHIFT = 2 -BNO055_ACCEL_OPERATION_MODE_BITSHIFT = 5 -BNO055_ACCEL_G_RANGE_BITSHIFT = 0 +BNO055_ACCEL_OPERATION_MODE_BITSHIFT = 0 +BNO055_ACCEL_BANDWIDTH_BITSHIFT = 3 +BNO055_ACCEL_G_RANGE_BITSHIFT = 6 # PAGE0 REGISTER DEFINITION START BNO055_CHIP_ID_ADDR = 0x00 @@ -404,7 +404,7 @@ def _operation_mode(self): def _update_accel_config(self): """Sets the acceleration config according to the datasheet (see set_mode).""" - byte = self._accel_g_range | (self._accel_bandwidth << 2) | (self._accel_operation_mode << 5) + byte = self._accel_operation_mode | (self._accel_bandwidth >> 3) | (self._accel_g_range >> 6) self._write_byte(BNO055_ACCEL_CFG_ADDR, byte & 0xFF) # Sleep for 20 ms to allow changes time to propagate time.sleep(0.02) @@ -467,7 +467,7 @@ def set_mode(self, mode): # too). time.sleep(0.03) - def set_accel_g_range(self, g_range: int = BNO055_ACCEL_G_RANGE_4G): + def set_accel_g_range(self, g_range = BNO055_ACCEL_G_RANGE_4G): """Sets the acceleration G-Range to the specified range. Available ranges: BNO055_ACCEL_G_RANGE_2G @@ -479,7 +479,7 @@ def set_accel_g_range(self, g_range: int = BNO055_ACCEL_G_RANGE_4G): self._accel_g_range = g_range self._update_accel_config() - def set_accel_bandwidth(self, bandwidth: int = BNO055_ACCEL_BANDWIDTH_64Hz): + def set_accel_bandwidth(self, bandwidth =BNO055_ACCEL_BANDWIDTH_64Hz): """Sets teh acceleration update bandwidth to the specified value. Available values: BNO055_ACCEL_BANDWIDTH_8Hz @@ -494,7 +494,7 @@ def set_accel_bandwidth(self, bandwidth: int = BNO055_ACCEL_BANDWIDTH_64Hz): self._accel_bandwidth = bandwidth self._update_accel_config() - def set_accel_operation_mode(self, mode: int = BNO055_ACCEL_OPERATION_MODE_NORMAL): + def set_accel_operation_mode(self, mode = BNO055_ACCEL_OPERATION_MODE_NORMAL): """Sets the acceleration operation to the specified mode. Available modes: BNO055_ACCEL_OPERATION_MODE_NORMAL From 4e9df54f9d9c54dd4ac4839b775b119506262d65 Mon Sep 17 00:00:00 2001 From: Scott Mudge Date: Sun, 21 Apr 2019 11:45:56 -0400 Subject: [PATCH 04/13] Added comment. --- Adafruit_BNO055/BNO055.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Adafruit_BNO055/BNO055.py b/Adafruit_BNO055/BNO055.py index 9ac0d05..e61025e 100644 --- a/Adafruit_BNO055/BNO055.py +++ b/Adafruit_BNO055/BNO055.py @@ -405,6 +405,8 @@ def _operation_mode(self): def _update_accel_config(self): """Sets the acceleration config according to the datasheet (see set_mode).""" byte = self._accel_operation_mode | (self._accel_bandwidth >> 3) | (self._accel_g_range >> 6) + + # Send config byte to accel config register addr self._write_byte(BNO055_ACCEL_CFG_ADDR, byte & 0xFF) # Sleep for 20 ms to allow changes time to propagate time.sleep(0.02) From e68875da49a2a2aeeff27d7efb41b11ee04d6c26 Mon Sep 17 00:00:00 2001 From: Scott Mudge Date: Sun, 21 Apr 2019 12:02:29 -0400 Subject: [PATCH 05/13] change to config mode first. --- Adafruit_BNO055/BNO055.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Adafruit_BNO055/BNO055.py b/Adafruit_BNO055/BNO055.py index e61025e..580059c 100644 --- a/Adafruit_BNO055/BNO055.py +++ b/Adafruit_BNO055/BNO055.py @@ -406,11 +406,17 @@ def _update_accel_config(self): """Sets the acceleration config according to the datasheet (see set_mode).""" byte = self._accel_operation_mode | (self._accel_bandwidth >> 3) | (self._accel_g_range >> 6) + # Change to config mode + self._config_mode() + # Send config byte to accel config register addr self._write_byte(BNO055_ACCEL_CFG_ADDR, byte & 0xFF) # Sleep for 20 ms to allow changes time to propagate time.sleep(0.02) + # Return to operation mode + self._operation_mode() + def begin(self, mode=OPERATION_MODE_NDOF): """Initialize the BNO055 sensor. Must be called once before any other BNO055 library functions. Will return True if the BNO055 was From 1a1414b2833aacb852d996286610d518008668b7 Mon Sep 17 00:00:00 2001 From: Scott Mudge Date: Sun, 21 Apr 2019 12:16:21 -0400 Subject: [PATCH 06/13] Trying to correct configuration bit. --- Adafruit_BNO055/BNO055.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Adafruit_BNO055/BNO055.py b/Adafruit_BNO055/BNO055.py index 580059c..816bc05 100644 --- a/Adafruit_BNO055/BNO055.py +++ b/Adafruit_BNO055/BNO055.py @@ -61,9 +61,9 @@ BNO055_ACCEL_OPERATION_MODE_DEEP_SUSPEND = 0b00000101 # Accel Config Bitshifts -BNO055_ACCEL_OPERATION_MODE_BITSHIFT = 0 -BNO055_ACCEL_BANDWIDTH_BITSHIFT = 3 -BNO055_ACCEL_G_RANGE_BITSHIFT = 6 +BNO055_ACCEL_BANDWIDTH_BITSHIFT = 2 +BNO055_ACCEL_OPERATION_MODE_BITSHIFT = 5 +BNO055_ACCEL_G_RANGE_BITSHIFT = 0 # PAGE0 REGISTER DEFINITION START BNO055_CHIP_ID_ADDR = 0x00 @@ -404,7 +404,8 @@ def _operation_mode(self): def _update_accel_config(self): """Sets the acceleration config according to the datasheet (see set_mode).""" - byte = self._accel_operation_mode | (self._accel_bandwidth >> 3) | (self._accel_g_range >> 6) + byte = self._accel_g_range | (self._accel_bandwidth << 2) | (self._accel_operation_mode << 5) + # byte = self._accel_operation_mode | (self._accel_bandwidth >> 3) | (self._accel_g_range >> 6) # Change to config mode self._config_mode() From 342b5be1aa4b337045afc2d938082944c6c535ce Mon Sep 17 00:00:00 2001 From: Scott Mudge Date: Sun, 21 Apr 2019 23:53:13 -0400 Subject: [PATCH 07/13] Switch to page 0x01 for accel config. --- Adafruit_BNO055/BNO055.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Adafruit_BNO055/BNO055.py b/Adafruit_BNO055/BNO055.py index 816bc05..b93aa0e 100644 --- a/Adafruit_BNO055/BNO055.py +++ b/Adafruit_BNO055/BNO055.py @@ -60,11 +60,6 @@ BNO055_ACCEL_OPERATION_MODE_LOW_POWER_2 = 0b00000100 BNO055_ACCEL_OPERATION_MODE_DEEP_SUSPEND = 0b00000101 -# Accel Config Bitshifts -BNO055_ACCEL_BANDWIDTH_BITSHIFT = 2 -BNO055_ACCEL_OPERATION_MODE_BITSHIFT = 5 -BNO055_ACCEL_G_RANGE_BITSHIFT = 0 - # PAGE0 REGISTER DEFINITION START BNO055_CHIP_ID_ADDR = 0x00 BNO055_ACCEL_REV_ID_ADDR = 0x01 @@ -409,16 +404,24 @@ def _update_accel_config(self): # Change to config mode self._config_mode() + # Set to Page 1 + self._write_byte(BNO055_PAGE_ID_ADDR, 0x01) + # Sleep, allow change + time.sleep(0.02) # Send config byte to accel config register addr self._write_byte(BNO055_ACCEL_CFG_ADDR, byte & 0xFF) # Sleep for 20 ms to allow changes time to propagate time.sleep(0.02) + # Set back to page zero (default) + self._write_byte(BNO055_PAGE_ID_ADDR, 0x00) + time.sleep(0.02) + # Return to operation mode self._operation_mode() - def begin(self, mode=OPERATION_MODE_NDOF): + def begin(self, mode=OPERATION_MODE_NDOF, **kwargs): """Initialize the BNO055 sensor. Must be called once before any other BNO055 library functions. Will return True if the BNO055 was successfully initialized, and False otherwise. From b62683e2b5ad5f6c9f192ece73179e6b8145a531 Mon Sep 17 00:00:00 2001 From: Scott Mudge Date: Sun, 21 Apr 2019 23:58:48 -0400 Subject: [PATCH 08/13] debugging --- Adafruit_BNO055/BNO055.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Adafruit_BNO055/BNO055.py b/Adafruit_BNO055/BNO055.py index b93aa0e..850e103 100644 --- a/Adafruit_BNO055/BNO055.py +++ b/Adafruit_BNO055/BNO055.py @@ -260,6 +260,8 @@ def __init__(self, rst=None, address=BNO055_ADDRESS_A, i2c=None, gpio=None, time.sleep(0.65) self._serial = None + self._mode = OPERATION_MODE_NDOF + self._accel_g_range = BNO055_ACCEL_G_RANGE_4G self._accel_bandwidth = BNO055_ACCEL_BANDWIDTH_64Hz self._accel_operation_mode = BNO055_ACCEL_OPERATION_MODE_NORMAL @@ -399,8 +401,8 @@ def _operation_mode(self): def _update_accel_config(self): """Sets the acceleration config according to the datasheet (see set_mode).""" - byte = self._accel_g_range | (self._accel_bandwidth << 2) | (self._accel_operation_mode << 5) - # byte = self._accel_operation_mode | (self._accel_bandwidth >> 3) | (self._accel_g_range >> 6) + # byte = self._accel_g_range | (self._accel_bandwidth << 2) | (self._accel_operation_mode << 5) + byte = self._accel_operation_mode | (self._accel_bandwidth >> 3) | (self._accel_g_range >> 6) # Change to config mode self._config_mode() From c06fe092d32430bd488a1023116a4c7e93baa44f Mon Sep 17 00:00:00 2001 From: Scott Mudge Date: Mon, 22 Apr 2019 00:11:28 -0400 Subject: [PATCH 09/13] debugging still --- Adafruit_BNO055/BNO055.py | 99 ++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 44 deletions(-) diff --git a/Adafruit_BNO055/BNO055.py b/Adafruit_BNO055/BNO055.py index 850e103..057f10b 100644 --- a/Adafruit_BNO055/BNO055.py +++ b/Adafruit_BNO055/BNO055.py @@ -404,8 +404,6 @@ def _update_accel_config(self): # byte = self._accel_g_range | (self._accel_bandwidth << 2) | (self._accel_operation_mode << 5) byte = self._accel_operation_mode | (self._accel_bandwidth >> 3) | (self._accel_g_range >> 6) - # Change to config mode - self._config_mode() # Set to Page 1 self._write_byte(BNO055_PAGE_ID_ADDR, 0x01) # Sleep, allow change @@ -420,9 +418,6 @@ def _update_accel_config(self): self._write_byte(BNO055_PAGE_ID_ADDR, 0x00) time.sleep(0.02) - # Return to operation mode - self._operation_mode() - def begin(self, mode=OPERATION_MODE_NDOF, **kwargs): """Initialize the BNO055 sensor. Must be called once before any other BNO055 library functions. Will return True if the BNO055 was @@ -430,6 +425,17 @@ def begin(self, mode=OPERATION_MODE_NDOF, **kwargs): """ # Save the desired normal operation mode. self._mode = mode + + # Copy kwargs to config + if kwargs is not None: + for key, value in kwargs.items(): + if key == 'accel_bandwidth': + self._accel_bandwidth = value + elif key == 'accel_g_range': + self._accel_g_range = value + elif key == 'accel_operation_mode': + self._accel_operation_mode = value + # First send a thow-away command and ignore any response or I2C errors # just to make sure the BNO is in a good state and ready to accept # commands (this seems to be necessary after a hard power down). @@ -466,6 +472,11 @@ def begin(self, mode=OPERATION_MODE_NDOF, **kwargs): self._write_byte(BNO055_PWR_MODE_ADDR, POWER_MODE_NORMAL) # Default to internal oscillator. self._write_byte(BNO055_SYS_TRIGGER_ADDR, 0x0) + + # Set accelerometer config + self._update_accel_config() + + # Enter normal operation mode. self._operation_mode() return True @@ -481,45 +492,45 @@ def set_mode(self, mode): # too). time.sleep(0.03) - def set_accel_g_range(self, g_range = BNO055_ACCEL_G_RANGE_4G): - """Sets the acceleration G-Range to the specified range. Available ranges: - - BNO055_ACCEL_G_RANGE_2G - BNO055_ACCEL_G_RANGE_4G - BNO055_ACCEL_G_RANGE_8G - BNO055_ACCEL_G_RANGE_16G - - """ - self._accel_g_range = g_range - self._update_accel_config() - - def set_accel_bandwidth(self, bandwidth =BNO055_ACCEL_BANDWIDTH_64Hz): - """Sets teh acceleration update bandwidth to the specified value. Available values: - - BNO055_ACCEL_BANDWIDTH_8Hz - BNO055_ACCEL_BANDWIDTH_16Hz - BNO055_ACCEL_BANDWIDTH_32Hz - BNO055_ACCEL_BANDWIDTH_64Hz - BNO055_ACCEL_BANDWIDTH_128Hz - BNO055_ACCEL_BANDWIDTH_256Hz - BNO055_ACCEL_BANDWIDTH_512Hz - BNO055_ACCEL_BANDWIDTH_1024Hz - """ - self._accel_bandwidth = bandwidth - self._update_accel_config() - - def set_accel_operation_mode(self, mode = BNO055_ACCEL_OPERATION_MODE_NORMAL): - """Sets the acceleration operation to the specified mode. Available modes: - - BNO055_ACCEL_OPERATION_MODE_NORMAL - BNO055_ACCEL_OPERATION_MODE_SUSPEND - BNO055_ACCEL_OPERATION_MODE_LOW_POWER_1 - BNO055_ACCEL_OPERATION_MODE_STANDBY - BNO055_ACCEL_OPERATION_MODE_LOW_POWER_2 - BNO055_ACCEL_OPERATION_MODE_DEEP_SUSPEND - """ - self._accel_operation_mode = mode - self._update_accel_config() + # def set_accel_g_range(self, g_range = BNO055_ACCEL_G_RANGE_4G): + # """Sets the acceleration G-Range to the specified range. Available ranges: + # + # BNO055_ACCEL_G_RANGE_2G + # BNO055_ACCEL_G_RANGE_4G + # BNO055_ACCEL_G_RANGE_8G + # BNO055_ACCEL_G_RANGE_16G + # + # """ + # self._accel_g_range = g_range + # self._update_accel_config() + # + # def set_accel_bandwidth(self, bandwidth =BNO055_ACCEL_BANDWIDTH_64Hz): + # """Sets teh acceleration update bandwidth to the specified value. Available values: + # + # BNO055_ACCEL_BANDWIDTH_8Hz + # BNO055_ACCEL_BANDWIDTH_16Hz + # BNO055_ACCEL_BANDWIDTH_32Hz + # BNO055_ACCEL_BANDWIDTH_64Hz + # BNO055_ACCEL_BANDWIDTH_128Hz + # BNO055_ACCEL_BANDWIDTH_256Hz + # BNO055_ACCEL_BANDWIDTH_512Hz + # BNO055_ACCEL_BANDWIDTH_1024Hz + # """ + # self._accel_bandwidth = bandwidth + # self._update_accel_config() + # + # def set_accel_operation_mode(self, mode = BNO055_ACCEL_OPERATION_MODE_NORMAL): + # """Sets the acceleration operation to the specified mode. Available modes: + # + # BNO055_ACCEL_OPERATION_MODE_NORMAL + # BNO055_ACCEL_OPERATION_MODE_SUSPEND + # BNO055_ACCEL_OPERATION_MODE_LOW_POWER_1 + # BNO055_ACCEL_OPERATION_MODE_STANDBY + # BNO055_ACCEL_OPERATION_MODE_LOW_POWER_2 + # BNO055_ACCEL_OPERATION_MODE_DEEP_SUSPEND + # """ + # self._accel_operation_mode = mode + # self._update_accel_config() def get_revision(self): """Return a tuple with revision information about the BNO055 chip. Will From 47f1ce2aa146b53da1bff7db59f977fea198d2aa Mon Sep 17 00:00:00 2001 From: Scott Mudge Date: Mon, 22 Apr 2019 00:24:33 -0400 Subject: [PATCH 10/13] reverting to old method, which seems to work fine. --- Adafruit_BNO055/BNO055.py | 99 +++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 55 deletions(-) diff --git a/Adafruit_BNO055/BNO055.py b/Adafruit_BNO055/BNO055.py index 057f10b..850e103 100644 --- a/Adafruit_BNO055/BNO055.py +++ b/Adafruit_BNO055/BNO055.py @@ -404,6 +404,8 @@ def _update_accel_config(self): # byte = self._accel_g_range | (self._accel_bandwidth << 2) | (self._accel_operation_mode << 5) byte = self._accel_operation_mode | (self._accel_bandwidth >> 3) | (self._accel_g_range >> 6) + # Change to config mode + self._config_mode() # Set to Page 1 self._write_byte(BNO055_PAGE_ID_ADDR, 0x01) # Sleep, allow change @@ -418,6 +420,9 @@ def _update_accel_config(self): self._write_byte(BNO055_PAGE_ID_ADDR, 0x00) time.sleep(0.02) + # Return to operation mode + self._operation_mode() + def begin(self, mode=OPERATION_MODE_NDOF, **kwargs): """Initialize the BNO055 sensor. Must be called once before any other BNO055 library functions. Will return True if the BNO055 was @@ -425,17 +430,6 @@ def begin(self, mode=OPERATION_MODE_NDOF, **kwargs): """ # Save the desired normal operation mode. self._mode = mode - - # Copy kwargs to config - if kwargs is not None: - for key, value in kwargs.items(): - if key == 'accel_bandwidth': - self._accel_bandwidth = value - elif key == 'accel_g_range': - self._accel_g_range = value - elif key == 'accel_operation_mode': - self._accel_operation_mode = value - # First send a thow-away command and ignore any response or I2C errors # just to make sure the BNO is in a good state and ready to accept # commands (this seems to be necessary after a hard power down). @@ -472,11 +466,6 @@ def begin(self, mode=OPERATION_MODE_NDOF, **kwargs): self._write_byte(BNO055_PWR_MODE_ADDR, POWER_MODE_NORMAL) # Default to internal oscillator. self._write_byte(BNO055_SYS_TRIGGER_ADDR, 0x0) - - # Set accelerometer config - self._update_accel_config() - - # Enter normal operation mode. self._operation_mode() return True @@ -492,45 +481,45 @@ def set_mode(self, mode): # too). time.sleep(0.03) - # def set_accel_g_range(self, g_range = BNO055_ACCEL_G_RANGE_4G): - # """Sets the acceleration G-Range to the specified range. Available ranges: - # - # BNO055_ACCEL_G_RANGE_2G - # BNO055_ACCEL_G_RANGE_4G - # BNO055_ACCEL_G_RANGE_8G - # BNO055_ACCEL_G_RANGE_16G - # - # """ - # self._accel_g_range = g_range - # self._update_accel_config() - # - # def set_accel_bandwidth(self, bandwidth =BNO055_ACCEL_BANDWIDTH_64Hz): - # """Sets teh acceleration update bandwidth to the specified value. Available values: - # - # BNO055_ACCEL_BANDWIDTH_8Hz - # BNO055_ACCEL_BANDWIDTH_16Hz - # BNO055_ACCEL_BANDWIDTH_32Hz - # BNO055_ACCEL_BANDWIDTH_64Hz - # BNO055_ACCEL_BANDWIDTH_128Hz - # BNO055_ACCEL_BANDWIDTH_256Hz - # BNO055_ACCEL_BANDWIDTH_512Hz - # BNO055_ACCEL_BANDWIDTH_1024Hz - # """ - # self._accel_bandwidth = bandwidth - # self._update_accel_config() - # - # def set_accel_operation_mode(self, mode = BNO055_ACCEL_OPERATION_MODE_NORMAL): - # """Sets the acceleration operation to the specified mode. Available modes: - # - # BNO055_ACCEL_OPERATION_MODE_NORMAL - # BNO055_ACCEL_OPERATION_MODE_SUSPEND - # BNO055_ACCEL_OPERATION_MODE_LOW_POWER_1 - # BNO055_ACCEL_OPERATION_MODE_STANDBY - # BNO055_ACCEL_OPERATION_MODE_LOW_POWER_2 - # BNO055_ACCEL_OPERATION_MODE_DEEP_SUSPEND - # """ - # self._accel_operation_mode = mode - # self._update_accel_config() + def set_accel_g_range(self, g_range = BNO055_ACCEL_G_RANGE_4G): + """Sets the acceleration G-Range to the specified range. Available ranges: + + BNO055_ACCEL_G_RANGE_2G + BNO055_ACCEL_G_RANGE_4G + BNO055_ACCEL_G_RANGE_8G + BNO055_ACCEL_G_RANGE_16G + + """ + self._accel_g_range = g_range + self._update_accel_config() + + def set_accel_bandwidth(self, bandwidth =BNO055_ACCEL_BANDWIDTH_64Hz): + """Sets teh acceleration update bandwidth to the specified value. Available values: + + BNO055_ACCEL_BANDWIDTH_8Hz + BNO055_ACCEL_BANDWIDTH_16Hz + BNO055_ACCEL_BANDWIDTH_32Hz + BNO055_ACCEL_BANDWIDTH_64Hz + BNO055_ACCEL_BANDWIDTH_128Hz + BNO055_ACCEL_BANDWIDTH_256Hz + BNO055_ACCEL_BANDWIDTH_512Hz + BNO055_ACCEL_BANDWIDTH_1024Hz + """ + self._accel_bandwidth = bandwidth + self._update_accel_config() + + def set_accel_operation_mode(self, mode = BNO055_ACCEL_OPERATION_MODE_NORMAL): + """Sets the acceleration operation to the specified mode. Available modes: + + BNO055_ACCEL_OPERATION_MODE_NORMAL + BNO055_ACCEL_OPERATION_MODE_SUSPEND + BNO055_ACCEL_OPERATION_MODE_LOW_POWER_1 + BNO055_ACCEL_OPERATION_MODE_STANDBY + BNO055_ACCEL_OPERATION_MODE_LOW_POWER_2 + BNO055_ACCEL_OPERATION_MODE_DEEP_SUSPEND + """ + self._accel_operation_mode = mode + self._update_accel_config() def get_revision(self): """Return a tuple with revision information about the BNO055 chip. Will From 0da0a73ad47a7bd74ddd330f7cba2b8f6f55793b Mon Sep 17 00:00:00 2001 From: Scott Mudge Date: Mon, 22 Apr 2019 00:28:28 -0400 Subject: [PATCH 11/13] changing --- Adafruit_BNO055/BNO055.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_BNO055/BNO055.py b/Adafruit_BNO055/BNO055.py index 850e103..0fb39f3 100644 --- a/Adafruit_BNO055/BNO055.py +++ b/Adafruit_BNO055/BNO055.py @@ -401,8 +401,8 @@ def _operation_mode(self): def _update_accel_config(self): """Sets the acceleration config according to the datasheet (see set_mode).""" - # byte = self._accel_g_range | (self._accel_bandwidth << 2) | (self._accel_operation_mode << 5) - byte = self._accel_operation_mode | (self._accel_bandwidth >> 3) | (self._accel_g_range >> 6) + byte = self._accel_g_range | (self._accel_bandwidth << 2) | (self._accel_operation_mode << 5) + # byte = self._accel_operation_mode | (self._accel_bandwidth >> 3) | (self._accel_g_range >> 6) # Change to config mode self._config_mode() From 81377ec738e95a201c22a0f4d4fd19c2ff25f41d Mon Sep 17 00:00:00 2001 From: Scott Mudge Date: Mon, 22 Apr 2019 00:33:40 -0400 Subject: [PATCH 12/13] cleanup --- Adafruit_BNO055/BNO055.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_BNO055/BNO055.py b/Adafruit_BNO055/BNO055.py index 0fb39f3..ec9a181 100644 --- a/Adafruit_BNO055/BNO055.py +++ b/Adafruit_BNO055/BNO055.py @@ -423,7 +423,7 @@ def _update_accel_config(self): # Return to operation mode self._operation_mode() - def begin(self, mode=OPERATION_MODE_NDOF, **kwargs): + def begin(self, mode=OPERATION_MODE_NDOF): """Initialize the BNO055 sensor. Must be called once before any other BNO055 library functions. Will return True if the BNO055 was successfully initialized, and False otherwise. From b70242d882410e560089b76f81584d3c4d1a3a94 Mon Sep 17 00:00:00 2001 From: Scott Mudge Date: Mon, 22 Apr 2019 00:34:09 -0400 Subject: [PATCH 13/13] additional cleanup --- Adafruit_BNO055/BNO055.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_BNO055/BNO055.py b/Adafruit_BNO055/BNO055.py index ec9a181..8ee152e 100644 --- a/Adafruit_BNO055/BNO055.py +++ b/Adafruit_BNO055/BNO055.py @@ -401,8 +401,8 @@ def _operation_mode(self): def _update_accel_config(self): """Sets the acceleration config according to the datasheet (see set_mode).""" + # pack bits into byte, see datasheet for more information. byte = self._accel_g_range | (self._accel_bandwidth << 2) | (self._accel_operation_mode << 5) - # byte = self._accel_operation_mode | (self._accel_bandwidth >> 3) | (self._accel_g_range >> 6) # Change to config mode self._config_mode()