adafruit / Adafruit_SI1145_Library

Arduino library for the SI1145 sensors in the Adafruit shop
Other
21 stars 36 forks source link

Added pointer to the i2c bus driver #11

Closed victors21 closed 4 years ago

victors21 commented 5 years ago

This fix is allow us to use software i2c or any other compatible instances of the i2c drivers which is derive from TwoWire

ladyada commented 5 years ago

thanks @caternuson do you have this chip?

ladyada commented 5 years ago

@victors21 have you tested this with hardware? if so which?

victors21 commented 5 years ago

@victors21 have you tested this with hardware? if so which?

Yep i have the chip and test it already works fine for me. Not sure about data accuracy but i am not need it very accurate. I am just to compare the data to get the way of changes.

ladyada commented 5 years ago

kk what hardware did you test with?

victors21 commented 5 years ago

Wemos D1 Mini(ESP8266) + SI1145 sensor + bme280 on the same bus sensor link https://ru.aliexpress.com/item/32823709540.html?spm=a2g0s.9042311.0.0.274233edJZOkur

caternuson commented 5 years ago

@ladyada Sry, missed this. Yep - I have one of these.

ladyada commented 5 years ago

@caternuson low priority! can add to yr list

caternuson commented 5 years ago

@victors21 This modification is actually slowly happening to all of the Arduino libs as part of an ongoing effort. The boiler plate set of constructors is:

  bool begin();
  bool begin(TwoWire *theWire);
  bool begin(uint8_t addr);
  bool begin(uint8_t addr, TwoWire *theWire);

and you can reference this library as an example: https://github.com/adafruit/Adafruit_MCP9808_Library/blob/master/Adafruit_MCP9808.h#L56

Can you update to that style?

Also, just curious - why was this needed? The current library should work as is with the default wire as provided by the Arduino ESP8266 BSP.

victors21 commented 5 years ago

@victors21 This modification is actually slowly happening to all of the Arduino libs as part of an ongoing effort. The boiler plate set of constructors is:

  bool begin();
  bool begin(TwoWire *theWire);
  bool begin(uint8_t addr);
  bool begin(uint8_t addr, TwoWire *theWire);

and you can reference this library as an example: https://github.com/adafruit/Adafruit_MCP9808_Library/blob/master/Adafruit_MCP9808.h#L56

Can you update to that style?

Also, just curious - why was this needed? The current library should work as is with the default wire as provided by the Arduino ESP8266 BSP.

Probably peoples want to use software i2c drivers cos of lack of pins on their devices with hardware i2c or they need 2 devices with the same address on the same project. Also my fix is same like u asked and can be use like begin() or begin(addres) or begin(address,TwoWire* bus). There has declared default parameters on it so all three calls is accaptable in this case.

caternuson commented 5 years ago

Can you do this with the default parameter approach?

si1145.begin(some_wire_pointer);

Where you'd use the default address but supply a different I2C bus.

victors21 commented 5 years ago

Can you do this with the default parameter approach?

si1145.begin(some_wire_pointer);

Where you'd use the default address but supply a different I2C bus.

Done, added one more call to make possible this way si1145.begin(some_wire_pointer);

ladyada commented 4 years ago

@caternuson looks ok if it passes test can merge!

caternuson commented 4 years ago

@victors21 what pins are you using for SDA/SCL?

victors21 commented 4 years ago

@victors21 what pins are you using for SDA/SCL?

I was used hardware i2c pins on my ESP8266. Generaly when i review the code of Wire library and core code of arduino for Platform IO i was disappointed. Core code of arduino framework did not allow to use few i2c drivers at the same time cos of pin number variables, timer handler and buffer is only one for all calls. So this fix will useless for my case but probably can use at other platforms e.g ESP32.

caternuson commented 4 years ago
#include "Adafruit_SI1145.h"

Adafruit_SI1145 uv = Adafruit_SI1145();

void setup() {
  Serial.begin(9600);  
  Serial.println("Adafruit SI1145 test");

  Wire.begin(2, 14);

  if (!uv.begin(&Wire)) {
    Serial.println("Didn't find Si1145");
    while (1);
  }
  Serial.println("OK!");
}

void loop() {
  Serial.print("Vis: "); Serial.print(uv.readVisible());
  Serial.print(" IR: "); Serial.println(uv.readIR());
  delay(1000);
}

Screenshot from 2019-09-24 08-26-17 setup

ladyada commented 4 years ago

thank you!