Merge pull request #15 from coelner/i2cPins

All free selection of I2c pins on ESP8266. This resolves #13.
This commit is contained in:
claws
2017-08-05 09:50:06 +09:30
committed by GitHub
3 changed files with 21 additions and 2 deletions
+14
View File
@@ -56,6 +56,20 @@ BH1750::BH1750(byte addr) {
}
/**
* Begin I2C and configure sensor
* @param SDA Date SCL Clock mode Measurment mode
*/
#if defined(ARDUINO_ARCH_ESP8266)
void BH1750::begin(uint8_t SDA, uint8_t SCL, uint8_t mode) {
// allow config of pins
Wire.begin(SDA,SCL);
// Configure sensor in specified mode
configure(mode);
}
#endif
/**
* Begin I2C and configure sensor
+4
View File
@@ -60,6 +60,10 @@ class BH1750 {
public:
BH1750 (byte addr = 0x23);
#if defined(ARDUINO_ARCH_ESP8266)
/* ==== On esp8266 it is possible to define I2C pins ==== */
void begin (uint8_t SDA, uint8_t SCL, uint8_t mode = BH1750_CONTINUOUS_HIGH_RES_MODE);
#endif
void begin (uint8_t mode = BH1750_CONTINUOUS_HIGH_RES_MODE);
void configure (uint8_t mode);
uint16_t readLightLevel(void);
+3 -2
View File
@@ -9,8 +9,8 @@
VCC -> 5V (3V3 on Arduino Due, Zero, MKR1000, etc)
GND -> GND
SCL -> SCL (A5 on Arduino Uno, Leonardo, etc or 21 on Mega and Due)
SDA -> SDA (A4 on Arduino Uno, Leonardo, etc or 20 on Mega and Due)
SCL -> SCL (A5 on Arduino Uno, Leonardo, etc or 21 on Mega and Due on esp8266 free selectable)
SDA -> SDA (A4 on Arduino Uno, Leonardo, etc or 20 on Mega and Due on esp8266 free selectable)
ADD -> (not connected) or GND
ADD pin uses to set sensor I2C address. If it has voltage greater or equal to
@@ -29,6 +29,7 @@ void setup(){
Serial.begin(9600);
lightMeter.begin();
//lightMeter.begin(begin(D4, D3)); //use this line on a esp8266
Serial.println(F("BH1750 Test"));
}