mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.6.0 Max44009
This commit is contained in:
parent
485efe5abf
commit
877d392562
@ -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
|
||||
|
||||
|
@ -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 @@ public:
|
||||
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)
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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();
|
||||
|
@ -5,7 +5,6 @@ Max44009 KEYWORD1
|
||||
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
configure KEYWORD2
|
||||
isConnected KEYWORD2
|
||||
getLux KEYWORD2
|
||||
getError KEYWORD2
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
name=Max44009
|
||||
version=0.5.3
|
||||
version=0.6.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
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=*
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
#### Could
|
||||
|
||||
- merge MAX44007 / MAX44009 library in the future. (shared base class?)
|
||||
|
||||
#### Wont
|
||||
|
||||
|
||||
#### MAX44007
|
||||
## Support
|
||||
|
||||
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/
|
||||
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,
|
||||
|
||||
|
@ -104,4 +104,5 @@ unittest(test_convertToLux)
|
||||
|
||||
unittest_main()
|
||||
|
||||
// --------
|
||||
|
||||
// -- END OF FILE --
|
||||
|
Loading…
Reference in New Issue
Block a user