Skip to content

Added ability to configure accelerometer #51

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

Merged
merged 6 commits into from
Aug 6, 2020
Merged

Conversation

evaherrada
Copy link
Collaborator

I can do this with the other sensors as well if you'd like me to.

@evaherrada
Copy link
Collaborator Author

evaherrada commented Jun 30, 2020

Something odd is going on with github actions. Tested it on this PR, another PR on this library, and a PR on a different circuitpython library and got the same failure. I'll take a look at it.

Edit: I guess it fixed itself

@evaherrada evaherrada linked an issue Jul 6, 2020 that may be closed by this pull request
@evaherrada evaherrada requested a review from a team July 10, 2020 14:57
@caternuson
Copy link
Contributor

CircuitPython libraries favor using properties instead of getter/setter functions, see here:
https://circuitpython.readthedocs.io/en/5.3.x/docs/design_guide.html#getters-setters

So you are essentially wanting to add 3 properties:

  • rng (or maybe acc_range or g-range?)
  • bandwidth
  • acc_mode

There are already several properties defined in this library you can use as a reference.

Also, be careful about Page 0 vs. Page 1 registers. You want to make sure you are accessing register 0x08 from Page 1. I'm not seeing anything that currently access anything in Page 1. But there is at least a _PAGE_REGISTER const already defined. And a few places where it is forced to Page 0.

@evaherrada
Copy link
Collaborator Author

@caternuson Thanks for taking a look at this. I'll make those changes now.

@evaherrada
Copy link
Collaborator Author

@caternuson Do you think it'd be worth adding the configuration for the gyro and magnetometer? It should be pretty much just copying and pasting the current code I've got (I've made the changes you asked, just have to test).

@caternuson
Copy link
Contributor

Sure. Might as well. To keep things clear as to what sensor a parameter is related to, how about these naming prefixes?

  • accel_
  • gyro_
  • magnet_

ex: accel_range, accel_bandwidth, accel_mode, etc.

@evaherrada
Copy link
Collaborator Author

@caternuson Yeah, I think that makes sense

@evaherrada
Copy link
Collaborator Author

@caternuson I have tested this and it does work well. The only issue arises when you're trying to use more than one non-fusion mode in the same run since the registers can't be written to even after the mode is switched. I seem to recall encountering this a few months ago, and I thought the issue was on the side of the bno055, but I could be completely misremembering.

@caternuson
Copy link
Contributor

Your getters change to Page 1 then set back to Page 0. But none of the setters do that. Is that OK?

@evaherrada
Copy link
Collaborator Author

evaherrada commented Jul 21, 2020

Your getters change to Page 1 then set back to Page 0. But none of the setters do that. Is that OK?

I think so. That being said, I'd feel better about the chances this could cause an issue later on if I had it change back to page 0, so I'll do that.

@caternuson
Copy link
Contributor

Ah - just noticed the return type is string, because of use of bin(). It's better to have things be symmetric. That is, the getter and setter should be of the same type. For example, this should work:

Adafruit CircuitPython 5.3.0 on 2020-04-29; Adafruit ItsyBitsy M4 Express with samd51g19
>>> import board
>>> import adafruit_bno055
>>> bno = adafruit_bno055.BNO055_I2C(board.I2C())
>>> bno.accel_range
'0b1'
>>> range = bno.accel_range
>>> bno.accel_range = range
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "adafruit_bno055.py", line 407, in accel_range
TypeError: can't convert 'int' object to str implicitly
>>> 

It also allows for comparisons, ex:

>>> adafruit_bno055.ACCEL_4G
1
>>> bno.accel_range
'0b1'
>>> bno.accel_range == adafruit_bno055.ACCEL_4G
False
>>> 

That should have been True.

@evaherrada
Copy link
Collaborator Author

@caternuson Ah, yeah. That definitely makes sense. I was wanting to display it 'visually' in binary since it is a lot easier to see what's going on that way, but it's definitely a lot better for it to return an int.

@caternuson
Copy link
Contributor

One more suggestion added. But those last updates are working better:

Adafruit CircuitPython 5.3.0 on 2020-04-29; Adafruit ItsyBitsy M4 Express with samd51g19
>>> import board
>>> import adafruit_bno055
>>> bno = adafruit_bno055.BNO055_I2C(board.I2C())
>>> range = bno.accel_range
>>> bno.accel_range = range
>>> bno.accel_range == adafruit_bno055.ACCEL_4G
True
>>> 

@evaherrada evaherrada requested a review from caternuson July 24, 2020 13:24
@caternuson
Copy link
Contributor

Cool. OK, calling it good at this point. Thanks for all the updates.

@evaherrada evaherrada merged commit 7f6d9fc into master Aug 6, 2020
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Aug 8, 2020
Updating https://github.com/adafruit/Adafruit_CircuitPython_BNO055 to 5.2.0 from 5.1.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_BNO055#51 from adafruit/accel_config

Updating https://github.com/adafruit/Adafruit_CircuitPython_AdafruitIO to 4.0.0 from 3.3.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_AdafruitIO#43 from brentru/fix-attribute-error
  > Merge pull request adafruit/Adafruit_CircuitPython_AdafruitIO#41 from 2bndy5/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Added the following libraries: Adafruit_CircuitPython_MS8607
@evaherrada evaherrada deleted the accel_config branch January 27, 2022 18:07
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

Successfully merging this pull request may close these issues.

Allow for accel config in sensor mode
2 participants