From b87cd4d80663c9dac6ae6413a2efb6e7a529c574 Mon Sep 17 00:00:00 2001 From: coelner Date: Wed, 26 Jul 2017 17:43:44 +0200 Subject: [PATCH 1/3] selectable i2c Pins for esp8266 and other --- BH1750.cpp | 14 ++++++++++++++ BH1750.h | 4 ++++ bh1750.patch | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 bh1750.patch diff --git a/BH1750.cpp b/BH1750.cpp index e7a2f30..ed48cf1 100644 --- a/BH1750.cpp +++ b/BH1750.cpp @@ -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 diff --git a/BH1750.h b/BH1750.h index 947283d..90dc4df 100644 --- a/BH1750.h +++ b/BH1750.h @@ -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); diff --git a/bh1750.patch b/bh1750.patch new file mode 100644 index 0000000..eb36042 --- /dev/null +++ b/bh1750.patch @@ -0,0 +1,40 @@ +diff --git a/BH1750.cpp b/BH1750.cpp +index e7a2f30..ed48cf1 100644 +--- a/BH1750.cpp ++++ b/BH1750.cpp +@@ -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 +diff --git a/BH1750.h b/BH1750.h +index 947283d..90dc4df 100644 +--- a/BH1750.h ++++ b/BH1750.h +@@ -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); From 8f38378a4b2f837946e25f1c2a02cdb1b5a3c433 Mon Sep 17 00:00:00 2001 From: coelner Date: Wed, 26 Jul 2017 17:47:57 +0200 Subject: [PATCH 2/3] selectable i2c Pins for esp8266 and other --- bh1750.patch | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 bh1750.patch diff --git a/bh1750.patch b/bh1750.patch deleted file mode 100644 index eb36042..0000000 --- a/bh1750.patch +++ /dev/null @@ -1,40 +0,0 @@ -diff --git a/BH1750.cpp b/BH1750.cpp -index e7a2f30..ed48cf1 100644 ---- a/BH1750.cpp -+++ b/BH1750.cpp -@@ -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 -diff --git a/BH1750.h b/BH1750.h -index 947283d..90dc4df 100644 ---- a/BH1750.h -+++ b/BH1750.h -@@ -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); From 895c0e6dd4cf2124a8a63285eb54204e01e13f8c Mon Sep 17 00:00:00 2001 From: coelner Date: Tue, 1 Aug 2017 20:59:39 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=09ge=C3=A4ndert:=20=20=20=20=20=20=20examp?= =?UTF-8?q?les/BH1750test/BH1750test.ino?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/BH1750test/BH1750test.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/BH1750test/BH1750test.ino b/examples/BH1750test/BH1750test.ino index 63bcb60..9a9b2b2 100644 --- a/examples/BH1750test/BH1750test.ino +++ b/examples/BH1750test/BH1750test.ino @@ -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")); }