pololu / vl53l0x-arduino

Pololu Arduino library for VL53L0X time-of-flight distance sensor
https://www.pololu.com/product/2490
Other
346 stars 162 forks source link

Updated to allow Wire port selectable from setup. #13

Closed mjs513 closed 4 years ago

mjs513 commented 7 years ago

I modified the library to make the Wire port selectable in the setup. Basically, you need to add one line in the examples (which I did):

sensor.begin(); - to use Wire as the default sensor.begin(&Wire1); - to use Wire1 as the default.

I also fixed the issues from the previous pull request. I tested this on a Teensy 3.5 so you might want to test on a couple of other boards?

Thanks Mike

mjs513 commented 7 years ago

Hi Ryan. The more I looked at this I decided that I wasn't happy with adding a sensor.begin command on top of the sensor.init. So I just finished modifying the code to do everything from Sensor.init. There are now basically for cases for init:

    bool init(void);   // defaults to Wire and io_2v8 = true
    bool init(TwoWire &theWire);  //Wire of your choice and defaults to io_2v8 = true
    bool init(bool io_2v8);  //defaults to Wire and io can be as before either true or false
    bool init(bool io_2v8, TwoWire &theWire);  // take you choice

and I changed the current bool init to bool begin(bool io_2v8);

I did test on the Teensy 3.5. If you agree with this I will push the update.

Mike

ryantm commented 7 years ago

@mjs513 That sounds reasonable. You could reduce that to only one function by using C++ argument defaults.

mjs513 commented 7 years ago

@ryantm If you are talking about something like: begin(io_2v8 = true, TwoWire &theWire = Wire)

don't think it would work. For instance I only wanted to change the Wire bus I would have to call it by begin(true, WireX) . If I do a begin(WireX) it tries to assign it io_2v8 first, the first item in the argument list. I tried this approach before and gave me errors. If you know a way around this please let me know.

asukiaaa commented 5 years ago

I want to use multiple sensor with using a board that multiple wire port. Is there any progress or feedback on this feature?

Thank you.

paynterf commented 4 years ago

What happened to this pull request? It appears it was not merged with master, even after 3 years. Was there a problem?

I'm asking because I have an identical problem with using VL53L0X sensors on multiple Teensy 3.5 I2C buses.

TIA,

Frank

kevin-pololu commented 4 years ago

Hi, Mike (mjs513).

We ended up adding this feature using a different pull request as a starting point, and we decided to provide separate functions for setting and getting the I2C bus instead of doing it through the constructor or init() function. Sorry we didn't resolve your pull request more promptly, but thank you for your contribution!

Kevin