0.4.4 MAX44009

This commit is contained in:
rob tillaart 2021-05-28 13:37:15 +02:00
parent 806402e1c7
commit 9a1789312c
14 changed files with 94 additions and 47 deletions

View File

@ -2,7 +2,7 @@
// FILE: Max44009.h // FILE: Max44009.h
// AUTHOR: Rob dot Tillaart at gmail dot com // AUTHOR: Rob dot Tillaart at gmail dot com
// VERSION: 0.4.3 // VERSION: 0.4.4
// PURPOSE: library for MAX44009 lux sensor Arduino // PURPOSE: library for MAX44009 lux sensor Arduino
// HISTORY: See Max440099.cpp // HISTORY: See Max440099.cpp
@ -31,7 +31,8 @@
#include "Arduino.h" #include "Arduino.h"
#define MAX44009_LIB_VERSION (F("0.4.3")) #define MAX44009_LIB_VERSION (F("0.4.4"))
#define MAX44009_DEFAULT_ADDRESS 0x4A #define MAX44009_DEFAULT_ADDRESS 0x4A
#define MAX44009_ALT_ADDRESS 0x4B #define MAX44009_ALT_ADDRESS 0x4B
@ -130,4 +131,5 @@ private:
TwoWire* _wire; TwoWire* _wire;
}; };
// END OF FILE // END OF FILE

View File

@ -8,6 +8,7 @@
// Released to the public domain // Released to the public domain
// //
#include "Wire.h" #include "Wire.h"
#include "Max44009.h" #include "Max44009.h"
@ -38,6 +39,7 @@ void setup()
myLux.enableInterrupt(); myLux.enableInterrupt();
} }
void loop() void loop()
{ {
uint32_t interval = 1000; uint32_t interval = 1000;
@ -60,7 +62,7 @@ void loop()
else Serial.println(); else Serial.println();
} }
} }
} }
// END OF FILE // END OF FILE

View File

@ -8,6 +8,7 @@
// Released to the public domain // Released to the public domain
// //
#include "Wire.h" #include "Wire.h"
#include "Max44009.h" #include "Max44009.h"
@ -27,6 +28,7 @@ void setup()
myLux.setAutomaticMode(); myLux.setAutomaticMode();
} }
void loop() void loop()
{ {
uint32_t interval = 100; uint32_t interval = 100;
@ -41,7 +43,7 @@ void loop()
int conf = myLux.getConfiguration(); int conf = myLux.getConfiguration();
int CDR = (conf & 0x80) >> 3; int CDR = (conf & 0x80) >> 3;
int TIM = (conf & 0x07); int TIM = (conf & 0x07);
int integrationTime = myLux.getIntegrationTime(); int integrationTime = myLux.getIntegrationTime();
if (err != 0) if (err != 0)
{ {
@ -62,7 +64,6 @@ void loop()
Serial.println(); Serial.println();
} }
} }
} }
// END OF FILE // END OF FILE

View File

@ -14,6 +14,7 @@
// per integration time. // per integration time.
// NB the getLux() call takes a bit more than 1 millisecond // NB the getLux() call takes a bit more than 1 millisecond
#include "Wire.h" #include "Wire.h"
#include "Max44009.h" #include "Max44009.h"
@ -24,6 +25,7 @@ uint32_t start = 0;
uint32_t stop = 0; uint32_t stop = 0;
int count = 0; int count = 0;
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@ -35,6 +37,7 @@ void setup()
myLux.setContinuousMode(); myLux.setContinuousMode();
} }
void loop() void loop()
{ {
uint32_t interval = 100; uint32_t interval = 100;
@ -68,4 +71,5 @@ void loop()
} }
} }
// END OF FILE
// -- END OF FILE --

View File

@ -1,13 +1,14 @@
// //
// FILE: max44009_setManualMode.ino // FILE: max44009_setManualMode.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.0 // VERSION: 0.1.1
// PURPOSE: demo of max44009 library // PURPOSE: demo of max44009 library
// DATE: 2020-01-30 // DATE: 2020-01-30
// //
// Released to the public domain // Released to the public domain
// //
#include "Wire.h" #include "Wire.h"
#include "Max44009.h" #include "Max44009.h"
@ -19,6 +20,7 @@ uint32_t lastChangeCDRTIM = 0;
uint8_t CDR = 0; uint8_t CDR = 0;
uint8_t TIM = 0; uint8_t TIM = 0;
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@ -30,6 +32,7 @@ void setup()
myLux.setManualMode(CDR, TIM); myLux.setManualMode(CDR, TIM);
} }
void loop() void loop()
{ {
uint32_t interval = 100; uint32_t interval = 100;
@ -56,18 +59,19 @@ void loop()
if (millis() - lastChangeCDRTIM >= 5000) if (millis() - lastChangeCDRTIM >= 5000)
{ {
lastChangeCDRTIM += 5000; lastChangeCDRTIM += 5000;
TIM++; TIM++;
if (TIM == 4) if (TIM == 4)
{ {
TIM = 0; TIM = 0;
CDR = (CDR + 1) & 1; CDR = (CDR + 1) & 1;
} }
myLux.setManualMode(CDR, TIM); myLux.setManualMode(CDR, TIM);
Serial.print("CDR:\t"); Serial.print("CDR:\t");
Serial.print((int)CDR); Serial.print((int)CDR);
Serial.print("\tTIM:\t"); Serial.print("\tTIM:\t");
Serial.println((int)TIM); Serial.println((int)TIM);
} }
} }
// END OF FILE // END OF FILE

View File

@ -8,6 +8,7 @@
// Released to the public domain // Released to the public domain
// //
#include "Wire.h" #include "Wire.h"
#include "Max44009.h" #include "Max44009.h"
@ -49,4 +50,5 @@ void loop()
} }
} }
// END OF FILE // END OF FILE

View File

@ -12,6 +12,7 @@
// Released to the public domain // Released to the public domain
// //
#include "Wire.h" #include "Wire.h"
#include "Max44009.h" #include "Max44009.h"
@ -23,6 +24,7 @@ Max44009 myLuxD(Max44009::Boolean::False);
uint32_t lastDisplay = 0; uint32_t lastDisplay = 0;
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@ -37,6 +39,7 @@ void setup()
myLuxD.configure(MAX44009_ALT_ADDRESS, &Wire1); myLuxD.configure(MAX44009_ALT_ADDRESS, &Wire1);
} }
void loop() { void loop() {
if (millis() - lastDisplay >= 1000) { if (millis() - lastDisplay >= 1000) {
lastDisplay += 1000; lastDisplay += 1000;
@ -49,4 +52,5 @@ void loop() {
} }
} }
// END OF FILE
// END OF FILE

View File

@ -8,6 +8,7 @@
// Released to the public domain // Released to the public domain
// //
#include "Wire.h" #include "Wire.h"
#include "Max44009.h" #include "Max44009.h"
@ -61,4 +62,5 @@ void loop()
} }
} }
// END OF FILE
// -- END OF FILE --

View File

@ -3,6 +3,7 @@
# Datatypes (KEYWORD1) # Datatypes (KEYWORD1)
Max44009 KEYWORD1 Max44009 KEYWORD1
# Methods and Functions (KEYWORD2) # Methods and Functions (KEYWORD2)
configure KEYWORD2 configure KEYWORD2
isConnected KEYWORD2 isConnected KEYWORD2
@ -32,6 +33,7 @@ getIntegrationTime KEYWORD2
# Instances (KEYWORD2) # Instances (KEYWORD2)
# Constants (LITERAL1) # Constants (LITERAL1)
MAX44009_LIB_VERSION LITERAL1 MAX44009_LIB_VERSION LITERAL1
MAX44009_DEFAULT_ADDRESS LITERAL1 MAX44009_DEFAULT_ADDRESS LITERAL1

View File

@ -15,7 +15,8 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/Max44009" "url": "https://github.com/RobTillaart/Max44009"
}, },
"version": "0.4.3", "version": "0.4.4",
"license": "MIT",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": "*" "platforms": "*"
} }

View File

@ -1,5 +1,5 @@
name=Max44009 name=Max44009
version=0.4.3 version=0.4.4
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Library for MAX44009 I2C LUX sensor Arduino. sentence=Library for MAX44009 I2C LUX sensor Arduino.
@ -7,5 +7,5 @@ paragraph=
category=Sensors category=Sensors
url=https://github.com/RobTillaart/Max44009 url=https://github.com/RobTillaart/Max44009
architectures=* architectures=*
includes=Wire.h, Max44009.h includes=Max44009.h
depends= depends=

View File

@ -1,12 +1,13 @@
// //
// FILE: Max44009.cpp // FILE: Max44009.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.4.3 // VERSION: 0.4.4
// PURPOSE: library for MAX44009 lux sensor Arduino // PURPOSE: library for MAX44009 lux sensor Arduino
// URL: https://github.com/RobTillaart/MAX44009 // URL: https://github.com/RobTillaart/MAX44009
// //
// HISTORY // HISTORY
// //
// 0.4.4 2021-05-27 arduino-lint
// 0.4.3 2020-12-30 arduino-ci, unit test // 0.4.3 2020-12-30 arduino-ci, unit test
// 0.4.2 2020-06-19 fix library.json // 0.4.2 2020-06-19 fix library.json
// 0.4.1 2020-03-21 #pragma, readme.nd, license.md // 0.4.1 2020-03-21 #pragma, readme.nd, license.md
@ -34,8 +35,10 @@
// 0.1.01 added interrupt code // 0.1.01 added interrupt code
// 0.1.00 initial version // 0.1.00 initial version
#include "Max44009.h" #include "Max44009.h"
#if defined(ESP8266) || defined(ESP32) #if defined(ESP8266) || defined(ESP32)
Max44009::Max44009(const uint8_t address, const uint8_t dataPin, const uint8_t clockPin) Max44009::Max44009(const uint8_t address, const uint8_t dataPin, const uint8_t clockPin)
{ {
@ -53,16 +56,19 @@ Max44009::Max44009(const uint8_t address, const uint8_t dataPin, const uint8_t c
} }
#endif #endif
Max44009::Max44009(const uint8_t address, const Boolean begin) Max44009::Max44009(const uint8_t address, const Boolean begin)
{ {
Max44009::configure(address, &Wire, begin); Max44009::configure(address, &Wire, begin);
} }
Max44009::Max44009(const Boolean begin) Max44009::Max44009(const Boolean begin)
{ {
Max44009::configure(MAX44009_DEFAULT_ADDRESS, &Wire, begin); Max44009::configure(MAX44009_DEFAULT_ADDRESS, &Wire, begin);
} }
void Max44009::configure(const uint8_t address, TwoWire *wire, const Boolean begin) void Max44009::configure(const uint8_t address, TwoWire *wire, const Boolean begin)
{ {
_address = address; _address = address;
@ -195,7 +201,7 @@ void Max44009::clrContinuousMode()
void Max44009::setManualMode(uint8_t CDR, uint8_t TIM) void Max44009::setManualMode(uint8_t CDR, uint8_t TIM)
{ {
if (CDR !=0) CDR = 1; if (CDR !=0) CDR = 1; // only 0 or 1
if (TIM > 7) TIM = 7; if (TIM > 7) TIM = 7;
uint8_t config = read(MAX44009_CONFIGURATION); uint8_t config = read(MAX44009_CONFIGURATION);
config |= MAX44009_CFG_MANUAL; config |= MAX44009_CFG_MANUAL;
@ -263,4 +269,5 @@ void Max44009::write(uint8_t reg, uint8_t value)
_error = _wire->endTransmission(); _error = _wire->endTransmission();
} }
// --- END OF FILE --- // --- END OF FILE ---

View File

@ -7,6 +7,7 @@
Library for MAX44009 / GY-49 I2C lux sensor Library for MAX44009 / GY-49 I2C lux sensor
## Description ## Description
a.k.a. GY-49 a.k.a. GY-49
@ -47,58 +48,71 @@ dynamic range from 0.045 lux to 188,000 lux.
### Constructor ### Constructor
- **Max44009(address, dataPin, clockPin)** dataPin, clockPin for ESP32, ESP8266 - **Max44009(address, dataPin, clockPin)** Constructor with dataPin (sda) and clockPin (scl) for ESP32 and ESP8266
- **Max44009(address, begin = Boolean::True)** - **Max44009(address, begin = Boolean::True)** Constructor for other boards e.g. UNO.
- **Max44009(begin = Boolean::True)** - **Max44009(begin = Boolean::True)** Constructor with default I2C address 0x4A == 74.
- **void configure(address, TwoWire \*wire, begin = Boolean::True)** Change I2C interface and address - **void configure(address, TwoWire \*wire, begin = Boolean::True)** Change I2C interface and address.
- **bool isConnected()** device available on I2C bus. - **bool isConnected()** returns true if the device address configured is available on I2C bus.
### Basic ### Basic
- **float getLux()** read the sensor. - **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. - **int getError()** returns last error.
```cpp
// ERROR CODES
#define MAX44009_OK 0
#define MAX44009_ERROR_WIRE_REQUEST -10
#define MAX44009_ERROR_OVERFLOW -20
#define MAX44009_ERROR_HIGH_BYTE -30
#define MAX44009_ERROR_LOW_BYTE -31
```
### Configure thresholds ### Configure thresholds
check datasheet for details check datasheet for details
- **void setHighThreshold(float)** - **void setHighThreshold(float)** sets the upper threshold for the interrupt generation (INT pulls LOW). Works only if INTE bit is set by **enableInterrupt()**.
- **float getHighThreshold(void)** - **float getHighThreshold(void)** returns the value set.
- **void setLowThreshold(float)** - **void setLowThreshold(float)** sets the lower threshold for the interrupt generation (INT pulls LOW). Works only if INTE bit is set by **enableInterrupt()**.
- **float getLowThreshold(void)** - **float getLowThreshold(void)** returns the value set.
- **void setThresholdTimer(uint8_t)** 2 seems practical minimum - **void setThresholdTimer(uint8_t)** Time the threshold needs to be exceeded, defined in steps of 100ms. 2 seems to be a practical minimum.
- **uint8_t getThresholdTimer()** returns - **uint8_t getThresholdTimer()** returns the value set.
### Configure interrupts ### Configure interrupts
check datasheet for details check datasheet for details
- **void enableInterrupt()** - **void enableInterrupt()** enables the upper and lower threshold interrupts.
- **void disableInterrupt()** - **void disableInterrupt()** disables the threshold interrupts.
- **bool interruptEnabled()** - **bool interruptEnabled()** returns 1 if the interrupt mode is enabled.
- **uint8_t getInterruptStatus()** - **uint8_t getInterruptStatus()** returns 1 if an interrupt has occurred.
### Configure flags ### Configure flags
check datasheet for details check datasheet for details
- **void setConfiguration(uint8_t)** - **void setConfiguration(uint8_t)** writes directly to configuration register. **warning** Use with care.
- **uint8_t getConfiguration()** - **uint8_t getConfiguration()** reads the current configuration register.
### Configure sample mode ### Configure sample mode
check datasheet for details check datasheet for details
- **void setAutomaticMode()** CCR = Current Divisor Ratio.
- **void setContinuousMode()** uses more power
- **void clrContinuousMode()** uses less power TIM = Integration time.
- **void setManualMode(uint8_t CDR, uint8_t TIM)**
- **int getIntegrationTime()** returns time in milliseconds - **void setAutomaticMode()** in automatic mode the MAX44009 determines the CDR and TIM parameters.
- **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 integration time manually. Effectively disable automatic mode.
- **int getIntegrationTime()** returns the set integration time in milliseconds
``` ```
CDR = Current Divisor Ratio CDR = Current Divisor Ratio

View File

@ -40,6 +40,7 @@ unittest_setup()
{ {
} }
unittest_teardown() unittest_teardown()
{ {
} }
@ -58,6 +59,7 @@ unittest(test_constructor)
// TODO more tests if WIRE works... // TODO more tests if WIRE works...
} }
unittest_main() unittest_main()
// -------- // --------