mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
0.5.1 MAX44009
This commit is contained in:
parent
63ee41d892
commit
14b6317b3e
@ -2,6 +2,10 @@ compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
- uno
|
||||
- leonardo
|
||||
- due
|
||||
- zero
|
||||
# - due
|
||||
# - zero
|
||||
# - leonardo
|
||||
- m4
|
||||
- esp32
|
||||
# - esp8266
|
||||
# - mega2560
|
||||
|
@ -4,10 +4,14 @@ name: Arduino CI
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
arduino_ci:
|
||||
runTest:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: Arduino-CI/action@master
|
||||
# Arduino-CI/action@v0.1.1
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
- run: |
|
||||
gem install arduino_ci
|
||||
arduino_ci.rb
|
||||
|
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2010-2021 Rob Tillaart
|
||||
Copyright (c) 2010-2022 Rob Tillaart
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
// FILE: Max44009.h
|
||||
// AUTHOR: Rob dot Tillaart at gmail dot com
|
||||
// VERSION: 0.5.0
|
||||
// VERSION: 0.5.1
|
||||
// PURPOSE: library for MAX44009 lux sensor Arduino
|
||||
// HISTORY: See Max440099.cpp
|
||||
|
||||
@ -32,36 +32,36 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
|
||||
#define MAX44009_LIB_VERSION (F("0.5.0"))
|
||||
#define MAX44009_LIB_VERSION (F("0.5.1"))
|
||||
|
||||
#define MAX44009_DEFAULT_ADDRESS 0x4A
|
||||
#define MAX44009_ALT_ADDRESS 0x4B
|
||||
#define MAX44009_DEFAULT_ADDRESS 0x4A
|
||||
#define MAX44009_ALT_ADDRESS 0x4B
|
||||
|
||||
|
||||
// REGISTERS
|
||||
#define MAX44009_INTERRUPT_STATUS 0x00
|
||||
#define MAX44009_INTERRUPT_ENABLE 0x01
|
||||
#define MAX44009_CONFIGURATION 0x02
|
||||
#define MAX44009_LUX_READING_HIGH 0x03
|
||||
#define MAX44009_LUX_READING_LOW 0x04
|
||||
#define MAX44009_THRESHOLD_HIGH 0x05
|
||||
#define MAX44009_THRESHOLD_LOW 0x06
|
||||
#define MAX44009_THRESHOLD_TIMER 0x07
|
||||
#define MAX44009_INTERRUPT_STATUS 0x00
|
||||
#define MAX44009_INTERRUPT_ENABLE 0x01
|
||||
#define MAX44009_CONFIGURATION 0x02
|
||||
#define MAX44009_LUX_READING_HIGH 0x03
|
||||
#define MAX44009_LUX_READING_LOW 0x04
|
||||
#define MAX44009_THRESHOLD_HIGH 0x05
|
||||
#define MAX44009_THRESHOLD_LOW 0x06
|
||||
#define MAX44009_THRESHOLD_TIMER 0x07
|
||||
|
||||
|
||||
// CONFIGURATION MASKS
|
||||
#define MAX44009_CFG_CONTINUOUS 0x80
|
||||
#define MAX44009_CFG_MANUAL 0x40
|
||||
#define MAX44009_CFG_CDR 0x08
|
||||
#define MAX44009_CFG_TIMER 0x07
|
||||
#define MAX44009_CFG_CONTINUOUS 0x80
|
||||
#define MAX44009_CFG_MANUAL 0x40
|
||||
#define MAX44009_CFG_CDR 0x08
|
||||
#define MAX44009_CFG_TIMER 0x07
|
||||
|
||||
|
||||
// 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
|
||||
#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
|
||||
|
||||
|
||||
class Max44009
|
||||
@ -87,11 +87,11 @@ public:
|
||||
int getError();
|
||||
|
||||
// threshold must be between 0 and 188006
|
||||
bool setHighThreshold(const float); // returns false if value out of range
|
||||
bool setHighThreshold(const float value); // returns false if value out of range
|
||||
float getHighThreshold(void);
|
||||
bool setLowThreshold(const float); // returns false if value out of range
|
||||
bool setLowThreshold(const float value); // returns false if value out of range
|
||||
float getLowThreshold(void);
|
||||
void setThresholdTimer(const uint8_t); // 2 seems practical minimum
|
||||
void setThresholdTimer(const uint8_t value); // 2 seems practical minimum
|
||||
uint8_t getThresholdTimer();
|
||||
|
||||
void enableInterrupt() { write(MAX44009_INTERRUPT_ENABLE, 1); };
|
||||
@ -124,11 +124,11 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
bool setThreshold(uint8_t, float);
|
||||
float getThreshold(uint8_t);
|
||||
bool setThreshold(uint8_t reg, float value);
|
||||
float getThreshold(uint8_t reg);
|
||||
|
||||
uint8_t read(uint8_t reg);
|
||||
void write(uint8_t, uint8_t);
|
||||
void write(uint8_t reg, uint8_t value);
|
||||
|
||||
uint8_t _address;
|
||||
uint8_t _data;
|
||||
@ -139,3 +139,4 @@ private:
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,12 +1,8 @@
|
||||
//
|
||||
// FILE: max44009_interrupt.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo of max44009 library
|
||||
// DATE: 2020-01-30
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
|
||||
#include "Wire.h"
|
||||
@ -65,4 +61,5 @@ void loop()
|
||||
}
|
||||
|
||||
|
||||
// END OF FILE
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,12 +1,8 @@
|
||||
//
|
||||
// FILE: max44009_setAutomaticMode.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo of max44009 library
|
||||
// DATE: 2020-01-30
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
|
||||
#include "Wire.h"
|
||||
@ -66,4 +62,6 @@ void loop()
|
||||
}
|
||||
}
|
||||
|
||||
// END OF FILE
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,18 +1,14 @@
|
||||
//
|
||||
// FILE: max44009_setContinuousMode.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo of max44009 library
|
||||
// DATE: 2020-01-30
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
// note that lux values are repeated a number of times
|
||||
// if read faster than the integration time.
|
||||
// So it makes no sense to call getLux() more than once
|
||||
// per integration time.
|
||||
// NB the getLux() call takes a bit more than 1 millisecond
|
||||
// note that lux values are repeated a number of times
|
||||
// if read faster than the integration time.
|
||||
// So it makes no sense to call getLux() more than once
|
||||
// per integration time.
|
||||
// NB the getLux() call takes a bit more than 1 millisecond
|
||||
|
||||
|
||||
#include "Wire.h"
|
||||
@ -73,3 +69,4 @@ void loop()
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,13 +1,8 @@
|
||||
//
|
||||
// FILE: max44009_setManualMode.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: demo of max44009 library
|
||||
// DATE: 2020-01-30
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
|
||||
#include "Wire.h"
|
||||
#include "Max44009.h"
|
||||
@ -74,4 +69,5 @@ void loop()
|
||||
}
|
||||
|
||||
|
||||
// END OF FILE
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,12 +1,8 @@
|
||||
//
|
||||
// FILE: max44009_test01.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.2
|
||||
// PURPOSE: demo of max44009 library
|
||||
// DATE: 2015-08-06
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
|
||||
#include "Wire.h"
|
||||
@ -51,4 +47,4 @@ void loop()
|
||||
}
|
||||
|
||||
|
||||
// END OF FILE
|
||||
// -- END OF FILE --
|
||||
|
@ -1,16 +1,15 @@
|
||||
//
|
||||
// FILE: max44009_test02.ino
|
||||
// AUTHOR: Moritz Ulmer
|
||||
// VERSION: 0.3.1
|
||||
// PURPOSE: demo of max44009 library
|
||||
// DATE: 2020-01-19
|
||||
//
|
||||
// NOTE: To select the alternative I2C address on the GY-49 breakout board,
|
||||
// the A0 pin has to be set to 3V3. It is soldered to GND by default.
|
||||
// See switch S1 / jp1 in the schematics.
|
||||
// Made for ESP specific; does not work on UNO;
|
||||
// DATE: 2020-01-19
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
#include "Wire.h"
|
||||
@ -53,4 +52,5 @@ void loop() {
|
||||
}
|
||||
|
||||
|
||||
// END OF FILE
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,12 +1,8 @@
|
||||
//
|
||||
// FILE: max44009_two_sensors.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo of max44009 library
|
||||
// DATE: 2020-02-16
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
|
||||
#include "Wire.h"
|
||||
@ -64,3 +60,4 @@ void loop()
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Syntax Coloring Map For Max44009
|
||||
# Syntax Colouring Map For Max44009
|
||||
|
||||
# Datatypes (KEYWORD1)
|
||||
# Data types (KEYWORD1)
|
||||
Max44009 KEYWORD1
|
||||
|
||||
|
||||
|
@ -15,8 +15,9 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Max44009.git"
|
||||
},
|
||||
"version": "0.5.0",
|
||||
"version": "0.5.1",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
"platforms": "*",
|
||||
"headers": "Max44009.h"
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=Max44009
|
||||
version=0.5.0
|
||||
version=0.5.1
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library for MAX44009 I2C LUX sensor Arduino.
|
||||
|
@ -1,12 +1,13 @@
|
||||
//
|
||||
// FILE: Max44009.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.5.0
|
||||
// VERSION: 0.5.1
|
||||
// PURPOSE: library for MAX44009 lux sensor Arduino
|
||||
// URL: https://github.com/RobTillaart/MAX44009
|
||||
//
|
||||
// HISTORY
|
||||
//
|
||||
// 0.5.1 2021-12-21 update library.json, license, minor edits
|
||||
// 0.5.0 2021-06-04 fix exponent math.
|
||||
// 0.4.4 2021-05-27 arduino-lint
|
||||
// 0.4.3 2020-12-30 arduino-ci, unit test
|
||||
|
@ -1,14 +1,18 @@
|
||||
|
||||
[![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)
|
||||
[![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)
|
||||
|
||||
|
||||
# MAX44009 I2C LUX sensor
|
||||
|
||||
Library for MAX44009 / GY-49 I2C lux sensor
|
||||
Library for MAX44009 / GY-49 I2C lux sensor.
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
a.k.a. GY-49
|
||||
|
||||
The MAX44009 ambient light sensor is an I2C sensor, that has a 22 bit
|
||||
@ -43,15 +47,15 @@ dynamic range from 0.045 lux to 188,000 lux.
|
||||
|
||||
## Interface
|
||||
|
||||
- **enum class Boolean { True, False }** enum class to prevent bool to be implicitly casted to int
|
||||
- **enum class Boolean { True, False }** enum class to prevent bool to be implicitly casted to int.
|
||||
|
||||
|
||||
### Constructor
|
||||
|
||||
- **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(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(address, TwoWire \*wire, begin = Boolean::True)** Change I2C interface and address.
|
||||
- **void configure(uint8_t 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.
|
||||
|
||||
|
||||
@ -74,11 +78,16 @@ dynamic range from 0.045 lux to 188,000 lux.
|
||||
|
||||
check datasheet for details
|
||||
|
||||
- **bool setHighThreshold(float)** 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(void)** returns the value set.
|
||||
- **bool setLowThreshold(float)** 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(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.
|
||||
- **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()**.
|
||||
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,
|
||||
defined in steps of 100ms. 2 seems to be a practical minimum.
|
||||
- **uint8_t getThresholdTimer()** returns the value set.
|
||||
|
||||
|
||||
@ -96,7 +105,8 @@ check datasheet for details
|
||||
|
||||
check datasheet for details
|
||||
|
||||
- **void setConfiguration(uint8_t)** writes directly to configuration register. **warning** Use with care.
|
||||
- **void setConfiguration(uint8_t)** writes directly to configuration register.
|
||||
**warning** Use with care.
|
||||
- **uint8_t getConfiguration()** reads the current configuration register.
|
||||
|
||||
|
||||
@ -108,10 +118,13 @@ 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 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.
|
||||
- **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
|
||||
|
||||
```
|
||||
@ -135,7 +148,8 @@ TIM = Integration time.
|
||||
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
|
||||
@ -157,3 +171,10 @@ 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 ;)
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
- improve documentation
|
||||
-
|
||||
|
||||
|
@ -38,6 +38,7 @@
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "MAX44009_LIB_VERSION: %s\n", (char *) MAX44009_LIB_VERSION);
|
||||
}
|
||||
|
||||
|
||||
@ -46,10 +47,35 @@ unittest_teardown()
|
||||
}
|
||||
|
||||
|
||||
unittest(test_constants)
|
||||
{
|
||||
assertEqual(MAX44009_DEFAULT_ADDRESS, 0x4A);
|
||||
assertEqual(MAX44009_ALT_ADDRESS , 0x4B);
|
||||
|
||||
assertEqual(MAX44009_INTERRUPT_STATUS , 0x00);
|
||||
assertEqual(MAX44009_INTERRUPT_ENABLE , 0x01);
|
||||
assertEqual(MAX44009_CONFIGURATION , 0x02);
|
||||
assertEqual(MAX44009_LUX_READING_HIGH , 0x03);
|
||||
assertEqual(MAX44009_LUX_READING_LOW , 0x04);
|
||||
assertEqual(MAX44009_THRESHOLD_HIGH , 0x05);
|
||||
assertEqual(MAX44009_THRESHOLD_LOW , 0x06);
|
||||
assertEqual(MAX44009_THRESHOLD_TIMER , 0x07);
|
||||
|
||||
assertEqual(MAX44009_CFG_CONTINUOUS , 0x80);
|
||||
assertEqual(MAX44009_CFG_MANUAL , 0x40);
|
||||
assertEqual(MAX44009_CFG_CDR , 0x08);
|
||||
assertEqual(MAX44009_CFG_TIMER , 0x07);
|
||||
|
||||
assertEqual(MAX44009_OK , 0 );
|
||||
assertEqual(MAX44009_ERROR_WIRE_REQUEST, -10);
|
||||
assertEqual(MAX44009_ERROR_OVERFLOW , -20);
|
||||
assertEqual(MAX44009_ERROR_HIGH_BYTE , -30);
|
||||
assertEqual(MAX44009_ERROR_LOW_BYTE , -31);
|
||||
}
|
||||
|
||||
|
||||
unittest(test_constructor)
|
||||
{
|
||||
fprintf(stderr, "VERSION: %s\n", MAX44009_LIB_VERSION);
|
||||
|
||||
Max44009 LuxA(0x4A);
|
||||
Wire.begin();
|
||||
|
||||
@ -62,8 +88,6 @@ unittest(test_constructor)
|
||||
|
||||
unittest(test_convertToLux)
|
||||
{
|
||||
fprintf(stderr, "VERSION: %s\n", MAX44009_LIB_VERSION);
|
||||
|
||||
Max44009 LuxA(0x4A);
|
||||
|
||||
assertEqualFloat(0.000, LuxA.convertToLux(0x00, 0x00), 0.0001);
|
||||
|
Loading…
Reference in New Issue
Block a user