Skip to content

mode setter appears wrong #26

New issue

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

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

Already on GitHub? Sign in to your account

Closed
peterhinch opened this issue May 3, 2019 · 4 comments
Closed

mode setter appears wrong #26

peterhinch opened this issue May 3, 2019 · 4 comments

Comments

@peterhinch
Copy link
Contributor

peterhinch commented May 3, 2019

I'm writing a MicroPython driver for your board. In my testing it is only possible to change the device mode if you first change the mode to _CONFIG_MODE. Unfortunately I don't have any hardware capable of running CircuitPython but I think the following test will fail:

import adafruit_bno055
from busio import I2C
from board import SDA, SCL

i2c = I2C(SCL, SDA)
imu = adafruit_bno055.BNO055(i2c)
print(imu.euler)  # Check it's working
imu.mode = 5
print(imu.mode)  # I think this will be unchanged

The need to set _CONFIG_MODE prior to setting any other mode is contradicted in the chip datasheet (section 3.3.1). Consequently before I submit a PR I would be grateful if someone could perform the above test to confirm my findings.

For reference this is my mode setting code. This includes delays mandated by the device datasheet.

    def mode(self, new_mode=None):
        old_mode = self._read(_MODE_REGISTER)
        if new_mode is not None:
            self._write(_MODE_REGISTER, _CONFIG_MODE)  # This is empirically necessary if the mode is to be changed
            time.sleep_ms(20)  # Datasheet table 3.6
            if new_mode != _CONFIG_MODE:
                self._write(_MODE_REGISTER, new_mode)
                time.sleep_ms(10)  # Table 3.6
        return old_mode
@caternuson
Copy link
Contributor

Hmmm...I think you are correct.

Adafruit CircuitPython 3.1.2 on 2019-01-07; Adafruit ItsyBitsy M4 Express with samd51g19
>>> import adafruit_bno055
>>> from busio import I2C
>>> from board import SDA, SCL
>>> i2c = I2C(SCL, SDA)
>>> imu = adafruit_bno055.BNO055(i2c)
>>> imu.mode
12
>>> imu.mode = 5
>>> imu.mode
12
>>> imu.mode = 0
>>> imu.mode
0
>>> imu.mode = 5
>>> imu.mode
5
>>>

@peterhinch
Copy link
Contributor Author

Thank you for confirming. I'll submit a PR in a day or two.

@caternuson
Copy link
Contributor

Fixed by #27

Thanks @peterhinch!

@tannewt
Copy link
Member

tannewt commented May 9, 2019

@peterhinch email me ([email protected]) if you'd like some hardware to test CircuitPython with. We really appreciate your fixes to the drivers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants