diff --git a/CHANGELOG.md b/CHANGELOG.md index 25930bd..ec0a1f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,12 +6,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.6.0] - 2023-10-02 +- refactor constructor around I2C interface (simpler) +- remove **configure()** +- update readme.md +- update examples + +---- + ## [0.5.3] - 2022-11-16 - add RP2040 in build-CI - add changelog.md - minor edit readme.md - ## [0.5.2] - 2022-01-05 - minor edits after creating Max44007 library diff --git a/Max44009.cpp b/Max44009.cpp index 602990d..a34246f 100644 --- a/Max44009.cpp +++ b/Max44009.cpp @@ -1,12 +1,10 @@ // // FILE: Max44009.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.5.3 +// VERSION: 0.6.0 +// DATE: 2010-??-?? // PURPOSE: library for MAX44009 lux sensor Arduino // URL: https://github.com/RobTillaart/MAX44009 -// -// HISTORY: see changelog.md - #include "Max44009.h" @@ -16,47 +14,12 @@ #define MAX44009_MAX_LUX (188006.0) -#if defined(ESP8266) || defined(ESP32) -Max44009::Max44009(const uint8_t address, const uint8_t dataPin, const uint8_t clockPin) -{ - _address = address; - _data = 0; - _error = MAX44009_OK; - _wire = &Wire; - - if ((dataPin < 255) && (clockPin < 255)) - { - _wire->begin(dataPin, clockPin); - } else { - _wire->begin(); - } -} -#endif - - -Max44009::Max44009(const uint8_t address, const Boolean begin) -{ - Max44009::configure(address, &Wire, begin); -} - - -Max44009::Max44009(const Boolean begin) -{ - Max44009::configure(MAX44009_DEFAULT_ADDRESS, &Wire, begin); -} - - -void Max44009::configure(const uint8_t address, TwoWire *wire, const Boolean begin) +Max44009::Max44009(const uint8_t address, TwoWire *wire) { _address = address; _data = 0; _error = MAX44009_OK; _wire = wire; - - if (begin == Boolean::True) - { - _wire->begin(); - } } diff --git a/Max44009.h b/Max44009.h index 40b60bf..f7f1bc4 100644 --- a/Max44009.h +++ b/Max44009.h @@ -1,10 +1,11 @@ #pragma once // FILE: Max44009.h -// AUTHOR: Rob dot Tillaart at gmail dot com -// VERSION: 0.5.3 +// AUTHOR: Rob Tillaart +// VERSION: 0.6.0 +// DATE: 2010-??-?? // PURPOSE: library for MAX44009 lux sensor Arduino -// HISTORY: See changelog.md + // breakout MAX44009 / GY-49 @@ -32,7 +33,7 @@ #include "Arduino.h" -#define MAX44009_LIB_VERSION (F("0.5.3")) +#define MAX44009_LIB_VERSION (F("0.6.0")) #define MAX44009_DEFAULT_ADDRESS 0x4A #define MAX44009_ALT_ADDRESS 0x4B @@ -67,20 +68,7 @@ class Max44009 { public: - // enum class to prevent bool to be implicitly casted to int - enum class Boolean { True, False }; - -#if defined(ESP8266) || defined(ESP32) - // dataPin and clockPin can be used for ESP8266 - Max44009(const uint8_t address, const uint8_t dataPin, const uint8_t clockPin); -#endif - - // constructor for UNO - Max44009(const uint8_t address, const Boolean begin = Boolean::True); - // default constructor with default address - Max44009(const Boolean begin = Boolean::True); - // Change I2C interface and address - void configure(const uint8_t address, TwoWire *wire, const Boolean begin = Boolean::True); + Max44009(const uint8_t address = MAX44009_DEFAULT_ADDRESS, TwoWire *wire = &Wire); bool isConnected(); float getLux(); @@ -105,7 +93,6 @@ class Max44009 void setAutomaticMode(); void setContinuousMode(); // uses more power void clrContinuousMode(); // uses less power - // CDR = Current Divisor Ratio // CDR = 1 ==> only 1/8th is measured // TIM = Time Integration Measurement (table) diff --git a/README.md b/README.md index 8d9203d..8b2c3a3 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,12 @@ [![Arduino CI](https://github.com/RobTillaart/MAX44009/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) -[![Arduino-lint](https://github.com/RobTillaart/Max44009/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/Max44009/actions/workflows/arduino-lint.yml) -[![JSON check](https://github.com/RobTillaart/Max44009/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/Max44009/actions/workflows/jsoncheck.yml) +[![Arduino-lint](https://github.com/RobTillaart/MAX44009/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/MAX44009/actions/workflows/arduino-lint.yml) +[![JSON check](https://github.com/RobTillaart/MAX44009/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/MAX44009/actions/workflows/jsoncheck.yml) +[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/MAX44009.svg)](https://github.com/RobTillaart/MAX44009/issues) + [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/MAX44009/blob/master/LICENSE) [![GitHub release](https://img.shields.io/github/release/RobTillaart/MAX44009.svg?maxAge=3600)](https://github.com/RobTillaart/MAX44009/releases) +[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/MAX44009.svg)](https://registry.platformio.org/libraries/robtillaart/MAX44009) # MAX44009 I2C LUX sensor @@ -15,10 +18,20 @@ Library for MAX44009 / GY-49 I2C lux sensor. a.k.a. GY-49 -The MAX44009 ambient light sensor is an I2C sensor, that has a 22 bit +The MAX44009 ambient light sensor is an I2C sensor, that has a 22 bit dynamic range from 0.045 lux to 188,000 lux. -Relates to https://github.com/RobTillaart/Max44007 + +#### MAX44007 + +The MAX44007 is an almost identical sensor that uses a step size of 0.025. +This implies that this library is not useable 1 to 1 for the MAX44007, however some parts will work/ + + +#### Related + +- https://github.com/RobTillaart/Max44007 (range 0.025 lux to 104,448 lux) +- https://github.com/RobTillaart/Max44009 (range 0.045 lux to 188,000 lux) ## Schema breakout max44009 / GY-49 @@ -49,21 +62,22 @@ Relates to https://github.com/RobTillaart/Max44007 ## Interface -- **enum class Boolean { True, False }** enum class to prevent bool to be implicitly casted to int. +```cpp +#include "Max44009.h" +``` +### Constructor -### Constructor - -- **Max44009(uint8_t address, uint8_t dataPin, uint8_t clockPin)** Constructor with dataPin (sda) and clockPin (scl) for ESP32 and ESP8266. -- **Max44009(uint8_t address, begin = Boolean::True)** Constructor for other boards e.g. UNO. -- **Max44009(begin = Boolean::True)** Constructor with default I2C address 0x4A == 74. -- **void configure(uint8_t address, TwoWire \*wire, begin = Boolean::True)** Change I2C interface and address. +- **Max44009(const uint8_t address = MAX44009_DEFAULT_ADDRESS, TwoWire \*wire = &Wire)** Constructor. +Optional address and optional I2C interface.\ - **bool isConnected()** returns true if the device address configured is available on I2C bus. +NOTE: The user must call **Wire.begin()** or **Wire.begin(SDA, SCL)** in **setup()**. -### Basic -- **float getLux()** read the sensor and return the value in LUX. If the value is negative, an error has occurred. +### Basic + +- **float getLux()** read the sensor and return the value in LUX. If the value is negative, an error has occurred. - **int getError()** returns last error. ```cpp @@ -80,15 +94,15 @@ Relates to https://github.com/RobTillaart/Max44007 check datasheet for details -- **bool setHighThreshold(float value)** sets the upper threshold for the interrupt -generation (INT pulls LOW). Works only if INTE bit is set by **enableInterrupt()**. +- **bool setHighThreshold(float value)** sets the upper threshold for the interrupt +generation (INT pulls LOW). Works only if INTE bit is set by **enableInterrupt()**. Function returns false if the value is out of range. - **float getHighThreshold()** returns the value set. -- **bool setLowThreshold(float value)** sets the lower threshold for the interrupt -generation (INT pulls LOW). Works only if INTE bit is set by **enableInterrupt()**. +- **bool setLowThreshold(float value)** sets the lower threshold for the interrupt +generation (INT pulls LOW). Works only if INTE bit is set by **enableInterrupt()**. Function returns false if the value is out of range. - **float getLowThreshold()** returns the value set. -- **void setThresholdTimer(uint8_t value)** Time the threshold needs to be exceeded, +- **void setThresholdTimer(uint8_t value)** Time the threshold needs to be exceeded, defined in steps of 100ms. 2 seems to be a practical minimum. - **uint8_t getThresholdTimer()** returns the value set. @@ -107,7 +121,7 @@ check datasheet for details check datasheet for details -- **void setConfiguration(uint8_t)** writes directly to configuration register. +- **void setConfiguration(uint8_t)** writes directly to configuration register. **warning** Use with care. - **uint8_t getConfiguration()** reads the current configuration register. @@ -120,12 +134,12 @@ CCR = Current Divisor Ratio. TIM = Integration time. -- **void setAutomaticMode()** in automatic mode the MAX44009 determines the CDR and TIM +- **void setAutomaticMode()** in automatic mode the MAX44009 determines the CDR and TIM parameters. -- **void setContinuousMode()** continuous mode uses more power than a "single" conversion. +- **void setContinuousMode()** continuous mode uses more power than a "single" conversion. Advantage is that the latest data is always available fast. -- **void clrContinuousMode()** uses less power so better for LOW power configurations. -- **void setManualMode(uint8_t CDR, uint8_t TIM)** Set the Current Divisor Ratio and the +- **void clrContinuousMode()** uses less power so better for LOW power configurations. +- **void setManualMode(uint8_t CDR, uint8_t TIM)** Set the Current Divisor Ratio and the integration time manually. Effectively disable automatic mode. - **int getIntegrationTime()** returns the set integration time in milliseconds @@ -147,11 +161,11 @@ integration time manually. Effectively disable automatic mode. ### Test functions -Function for the conversion math, not meant to be used directly, +Function for the conversion math, not meant to be used directly, but by making them public they become testable. -- **float convertToLux(uint8_t datahigh, uint8_t datalow)** convert intern register -format to a LUX value. +- **float convertToLux(uint8_t dataHigh, uint8_t dataLow)** convert intern register +format to a LUX value. ## Examples @@ -167,22 +181,36 @@ format to a LUX value. ## Notes Please be aware this is a **3.3 Volt device** so it should not be connected -to an Arduino UNO or other 5 Volt device directly. +to an Arduino UNO or other 5 Volt device directly. Use a level convertor to solve this. Do not forget to connect the address pin as you cannot read the sensor in a reliable way. As the line will float it will sometimes have the right address and sometimes not. (been there ;) +Pull ups on I2C bus are recommended. + ## Future +#### Must + - improve documentation -- merge MAX44007 library in the future. (shared base class?) +#### Should -#### MAX44007 +#### Could -The MAX44007 is an almost identical sensor that uses a step size of 0.025. -This implies that this library is not useable 1 to 1 for the MAX44007, however some parts will work/ +- merge MAX44007 / MAX44009 library in the future. (shared base class?) + +#### Wont + + +## Support + +If you appreciate my libraries, you can support the development and maintenance. +Improve the quality of the libraries by providing issues and Pull Requests, or +donate through PayPal or GitHub sponsors. + +Thank you, diff --git a/examples/max44009_interrupt/max44009_interrupt.ino b/examples/max44009_interrupt/max44009_interrupt.ino index c229244..cb6242e 100644 --- a/examples/max44009_interrupt/max44009_interrupt.ino +++ b/examples/max44009_interrupt/max44009_interrupt.ino @@ -16,7 +16,8 @@ uint32_t lastDisplay = 0; void setup() { Serial.begin(115200); - Serial.print("\nStart max44009_interrupt : "); + Serial.println(__FILE__); + Serial.print("MAX44009_LIB_VERSION: "); Serial.println(MAX44009_LIB_VERSION); Wire.begin(); diff --git a/examples/max44009_setAutomaticMode/max44009_setAutomaticMode.ino b/examples/max44009_setAutomaticMode/max44009_setAutomaticMode.ino index c8d2af0..ec7b147 100644 --- a/examples/max44009_setAutomaticMode/max44009_setAutomaticMode.ino +++ b/examples/max44009_setAutomaticMode/max44009_setAutomaticMode.ino @@ -16,7 +16,8 @@ uint32_t lastDisplay = 0; void setup() { Serial.begin(115200); - Serial.print("\nStart max44009_setAutomaticMode : "); + Serial.println(__FILE__); + Serial.print("MAX44009_LIB_VERSION: "); Serial.println(MAX44009_LIB_VERSION); Wire.begin(); diff --git a/examples/max44009_setContinuousMode/max44009_setContinuousMode.ino b/examples/max44009_setContinuousMode/max44009_setContinuousMode.ino index 6da80da..f418524 100644 --- a/examples/max44009_setContinuousMode/max44009_setContinuousMode.ino +++ b/examples/max44009_setContinuousMode/max44009_setContinuousMode.ino @@ -25,7 +25,8 @@ int count = 0; void setup() { Serial.begin(115200); - Serial.print("\nStart max44009_setContinuousMode : "); + Serial.println(__FILE__); + Serial.print("MAX44009_LIB_VERSION: "); Serial.println(MAX44009_LIB_VERSION); Wire.begin(); diff --git a/examples/max44009_setManualMode/max44009_setManualMode.ino b/examples/max44009_setManualMode/max44009_setManualMode.ino index 49e3f88..039006a 100644 --- a/examples/max44009_setManualMode/max44009_setManualMode.ino +++ b/examples/max44009_setManualMode/max44009_setManualMode.ino @@ -19,7 +19,8 @@ uint8_t TIM = 0; void setup() { Serial.begin(115200); - Serial.print("\nStart max44009_setManualMode : "); + Serial.println(__FILE__); + Serial.print("MAX44009_LIB_VERSION: "); Serial.println(MAX44009_LIB_VERSION); Wire.begin(); diff --git a/examples/max44009_test01/max44009_test01.ino b/examples/max44009_test01/max44009_test01.ino index 9411456..97cf7b5 100644 --- a/examples/max44009_test01/max44009_test01.ino +++ b/examples/max44009_test01/max44009_test01.ino @@ -29,7 +29,8 @@ uint32_t lastDisplay = 0; void setup() { Serial.begin(115200); - Serial.print("Start max44009_test01 : "); + Serial.println(__FILE__); + Serial.print("MAX44009_LIB_VERSION: "); Serial.println(MAX44009_LIB_VERSION); Wire.begin(); diff --git a/examples/max44009_test02/max44009_test02.ino b/examples/max44009_test02/max44009_test02.ino index 0f2e1d2..f095ee1 100644 --- a/examples/max44009_test02/max44009_test02.ino +++ b/examples/max44009_test02/max44009_test02.ino @@ -16,10 +16,10 @@ #include "Max44009.h" // Don't begin I2C interface (Wire). Will be called in setup() -Max44009 myLuxA(Max44009::Boolean::False); -Max44009 myLuxB(Max44009::Boolean::False); -Max44009 myLuxC(Max44009::Boolean::False); -Max44009 myLuxD(Max44009::Boolean::False); +Max44009 myLuxA(MAX44009_DEFAULT_ADDRESS, &Wire); +Max44009 myLuxB(MAX44009_ALT_ADDRESS, &Wire); +Max44009 myLuxC(MAX44009_DEFAULT_ADDRESS, &Wire1); +Max44009 myLuxD(MAX44009_ALT_ADDRESS, &Wire1); uint32_t lastDisplay = 0; @@ -27,15 +27,12 @@ uint32_t lastDisplay = 0; void setup() { Serial.begin(115200); - Serial.print("Start max44009_test02 : "); + Serial.println(__FILE__); + Serial.print("MAX44009_LIB_VERSION: "); Serial.println(MAX44009_LIB_VERSION); Wire.begin(19, 18); Wire1.begin(22, 23); - myLuxA.configure(MAX44009_DEFAULT_ADDRESS, &Wire); - myLuxB.configure(MAX44009_ALT_ADDRESS, &Wire); - myLuxC.configure(MAX44009_DEFAULT_ADDRESS, &Wire1); - myLuxD.configure(MAX44009_ALT_ADDRESS, &Wire1); } diff --git a/examples/max44009_two_sensors/max44009_two_sensors.ino b/examples/max44009_two_sensors/max44009_two_sensors.ino index 9e45947..b99edb4 100644 --- a/examples/max44009_two_sensors/max44009_two_sensors.ino +++ b/examples/max44009_two_sensors/max44009_two_sensors.ino @@ -18,7 +18,8 @@ uint32_t count = 0; void setup() { Serial.begin(115200); - Serial.print("Start max44009_two_sensors : "); + Serial.println(__FILE__); + Serial.print("MAX44009_LIB_VERSION: "); Serial.println(MAX44009_LIB_VERSION); Wire.begin(); diff --git a/keywords.txt b/keywords.txt index e0f6494..cb5ea81 100644 --- a/keywords.txt +++ b/keywords.txt @@ -5,7 +5,6 @@ Max44009 KEYWORD1 # Methods and Functions (KEYWORD2) -configure KEYWORD2 isConnected KEYWORD2 getLux KEYWORD2 getError KEYWORD2 diff --git a/library.json b/library.json index b6c7fd4..81aee77 100644 --- a/library.json +++ b/library.json @@ -15,9 +15,9 @@ "type": "git", "url": "https://github.com/RobTillaart/Max44009.git" }, - "version": "0.5.3", + "version": "0.6.0", "license": "MIT", - "frameworks": "arduino", + "frameworks": "*", "platforms": "*", "headers": "Max44009.h" } diff --git a/library.properties b/library.properties index 099ec31..feaaf24 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ name=Max44009 -version=0.5.3 +version=0.6.0 author=Rob Tillaart maintainer=Rob Tillaart -sentence=Library for MAX44009 I2C LUX sensor Arduino. -paragraph= +sentence=Library for MAX44009 I2C LUX sensor Arduino. +paragraph= category=Sensors url=https://github.com/RobTillaart/Max44009 architectures=* diff --git a/test/unit_test_001.cpp b/test/unit_test_001.cpp index 2f0a9fe..5590364 100644 --- a/test/unit_test_001.cpp +++ b/test/unit_test_001.cpp @@ -104,4 +104,5 @@ unittest(test_convertToLux) unittest_main() -// -------- + +// -- END OF FILE --