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
// AUTHOR: Rob dot Tillaart at gmail dot com
// VERSION: 0.4.3
// VERSION: 0.4.4
// PURPOSE: library for MAX44009 lux sensor Arduino
// HISTORY: See Max440099.cpp
@ -31,7 +31,8 @@
#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_ALT_ADDRESS 0x4B
@ -130,4 +131,5 @@ private:
TwoWire* _wire;
};
// END OF FILE

View File

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

View File

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

View File

@ -14,6 +14,7 @@
// per integration time.
// NB the getLux() call takes a bit more than 1 millisecond
#include "Wire.h"
#include "Max44009.h"
@ -24,6 +25,7 @@ uint32_t start = 0;
uint32_t stop = 0;
int count = 0;
void setup()
{
Serial.begin(115200);
@ -35,6 +37,7 @@ void setup()
myLux.setContinuousMode();
}
void loop()
{
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
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// VERSION: 0.1.1
// PURPOSE: demo of max44009 library
// DATE: 2020-01-30
//
// Released to the public domain
//
#include "Wire.h"
#include "Max44009.h"
@ -19,6 +20,7 @@ uint32_t lastChangeCDRTIM = 0;
uint8_t CDR = 0;
uint8_t TIM = 0;
void setup()
{
Serial.begin(115200);
@ -30,6 +32,7 @@ void setup()
myLux.setManualMode(CDR, TIM);
}
void loop()
{
uint32_t interval = 100;
@ -56,18 +59,19 @@ void loop()
if (millis() - lastChangeCDRTIM >= 5000)
{
lastChangeCDRTIM += 5000;
TIM++;
if (TIM == 4)
{
TIM = 0;
CDR = (CDR + 1) & 1;
}
TIM++;
if (TIM == 4)
{
TIM = 0;
CDR = (CDR + 1) & 1;
}
myLux.setManualMode(CDR, TIM);
Serial.print("CDR:\t");
Serial.print((int)CDR);
Serial.print("\tTIM:\t");
Serial.println((int)TIM);
Serial.print("CDR:\t");
Serial.print((int)CDR);
Serial.print("\tTIM:\t");
Serial.println((int)TIM);
}
}
// END OF FILE

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,12 +1,13 @@
//
// FILE: Max44009.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.4.3
// VERSION: 0.4.4
// PURPOSE: library for MAX44009 lux sensor Arduino
// URL: https://github.com/RobTillaart/MAX44009
//
// HISTORY
//
// 0.4.4 2021-05-27 arduino-lint
// 0.4.3 2020-12-30 arduino-ci, unit test
// 0.4.2 2020-06-19 fix library.json
// 0.4.1 2020-03-21 #pragma, readme.nd, license.md
@ -34,8 +35,10 @@
// 0.1.01 added interrupt code
// 0.1.00 initial version
#include "Max44009.h"
#if defined(ESP8266) || defined(ESP32)
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
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)
{
_address = address;
@ -195,7 +201,7 @@ void Max44009::clrContinuousMode()
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;
uint8_t config = read(MAX44009_CONFIGURATION);
config |= MAX44009_CFG_MANUAL;
@ -263,4 +269,5 @@ void Max44009::write(uint8_t reg, uint8_t value)
_error = _wire->endTransmission();
}
// --- END OF FILE ---

View File

@ -7,6 +7,7 @@
Library for MAX44009 / GY-49 I2C lux sensor
## Description
a.k.a. GY-49
@ -47,58 +48,71 @@ dynamic range from 0.045 lux to 188,000 lux.
### Constructor
- **Max44009(address, dataPin, clockPin)** dataPin, clockPin for ESP32, ESP8266
- **Max44009(address, begin = Boolean::True)**
- **Max44009(begin = Boolean::True)**
- **void configure(address, TwoWire \*wire, begin = Boolean::True)** Change I2C interface and address
- **bool isConnected()** device available on I2C bus.
- **Max44009(address, dataPin, clockPin)** Constructor with dataPin (sda) and clockPin (scl) for ESP32 and ESP8266
- **Max44009(address, begin = Boolean::True)** Constructor for other boards e.g. UNO.
- **Max44009(begin = Boolean::True)** Constructor with default I2C address 0x4A == 74.
- **void configure(address, TwoWire \*wire, begin = Boolean::True)** Change I2C interface and address.
- **bool isConnected()** returns true if the device address configured is available on I2C bus.
### 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.
```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
check datasheet for details
- **void setHighThreshold(float)**
- **float getHighThreshold(void)**
- **void setLowThreshold(float)**
- **float getLowThreshold(void)**
- **void setThresholdTimer(uint8_t)** 2 seems practical minimum
- **uint8_t getThresholdTimer()** returns
- **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)** returns the value set.
- **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)** returns the value set.
- **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 the value set.
### Configure interrupts
check datasheet for details
- **void enableInterrupt()**
- **void disableInterrupt()**
- **bool interruptEnabled()**
- **uint8_t getInterruptStatus()**
- **void enableInterrupt()** enables the upper and lower threshold interrupts.
- **void disableInterrupt()** disables the threshold interrupts.
- **bool interruptEnabled()** returns 1 if the interrupt mode is enabled.
- **uint8_t getInterruptStatus()** returns 1 if an interrupt has occurred.
### Configure flags
check datasheet for details
- **void setConfiguration(uint8_t)**
- **uint8_t getConfiguration()**
- **void setConfiguration(uint8_t)** writes directly to configuration register. **warning** Use with care.
- **uint8_t getConfiguration()** reads the current configuration register.
### Configure sample mode
check datasheet for details
- **void setAutomaticMode()**
- **void setContinuousMode()** uses more power
- **void clrContinuousMode()** uses less power
- **void setManualMode(uint8_t CDR, uint8_t TIM)**
- **int getIntegrationTime()** returns time in milliseconds
CCR = Current Divisor Ratio.
TIM = Integration time.
- **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

View File

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