mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
update libraries A-D
This commit is contained in:
parent
2b97b8d4be
commit
a19ec7f025
@ -1,13 +1,15 @@
|
||||
# Arduino libraries
|
||||
|
||||
**NOTE** these libraries will all get their own repo, so this repository
|
||||
does not have the latest version of all libs anymore. That said I will update
|
||||
this bulk repo on request or if time permit.
|
||||
|
||||
|
||||
### Introduction
|
||||
This repository contains several Arduino libraries I have written to be used in applications.
|
||||
Most of them include example code how the libraries can be used.
|
||||
Furthermore this repository contains a few stand alone applications.
|
||||
|
||||
**NOTE** these libraries will all get their own repo, so this repository
|
||||
does not have the latest version of all libs anymore. That said I will update
|
||||
this bulk repo on request or if time permit.
|
||||
|
||||
### Questions
|
||||
For questions about the usage of the libraries, please post a question on the Arduino
|
||||
|
@ -1,16 +1,17 @@
|
||||
//
|
||||
// FILE: ACS712.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// DATE: 2020-03-17
|
||||
// AUTHOR: Rob Tillaart, Pete Thompson
|
||||
// VERSION: 0.2.0
|
||||
// DATE: 2020-08-02
|
||||
// PURPOSE: ACS712 library - current measurement
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.0 2020-03-17 initial version
|
||||
// 0.1.1 2020-03-18 first release version
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
// 0.1.2 2020-03-21 automatic formfactor test
|
||||
// 0.1.3 2020-05-27 fix library.json
|
||||
// 0.1.4 2020-08-02 Allow for faster processors
|
||||
// 0.2.0 2020-08-02 Add autoMidPoint
|
||||
|
||||
#include "ACS712.h"
|
||||
|
||||
@ -22,26 +23,43 @@ ACS712::ACS712(uint8_t analogPin, float volts, uint16_t maxADC, uint8_t mVperA)
|
||||
_mVperAmpere = mVperA;
|
||||
_formFactor = 0.70710678119; // 0.5 * sqrt(2); TODO: should be smaller in practice 0.5 ?
|
||||
_midPoint = maxADC / 2;
|
||||
_noisemV = 21; // Noise is 21mV according to datasheet
|
||||
}
|
||||
|
||||
int ACS712::mA_AC()
|
||||
int ACS712::mA_AC(uint8_t freq)
|
||||
{
|
||||
uint32_t start = micros();
|
||||
uint16_t period = ((freq == 60) ? 16670 : 20000);
|
||||
uint16_t samples = 0;
|
||||
uint16_t zeros = 0;
|
||||
int _min, _max;
|
||||
_min = _max = analogRead(_pin);
|
||||
while (micros() - start < 20000) // UNO ~180 samples...
|
||||
while (micros() - start < period) // UNO ~180 samples...
|
||||
{
|
||||
samples++;
|
||||
int val = analogRead(_pin);
|
||||
if (val < _min) _min = val;
|
||||
if (val > _max) _max = val;
|
||||
if (abs(val - _midPoint) <= (_noisemV/_mVpstep)) zeros++;
|
||||
}
|
||||
int p2p = (_max - _min);
|
||||
// TODO determine _formFactor
|
||||
// two counters, a threshold and math is needed
|
||||
// D = (1.0 - #samples close to zero ) / #samples
|
||||
// FF = D * 0.5 * sqrt(2);
|
||||
|
||||
// math could be partially precalculated
|
||||
|
||||
// automatic determine _formFactor / crest factor
|
||||
float D = 0;
|
||||
float FF = 0;
|
||||
if (zeros > samples * 0.025)
|
||||
{
|
||||
D = 1.0 - (1.0 * zeros) / samples; // % SAMPLES NONE ZERO
|
||||
FF = sqrt(D) * 0.5 * sqrt(2); // ASSUME NON ZERO PART ~ SINUS
|
||||
}
|
||||
else // # zeros is small => D --> 1 --> sqrt(D) --> 1
|
||||
{
|
||||
FF = 0.5 * sqrt(2);
|
||||
}
|
||||
_formFactor = FF;
|
||||
|
||||
// math could be partially precalculated: C = 1000.0 * 0.5 * _mVpstep / _mVperAmpere;
|
||||
// rounding?
|
||||
return 1000.0 * 0.5 * p2p * _mVpstep * _formFactor / _mVperAmpere;
|
||||
}
|
||||
|
||||
@ -53,4 +71,22 @@ int ACS712::mA_DC()
|
||||
return 1000.0 * steps * _mVpstep / _mVperAmpere;
|
||||
}
|
||||
|
||||
// configure by sampling for 2 cycles of AC
|
||||
// Also works for DC as long as no current flowing
|
||||
void ACS712::autoMidPoint(uint8_t freq)
|
||||
{
|
||||
uint32_t start = micros();
|
||||
uint16_t twoPeriods = ((freq == 60) ? 16670 : 20000) * 2;
|
||||
uint32_t total = 0;
|
||||
uint32_t samples = 0;
|
||||
while (micros() - start < twoPeriods) {
|
||||
uint16_t reading = analogRead(_pin);
|
||||
total += reading;
|
||||
samples ++;
|
||||
// Delaying ensures we won't overflow since we'll perform a maximum of 40,000 reads
|
||||
delayMicroseconds(1);
|
||||
}
|
||||
_midPoint = total / samples;
|
||||
}
|
||||
|
||||
// END OF FILE
|
||||
|
@ -2,18 +2,16 @@
|
||||
//
|
||||
// FILE: ACS712.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// DATE: 2020-03-17
|
||||
// VERSION: 0.2.0
|
||||
// DATE: 2020-08-02
|
||||
// PURPOSE: ACS712 library - current measurement
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
// Tested with a RobotDyn ACS712 20A breakout + UNO.
|
||||
//
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define ACS712_LIB_VERSION "0.1.1"
|
||||
#define ACS712_LIB_VERSION "0.1.3"
|
||||
|
||||
|
||||
class ACS712
|
||||
@ -31,8 +29,8 @@ class ACS712
|
||||
ACS712(uint8_t analogPin, float volts = 5.0, uint16_t maxADC = 1023, uint8_t mVperA = 100);
|
||||
|
||||
// returns mA
|
||||
// blocks 20-21 ms to sample a whole 50 or 60 Hz period. // TODO HZ as param ??
|
||||
int mA_AC();
|
||||
// blocks 20-21 ms to sample a whole 50 or 60 Hz period.
|
||||
int mA_AC(uint8_t freq = 50);
|
||||
|
||||
// returns mA
|
||||
// blocks < 1 ms
|
||||
@ -43,11 +41,17 @@ class ACS712
|
||||
inline uint16_t getMidPoint() { return _midPoint; };
|
||||
inline void incMidPoint() { _midPoint++; };
|
||||
inline void decMidPoint() { _midPoint--; };
|
||||
// Auto midPoint, assuming zero DC current or any AC current
|
||||
void autoMidPoint(uint8_t freq = 50);
|
||||
|
||||
// also known as crest factor; affects AC only
|
||||
inline void setFormFactor(float ff) { _formFactor = ff; };
|
||||
inline float getFormFactor() { return _formFactor; };
|
||||
|
||||
// noise
|
||||
inline void setNoisemV(uint8_t noisemV) { _noisemV = noisemV; };
|
||||
inline uint8_t getNoisemV() { return _noisemV; };
|
||||
|
||||
// AC and DC
|
||||
inline void setmVperAmp(uint8_t mva) { _mVperAmpere = mva; };
|
||||
inline uint8_t getmVperAmp() { return _mVperAmpere; };
|
||||
@ -58,6 +62,7 @@ class ACS712
|
||||
float _formFactor; // P2P -> RMS
|
||||
uint8_t _mVperAmpere;
|
||||
uint16_t _midPoint;
|
||||
uint8_t _noisemV;
|
||||
};
|
||||
|
||||
// END OF FILE
|
||||
|
21
libraries/ACS712/LICENSE
Normal file
21
libraries/ACS712/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 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
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -15,17 +15,28 @@
|
||||
// ACS712 30A uses 66 mV per A
|
||||
|
||||
ACS712 ACS(A0, 5.0, 1023, 100);
|
||||
// ESP 32 example (requires resistors to step down the logic voltage)
|
||||
//ACS712 ACS(25, 5.0, 4095, 185);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
|
||||
ACS.autoMidPoint();
|
||||
Serial.print("MidPoint: ");
|
||||
Serial.print(ACS.getMidPoint());
|
||||
Serial.print(". Noise mV: ");
|
||||
Serial.println(ACS.getNoisemV());
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int mA = ACS.mA_AC();
|
||||
Serial.println(mA);
|
||||
Serial.print("mA: ");
|
||||
Serial.print(mA);
|
||||
Serial.print(". Form factor: ");
|
||||
Serial.println(ACS.getFormFactor());
|
||||
}
|
||||
|
||||
// END OF FILE
|
||||
|
@ -15,11 +15,14 @@
|
||||
// ACS712 30A uses 66 mV per A
|
||||
|
||||
ACS712 ACS(A0, 5.0, 1023, 100);
|
||||
// ESP 32 example (requires resistors to step down the logic voltage)
|
||||
//ACS712 ACS(25, 5.0, 4095, 185);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
ACS.autoMidPoint();
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
@ -15,11 +15,14 @@
|
||||
// ACS712 30A uses 66 mV per A
|
||||
|
||||
ACS712 ACS(A0, 5.0, 1023, 100);
|
||||
// ESP 32 example (requires resistors to step down the logic voltage)
|
||||
//ACS712 ACS(25, 5.0, 4095, 185);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
ACS.autoMidPoint();
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
@ -15,11 +15,14 @@
|
||||
// ACS712 30A uses 66 mV per A
|
||||
|
||||
ACS712 ACS(A0, 5.0, 1023, 100);
|
||||
// ESP 32 example (requires resistors to step down the logic voltage)
|
||||
//ACS712 ACS(25, 5.0, 4095, 185);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
ACS.autoMidPoint();
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
@ -8,17 +8,20 @@
|
||||
"name": "Rob Tillaart",
|
||||
"email": "Rob.Tillaart@gmail.com",
|
||||
"maintainer": true
|
||||
},
|
||||
{
|
||||
"name": "Pete Thompson",
|
||||
"email": "pete.thompson@yahoo.com",
|
||||
"maintainer": false
|
||||
}
|
||||
|
||||
],
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Arduino.git"
|
||||
"url": "https://github.com/RobTillaart/ACS712"
|
||||
},
|
||||
"version":"0.1.1",
|
||||
"version":"0.2.0",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"export": {
|
||||
"include": "libraries/ACS712"
|
||||
}
|
||||
"platforms": "*"
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
name=ACS712
|
||||
version=0.1.1
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
version=0.2.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>, Pete Thompson <pete.thompson@yahoo.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=ACS712 library for Arduino.
|
||||
sentence=ACS712 library for Arduino.
|
||||
paragraph=Current measurement, tested with RobotDyn ACDC 20A Module.
|
||||
category=Signal Input/Output
|
||||
url=https://github.com/RobTillaart/Arduino.git
|
||||
architectures=*
|
||||
url=https://github.com/RobTillaart/ACS712
|
||||
architectures=*
|
||||
includes=ACS712.h
|
||||
depends=
|
||||
|
@ -1,57 +1,43 @@
|
||||
# ACS712
|
||||
|
||||
# ACS712 Library
|
||||
Current Sensor - 5A, 20A, 30A
|
||||
|
||||
## Description
|
||||
|
||||
The ACS712 is a chip to measure current, both AC or DC. The chip has an
|
||||
analog output that provides a voltage that is lineair with the current.
|
||||
The ACS712 is a chip to measure current, both AC or DC. The chip has an
|
||||
analog output that provides a voltage that is lineair with the current.
|
||||
The ACS712 library supports only a built in ADC by means of analogRead().
|
||||
There are 2 core functions:
|
||||
|
||||
* int mA_DC()
|
||||
* int mA_AC()
|
||||
* **int mA_DC()**
|
||||
* **int mA_AC()**
|
||||
|
||||
To measure DC current a single analogRead() with some conversion math is sufficient to get
|
||||
To measure DC current a single analogRead() with some conversion math is sufficient to get
|
||||
a value. To stabilize the signal analogRead() is called twice.
|
||||
|
||||
To measure AC current **a blocking loop for 20 millis** is run to determine the
|
||||
peak to peak value which is converted to the RMS value. To convert the peak2peak
|
||||
value to RMS one need the so called crest or form factor. This factor depends heavily
|
||||
To measure AC current **a blocking loop for 20 millis** is run to determine the
|
||||
peak to peak value which is converted to the RMS value. To convert the peak2peak
|
||||
value to RMS one need the so called crest or form factor. This factor depends heavily
|
||||
on the signal form. For a perfect sinus the value is sqrt(2)/2.
|
||||
|
||||
## Test
|
||||
|
||||
The library is tested with the RobotDyn ACS712 20A breakout and an Arduino UNO.
|
||||
|
||||
|
||||
## Operation
|
||||
|
||||
With the constructor the parameters volts and maxADC (steps) of the ADC are set
|
||||
together with the milliVolt per Ampere value. The last parameter can be adjusted
|
||||
afterwards, e.g. to callibrate its value runtime. This parameter affects both
|
||||
With the constructor the parameters **volts** and **maxADC (steps)** of the ADC are set
|
||||
together with the **milliVolt per Ampere** value. The last parameter can be adjusted
|
||||
afterwards, e.g. to callibrate this value runtime. Note this parameter affects both
|
||||
AC and DC measurements.
|
||||
|
||||
To callibrate the zero level for DC measurements, 4 functions are available to
|
||||
To callibrate the zero level for DC measurements, 5 functions are available to
|
||||
adjust the midPoint.
|
||||
|
||||
To callibrate the RMS value for AC measurements, 2 functions are available to
|
||||
To callibrate the RMS value for AC measurements, 2 functions are available to
|
||||
get and set the formFactor.
|
||||
|
||||
To callibrate the noise level (used for AC measurements), 2 functions are available to
|
||||
get and set the noise in mV.
|
||||
|
||||
The examples show the basic working of the functions.
|
||||
|
||||
## Todo
|
||||
|
||||
* Test more.
|
||||
* Determine the crest factor automatically
|
||||
* ...
|
||||
|
||||
## Credits
|
||||
|
||||
-
|
||||
|
||||
## License
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
|
@ -1,12 +1,10 @@
|
||||
//
|
||||
// FILE: AD524X.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: see AD524X.h file
|
||||
// VERSION: 0.2.1
|
||||
// PURPOSE: I2C digital potentiometer AD5241 AD5242
|
||||
// DATE: 2013-10-12
|
||||
// URL:
|
||||
//
|
||||
// Released to the public domain
|
||||
// URL: https://github.com/RobTillaart/AD524X
|
||||
//
|
||||
|
||||
#include "AD524X.h"
|
||||
@ -123,4 +121,4 @@ uint8_t AD524X::send(const uint8_t cmd, const uint8_t value)
|
||||
return Wire.endTransmission();
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
@ -1,26 +1,17 @@
|
||||
#pragma once
|
||||
//
|
||||
// FILE: AD524X.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.03
|
||||
// VERSION: 0.2.1
|
||||
// PURPOSE: I2C digital PotentioMeter AD5241 AD5242
|
||||
// DATE: 2013-10-12
|
||||
// URL:
|
||||
//
|
||||
// Released to the public domain
|
||||
// URL: https://github.com/RobTillaart/AD524X
|
||||
//
|
||||
|
||||
#ifndef AD524X_h
|
||||
#define AD524X_h
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
#include "Wire.h"
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
#define AD524X_VERSION "0.1.03"
|
||||
#define AD524X_VERSION "0.2.1"
|
||||
|
||||
#define AS524X_OK 0
|
||||
#define AS524X_ERROR 100
|
||||
@ -61,6 +52,4 @@ private:
|
||||
uint8_t _O2;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "AD524X",
|
||||
"keywords": "I2C,digital,PotentioMeter,AD5241,AD5242",
|
||||
"description": "The library controls digital PotentioMeter AD5241 AD5242",
|
||||
"description": "Library to control digital potentiometer AD5241 AD5242",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
@ -13,12 +13,9 @@
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Arduino.git"
|
||||
"url": "https://github.com/RobTillaart/AD524X"
|
||||
},
|
||||
"version":"0.1.3",
|
||||
"version":"0.2.1",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"export": {
|
||||
"include": "libraries/AD524X"
|
||||
}
|
||||
"platforms": "*"
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
name=AD524X
|
||||
version=0.1.3
|
||||
version=0.2.1
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino Library for AD524X
|
||||
paragraph=The library controls digital PotentioMeter AD5241 AD5242
|
||||
paragraph=Library to control digital potentiometer AD5241 AD5242
|
||||
category=Signal Input/Output
|
||||
url=https://github.com/RobTillaart/Arduino/tree/master/libraries/AD524X
|
||||
architectures=*
|
||||
url=https://github.com/RobTillaart/AD524X
|
||||
architectures=*
|
||||
includes=AD524X.h
|
||||
depends=
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: AM232X.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.1
|
||||
// VERSION: 0.2.3
|
||||
// PURPOSE: AM232X library for AM2320 for Arduino.
|
||||
//
|
||||
// HISTORY:
|
||||
@ -15,6 +15,8 @@
|
||||
// 0.1.5 2020-03-25 refactor, add read() to begin()
|
||||
// 0.2.0 2020-05-03 made temperature + humidity private, add wrapper functions.
|
||||
// 0.2.1 2020-05-06 fix temperature function (thanks Chade)
|
||||
// 0.2.2 2020-05-12 added ESP32 support
|
||||
// 0.2.3 2020-05-27 update library.json
|
||||
//
|
||||
|
||||
#include <AM232X.h>
|
||||
@ -25,7 +27,7 @@
|
||||
//
|
||||
// PUBLIC
|
||||
//
|
||||
#ifdef ESP8266
|
||||
#if defined (ESP8266) || defined(ESP32)
|
||||
void AM232X::begin(uint8_t sda, uint8_t scl)
|
||||
{
|
||||
Wire.begin(sda, scl);
|
||||
@ -279,4 +281,4 @@ uint16_t AM232X::crc16(uint8_t *ptr, uint8_t len)
|
||||
return crc;
|
||||
}
|
||||
|
||||
// END OF FILE
|
||||
// -- END OF FILE --
|
||||
|
@ -3,7 +3,7 @@
|
||||
// FILE: AM232X.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: AM232X library for Arduino
|
||||
// VERSION: 0.2.1
|
||||
// VERSION: 0.2.3
|
||||
// HISTORY: See AM232X.cpp
|
||||
// URL: https://github.com/RobTillaart/AM232X
|
||||
//
|
||||
@ -11,7 +11,7 @@
|
||||
#include "Wire.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
#define AM232X_LIB_VERSION "0.2.1"
|
||||
#define AM232X_LIB_VERSION "0.2.3"
|
||||
|
||||
#define AM232X_OK 0
|
||||
#define AM232X_ERROR_UNKNOWN -10
|
||||
@ -36,9 +36,9 @@
|
||||
class AM232X
|
||||
{
|
||||
public:
|
||||
#ifdef ESP8266
|
||||
#if defined (ESP8266) || defined(ESP32)
|
||||
void begin(uint8_t sda, uint8_t scl);
|
||||
#endif
|
||||
#endif
|
||||
void begin();
|
||||
|
||||
int read();
|
||||
@ -68,4 +68,4 @@ private:
|
||||
uint16_t crc16(uint8_t *ptr, uint8_t len);
|
||||
};
|
||||
|
||||
// END OF FILE
|
||||
// -- END OF FILE --
|
||||
|
@ -15,10 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/AM232X"
|
||||
},
|
||||
"version":"0.2.1",
|
||||
"version":"0.2.3",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"export": {
|
||||
"include": "AM232X"
|
||||
}
|
||||
"platforms": "*"
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=AM232X
|
||||
version=0.2.1
|
||||
version=0.2.3
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for AM2320 AM2321 and AM2323 I2C temperature and humidity sensor.
|
||||
|
@ -1,16 +1,16 @@
|
||||
//
|
||||
// FILE: AnalogKeypad.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.2
|
||||
// VERSION: 0.1.4
|
||||
// DATE: 2019-01-31
|
||||
// PURPOSE: Class for analog keypad
|
||||
// PURPOSE: Class for (Robotdyn) 4x4 and 4x3 analog keypad
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.0 - 2019-01-31 initial version
|
||||
// 0.1.1 - 2019-02-01 add pressed() event() last()
|
||||
// 0.1.2 - 2019-02-01 refactored rawRead(), first stable version
|
||||
//
|
||||
// Released to the public domain
|
||||
// 0.1.0 2019-01-31 initial version
|
||||
// 0.1.1 2019-02-01 add pressed() event() last()
|
||||
// 0.1.2 2019-02-01 refactored rawRead(), first stable version
|
||||
// 0.1.3 2020-03-25 minor refactoring
|
||||
// 0.1.4 2020-05-27 update library.json
|
||||
//
|
||||
|
||||
#include "AnalogKeypad.h"
|
||||
@ -23,6 +23,7 @@
|
||||
// build in ADC.
|
||||
//
|
||||
// Arduino UNO3 build in ==> 10 BITS
|
||||
// so AKP_SHIFT ==> 2
|
||||
//
|
||||
#define AKP_BITS 10
|
||||
#define AKP_SHIFT (AKP_BITS - 8)
|
||||
@ -46,7 +47,7 @@ uint8_t AnalogKeypad::event()
|
||||
|
||||
_lastKey = _key;
|
||||
|
||||
return rv; // return rv | _key; ????
|
||||
return rv;
|
||||
}
|
||||
|
||||
uint8_t AnalogKeypad::pressed()
|
||||
@ -90,7 +91,8 @@ uint8_t AnalogKeypad::rawRead()
|
||||
|
||||
// handle NOKEY first
|
||||
if (val < 57) return 0;
|
||||
// reduce average # compares by 2
|
||||
|
||||
// reduce average # compares by 2 (4x4 keypad)
|
||||
if (val < 135)
|
||||
{
|
||||
if (val < 62) return 16;
|
||||
|
@ -1,20 +1,16 @@
|
||||
#pragma once
|
||||
//
|
||||
// FILE: AnalogKeypad.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.2
|
||||
// VERSION: 0.1.4
|
||||
// DATE: 2019-01-31
|
||||
// PURPOSE: Class for analog keypad
|
||||
// URL: https://github.com/RobTillaart/Arduino.git
|
||||
// PURPOSE: Class for (Robotdyn) 4x4 and 4x3 analog keypad
|
||||
// URL: https://github.com/RobTillaart/AnalogKeypad
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
#ifndef AnalogKeypad_h
|
||||
#define AnalogKeypad_h
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define ANALOGKEYPAD_LIB_VERSION "0.1.2"
|
||||
#define ANALOGKEYPAD_LIB_VERSION "0.1.4"
|
||||
|
||||
#define NOKEY 0x00
|
||||
#define PRESSED 0x80
|
||||
@ -48,5 +44,4 @@ private:
|
||||
uint8_t _lastKey;
|
||||
};
|
||||
|
||||
#endif
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
21
libraries/AnalogKeypad/LICENSE
Normal file
21
libraries/AnalogKeypad/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019-2020 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
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
31
libraries/AnalogKeypad/README.md
Normal file
31
libraries/AnalogKeypad/README.md
Normal file
@ -0,0 +1,31 @@
|
||||
# AnalogKeypad
|
||||
|
||||
Library for (Robotdyn) 4x4 and 4x3 analog keypad
|
||||
|
||||
## Description
|
||||
AnalogKeypad is a simple library to read the keys from a (robotdyn) 4x4 or 4x3 keypad.
|
||||
No other keypads are tested, but they should work with this library after adjusting
|
||||
the **MAGIC NUMBERS** in the function **rawRead()**.
|
||||
|
||||
## Operation
|
||||
The simplest usage is to use the **read()** function.
|
||||
This will return a 0 (NOKEY) when no key is pressed and
|
||||
a number 1 to 16 for the keys pressed. Note the return value may
|
||||
fluctuate randomly when multiple keys are pressed.
|
||||
|
||||
The **pressed()** function is a bit more robust.
|
||||
It returns the key pressed first, so multiple key presses simultaniously
|
||||
are less likely to disturbe your program.
|
||||
|
||||
The **event()** function checks if an event has happened.
|
||||
The events are:
|
||||
* PRESSED 0x80
|
||||
* RELEASED 0x40
|
||||
* REPEATED 0x20
|
||||
* CHANGED 0x10
|
||||
|
||||
**key()** can be called to check the last key involved.
|
||||
|
||||
|
||||
|
||||
|
@ -1,24 +1,11 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For AnalogKeypad
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
AnalogKeypad KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
read KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Instances (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "AnalogKeypad",
|
||||
"keywords": "Analog Keypad",
|
||||
"description": "Class for Robotdyn 4x4 analog keypad.",
|
||||
"keywords": "Analog Keypad 4x4 4x3",
|
||||
"description": "Arduino Library for (Robotdyn) 4x4 and 4x3 AnalogKeypad.",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
@ -13,12 +13,9 @@
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Arduino.git"
|
||||
"url": "https://github.com/RobTillaart/AnalogKeypad"
|
||||
},
|
||||
"version":"0.1.2",
|
||||
"version":"0.1.4",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"export": {
|
||||
"include": "libraries/AnalogKeypad"
|
||||
}
|
||||
"platforms": "*"
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
name=AnalogKeypad
|
||||
version=0.1.2
|
||||
version=0.1.4
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino Library for AnalogKeypad
|
||||
paragraph=Class for (Robotdyn) 4x4 and 4x3 AnalogKeypad
|
||||
sentence=Arduino Library for (Robotdyn) 4x4 and 4x3 AnalogKeypad
|
||||
paragraph=Might need tuning per device.
|
||||
category=Signal Input/Output
|
||||
url=https://github.com/RobTillaart/Arduino/tree/master/libraries/AnalogKeypad
|
||||
architectures=*
|
||||
url=https://github.com/RobTillaart/AnalogKeypad
|
||||
architectures=*
|
||||
includes=AnalogKeypad.h
|
||||
depends=
|
@ -1,9 +1,9 @@
|
||||
//
|
||||
// FILE: AnalogPin.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.04
|
||||
// DATE: 2014-10-05
|
||||
// PURPOSE: wrapper class for analogRead
|
||||
// VERSION: 0.2.3
|
||||
// DATE: 2013-09-09
|
||||
// PURPOSE: wrapper for analogRead with smoothing and noise filtering
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.00 - 2013-09-09 initial version
|
||||
@ -11,6 +11,10 @@
|
||||
// 0.1.02 - 2014-10-05 changed signatures datatypes
|
||||
// 0.1.03 - 2014-12-07 some refactor
|
||||
// 0.1.04 - 2015-03-06 refactor smaller footprint
|
||||
// 0.2.00 - 2015-05-14 added prescale support
|
||||
// 0.2.01 - 2015-12-19 breaking interface; big refactor;
|
||||
// 0.2.2 2020-03-25 refactor AVR specific code; bugfix
|
||||
// 0.2.3 2020-05-27 update library.json
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
@ -20,33 +24,53 @@
|
||||
AnalogPin::AnalogPin(const uint8_t pin)
|
||||
{
|
||||
_pin = pin;
|
||||
_prevValue = analogRead(pin);
|
||||
_prescale = 7;
|
||||
_alpha = 0;
|
||||
_noise = 0;
|
||||
rawRead();
|
||||
_prevValue = _value;
|
||||
}
|
||||
|
||||
int AnalogPin::read(const uint8_t noise)
|
||||
int AnalogPin::read(const bool twice)
|
||||
{
|
||||
int value = analogRead(_pin);
|
||||
if (noise == 0 || ((value - _prevValue) & 0x7FFF) > noise)
|
||||
if (twice) rawRead();
|
||||
rawRead();
|
||||
if (_noise == 0 || ((_value - _prevValue) & 0x7FFF) > _noise)
|
||||
{
|
||||
_prevValue = value;
|
||||
_prevValue = _value;
|
||||
}
|
||||
return _prevValue;
|
||||
}
|
||||
|
||||
int AnalogPin::readSmoothed(uint8_t alpha)
|
||||
int AnalogPin::readSmoothed()
|
||||
{
|
||||
if (alpha > 31) alpha = 31;
|
||||
int value = analogRead(_pin);
|
||||
if (alpha > 0)
|
||||
rawRead();
|
||||
if (_alpha > 0)
|
||||
{
|
||||
value = value + (alpha * (_prevValue - value)) / 32;
|
||||
_value = _value + (_alpha * (_prevValue - _value)) / 32;
|
||||
}
|
||||
_prevValue = value;
|
||||
return value;
|
||||
_prevValue = _value;
|
||||
return _value;
|
||||
}
|
||||
|
||||
int AnalogPin::readPrevious()
|
||||
void AnalogPin::rawRead()
|
||||
{
|
||||
return _prevValue;
|
||||
#if defined(ARDUINO_ARCH_AVR)
|
||||
// remember old register value
|
||||
uint8_t ADCSRA_TMP = ADCSRA;
|
||||
ADCSRA = (ADCSRA | 0x07) & (0xF8 | _prescale);
|
||||
#elif defined(ARDUINO_ARCH_SAM)
|
||||
#else
|
||||
#endif
|
||||
|
||||
_value = analogRead(_pin);
|
||||
|
||||
#if defined(ARDUINO_ARCH_AVR)
|
||||
// restore register
|
||||
ADCSRA = ADCSRA_TMP;
|
||||
#elif defined(ARDUINO_ARCH_SAM)
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
// -- END OF FILE --
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -1,42 +1,57 @@
|
||||
#pragma once
|
||||
//
|
||||
// FILE: AnalogPin.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.04
|
||||
// DATE: 2014-10-05
|
||||
// PURPOSE: wrapper class for analogRead
|
||||
// URL:
|
||||
//
|
||||
// Released to the public domain
|
||||
// VERSION: 0.2.3
|
||||
// DATE: 2013-09-09
|
||||
// PURPOSE: wrapper for analogRead with smoothing and noise filtering
|
||||
// URL: https://github.com/RobTillaart/AnalogPin
|
||||
//
|
||||
|
||||
#ifndef AnalogPin_h
|
||||
#define AnalogPin_h
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#define ANALOGPIN_LIB_VERSION "0.1.04"
|
||||
#define ANALOGPIN_LIB_VERSION "0.2.3"
|
||||
|
||||
class AnalogPin
|
||||
{
|
||||
public:
|
||||
AnalogPin(const uint8_t);
|
||||
|
||||
// noise 0..255; in practice 0..4
|
||||
int read(uint8_t noise = 0);
|
||||
explicit AnalogPin(const uint8_t pin);
|
||||
|
||||
// prescale = { 2..7 }, imho 2 is bad, 3 is pretty noisy, 4 and 5 are acceptable, 6 and 7 are good. Depends on project!!!
|
||||
// time indication per analogRead for different prescale values on UNO
|
||||
// 2 => 14 uSec 5 => 38 uSec
|
||||
// 3 => 18 uSec 6 => 63 uSec
|
||||
// 4 => 24 uSec 7 => 120 uSec (default/normal)
|
||||
void setPrescaler(const uint8_t prescale = 7) { _prescale = constrain(prescale, 2, 7); };
|
||||
inline uint8_t getPrescaler(void) const { return _prescale; };
|
||||
|
||||
// noise 0..255; in practice only small values are used (0..10).
|
||||
inline void setNoiseThreshold(const uint8_t noise = 0) { _noise = noise; };
|
||||
inline uint8_t getNoiseThreshold(void) const { return _noise; };
|
||||
|
||||
// alpha 0..31;
|
||||
int readSmoothed(uint8_t alpha = 0);
|
||||
void setSmoothWeight(const uint8_t alpha = 0) { _alpha = min(alpha, 31); };
|
||||
inline uint8_t getSmoothWeight(void) const { return _alpha; };
|
||||
|
||||
int readPrevious();
|
||||
// set twice to true to do analogRead twice to reduce noise too
|
||||
int read(const bool twice = false);
|
||||
int readSmoothed();
|
||||
|
||||
// expose internal data as that might be useful.
|
||||
inline int readPrevious(void) const { return _prevValue; }
|
||||
inline int readLast(void) const { return _value; }
|
||||
|
||||
private:
|
||||
|
||||
void rawRead();
|
||||
|
||||
uint8_t _pin;
|
||||
int _prevValue;
|
||||
uint8_t _alpha;
|
||||
uint8_t _noise;
|
||||
uint8_t _prescale;
|
||||
int _value;
|
||||
int _prevValue;
|
||||
};
|
||||
|
||||
#endif
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
21
libraries/AnalogPin/LICENSE
Normal file
21
libraries/AnalogPin/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2014-2020 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
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
54
libraries/AnalogPin/README.md
Normal file
54
libraries/AnalogPin/README.md
Normal file
@ -0,0 +1,54 @@
|
||||
# AnalogPin
|
||||
Arduino library to add functionality on top of analogRead()
|
||||
|
||||
## Description
|
||||
AnalogPin is an Arduino class that adds noise filtering and smoothing
|
||||
to analogRead().
|
||||
Furthermore it can speed up the analogRead() function by tuning the prescaler.
|
||||
This latter is AVR only.
|
||||
|
||||
## Operation
|
||||
|
||||
**readLast()** returns the last read value without reading a new one.
|
||||
|
||||
**get/setPrescaler(prescale)** can be used to speed up analogRead().
|
||||
|
||||
The effect is that both the accuracy and precission are affected.
|
||||
You should verify if this is acceptable for your project.
|
||||
***Works only for AVR based boards***
|
||||
|
||||
|
||||
**get/setNoiseThreshold(noise)** is used to set the noise threshold to be used by
|
||||
the **read()** function.
|
||||
|
||||
**read(twice)** implements an **analogRead()** that supresses small noise fluctuations.
|
||||
The parameter twice is used to force analogRead() to be executed twice to reduce noise
|
||||
from the multiplexing.
|
||||
|
||||
Example: if the previous read has the value 300 and you
|
||||
want to interpret all subsequent readings between 290
|
||||
and 310 as 300 (the same) your code should look like:
|
||||
```
|
||||
AP.setNoiseThreshold(10);
|
||||
AP.read();
|
||||
```
|
||||
|
||||
**get/setSmoothWeight(alpha)** is used to set the weight factor for the **readSmoothed()** function.
|
||||
|
||||
The weight of the previous read is **alpha/32**.
|
||||
A higher alpha will dampen the signal more, a lower alpha
|
||||
will follow the actual signal better.
|
||||
This can be used to suppress noise too.
|
||||
|
||||
```
|
||||
AP.setSmoothWeight(4); // weight = 4/32 = 1/8 = 12.5%
|
||||
AP.readSmoothed();
|
||||
```
|
||||
|
||||
**readSmoothed()** implements an analogRead with a running average build in.
|
||||
|
||||
Two functions that expose information that might sometimes be useful.
|
||||
**readPrevious()** returns the previous value read.
|
||||
|
||||
**readLast()** returns the last value read.
|
||||
|
@ -1,11 +1,9 @@
|
||||
//
|
||||
// FILE: AnalogPin.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.02
|
||||
// VERSION: 0.3.0
|
||||
// PURPOSE: example sketch
|
||||
// URL:
|
||||
//
|
||||
// Released to the public domain
|
||||
// URL: https://github.com/RobTillaart/AnalogPin
|
||||
//
|
||||
|
||||
#include "AnalogPin.h"
|
||||
@ -13,11 +11,75 @@
|
||||
AnalogPin INA(A0);
|
||||
AnalogPin INB(A1);
|
||||
|
||||
uint32_t start, stop;
|
||||
uint32_t val;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.print("example AnalogPin: ");
|
||||
Serial.print("example AnalogPin: ");
|
||||
Serial.println(ANALOGPIN_LIB_VERSION);
|
||||
Serial.println("time in msec");
|
||||
|
||||
INB.setPrescaler(5); // fast sampling
|
||||
|
||||
Serial.println("\nINA.read()");
|
||||
val = 0;
|
||||
start = millis();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
val += INA.read();
|
||||
}
|
||||
stop = millis();
|
||||
Serial.print("TIME:\t ");
|
||||
Serial.println(stop - start);
|
||||
Serial.print("VALUE:\t ");
|
||||
Serial.println(val / 1000);
|
||||
|
||||
|
||||
Serial.println("\nINA.read() noise filtering");
|
||||
val = 0;
|
||||
INA.setNoiseThreshold(10);
|
||||
start = millis();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
val += INA.read();
|
||||
}
|
||||
stop = millis();
|
||||
Serial.print("TIME:\t ");
|
||||
Serial.println(stop - start);
|
||||
Serial.print("VALUE:\t ");
|
||||
Serial.println(val / 1000);
|
||||
|
||||
|
||||
Serial.println("\nINA.readSmoothed() alpha = 16/32");
|
||||
val = 0;
|
||||
INA.setSmoothWeight(16);
|
||||
start = millis();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
val += INA.readSmoothed();
|
||||
}
|
||||
stop = millis();
|
||||
Serial.print("TIME:\t ");
|
||||
Serial.println(stop - start);
|
||||
Serial.print("VALUE:\t ");
|
||||
Serial.println(val / 1000);
|
||||
|
||||
Serial.println("\nINB.read() - prescaler=5");
|
||||
val = 0;
|
||||
start = millis();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
val += INB.read();
|
||||
}
|
||||
stop = millis();
|
||||
Serial.print("TIME:\t ");
|
||||
Serial.println(stop - start);
|
||||
Serial.print("VALUE:\t ");
|
||||
Serial.println(val / 1000);
|
||||
Serial.println();
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
@ -25,16 +87,11 @@ void loop()
|
||||
{
|
||||
Serial.print(INA.read());
|
||||
Serial.print('\t');
|
||||
|
||||
Serial.print(INA.read(10));
|
||||
Serial.print(INA.read());
|
||||
Serial.print('\t');
|
||||
|
||||
Serial.print(INA.readSmoothed(16));
|
||||
Serial.print('\t');
|
||||
|
||||
Serial.print(INA.readPrevious());
|
||||
|
||||
Serial.print(INA.readSmoothed());
|
||||
Serial.println();
|
||||
delay(100);
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -0,0 +1,49 @@
|
||||
//
|
||||
// FILE: AnalogPin_prescaler.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.0
|
||||
// PURPOSE: example sketch
|
||||
// URL: https://github.com/RobTillaart/AnalogPin
|
||||
//
|
||||
|
||||
#include "AnalogPin.h"
|
||||
|
||||
AnalogPin AR(A0);
|
||||
|
||||
uint32_t start, stop;
|
||||
uint32_t val;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.print("\nExample AnalogPin_prescaler, LIB VERSION: ");
|
||||
Serial.println(ANALOGPIN_LIB_VERSION);
|
||||
Serial.println("\ntime in msec for 1000 reads");
|
||||
|
||||
for (int ps = 2; ps < 8; ps++)
|
||||
{
|
||||
Serial.print("\nAR.setPrescaler: ");
|
||||
Serial.println(ps);
|
||||
AR.setPrescaler(ps);
|
||||
|
||||
Serial.println("AR.read()");
|
||||
delay(100);
|
||||
|
||||
val = 0;
|
||||
start = millis();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
val += AR.read();
|
||||
}
|
||||
stop = millis();
|
||||
Serial.print("TIME:\t ");
|
||||
Serial.println(stop - start);
|
||||
Serial.print("VALUE:\t ");
|
||||
Serial.println(val / 1000);
|
||||
}
|
||||
Serial.println("\nDone...");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
@ -13,12 +13,9 @@
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Arduino.git"
|
||||
"url": "https://github.com/RobTillaart/AnalogPin"
|
||||
},
|
||||
"version":"0.1.4",
|
||||
"version":"0.2.3",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"export": {
|
||||
"include": "libraries/AnalogPin"
|
||||
}
|
||||
"platforms": "*"
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
name=AnalogPin
|
||||
version=0.1.4
|
||||
version=0.2.3
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino Library for AnalogPin
|
||||
paragraph=Class for smoothing analogReads
|
||||
category=Signal Input/Output
|
||||
url=https://github.com/RobTillaart/Arduino/tree/master/libraries/AnalogPin
|
||||
architectures=*
|
||||
url=https://github.com/RobTillaart/AnalogPin
|
||||
architectures=*
|
||||
includes=AnalogPin.h
|
||||
depends=
|
||||
|
@ -1,13 +1,14 @@
|
||||
//
|
||||
// FILE: Angle.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.06
|
||||
// VERSION: 0.1.8
|
||||
// PURPOSE: library for Angle math for Arduino
|
||||
// URL: http://forum.arduino.cc/index.php?topic=339402
|
||||
|
||||
// URL: https://github.com/RobTillaart/Angle
|
||||
// http://forum.arduino.cc/index.php?topic=339402
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
// 0.1.8 2020-05-27 update library.json
|
||||
// 0.1.7 2020-03-26 refactor #pragma once
|
||||
// 0.1.06 - fixed bug negative values.
|
||||
// 0.1.05 - added AngleFormat proxy added 03/03/15 by Christoper Andrews.
|
||||
// 0.1.04 - changed thousands in tenthousands, string constructor
|
||||
@ -35,7 +36,7 @@ Angle::Angle(int dd, int mm, int ss, int tt) // todo optimize
|
||||
t = tt;
|
||||
// TODO
|
||||
// normalize();
|
||||
// assume only one param is neg at most...
|
||||
// assume only one (largest) parameter is negative at most...
|
||||
if (d < 0) { d = -d; neg = true; }
|
||||
if (m < 0) { m = -m; neg = true; }
|
||||
if (s < 0) { s = -s; neg = true; }
|
||||
@ -329,4 +330,4 @@ void Angle::normalize() // TOCHECK
|
||||
if (d == 0 && m == 0 && s == 0 && t == 0) neg = false;
|
||||
}
|
||||
|
||||
// --- END OF FILE ---
|
||||
// --- END OF FILE ---
|
||||
|
@ -1,28 +1,19 @@
|
||||
#ifndef ANGLE_H
|
||||
#define ANGLE_H
|
||||
#pragma once
|
||||
//
|
||||
// FILE: Angle.h
|
||||
// AUTHOR: Rob dot Tillaart at gmail dot com
|
||||
// VERSION: 0.1.06
|
||||
// VERSION: 0.1.8
|
||||
// PURPOSE: angle library for Arduino
|
||||
// HISTORY: See angle.cpp
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
// AngleFormat proxy added 03/03/15 by Christoper Andrews.
|
||||
//
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "math.h"
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#include "Printable.h"
|
||||
|
||||
#define ANGLE_LIB_VERSION "0.1.06"
|
||||
#define ANGLE_LIB_VERSION "0.1.8"
|
||||
|
||||
class Angle;
|
||||
|
||||
@ -99,4 +90,5 @@ private:
|
||||
int s; // seconds
|
||||
int t; // tenhousands
|
||||
};
|
||||
#endif
|
||||
|
||||
// -- END OF FILE
|
||||
|
21
libraries/Angle/LICENSE
Normal file
21
libraries/Angle/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2015-2020 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
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
27
libraries/Angle/README.md
Normal file
27
libraries/Angle/README.md
Normal file
@ -0,0 +1,27 @@
|
||||
# Angle
|
||||
|
||||
Arduino library for basic math for Angles in degrees, minute, seconds
|
||||
|
||||
## Description
|
||||
|
||||
Angle is an Arduino class to print, compare and do basic math with angles
|
||||
in degrees, minutes seconds and tenthousands. The class was created to be
|
||||
able to print an angle with minutes and seconds instead of as a floating point
|
||||
or radians.
|
||||
|
||||
To make the library more useful basic math (+ - \* / )
|
||||
and comparisons ( == != < <= > >= )
|
||||
are added to the class.
|
||||
|
||||
## Operation
|
||||
|
||||
There are three constructors
|
||||
* Angle(int dd=0, int mm=0, int ss=0, int tt=0);
|
||||
* Angle(double alpha);
|
||||
* Angle(char * str); // str represents a double as string e.g. "45.31234"
|
||||
|
||||
For other functions and operators check examples for now.
|
||||
|
||||
## Note
|
||||
The library has not been tested extensively and it could still contain
|
||||
bugs. Especially the constructor does not check input so use it carefully.
|
@ -8,17 +8,19 @@
|
||||
"name": "Rob Tillaart",
|
||||
"email": "Rob.Tillaart@gmail.com",
|
||||
"maintainer": true
|
||||
},
|
||||
{
|
||||
"name": "Christopher Andrews",
|
||||
"email": "-",
|
||||
"maintainer": false
|
||||
}
|
||||
],
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Arduino.git"
|
||||
"url": "https://github.com/RobTillaart/Angle.git"
|
||||
},
|
||||
"version":"0.1.6",
|
||||
"version":"0.1.8",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"export": {
|
||||
"include": "libraries/Angle"
|
||||
}
|
||||
"platforms": "*"
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
name=Angle
|
||||
version=0.1.6
|
||||
version=0.1.8
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library to convert between floating point angle to minutes hours representation.
|
||||
paragraph=
|
||||
category=Data Processing
|
||||
url=https://github.com/RobTillaart/Arduino/tree/master/libraries/Angle
|
||||
architectures=*
|
||||
url=https://github.com/RobTillaart/Angle
|
||||
architectures=*
|
||||
includes=Angle.h
|
||||
depends=
|
||||
|
@ -1,23 +1,21 @@
|
||||
//
|
||||
// FILE: AverageAngle.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.2
|
||||
// VERSION: 0.1.4
|
||||
// PURPOSE: class for averaging angles
|
||||
// URL: https://github.com/RobTillaart/Arduino
|
||||
// URL: https://github.com/RobTillaart/AverageAngle
|
||||
//
|
||||
// HISTORY:
|
||||
//
|
||||
// 0.1.0 2017-11-21 initial version
|
||||
// 0.1.1 2017-12-09 fixed negative values of average
|
||||
// 0.1.2 2018-03-30 added getAverageLength, getTotalLength + zero-test
|
||||
// 0.1.3 2020-03-26 #pragma once; removed pre 1.00 support; readme.md
|
||||
// 0.1.4 2020-05-27 update library.json
|
||||
|
||||
#include "AverageAngle.h"
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//
|
||||
// PUBLIC
|
||||
//
|
||||
AverageAngle::AverageAngle(const enum AngleType type)
|
||||
{
|
||||
_type = type;
|
||||
@ -28,7 +26,7 @@ void AverageAngle::add(float alpha, float length)
|
||||
{
|
||||
if (_type == AverageAngle::DEGREES )
|
||||
{
|
||||
alpha *= (PI / 180.0);
|
||||
alpha *= DEG_TO_RAD; // (PI / 180.0);
|
||||
}
|
||||
_sumx += (cos(alpha) * length);
|
||||
_sumy += (sin(alpha) * length);
|
||||
@ -45,10 +43,10 @@ void AverageAngle::reset()
|
||||
float AverageAngle::getAverage()
|
||||
{
|
||||
float angle = atan2(_sumy, _sumx);
|
||||
if (angle < 0) angle += (PI*2);
|
||||
if (angle < 0) angle += TWO_PI; // (PI * 2);
|
||||
if (_type == AverageAngle::DEGREES )
|
||||
{
|
||||
angle *= (180.0 / PI);
|
||||
angle *= RAD_TO_DEG; // (180.0 / PI);
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
@ -65,4 +63,4 @@ float AverageAngle::getAverageLength()
|
||||
return hypot(_sumy, _sumx) / _count;
|
||||
}
|
||||
|
||||
// END OF FILE
|
||||
// -- END OF FILE --
|
||||
|
@ -1,24 +1,16 @@
|
||||
#ifndef AVERAGEANGLE_H
|
||||
#define AVERAGEANGLE_H
|
||||
#pragma once
|
||||
//
|
||||
// FILE: AverageAngle.h
|
||||
// AUTHOR: Rob dot Tillaart at gmail dot com
|
||||
// VERSION: 0.1.2
|
||||
// VERSION: 0.1.4
|
||||
// PURPOSE: class for averaging angles
|
||||
// HISTORY: See AverageAngle.cpp
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "math.h"
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#define AVERAGE_ANGLE_LIB_VERSION "0.1.2"
|
||||
#define AVERAGE_ANGLE_LIB_VERSION "0.1.4"
|
||||
|
||||
class AverageAngle
|
||||
{
|
||||
@ -27,15 +19,15 @@ public:
|
||||
|
||||
AverageAngle(const enum AngleType type = DEGREES);
|
||||
|
||||
void add(float alpha, float length = 1.0);
|
||||
void reset();
|
||||
int count() { return _count; };
|
||||
float getAverage();
|
||||
void add(float alpha, float length = 1.0);
|
||||
void reset();
|
||||
uint32_t count() { return _count; };
|
||||
float getAverage();
|
||||
|
||||
float getTotalLength();
|
||||
float getAverageLength();
|
||||
float getTotalLength();
|
||||
float getAverageLength();
|
||||
|
||||
enum AngleType type() { return _type; };
|
||||
enum AngleType type() { return _type; };
|
||||
|
||||
private:
|
||||
enum AngleType _type;
|
||||
@ -43,4 +35,5 @@ private:
|
||||
float _sumy;
|
||||
uint32_t _count;
|
||||
};
|
||||
#endif
|
||||
|
||||
// -- END OF FILE --
|
||||
|
21
libraries/AverageAngle/LICENSE
Normal file
21
libraries/AverageAngle/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017-2020 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
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
49
libraries/AverageAngle/README.md
Normal file
49
libraries/AverageAngle/README.md
Normal file
@ -0,0 +1,49 @@
|
||||
# AverageAngle
|
||||
Arduino library to calculate correctly the average of multiple angles
|
||||
|
||||
## Description
|
||||
|
||||
AverageAngle is an class to calculate the average of angles.
|
||||
|
||||
This is especially useful when angles are around 0 degrees,
|
||||
e.g. from a compass sensor or the resultant of a track.
|
||||
Example, the average angle of 359 and 1 is 0, not 179 (most of the time)
|
||||
|
||||
Furthermore the AverageAngle can also include the **length (weight)** of the angle
|
||||
as if it is a vector. Default this length is set to 1 so all angles are by default of
|
||||
equal weight.
|
||||
|
||||
Example: The average angle of 359 (len=2) and 1(len=1) is 359.something not zero.
|
||||
|
||||
|
||||
## Operation
|
||||
|
||||
If you want to average 5 compass readings you can just add the angles and
|
||||
do not use the length parameter.
|
||||
```
|
||||
AA.reset();
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
AA.add(compass.readHeading());
|
||||
delay(100); // e.g. compass needs some time
|
||||
}
|
||||
Serial.println(AA.getAverage());
|
||||
```
|
||||
|
||||
|
||||
If you want to average a track, e.g. 5 steps North, 3 steps west etc, you
|
||||
need to include the length of each step.
|
||||
```
|
||||
AA.reset();
|
||||
AA.add(90, 5); // 5 steps north
|
||||
AA.add(180, 3); // 3 steps west
|
||||
Serial.println(AA.getAverage());
|
||||
Serial.println(AA.getTotalLength());
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
285
libraries/AverageAngle/examples/AverageAngle2/AverageAngle2.ino
Normal file
285
libraries/AverageAngle/examples/AverageAngle2/AverageAngle2.ino
Normal file
@ -0,0 +1,285 @@
|
||||
//
|
||||
// FILE: averageAngle.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.0.1
|
||||
// PURPOSE: demonstates the usage of the AverageAngle Class
|
||||
//
|
||||
// HISTORY: 0.1.0 2017-11-21 initial version
|
||||
|
||||
#include "AverageAngle.h"
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
|
||||
test0();
|
||||
test1();
|
||||
test2(1000);
|
||||
test3(1000);
|
||||
test4();
|
||||
test5();
|
||||
test6();
|
||||
test7();
|
||||
test8();
|
||||
test9();
|
||||
test10(1000);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
void test0()
|
||||
{
|
||||
AverageAngle AA(AverageAngle::DEGREES);
|
||||
|
||||
AA.reset();
|
||||
AA.add(10, 10);
|
||||
int cnt = AA.count();
|
||||
float avg = AA.getAverage();
|
||||
float len = AA.getAverageLength();
|
||||
|
||||
Serial.println(__FUNCTION__);
|
||||
Serial.print("COUNT:\t");
|
||||
Serial.println(cnt);
|
||||
Serial.print("AVG:\t");
|
||||
Serial.println(avg, 6);
|
||||
Serial.print("LEN:\t");
|
||||
Serial.println(len, 6);
|
||||
Serial.println("EXPECT:\t10, 10");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void test1()
|
||||
{
|
||||
AverageAngle AA(AverageAngle::DEGREES);
|
||||
|
||||
AA.reset();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
AA.add(i, i);
|
||||
}
|
||||
int cnt = AA.count();
|
||||
float avg = AA.getAverage();
|
||||
float len = AA.getAverageLength();
|
||||
|
||||
Serial.println(__FUNCTION__);
|
||||
Serial.print("COUNT:\t");
|
||||
Serial.println(cnt);
|
||||
Serial.print("AVG:\t");
|
||||
Serial.println(avg, 6);
|
||||
Serial.print("LEN:\t");
|
||||
Serial.println(len, 6);
|
||||
Serial.println("EXPECT:\t6.33, 4.5");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void test2(int count)
|
||||
{
|
||||
AverageAngle AA(AverageAngle::DEGREES);
|
||||
|
||||
AA.reset();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
AA.add(random(180), random(10));
|
||||
}
|
||||
int cnt = AA.count();
|
||||
float avg = AA.getAverage();
|
||||
float len = AA.getAverageLength();
|
||||
|
||||
Serial.println(__FUNCTION__);
|
||||
Serial.print("COUNT:\t");
|
||||
Serial.println(cnt);
|
||||
Serial.print("AVG:\t");
|
||||
Serial.println(avg, 6);
|
||||
Serial.print("LEN:\t");
|
||||
Serial.println(len, 6);
|
||||
Serial.println("EXPECT:\t~90, 2.85");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void test3(int count)
|
||||
{
|
||||
AverageAngle AA(AverageAngle::RADIANS);
|
||||
|
||||
AA.reset();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
AA.add( PI / 180 * random(180), random(10));
|
||||
}
|
||||
int cnt = AA.count();
|
||||
float avg = AA.getAverage();
|
||||
float len = AA.getAverageLength();
|
||||
|
||||
Serial.println(__FUNCTION__);
|
||||
Serial.print("COUNT:\t");
|
||||
Serial.println(cnt);
|
||||
Serial.print("AVG:\t");
|
||||
Serial.println(avg, 6);
|
||||
Serial.print("LEN:\t");
|
||||
Serial.println(len, 6);
|
||||
Serial.println("EXPECT:\t~PI/2, 2.93");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void test4()
|
||||
{
|
||||
AverageAngle AA(AverageAngle::DEGREES);
|
||||
|
||||
AA.reset();
|
||||
|
||||
AA.add(358, 1);
|
||||
AA.add(359, 2);
|
||||
AA.add(0, 3);
|
||||
AA.add(1, 2);
|
||||
AA.add(2, 1);
|
||||
|
||||
int cnt = AA.count();
|
||||
float avg = AA.getAverage();
|
||||
float len = AA.getAverageLength();
|
||||
|
||||
Serial.println(__FUNCTION__);
|
||||
Serial.print("COUNT:\t");
|
||||
Serial.println(cnt);
|
||||
Serial.print("AVG:\t");
|
||||
Serial.println(avg, 6);
|
||||
Serial.print("LEN:\t");
|
||||
Serial.println(len, 6);
|
||||
Serial.println("EXPECT:\t~0, 1.8");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void test5()
|
||||
{
|
||||
AverageAngle AA(AverageAngle::DEGREES);
|
||||
|
||||
AA.reset();
|
||||
|
||||
AA.add(357, 3);
|
||||
AA.add(358, 1);
|
||||
AA.add(359, 5);
|
||||
AA.add(360, 1);
|
||||
AA.add(1, 3);
|
||||
|
||||
int cnt = AA.count();
|
||||
float avg = AA.getAverage();
|
||||
float len = AA.getAverageLength();
|
||||
|
||||
Serial.println(__FUNCTION__);
|
||||
Serial.print("COUNT:\t");
|
||||
Serial.println(cnt);
|
||||
Serial.print("AVG:\t");
|
||||
Serial.println(avg, 6);
|
||||
Serial.print("LEN:\t");
|
||||
Serial.println(len, 6);
|
||||
Serial.println("EXPECT:\t~359, 2.6");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void test6()
|
||||
{
|
||||
AverageAngle AA(AverageAngle::DEGREES);
|
||||
|
||||
AA.reset();
|
||||
|
||||
AA.add(359, 5);
|
||||
AA.add(360, 3);
|
||||
AA.add(361, 2);
|
||||
AA.add(362, 3);
|
||||
AA.add(363, 5);
|
||||
|
||||
int cnt = AA.count();
|
||||
float avg = AA.getAverage();
|
||||
float len = AA.getAverageLength();
|
||||
|
||||
Serial.println(__FUNCTION__);
|
||||
Serial.print("COUNT:\t");
|
||||
Serial.println(cnt);
|
||||
Serial.print("AVG:\t");
|
||||
Serial.println(avg, 6);
|
||||
Serial.print("LEN:\t");
|
||||
Serial.println(len, 6);
|
||||
Serial.println("EXPECT:\t~1, 3.6");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void test7()
|
||||
{
|
||||
AverageAngle AA(AverageAngle::DEGREES);
|
||||
AverageAngle BB(AverageAngle::RADIANS);
|
||||
Serial.println(__FUNCTION__);
|
||||
Serial.print("AA:\t");
|
||||
Serial.println(AA.type());
|
||||
Serial.print("BB:\t");
|
||||
Serial.println(BB.type());
|
||||
Serial.println("EXPECT:\tAA=0 BB=1");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void test8()
|
||||
{
|
||||
AverageAngle AA(AverageAngle::DEGREES);
|
||||
|
||||
AA.reset();
|
||||
int cnt = AA.count();
|
||||
float avg = AA.getAverage();
|
||||
float len = AA.getAverageLength();
|
||||
|
||||
Serial.println(__FUNCTION__);
|
||||
Serial.print("COUNT:\t");
|
||||
Serial.println(cnt);
|
||||
Serial.print("AVG:\t");
|
||||
Serial.println(avg, 6);
|
||||
Serial.print("LEN:\t");
|
||||
Serial.println(len, 6);
|
||||
Serial.println("EXPECT:\t0, 0");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void test9()
|
||||
{
|
||||
AverageAngle AA(AverageAngle::DEGREES);
|
||||
|
||||
AA.reset();
|
||||
AA.add(0);
|
||||
int cnt = AA.count();
|
||||
float avg = AA.getAverage();
|
||||
float len = AA.getAverageLength();
|
||||
|
||||
Serial.println(__FUNCTION__);
|
||||
Serial.print("COUNT:\t");
|
||||
Serial.println(cnt);
|
||||
Serial.print("AVG:\t");
|
||||
Serial.println(avg, 6);
|
||||
Serial.print("AVGLEN:\t");
|
||||
Serial.println(len, 6);
|
||||
Serial.println("EXPECT:\t0, 1");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void test10(int count)
|
||||
{
|
||||
AverageAngle AA(AverageAngle::DEGREES);
|
||||
|
||||
AA.reset();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
AA.add(random(180), random(10));
|
||||
}
|
||||
int cnt = AA.count();
|
||||
float avg = AA.getAverage();
|
||||
float len = AA.getTotalLength();
|
||||
|
||||
Serial.println(__FUNCTION__);
|
||||
Serial.print("COUNT:\t");
|
||||
Serial.println(cnt);
|
||||
Serial.print("AVG:\t");
|
||||
Serial.println(avg, 6);
|
||||
Serial.print("TOTLEN:\t");
|
||||
Serial.println(len, 6);
|
||||
Serial.println("EXPECT:\t90, ~2500-3000");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
// END OF FILE
|
@ -13,12 +13,9 @@
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Arduino.git"
|
||||
"url": "https://github.com/RobTillaart/AverageAngle.git"
|
||||
},
|
||||
"version":"0.1.2",
|
||||
"version":"0.1.4",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"export": {
|
||||
"include": "libraries/AverageAngle"
|
||||
}
|
||||
"platforms": "*"
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
name=AverageAngle
|
||||
version=0.1.2
|
||||
version=0.1.4
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library to average angles
|
||||
sentence=Library to average angles correctly around 0.
|
||||
paragraph=
|
||||
category=Data Processing
|
||||
url=https://github.com/RobTillaart/Arduino/tree/master/libraries/AverageAngle
|
||||
architectures=*
|
||||
url=https://github.com/RobTillaart/AverageAngle
|
||||
architectures=*
|
||||
includes=AverageAngle.h
|
||||
depends=
|
||||
|
21
libraries/AvrHeap/LICENSE
Normal file
21
libraries/AvrHeap/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2015-2020 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
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
12
libraries/AvrHeap/README.md
Normal file
12
libraries/AvrHeap/README.md
Normal file
@ -0,0 +1,12 @@
|
||||
# AVRheap
|
||||
Arduino library to investigate the heap of an avr processor, e.g. UNO (AVR328).
|
||||
|
||||
Note: this is an experimental library, not for beginners.
|
||||
|
||||
## Description
|
||||
This library can analyze runtime the structure of the heap,
|
||||
this is useful for debugging memory allocation.
|
||||
|
||||
## Operation
|
||||
|
||||
See example heapdemo2.ino
|
@ -1,15 +1,17 @@
|
||||
//
|
||||
// FILE: avrheap.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.5
|
||||
// PURPOSE: library for avrheap Arduino
|
||||
// URL: http://forum.arduino.cc/index.php?topic=355660
|
||||
|
||||
// VERSION: 0.2.1
|
||||
// PURPOSE: experimental library for heap Arduino UNO
|
||||
// URL: https://github.com/RobTillaart/avrheap
|
||||
//
|
||||
// REFERENCES
|
||||
// http://forum.arduino.cc/index.php?topic=27536.15
|
||||
// http://forum.arduino.cc/index.php?topic=355660
|
||||
//
|
||||
// Released to the public domain
|
||||
// HISTORY
|
||||
// 0.2.1 2020-05-27 update library.json
|
||||
// 0.2.0 2020-03-27 Removed support for pre 1.0 version
|
||||
// 0.1.5 - fix typo #116 - Thanks to DMNC
|
||||
// 0.1.04 - new methods incl PrintTo support - Thanks to Whandall
|
||||
// !! breaking interface
|
||||
@ -120,6 +122,7 @@ size_t dumpAlloced(Print& p, byte *ptr, bool withDump)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Avrheap::Avrheap()
|
||||
{
|
||||
};
|
||||
@ -244,7 +247,6 @@ size_t Avrheap::heapWalk(Print& pr, bool withDump) const
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
bool Avrheap::inFreeList(uint16_t addr)
|
||||
{
|
||||
for (struct __freelist* p = __flp; p; p = p->next)
|
||||
@ -270,7 +272,4 @@ size_t Avrheap::printTo(Print& p) const
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// --- END OF FILE ---
|
||||
// --- END OF FILE ---
|
||||
|
@ -1,24 +1,20 @@
|
||||
#ifndef AVRHEAP_H
|
||||
#define AVRHEAP_H
|
||||
#pragma once
|
||||
//
|
||||
// FILE: Avrheap.h
|
||||
// AUTHOR: Rob dot Tillaart at gmail dot com
|
||||
// VERSION: 0.1.5
|
||||
// PURPOSE: heap library for Arduino (AVR)
|
||||
// FILE: avrheap.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.1
|
||||
// PURPOSE: experimental library for heap Arduino UNO
|
||||
// HISTORY: See avrheap.cpp
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#if !defined(ARDUINO_ARCH_AVR)
|
||||
#error “Avrheap library only AVR boards, tested only with UNO.”
|
||||
#endif
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Printable.h"
|
||||
|
||||
#define AVRHEAP_LIB_VERSION "0.1.5"
|
||||
#define AVRHEAP_LIB_VERSION "0.2.1"
|
||||
|
||||
class Avrheap : public Printable
|
||||
{
|
||||
@ -49,4 +45,4 @@ size_t dumpR(Print& p, byte* adr, int len);
|
||||
size_t dumpAlloced(Print& p, byte *ptr, bool withDump = true);
|
||||
size_t dumpAlloced(byte *ptr, bool withDump = true);
|
||||
|
||||
#endif
|
||||
// -- END OF FILE --
|
||||
|
91
libraries/AvrHeap/examples/heapdemo/heapdemo.ino
Normal file
91
libraries/AvrHeap/examples/heapdemo/heapdemo.ino
Normal file
@ -0,0 +1,91 @@
|
||||
//
|
||||
// FILE: heapdemo.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.00
|
||||
// PURPOSE: heapdemo
|
||||
// DATE: 2015-10-25
|
||||
// URL:
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
#include "avrheap.h"
|
||||
|
||||
Avrheap myheap;
|
||||
|
||||
int *par[10];
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.print("Start ");
|
||||
Serial.println(__FILE__);
|
||||
Serial.println(AVRHEAP_LIB_VERSION);
|
||||
|
||||
Serial.println();
|
||||
Serial.print("HEAP ADDR:\t");
|
||||
Serial.println(myheap.startAddress());
|
||||
Serial.println();
|
||||
|
||||
// allocate 10 chunks
|
||||
Serial.println("ptr\taddr");
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
par[i] = (int*) malloc(i * 3); // all different sizes
|
||||
*par[i] = 0;
|
||||
Serial.print(i);
|
||||
Serial.print('\t');
|
||||
Serial.println((int)par[i], DEC);
|
||||
}
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
myheap.dump(80);
|
||||
Serial.println("\nfollowHeap");
|
||||
myheap.followHeap();
|
||||
|
||||
|
||||
Serial.print("fragmented: ");
|
||||
Serial.println(myheap.isFragmented() ? "True" : "False");
|
||||
Serial.print("count: ");
|
||||
Serial.println(myheap.freeListCount());
|
||||
Serial.print("size: ");
|
||||
Serial.println(myheap.freeListSize());
|
||||
Serial.println("dump: ");
|
||||
myheap.freeListDump();
|
||||
|
||||
Serial.println("free 3 pointers");
|
||||
free(par[3]);
|
||||
free(par[5]);
|
||||
free(par[7]);
|
||||
|
||||
Serial.print("fragmented: ");
|
||||
Serial.println(myheap.isFragmented() ? "True" : "False");
|
||||
Serial.print("count: ");
|
||||
Serial.println(myheap.freeListCount());
|
||||
Serial.print("size: ");
|
||||
Serial.println(myheap.freeListSize());
|
||||
Serial.println("dump: ");
|
||||
myheap.freeListDump();
|
||||
|
||||
Serial.println("1 malloc");
|
||||
par[3] = (int*) malloc(10);
|
||||
|
||||
Serial.print("fragmented:\t");
|
||||
Serial.println(myheap.isFragmented() ? "True" : "False");
|
||||
Serial.print("count:\t");
|
||||
Serial.println(myheap.freeListCount());
|
||||
Serial.print("size:\t");
|
||||
Serial.println(myheap.freeListSize());
|
||||
Serial.println("dump: ");
|
||||
myheap.freeListDump();
|
||||
|
||||
Serial.println();
|
||||
myheap.dump(80);
|
||||
Serial.println("\nfollowHeap");
|
||||
myheap.followHeap();
|
||||
Serial.println("\ndone");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{}
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: heapdemo2.ino
|
||||
// AUTHOR: Rob Tillaart (
|
||||
// VERSION: 0.1.00
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo AvrHeap class
|
||||
// DATE: 2015-10-25
|
||||
// URL: http://forum.arduino.cc/index.php?topic=355660
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "Avrheap",
|
||||
"keywords": "heap,dump,walk,free,list,debug,analyze",
|
||||
"description": "Library to runtime analyze the structure of the heap (AVR328).",
|
||||
"description": "Library to runtime analyze the structure of the heap (AVR328).\n Note:not a beginners library",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
@ -13,12 +13,9 @@
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Arduino.git"
|
||||
"url": "https://github.com/RobTillaart/avrheap.git"
|
||||
},
|
||||
"version":"0.1.5",
|
||||
"version":"0.2.1",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "atmelavr",
|
||||
"export": {
|
||||
"include": "libraries/Avrheap"
|
||||
}
|
||||
"platforms": "avr"
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
name=AvrHeap
|
||||
version=0.1.5
|
||||
version=0.2.1
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library to runtime analyze the structure of the heap (AVR328).
|
||||
paragraph=
|
||||
paragraph=not a beginners library
|
||||
category=Other
|
||||
url=https://github.com/RobTillaart/Arduino/tree/master/libraries/
|
||||
architectures=avr
|
||||
url=https://github.com/RobTillaart/avrheap
|
||||
architectures=avr
|
||||
includes=avrheap.h
|
||||
depends=
|
||||
|
@ -1,95 +1,233 @@
|
||||
//
|
||||
// FILE: BH1750FVI.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// VERSION: 0.2.4
|
||||
// PURPOSE: library for BH1750FVI lux sensor Arduino
|
||||
// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries
|
||||
// URL: https://github.com/RobTillaart/BH1750FVI
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
// 0.1.0 2020-02-02 - initial version
|
||||
// 0.1.0 2020-02-02 initial version
|
||||
// 0.1.1 2020-03-28 refactor
|
||||
// 0.1.2 2020-03-29 unique name in repo, and new release tag.
|
||||
// 0.1.3 2020-06-05 fix library.json file
|
||||
// 0.1.4 2020-08-14 cleanup tabs/spaces;
|
||||
// 0.2.0 2020-08-18 implement logic for LOW & HIGH2;
|
||||
// implement correctionfactor; examples;
|
||||
// 0.2.1 2020-08-31 implement angle factor
|
||||
// 0.2.2 2020-09-04 implement temperature compensation
|
||||
// 0.2.3 2020-09-04 implement wavelength compensation
|
||||
// 0.2.4 2020-11-27 fix #10 rename _sensitivityFactor for ESP32
|
||||
|
||||
#include "BH1750FVI.h"
|
||||
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
BH1750FVI::BH1750FVI(const uint8_t address, const uint8_t dataPin, const uint8_t clockPin)
|
||||
{
|
||||
_address = address;
|
||||
_data = 0;
|
||||
_error = BH1750FVI_OK;
|
||||
_factor = 69;
|
||||
_wire = &Wire;
|
||||
_address = address;
|
||||
_data = 0;
|
||||
_error = BH1750FVI_OK;
|
||||
_sensitivityFactor = BH1750FVI_REFERENCE_TIME;
|
||||
_mode = BH1750FVI_MODE_HIGH;
|
||||
_wire = &Wire;
|
||||
|
||||
if ((dataPin < 255) && (clockPin < 255))
|
||||
{
|
||||
_wire->begin(dataPin, clockPin);
|
||||
} else {
|
||||
_wire->begin();
|
||||
}
|
||||
if ((dataPin < 255) && (clockPin < 255))
|
||||
{
|
||||
_wire->begin(dataPin, clockPin);
|
||||
} else {
|
||||
_wire->begin();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
BH1750FVI::BH1750FVI(const uint8_t address, TwoWire *wire)
|
||||
{
|
||||
_address = address;
|
||||
_data = 0;
|
||||
_error = BH1750FVI_OK;
|
||||
_factor = 69;
|
||||
_wire = wire;
|
||||
_wire->begin();
|
||||
_address = address;
|
||||
_data = 0;
|
||||
_error = BH1750FVI_OK;
|
||||
_sensitivityFactor = BH1750FVI_REFERENCE_TIME; // P11
|
||||
_mode = BH1750FVI_MODE_HIGH;
|
||||
_wire = wire;
|
||||
_wire->begin();
|
||||
}
|
||||
|
||||
bool BH1750FVI::isReady()
|
||||
{
|
||||
// max times from datasheet P2 + P11;
|
||||
uint8_t timeout[3] = { 16, 120, 120 };
|
||||
if (_mode < 3)
|
||||
{
|
||||
float f = timeout[_mode] * _sensitivityFactor / BH1750FVI_REFERENCE_TIME;
|
||||
return (millis() - _requestTime) > f;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
float BH1750FVI::getRaw(void)
|
||||
{
|
||||
return readData() * 0.833333333333f; // == 1 / 1.2;
|
||||
}
|
||||
|
||||
float BH1750FVI::getLux(void)
|
||||
{
|
||||
return readData() / 1.2;
|
||||
// lux without mode correction
|
||||
float lux = getRaw();
|
||||
|
||||
// sensitivity factor
|
||||
if (_sensitivityFactor != BH1750FVI_REFERENCE_TIME)
|
||||
{
|
||||
lux *= (1.0 * BH1750FVI_REFERENCE_TIME) / _sensitivityFactor;
|
||||
}
|
||||
// angle compensation
|
||||
if (_angle != 0)
|
||||
{
|
||||
lux *= _angleFactor;
|
||||
}
|
||||
// temperature compensation.
|
||||
if (_temp != 20)
|
||||
{
|
||||
float tempFactor = 1.0f - (_temp - 20.0f) / 2000.0f;
|
||||
lux *= tempFactor;
|
||||
}
|
||||
// wavelength compensation.
|
||||
if (_waveLength != 580)
|
||||
{
|
||||
lux *= _waveLengthFactor;
|
||||
}
|
||||
if (_mode == BH1750FVI_MODE_HIGH2)
|
||||
{
|
||||
lux *= 0.5f; // P11
|
||||
}
|
||||
|
||||
return lux;
|
||||
}
|
||||
|
||||
int BH1750FVI::getError()
|
||||
{
|
||||
int e = _error;
|
||||
_error = BH1750FVI_OK;
|
||||
return e;
|
||||
int e = _error;
|
||||
_error = BH1750FVI_OK;
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////
|
||||
//
|
||||
// operational mode
|
||||
//
|
||||
void BH1750FVI::setContHighRes()
|
||||
{
|
||||
_mode = BH1750FVI_MODE_HIGH;
|
||||
command(BH1750FVI_CONT_HIGH);
|
||||
_requestTime = millis();
|
||||
};
|
||||
|
||||
void BH1750FVI::setContHigh2Res()
|
||||
{
|
||||
_mode = BH1750FVI_MODE_HIGH2;
|
||||
command(BH1750FVI_CONT_HIGH2);
|
||||
_requestTime = millis();
|
||||
};
|
||||
|
||||
void BH1750FVI::setContLowRes()
|
||||
{
|
||||
_mode = BH1750FVI_MODE_LOW;
|
||||
command(BH1750FVI_CONT_LOW);
|
||||
_requestTime = millis();
|
||||
};
|
||||
|
||||
void BH1750FVI::setOnceHighRes()
|
||||
{
|
||||
_mode = BH1750FVI_MODE_HIGH;
|
||||
command(BH1750FVI_ONCE_HIGH);
|
||||
_requestTime = millis();
|
||||
};
|
||||
|
||||
void BH1750FVI::setOnceHigh2Res()
|
||||
{
|
||||
_mode = BH1750FVI_MODE_HIGH2;
|
||||
command(BH1750FVI_ONCE_HIGH2);
|
||||
_requestTime = millis();
|
||||
};
|
||||
|
||||
void BH1750FVI::setOnceLowRes()
|
||||
{
|
||||
_mode = BH1750FVI_MODE_LOW;
|
||||
command(BH1750FVI_ONCE_LOW);
|
||||
_requestTime = millis();
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////
|
||||
//
|
||||
// measurement timing
|
||||
//
|
||||
// P11 datasheet
|
||||
void BH1750FVI::changeTiming(uint8_t val)
|
||||
{
|
||||
_factor = val;
|
||||
uint8_t Hbits = 0x40 | (val >> 5);
|
||||
uint8_t Lbits = 0x60 | (val & 0x1F);
|
||||
command(Hbits);
|
||||
command(Lbits);
|
||||
val = constrain(val, 31, 254);
|
||||
_sensitivityFactor = val;
|
||||
// P5 instruction set table
|
||||
uint8_t Hbits = 0x40 | (val >> 5);
|
||||
uint8_t Lbits = 0x60 | (val & 0x1F);
|
||||
command(Hbits);
|
||||
command(Lbits);
|
||||
}
|
||||
|
||||
void BH1750FVI::setCorrectionFactor(float f)
|
||||
{
|
||||
uint8_t timingValue = round(69 * constrain(f, 0.01, 3.68));
|
||||
changeTiming(timingValue);
|
||||
// 31 .. 254 are range P11 - constrained in changeTIming call
|
||||
uint8_t timingValue = round(BH1750FVI_REFERENCE_TIME * f);
|
||||
changeTiming(timingValue);
|
||||
}
|
||||
|
||||
float BH1750FVI::getCorrectionFactor()
|
||||
{
|
||||
float f = 1.0f / BH1750FVI_REFERENCE_TIME;
|
||||
return _sensitivityFactor * f;
|
||||
}
|
||||
|
||||
void BH1750FVI::setAngle(int degrees)
|
||||
{
|
||||
_angle = constrain(degrees, -89, 89);
|
||||
// Lamberts Law.
|
||||
_angleFactor = 1.0f / cos(_angle * (PI / 180.0f));
|
||||
}
|
||||
|
||||
// interpolation tables uses more RAM (versus progmem)
|
||||
void BH1750FVI::setWaveLength(int waveLength)
|
||||
{
|
||||
_waveLength = constrain(waveLength, 400, 715);
|
||||
float tmp = 1.0f;
|
||||
if (_waveLength < 440) tmp = 0.01f + (_waveLength - 400) * 0.09f / 40.0f;
|
||||
else if (_waveLength < 510) tmp = 0.10f + (_waveLength - 440) * 0.80f / 70.0f;
|
||||
else if (_waveLength < 545) tmp = 0.90f - (_waveLength - 510) * 0.10f / 35.0f;
|
||||
else if (_waveLength < 580) tmp = 0.80f + (_waveLength - 545) * 0.20f / 35.0f;
|
||||
else if (_waveLength < 700) tmp = 1.00f - (_waveLength - 580) * 0.93f / 120.0f;
|
||||
else if (_waveLength < 715) tmp = 0.07f - (_waveLength - 700) * 0.07f / 15.0f;
|
||||
else if (_waveLength == 715) tmp = 0.01f;
|
||||
_waveLengthFactor = 1.0f / tmp;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
//
|
||||
// PRIVATE
|
||||
//
|
||||
|
||||
uint16_t BH1750FVI::readData()
|
||||
{
|
||||
if (_wire->requestFrom(_address, (uint8_t) 2) != 2)
|
||||
{
|
||||
_error = BH1750FVI_ERROR_WIRE_REQUEST;
|
||||
return _data; // last value
|
||||
}
|
||||
_data = _wire->read();
|
||||
_data <<= 8;
|
||||
_data += _wire->read();
|
||||
return _data;
|
||||
if (_wire->requestFrom(_address, (uint8_t) 2) != 2)
|
||||
{
|
||||
_error = BH1750FVI_ERROR_WIRE_REQUEST;
|
||||
return _data; // last value
|
||||
}
|
||||
_data = _wire->read();
|
||||
_data <<= 8;
|
||||
_data += _wire->read();
|
||||
return _data;
|
||||
}
|
||||
|
||||
void BH1750FVI::command(uint8_t value)
|
||||
{
|
||||
_wire->beginTransmission(_address);
|
||||
_wire->write(value);
|
||||
_error = _wire->endTransmission();
|
||||
_wire->beginTransmission(_address);
|
||||
_wire->write(value);
|
||||
_error = _wire->endTransmission();
|
||||
}
|
||||
|
||||
// --- END OF FILE ---
|
||||
|
@ -1,52 +1,55 @@
|
||||
#ifndef BH1750FVI_H
|
||||
#define BH1750FVI_H
|
||||
//
|
||||
#pragma once
|
||||
//
|
||||
// FILE: BH1750FVI_H.h
|
||||
// AUTHOR: Rob dot Tillaart at gmail dot com
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: library for BH1750FVI lux sensor Arduino
|
||||
// VERSION: 0.2.4
|
||||
// PURPOSE: Arduino library for BH1750FVI (GY-30) lux sensor
|
||||
// HISTORY: See BH1750FVI.cpp
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
|
||||
// breakout BH1750FVI / GY-30
|
||||
//
|
||||
// +-----------------------+
|
||||
// GND |o |
|
||||
// ADD |o |
|
||||
// SDA |o |
|
||||
// SDA |o + | + = sensor
|
||||
// SCL |o |
|
||||
// VCC |o |
|
||||
// +-----------------------+
|
||||
//
|
||||
// ADDRESS:
|
||||
// 0 = 0x23
|
||||
// 1 = 0x5C
|
||||
// ADD = ADDRESS:
|
||||
// 0 = 0x23
|
||||
// 1 = 0x5C
|
||||
//
|
||||
|
||||
#include "Wire.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
#define BH1750FVI_LIB_VERSION "0.1.0"
|
||||
#define BH1750FVI_LIB_VERSION "0.2.4"
|
||||
#define BH1750FVI_DEFAULT_ADDRESS 0x23
|
||||
#define BH1750FVI_ALT_ADDRESS 0x5C
|
||||
#define BH1750FVI_ALT_ADDRESS 0x5C
|
||||
|
||||
// COMMANDS
|
||||
#define BH1750FVI_POWER_ON 0x00
|
||||
#define BH1750FVI_POWER_OFF 0x01
|
||||
#define BH1750FVI_RESET 0x07
|
||||
#define BH1750FVI_CONT_HIGH 0x10
|
||||
#define BH1750FVI_CONT_HIGH2 0x11
|
||||
#define BH1750FVI_CONT_LOW 0x13
|
||||
#define BH1750FVI_ONCE_HIGH 0x20
|
||||
#define BH1750FVI_ONCE_HIGH2 0x21
|
||||
#define BH1750FVI_ONCE_LOW 0x23
|
||||
// COMMANDS P5
|
||||
#define BH1750FVI_POWER_ON 0x00
|
||||
#define BH1750FVI_POWER_OFF 0x01
|
||||
#define BH1750FVI_RESET 0x07
|
||||
#define BH1750FVI_CONT_HIGH 0x10
|
||||
#define BH1750FVI_CONT_HIGH2 0x11
|
||||
#define BH1750FVI_CONT_LOW 0x13
|
||||
#define BH1750FVI_ONCE_HIGH 0x20
|
||||
#define BH1750FVI_ONCE_HIGH2 0x21
|
||||
#define BH1750FVI_ONCE_LOW 0x23
|
||||
|
||||
#define BH1750FVI_REFERENCE_TIME 0x45 // 69
|
||||
|
||||
#define BH1750FVI_MODE_LOW 0x00
|
||||
#define BH1750FVI_MODE_HIGH 0x01
|
||||
#define BH1750FVI_MODE_HIGH2 0x02
|
||||
|
||||
// ERROR CODES
|
||||
#define BH1750FVI_OK 0
|
||||
#define BH1750FVI_ERROR_WIRE_REQUEST -10
|
||||
#define BH1750FVI_OK 0
|
||||
#define BH1750FVI_ERROR_WIRE_REQUEST -10
|
||||
|
||||
|
||||
class BH1750FVI
|
||||
@ -54,48 +57,77 @@ class BH1750FVI
|
||||
public:
|
||||
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
// dataPin and clockPin can be used for ESP8266
|
||||
BH1750FVI(const uint8_t address, const uint8_t dataPin, const uint8_t clockPin);
|
||||
// dataPin and clockPin can be used for ESP8266
|
||||
BH1750FVI(const uint8_t address , const uint8_t dataPin, const uint8_t clockPin);
|
||||
#endif
|
||||
|
||||
BH1750FVI(const uint8_t address, TwoWire *wire = &Wire);
|
||||
BH1750FVI(const uint8_t address, TwoWire *wire = &Wire);
|
||||
|
||||
float getLux();
|
||||
int getError();
|
||||
float getRaw(); // no HIGH2 mode + no sensitivity factor.
|
||||
float getLux();
|
||||
int getError();
|
||||
|
||||
void powerOn() { command(BH1750FVI_POWER_ON); };
|
||||
void powerOff() { command(BH1750FVI_POWER_OFF); };
|
||||
void reset() { command(BH1750FVI_RESET); };
|
||||
void powerOn() { command(BH1750FVI_POWER_ON); };
|
||||
void powerOff() { command(BH1750FVI_POWER_OFF); };
|
||||
void reset() { command(BH1750FVI_RESET); };
|
||||
|
||||
// MODE TIME RESOLUTION
|
||||
// High 120 ms 0.5 lux // recommended
|
||||
// High2 120 ms 1 lux
|
||||
// Low 16 ms 4 lux
|
||||
void setContHighRes() { command(BH1750FVI_CONT_HIGH); };
|
||||
void setContHigh2Res() { command(BH1750FVI_CONT_HIGH2); };
|
||||
void setContLowRes() { command(BH1750FVI_CONT_LOW); };
|
||||
void setOnceHighRes() { command(BH1750FVI_ONCE_HIGH); };
|
||||
void setOnceHigh2Res() { command(BH1750FVI_ONCE_HIGH2); };
|
||||
void setOnceLowRes() { command(BH1750FVI_ONCE_LOW); };
|
||||
// MODE TIME RESOLUTION
|
||||
// 2 HIGH2 120 ms 0.5 lux // recommended max * 1.5 = 180 ms
|
||||
// 1 HIGH 120 ms 1.0 lux
|
||||
// 0 LOW 16 ms 4.0 lux
|
||||
uint8_t getMode() { return _mode; };
|
||||
|
||||
// read datasheet about details of the correction factor
|
||||
// to be used for very high and very low brightness
|
||||
// or to correct for e.g. transparancy
|
||||
void changeTiming(uint8_t val); // 69 is default
|
||||
void setCorrectionFactor(float f); // 0.01 .. 3.68
|
||||
float getCorrectionFactor() { return _factor / 69.0; };
|
||||
void setContHighRes();
|
||||
void setContHigh2Res();
|
||||
void setContLowRes();
|
||||
|
||||
void setOnceHighRes();
|
||||
void setOnceHigh2Res();
|
||||
void setOnceLowRes();
|
||||
bool isReady(); // only after setOnce...Res();
|
||||
|
||||
// read datasheet P11 about details of the correction or sensitivity factor
|
||||
// to be used for very high and very low brightness
|
||||
// or to correct for e.g. transparancy
|
||||
void changeTiming(uint8_t val); // 69 is default = BH1750FVI_REFERENCE_TIME
|
||||
void setCorrectionFactor(float f); // 0.45 .. 3.68
|
||||
float getCorrectionFactor();
|
||||
|
||||
// read datasheet P3 and check figure 4 and 5.
|
||||
// setAngle is constrained to -89..+89
|
||||
void setAngle(int degrees);
|
||||
int getAngle() { return _angle; };
|
||||
|
||||
// datasheet P3 figure 7
|
||||
// Effect of temperature is about 3% / 60°C ~~ 1% / 20°C
|
||||
// to be used if temp is really hot or cold.
|
||||
void setTemperature(int temp) { _temp = temp; };
|
||||
int getTemperature() { return _temp; };
|
||||
|
||||
|
||||
// datasheet Page 3 figure 1 (experimental correction)
|
||||
// Effect of wavelength can be substantial,
|
||||
// correctionfactor is calculated by multiple linear approximations.
|
||||
void setWaveLength(int waveLength);
|
||||
int getWaveLength() { return _waveLength; };
|
||||
|
||||
private:
|
||||
uint16_t readData();
|
||||
void command(uint8_t value);
|
||||
uint16_t readData();
|
||||
void command(uint8_t value);
|
||||
|
||||
uint8_t _address;
|
||||
uint16_t _data;
|
||||
int _error;
|
||||
uint8_t _factor;
|
||||
uint8_t _address;
|
||||
uint16_t _data;
|
||||
int _error;
|
||||
uint8_t _sensitivityFactor;
|
||||
uint8_t _mode;
|
||||
uint32_t _requestTime = 0;
|
||||
float _angleFactor = 1;
|
||||
int _angle = 0;
|
||||
int _temp = 20;
|
||||
float _waveLengthFactor = 1;
|
||||
int _waveLength = 580;
|
||||
|
||||
TwoWire* _wire;
|
||||
TwoWire* _wire;
|
||||
};
|
||||
#endif
|
||||
|
||||
// END OF FILE
|
||||
// -- END OF FILE --
|
||||
|
21
libraries/BH1750FVI/LICENSE
Normal file
21
libraries/BH1750FVI/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 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
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -0,0 +1,94 @@
|
||||
//
|
||||
// FILE: BH1750FVI_angle_measurement.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: demo of BH1750FVI lux scanner library
|
||||
// DATE: 2020-08-31
|
||||
//
|
||||
|
||||
/*
|
||||
BH1750FVI_angle_measurement
|
||||
|
||||
Experimental application
|
||||
|
||||
first take a reference measurement for 5 seconds
|
||||
holding the sensor flat under a light source.
|
||||
|
||||
Then take a second reference for 5 seconds
|
||||
holding the sensor at 90 degrees.
|
||||
|
||||
Thereafter hold the sensor at any angle and the
|
||||
Arduino will estimate the angle based upon the
|
||||
Lux level compared to the references.
|
||||
|
||||
First trials are not not too bad, roughly within 15° accuracy
|
||||
|
||||
*/
|
||||
|
||||
#include "BH1750FVI.h"
|
||||
|
||||
BH1750FVI myLux(0x23);
|
||||
|
||||
float ref1 = 0;
|
||||
float ref2 = 0;
|
||||
|
||||
|
||||
float measure(int seconds, bool minimum = false)
|
||||
{
|
||||
float mn = 1e8;
|
||||
float mx = 0;
|
||||
uint32_t start = millis();
|
||||
while (millis() - start < (seconds * 1000UL))
|
||||
{
|
||||
float val = myLux.getLux();
|
||||
if (val > mx) mx = val;
|
||||
if (val < mn) mn = val;
|
||||
delay(200);
|
||||
}
|
||||
if (minimum) return mn;
|
||||
return mx;
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.print(__FILE__);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
myLux.powerOn();
|
||||
myLux.setContHighRes();
|
||||
|
||||
Serial.println("Reference 1");
|
||||
ref1 = measure(5, false);
|
||||
|
||||
Serial.println("Reference 2");
|
||||
ref2 = measure(5, true);
|
||||
Serial.println("Start");
|
||||
Serial.println(ref1);
|
||||
Serial.println(ref2);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
float val = measure(1, false);
|
||||
|
||||
val = map(val, ref2, ref1, 0, ref1); // does not constrain...
|
||||
|
||||
// prevent NAN
|
||||
float f = val / ref1; // map to 0..1
|
||||
if (f > 1) f = 1; // constrain upper
|
||||
if (f < -1) f = -1; // constrain lower
|
||||
|
||||
Serial.print(val, 1);
|
||||
Serial.print("\t");
|
||||
Serial.print(f);
|
||||
Serial.print("\t");
|
||||
Serial.print(acos(f) * 180 / PI);
|
||||
Serial.print("\t");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,18 @@
|
||||
/*
|
||||
BH1750FVI_angle_measurement.ino
|
||||
|
||||
Experimental application
|
||||
|
||||
first take a reference measurement for 5 seconds
|
||||
holding the sensor flat under a light source.
|
||||
|
||||
Then take a second reference for 5 seconds
|
||||
holding the sensor at 90 degrees.
|
||||
|
||||
Thereafter hold the sensor at any angle and the
|
||||
Arduino will estimate the angle based upon the
|
||||
Lux level compared to the references.
|
||||
|
||||
First trials are not not too bad, roughly within 15° accuracy
|
||||
|
||||
*/
|
@ -0,0 +1,65 @@
|
||||
//
|
||||
// FILE: BH1750FVI_async.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo of BH1750FVI lux scanner library
|
||||
// DATE: 2020-08-20
|
||||
//
|
||||
|
||||
#include "BH1750FVI.h"
|
||||
|
||||
BH1750FVI myLux(0x23);
|
||||
|
||||
float correctionFactor = 0.45; // min value see datasheet
|
||||
uint32_t count = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.print(__FILE__);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
|
||||
myLux.powerOn();
|
||||
myLux.setContHighRes();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (myLux.isReady())
|
||||
{
|
||||
float val = myLux.getLux();
|
||||
|
||||
if (count % 20 == 0)
|
||||
{
|
||||
Serial.println("\nCNT \tLUX \tMODE \tFACTOR \tRAWLUX");
|
||||
}
|
||||
|
||||
Serial.print(count);
|
||||
Serial.print("\t");
|
||||
Serial.print(val, 1);
|
||||
Serial.print("\t");
|
||||
Serial.print(myLux.getMode());
|
||||
Serial.print("\t");
|
||||
Serial.print(myLux.getCorrectionFactor(), 2);
|
||||
Serial.print("\t");
|
||||
Serial.println(val / myLux.getCorrectionFactor(), 1);
|
||||
|
||||
// note correctionfactor are steps of 1/69 internally, see datasheet
|
||||
correctionFactor += 0.05;
|
||||
if (correctionFactor > 3.68) // 0.45 - 3.68 = 45 steps of 0.05
|
||||
{
|
||||
correctionFactor = 0.45;
|
||||
Serial.println();
|
||||
}
|
||||
myLux.setCorrectionFactor(correctionFactor); // 0.45 .. 3.68
|
||||
|
||||
count++;
|
||||
}
|
||||
delay(1000);
|
||||
// do other things here
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
@ -5,8 +5,9 @@
|
||||
// PURPOSE: demo of BH1750FVI lux scanner library
|
||||
// DATE: 2020-02-02
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
// This is a minimal version, which can be optimized by
|
||||
// using mylux.getRaw() instead of myLux.getLux(); line38
|
||||
// gain on UNO: ~350 bytes smaller
|
||||
|
||||
#include "BH1750FVI.h"
|
||||
|
||||
@ -30,7 +31,7 @@ void setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
int interval = 100;
|
||||
uint16_t interval = 100;
|
||||
if (millis() - lastUpdate >= interval)
|
||||
{
|
||||
lastUpdate += interval;
|
||||
@ -40,4 +41,4 @@ void loop()
|
||||
|
||||
}
|
||||
|
||||
// END OF FILE
|
||||
// -- END OF FILE --
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: BH1750FVI_cont_low_res.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: demo of BH1750FVI lux scanner library
|
||||
// DATE: 2020-02-02
|
||||
//
|
||||
@ -30,7 +30,7 @@ void setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
int interval = 100;
|
||||
uint16_t interval = 100;
|
||||
if (millis() - lastUpdate >= interval)
|
||||
{
|
||||
lastUpdate += interval;
|
||||
|
@ -0,0 +1,43 @@
|
||||
//
|
||||
// FILE: BH1750FVI_setAngle.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo of BH1750FVI lux scanner library
|
||||
// DATE: 2020-08-31
|
||||
//
|
||||
|
||||
#include "BH1750FVI.h"
|
||||
|
||||
BH1750FVI myLux(0x23);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.print(__FILE__);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
|
||||
myLux.powerOn();
|
||||
myLux.setContHighRes();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
for (int x = -90; x < 90; x += 1)
|
||||
{
|
||||
myLux.setAngle(x);
|
||||
float val = myLux.getLux();
|
||||
|
||||
Serial.print(val, 1);
|
||||
Serial.print("\t");
|
||||
Serial.print(myLux.getAngle());
|
||||
Serial.print("\t");
|
||||
Serial.println();
|
||||
delay(20);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
@ -1,12 +1,10 @@
|
||||
//
|
||||
// FILE: setCorrectionFactor.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: demo of BH1750FVI lux scanner library
|
||||
// DATE: 2020-02-02
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
#include "BH1750FVI.h"
|
||||
|
||||
@ -14,7 +12,7 @@ BH1750FVI myLux(0x23);
|
||||
|
||||
uint32_t lastUpdate = 0;
|
||||
|
||||
float correctionFactor = 0.01;
|
||||
float correctionFactor = 0.45; // min value see datasheet
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -31,11 +29,12 @@ void setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
int interval = 100;
|
||||
uint16_t interval = 180; // max time see datasheet P2
|
||||
if (millis() - lastUpdate >= interval)
|
||||
{
|
||||
lastUpdate += interval;
|
||||
float val = myLux.getLux();
|
||||
|
||||
Serial.print(val, 1);
|
||||
Serial.print("\t");
|
||||
Serial.print(myLux.getCorrectionFactor(), 3);
|
||||
@ -43,11 +42,14 @@ void loop()
|
||||
Serial.println(val / myLux.getCorrectionFactor(), 1);
|
||||
|
||||
// note correctionfactor are steps of 1/69 internally, see datasheet
|
||||
myLux.setCorrectionFactor(correctionFactor); // 0.01 .. 3.68
|
||||
correctionFactor += 0.01;
|
||||
if (correctionFactor > 3.68) correctionFactor = 0.01;
|
||||
myLux.setCorrectionFactor(correctionFactor); // 0.45 .. 3.68
|
||||
correctionFactor += 0.05;
|
||||
if (correctionFactor > 3.68)
|
||||
{
|
||||
correctionFactor = 0.45;
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// END OF FILE
|
||||
// -- END OF FILE --
|
||||
|
@ -0,0 +1,44 @@
|
||||
//
|
||||
// FILE: BH1750FVI_setTemperature.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo of BH1750FVI lux scanner library
|
||||
// DATE: 2020-09-04
|
||||
//
|
||||
|
||||
#include "BH1750FVI.h"
|
||||
|
||||
BH1750FVI myLux(0x23);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.print(__FILE__);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
|
||||
myLux.powerOn();
|
||||
myLux.setContHighRes();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
for (int t = -60; t < 100; t += 10)
|
||||
{
|
||||
myLux.setTemperature(t);
|
||||
float val = myLux.getLux();
|
||||
|
||||
Serial.print(val, 1);
|
||||
Serial.print("\t");
|
||||
Serial.print(myLux.getTemperature());
|
||||
Serial.print("\t");
|
||||
Serial.println();
|
||||
delay(20);
|
||||
}
|
||||
Serial.println();
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,47 @@
|
||||
//
|
||||
// FILE: BH1750FVI_setWaveLength.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo of BH1750FVI lux scanner library
|
||||
// DATE: 2020-09-04
|
||||
//
|
||||
|
||||
#include "BH1750FVI.h"
|
||||
|
||||
BH1750FVI myLux(0x23);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.print(__FILE__);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
|
||||
myLux.powerOn();
|
||||
myLux.setContHighRes();
|
||||
|
||||
for (int wl = 400; wl < 715; wl++)
|
||||
{
|
||||
myLux.setWaveLength(wl);
|
||||
float val = myLux.getLux();
|
||||
|
||||
Serial.print(val, 1);
|
||||
Serial.print("\t");
|
||||
Serial.print(myLux.getWaveLength());
|
||||
Serial.print("\t");
|
||||
Serial.println();
|
||||
delay(20);
|
||||
}
|
||||
Serial.println();
|
||||
delay(1000);
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,64 @@
|
||||
//
|
||||
// FILE: BH1750FVI_single_shot_3_res.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo of BH1750FVI lux scanner library
|
||||
// DATE: 2020-08-20
|
||||
//
|
||||
|
||||
#include "BH1750FVI.h"
|
||||
|
||||
BH1750FVI myLux(0x23);
|
||||
|
||||
uint32_t lastUpdate = 0;
|
||||
float val;
|
||||
uint32_t count = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.print(__FILE__);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
|
||||
myLux.powerOn();
|
||||
myLux.setContLowRes();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (count % 20 == 0)
|
||||
{
|
||||
Serial.println("\nLOW \tHIGH \tHIGH2 \tRAW");
|
||||
}
|
||||
count++;
|
||||
myLux.setOnceLowRes();
|
||||
delay(200);
|
||||
val = myLux.getLux();
|
||||
Serial.print(val, 1);
|
||||
Serial.print('\t');
|
||||
|
||||
myLux.setOnceHighRes();
|
||||
delay(200);
|
||||
val = myLux.getLux();
|
||||
Serial.print(val, 1);
|
||||
Serial.print('\t');
|
||||
|
||||
myLux.setOnceHigh2Res();
|
||||
delay(200);
|
||||
val = myLux.getLux();
|
||||
Serial.print(val, 1);
|
||||
Serial.print('\t');
|
||||
|
||||
myLux.setOnceHighRes();
|
||||
delay(200);
|
||||
val = myLux.getRaw();
|
||||
Serial.print(val, 1);
|
||||
Serial.print('\t');
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
@ -1,26 +1,37 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For BH1750FVI
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
BH1750FVI KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
getRaw KEYWORD2
|
||||
getLux KEYWORD2
|
||||
getError KEYWORD2
|
||||
|
||||
powerOn KEYWORD2
|
||||
powerOff KEYWORD2
|
||||
reset KEYWORD2
|
||||
|
||||
setContHighRes KEYWORD2
|
||||
setContHigh2Res KEYWORD2
|
||||
setContLowRes KEYWORD2
|
||||
setOnceHighRes KEYWORD2
|
||||
setOnceHigh2Res KEYWORD2
|
||||
setOnceLowRes KEYWORD2
|
||||
isReady KEYWORD2
|
||||
|
||||
changeTiming KEYWORD2
|
||||
setCorrectionFactor KEYWORD2
|
||||
getCorrectionFactor KEYWORD2
|
||||
|
||||
setAngle KEYWORD2
|
||||
getAngle KEYWORD2
|
||||
setTemperature KEYWORD2
|
||||
getTemperature KEYWORD2
|
||||
setWaveLength KEYWORD2
|
||||
getWaveLength KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Instances (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "BH1750FVI",
|
||||
"keywords": "BH1750FVI, Lux, light, GY-30",
|
||||
"description": "library for BH1750FVI Lux sensor Arduino.",
|
||||
"name": "BH1750FVI_RT",
|
||||
"keywords": "BH1750FVI, BH1750, Lux, light, GY-30, GY30",
|
||||
"description": "Arduino library for BH1750FVI (GY-30) lux sensor. Includes compensation for angle, temperature and (experimental) wavelength.",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
@ -13,12 +13,9 @@
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Arduino.git"
|
||||
"url": "https://github.com/RobTillaart/BH1750FVI_RT.git"
|
||||
},
|
||||
"version": "0.1.0",
|
||||
"version": "0.2.4",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"export": {
|
||||
"include": "libraries/BH1750FVI"
|
||||
}
|
||||
"platforms": "*"
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
name=BH1750FVI
|
||||
version=0.1.0
|
||||
name=BH1750FVI_RT
|
||||
version=0.2.4
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library for BH1750FVI lux sensor Arduino
|
||||
paragraph=
|
||||
sentence=Arduino library for BH1750FVI (GY-30) lux sensor
|
||||
paragraph=Includes compensation for angle, temperature and (experimental) wavelength.
|
||||
category=Sensors
|
||||
url=https://github.com/RobTillaart/Arduino/tree/master/libraries/
|
||||
architectures=*
|
||||
url=https://github.com/RobTillaart/BH1750FVI_RT
|
||||
architectures=*
|
||||
includes=BH1750FVI.h
|
||||
depends=
|
||||
|
@ -1,10 +1,153 @@
|
||||
# BH1750FVI_RT
|
||||
|
||||
# BH1750FVI I2C LUX sensor
|
||||
Arduino library for BH1750FVI (GY-30) 16 bit I2C Lux sensor
|
||||
|
||||
library for BH1750FVI (GY-30) Lux sensor for Arduino.
|
||||
## Description
|
||||
|
||||
## Examples
|
||||
The BH1750FVI is a 16 bit lux sensor with an I2C interface
|
||||
It is possible to detect a wide range from 0.11 - 100000 lux.
|
||||
|
||||
To be able to support this wide range, the sensor can operate in three modi.
|
||||
|
||||
| ID | Mode | Integration time | Resolution | Notes |
|
||||
|:----:|:----:|:----:|:----:|:----|
|
||||
| 0 | LOW | 16 ms | 4.0 Lux | to measure very bright light |
|
||||
| 1 | HIGH | 120 ms | 1.0 lux | default |
|
||||
| 2 | HIGH2 | 120 ms | 0.5 lux | to measure very dim light |
|
||||
|
||||
Furthermore one can set a correction factor to reduce / increase the
|
||||
integration time of the sensor.
|
||||
The factor should be between 0.45 - 3.68.
|
||||
It can be used to increase the working range like very bright or very low light conditions.
|
||||
Another aplication is to correct the transparancy of material, or the type of light used.
|
||||
|
||||
Note that the typical integration time will differ if the correction factor is changed.
|
||||
The **isReady()** an **getLux()** functions keep track of the adjustment needed.
|
||||
|
||||
## Interface hardware
|
||||
|
||||
Library was tested with a breakout board.
|
||||
|
||||
```
|
||||
// breakout BH1750FVI / GY-30
|
||||
//
|
||||
// +-----------------------+
|
||||
// GND |o |
|
||||
// ADD |o |
|
||||
// SDA |o + | + = sensor
|
||||
// SCL |o |
|
||||
// VCC |o |
|
||||
// +-----------------------+
|
||||
//
|
||||
// ADD = ADDRESS:
|
||||
// 0 = 0x23
|
||||
// 1 = 0x5C
|
||||
//
|
||||
```
|
||||
The sensor works on 2.4 - 3.6 volt so be careful not to connect directly to 5.0 volt.
|
||||
(Note: the breakout board was 5 volt tolerant)
|
||||
|
||||
## Interface API
|
||||
|
||||
- **BH1750FVI(address, dataPin, clockPin)** ESP constructor with I2C parameters
|
||||
- **BH1750FVI(address, TwoWire \*wire = &Wire)** constructor for other platforms
|
||||
- **getRaw()** reads the lux sensor,
|
||||
- **getLux()** reads the lux sensor and corrects for correctionFactor and for HIGH2 mode,
|
||||
- **getError()** get the latest error, mainly for debugging,
|
||||
- **powerOn()** wakes up the sensor,
|
||||
- **powerOff()** set sensor to sleep,
|
||||
- **reset()** resets the dataregister to 0, effectively removing last measurement.
|
||||
- **getMode()** gets the mode set by one of the set functions. See table above.
|
||||
- **setContHighRes()** continuous mode in HIGH resolution
|
||||
- **setContHigh2Res()** continuous mode in HIGH2 resolution
|
||||
- **setContLowRes()** continuous mode in LOW resolution
|
||||
- **setOnceHighRes()** single shot mode in HIGH resolution
|
||||
- **setOnceHigh2Res()** single shot mode in HIGH2 resolution
|
||||
- **setOnceLowRes()** single shot mode in LOW resolution
|
||||
- **isReady()** can be used to check if the sensor is ready.
|
||||
This is based on a calculated time, the sensor does not have a means to indicate ready directly.
|
||||
Needed only for the single shot modi.
|
||||
The function **isReady()** takes the correctionfactor into account.
|
||||
|
||||
**CorrectionFactor**
|
||||
|
||||
Please read datasheet P11 about details of the correction factor.
|
||||
- **changeTiming(uint8_t val)** 69 is default = BH1750FVI_REFERENCE_TIME
|
||||
- **setCorrectionFactor(float f)** prefered wrapper around changeTiming f = 0.45 .. 3.68
|
||||
- **getCorrectionFactor()** returns the correction factor.
|
||||
Note this can differ as it is stores as an integer internally.
|
||||
|
||||
**Angle sensitivity**
|
||||
|
||||
Note: experimental - use carefully
|
||||
|
||||
The lux sensor is really sensitive for the angle of the light.
|
||||
If one makes measurements outside, the position of the sun changes
|
||||
during the day. The **setAngle(degrees)** function provides a mean to correct that.
|
||||
|
||||
The angle adjustments is based upon the figure 4 and 5 (directional characteristics.)
|
||||
which describe **Lambert’s Cosine Law**. (details see wikipedia)
|
||||
So the correction factor is ```factor = 1.0 / cos(angle)```.
|
||||
At 90 degrees it would fail (divide by zero) so the input is constrained
|
||||
to angles between -89 - +89 degrees.
|
||||
|
||||
If the light is perpendicular on the sensor the angle to use is 0 degrees.
|
||||
Light coming from the side is 90 degrees.
|
||||
|
||||
- **setAngle(int degrees)** adjust the lux to incoming angle in dgrees
|
||||
- **getAngle()** returns set angle in degrees, 0 by default is perpendicular
|
||||
|
||||
**Temperature Compensation**
|
||||
|
||||
The reference temperature of the sensor = 20°C.
|
||||
The effect of temperature is small, about 3% per 60°C ==> 1% per 20°C
|
||||
so only on either a hot roof or on a icy cold day the effect is measurable.
|
||||
|
||||
- **setTemperature(int T)** see datasheet P3 fig7
|
||||
- **getTemperature()** returns temperature set, default = 20°C
|
||||
|
||||
|
||||
## Notes
|
||||
**Spectral Compensation ! EXPERIMENTAL !**
|
||||
|
||||
Spectral compensation is experimental and not tested. It is a compensation based upon the
|
||||
graph figure 1, page 3 of the datasheet. If one has light of a known wavelength one can
|
||||
compensate for it by setting the wavelength. It can also be used when using filters.
|
||||
As said it is not tested so use at your own risk, but I am interested in your experiences
|
||||
if you do real tests with it.
|
||||
|
||||
- **void setSpectral(int wavelength)** set wavelength,
|
||||
- **int getSpectral()** returns wavelength
|
||||
|
||||
As the graph (figure 1) is not lineair it is approximated by linear interpolation with the
|
||||
following six points.
|
||||
|
||||
| WaveLength | Perc % |
|
||||
|:----|:----:|
|
||||
| 400 | 1 |
|
||||
| 440 | 10 |
|
||||
| 510 | 90 |
|
||||
| 545 | 80 |
|
||||
| 580 | 100 |
|
||||
| 700 | 07 |
|
||||
| 725 | 1 |
|
||||
|
||||
Values outside the range will be mapped upon 400 or 715.
|
||||
Default wavelength will be 580 as that gives 100%
|
||||
|
||||
|
||||
## Ideas
|
||||
|
||||
**Intelligent isReady()**
|
||||
|
||||
After a **getLux()** call one can clean the dataregister explicitly with
|
||||
**reset()**. Then a call to **isReady()** fetches data and as long as
|
||||
data equals zero the sensor is not ready.
|
||||
|
||||
**DVI interface**
|
||||
|
||||
To investigate, sort of external reset?
|
||||
|
||||
|
||||
## Operation
|
||||
|
||||
See samples...
|
||||
|
@ -1,13 +1,16 @@
|
||||
//
|
||||
// FILE: BitArray.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.8
|
||||
// VERSION: 0.2.1
|
||||
// PURPOSE: BitArray library for Arduino
|
||||
// URL: http://forum.arduino.cc/index.php?topic=361167
|
||||
// URL: https://github.com/RobTillaart/BitArray
|
||||
// http://forum.arduino.cc/index.php?topic=361167
|
||||
//
|
||||
// 16 bit clear is faster --> verify correctness
|
||||
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
// 0.2.1 2020-06-05 fix library.json
|
||||
// 0.2.0 2020-03-28 #pragma once, readme, fix fibnacci demo
|
||||
// 0.1.9 - fix constructor bug
|
||||
// 0.1.8 - added toggle
|
||||
// 0.1.07 - private calls inline -> performance & footprint
|
||||
// 0.1.06 - refactored
|
||||
@ -21,6 +24,14 @@
|
||||
|
||||
#include "BitArray.h"
|
||||
|
||||
BitArray::BitArray()
|
||||
{
|
||||
for (uint8_t i = 0; i < BA_MAX_SEGMENTS; i++)
|
||||
{
|
||||
_ar[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
BitArray::~BitArray()
|
||||
{
|
||||
for (uint8_t i = 0; i < BA_MAX_SEGMENTS; i++)
|
||||
@ -72,6 +83,7 @@ uint32_t BitArray::get(const uint16_t idx)
|
||||
// if (idx >= _size) return BA_IDX_RANGE;
|
||||
uint32_t v = 0;
|
||||
uint16_t pos = idx * _bits;
|
||||
|
||||
for (uint8_t i = _bits; i-- > 0;)
|
||||
{
|
||||
v <<= 1;
|
||||
@ -80,6 +92,7 @@ uint32_t BitArray::get(const uint16_t idx)
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
uint32_t BitArray::set(const uint16_t idx, uint32_t value)
|
||||
{
|
||||
// if (_error != BA_OK) return BA_ERR;
|
||||
@ -109,19 +122,38 @@ uint32_t BitArray::toggle(const uint16_t idx)
|
||||
return v;
|
||||
}
|
||||
|
||||
// void BitArray::clear()
|
||||
// {
|
||||
// uint16_t b = _bytes;
|
||||
// for (uint8_t s = 0; s < _segments; s++)
|
||||
// {
|
||||
// uint8_t *p = _ar[s];
|
||||
// if (p)
|
||||
// {
|
||||
// uint8_t t = min(b, BA_SEGMENT_SIZE);
|
||||
// b -= t;
|
||||
// while(t--)
|
||||
// {
|
||||
// *p++ = 0;
|
||||
// }
|
||||
// }
|
||||
// if (b == 0) break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// 16 bit address usage is faster
|
||||
void BitArray::clear()
|
||||
{
|
||||
uint16_t b = _bytes;
|
||||
for (uint8_t s = 0; s < _segments; s++)
|
||||
{
|
||||
uint8_t *p = _ar[s];
|
||||
uint8_t *q = _ar[s];
|
||||
uint16_t *p = (uint16_t*)q;
|
||||
if (p)
|
||||
{
|
||||
uint8_t t = min(b, BA_SEGMENT_SIZE);
|
||||
b -= t;
|
||||
while(t--)
|
||||
for (uint8_t t = 0; t < BA_SEGMENT_SIZE/2; t++)
|
||||
{
|
||||
*p++ = 0;
|
||||
*p++ = 0;
|
||||
}
|
||||
}
|
||||
if (b == 0) break;
|
||||
@ -141,7 +173,7 @@ inline uint8_t BitArray::_bitget(uint16_t pos)
|
||||
uint8_t by = re / 8;
|
||||
uint8_t bi = re & 7;
|
||||
uint8_t * p = _ar[se];
|
||||
|
||||
|
||||
return (p[by] >> bi) & 0x01; // bitRead(p[by], bi);
|
||||
}
|
||||
|
||||
@ -157,7 +189,7 @@ inline void BitArray::_bitset(uint16_t pos, uint8_t value)
|
||||
uint8_t by = re / 8;
|
||||
uint8_t bi = re & 7;
|
||||
uint8_t * p = _ar[se];
|
||||
|
||||
|
||||
if (value == 0) p[by] &= ~(1 << bi); // bitClear(p[by], bi);
|
||||
else p[by] |= (1 << bi); // bitSet(p[by], bi);
|
||||
}
|
||||
@ -174,7 +206,7 @@ inline uint8_t BitArray::_bittoggle(const uint16_t pos)
|
||||
uint8_t by = re / 8;
|
||||
uint8_t bi = re & 7;
|
||||
uint8_t * p = _ar[se];
|
||||
|
||||
|
||||
uint8_t mask = 1 << bi;
|
||||
p[by] ^= mask;
|
||||
return (mask > 0);
|
||||
|
@ -1,37 +1,31 @@
|
||||
#ifndef BitArray_H
|
||||
#define BitArray_H
|
||||
#pragma once
|
||||
//
|
||||
// FILE: BitArray.h
|
||||
// FILE: bitArray.h
|
||||
// AUTHOR: Rob dot Tillaart at gmail dot com
|
||||
// VERSION: 0.1.8
|
||||
// VERSION: 0.2.1
|
||||
// PURPOSE: BitArray library for Arduino
|
||||
// HISTORY: See BitArray.cpp
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
// URL: https://github.com/RobTillaart/BitArray
|
||||
|
||||
|
||||
// BitArray allows you to make a compact array of objects with a size
|
||||
// expressed in bits. typically 1..10.
|
||||
// The interface uses uint32_t as that will be enough for most purposes.
|
||||
// The main requirement is to optimize storage space
|
||||
//
|
||||
// the bitarray uses an array of segments and the space per segment
|
||||
// the bitarray uses an array of segments and the space per segment
|
||||
// may not exceed 256 bytes as this is a limit on some processors.
|
||||
//
|
||||
// Originally created to store lot of numbers between 1..6 dice rolls
|
||||
// the storage is also usable to store e.g. raw 10 bit analogReads
|
||||
// see demo sketches.
|
||||
//
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#define BITARRAY_LIB_VERSION "0.1.8"
|
||||
#define BITARRAY_LIB_VERSION "0.2.1"
|
||||
|
||||
#define BA_SEGMENT_SIZE 200
|
||||
|
||||
// max memory is board type dependant
|
||||
// max memory is board type dependent
|
||||
// note the bitArray does not use all of the RAM
|
||||
// 1K - max 600
|
||||
#if defined(__AVR_ATmega168__)
|
||||
@ -70,7 +64,7 @@
|
||||
class BitArray
|
||||
{
|
||||
public:
|
||||
BitArray() {};
|
||||
BitArray();
|
||||
~BitArray();
|
||||
|
||||
uint8_t begin(const uint8_t bits, const uint16_t size);
|
||||
@ -80,8 +74,8 @@ public:
|
||||
uint16_t bits() { return _bits; };
|
||||
uint16_t segments() { return _segments; };
|
||||
uint8_t getError() { return _error; };
|
||||
void clear();
|
||||
|
||||
void clear();
|
||||
uint32_t get(const uint16_t idx);
|
||||
uint32_t set(const uint16_t idx, uint32_t value);
|
||||
uint32_t toggle(const uint16_t idx);
|
||||
@ -98,4 +92,4 @@ private:
|
||||
uint8_t _error = BA_NO_MEMORY_ERR;
|
||||
};
|
||||
|
||||
#endif
|
||||
// -- END OF FILE --
|
||||
|
21
libraries/BitArray/LICENSE
Normal file
21
libraries/BitArray/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2015-2020 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
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
41
libraries/BitArray/README.md
Normal file
41
libraries/BitArray/README.md
Normal file
@ -0,0 +1,41 @@
|
||||
# BitArray
|
||||
Arduino library for compact array of objects with a size expressed in bits. typically 1..10
|
||||
|
||||
## Description
|
||||
The BitArray class allows the user to instantiate an array of elements, each of the same size in bits.
|
||||
For example one could create an array of 100 throws with a dice. Normally this would take 100 bytes,
|
||||
but BitArray can store one throw in 3 bits, so 100 throws in approx 40 bytes.
|
||||
Another example is to store multiple 10 bit analogRead() values efficiently
|
||||
|
||||
The class is optimized for storage and takes care of efficiently packing the elements
|
||||
into multiple bytes, and byte borders. Depending where an element is located writing and reading
|
||||
can take more time. You need to check if your application needs more performance than
|
||||
this library can deliver.
|
||||
|
||||
The BitArray library is one from a set of three:
|
||||
* BitArray for elements of user defined size in bits (values 0 .. 2^n-1)
|
||||
* BoolArray for elements of 1 bit (values 0 .. 1)
|
||||
* nybbleArray for elements of 4 bits (values 0 .. 15)
|
||||
|
||||
|
||||
## Operations
|
||||
In the function **begin(#elementsize, #elements)** the element size and number of elements
|
||||
needs to be defined. The maximum number of elements is 65535 if memory allows,
|
||||
the maximum element size is 32.
|
||||
|
||||
The basic functions of the class are
|
||||
* **set(index, value)**
|
||||
* **get(index)**
|
||||
* **toggle(index)**
|
||||
* **clear()**
|
||||
|
||||
Check out the examples.
|
||||
|
||||
## Notes
|
||||
The BitArray class dynamicly allocates memory, so called BA_SEGMENTS,
|
||||
each of 200 bytes.
|
||||
As the memory size of different processors differ the maximum amount of SEGMENTS
|
||||
depends on architecture.
|
||||
|
||||
The library is tested on AVR architecture only.
|
||||
|
86
libraries/BitArray/examples/bitArrayDemo3/performance_1.8.0
Normal file
86
libraries/BitArray/examples/bitArrayDemo3/performance_1.8.0
Normal file
@ -0,0 +1,86 @@
|
||||
Start C:\Users\Rob\Desktop\WORK\Arduino\libraries\BitArray\examples\bitArrayDemo3\bitArrayDemo3.ino
|
||||
LIB VERSION: 0.1.8
|
||||
CAPACITY: 10000
|
||||
MEMORY: 1250
|
||||
BITS: 1
|
||||
SEGMENTS: 7
|
||||
|
||||
GET:
|
||||
DURATION: 113396
|
||||
DURATION: 222296
|
||||
X: 6792
|
||||
|
||||
SET:
|
||||
DURATION: 84468
|
||||
DURATION: 164444
|
||||
|
||||
CLEAR:
|
||||
DURATION: 548
|
||||
|
||||
TOGGLE:
|
||||
DURATION: 105244
|
||||
DURATION: 205948
|
||||
Done...
|
||||
CAPACITY: 5000
|
||||
MEMORY: 1250
|
||||
BITS: 2
|
||||
SEGMENTS: 7
|
||||
|
||||
GET:
|
||||
DURATION: 89184
|
||||
DURATION: 176084
|
||||
X: 51288
|
||||
|
||||
SET:
|
||||
DURATION: 73152
|
||||
DURATION: 144008
|
||||
|
||||
CLEAR:
|
||||
DURATION: 548
|
||||
|
||||
TOGGLE:
|
||||
DURATION: 86064
|
||||
DURATION: 169796
|
||||
Done...
|
||||
CAPACITY: 3333
|
||||
MEMORY: 1250
|
||||
BITS: 3
|
||||
SEGMENTS: 7
|
||||
|
||||
GET:
|
||||
DURATION: 81104
|
||||
DURATION: 160656
|
||||
X: 120501
|
||||
|
||||
SET:
|
||||
DURATION: 69368
|
||||
DURATION: 137184
|
||||
|
||||
CLEAR:
|
||||
DURATION: 548
|
||||
|
||||
TOGGLE:
|
||||
DURATION: 79660
|
||||
DURATION: 157720
|
||||
Done...
|
||||
CAPACITY: 2500
|
||||
MEMORY: 1250
|
||||
BITS: 4
|
||||
SEGMENTS: 7
|
||||
|
||||
GET:
|
||||
DURATION: 77084
|
||||
DURATION: 152972
|
||||
X: 231717
|
||||
|
||||
SET:
|
||||
DURATION: 67492
|
||||
DURATION: 133792
|
||||
|
||||
CLEAR:
|
||||
DURATION: 552
|
||||
|
||||
TOGGLE:
|
||||
DURATION: 76472
|
||||
DURATION: 151712
|
||||
Done...
|
86
libraries/BitArray/examples/bitArrayDemo3/performance_1.9.0
Normal file
86
libraries/BitArray/examples/bitArrayDemo3/performance_1.9.0
Normal file
@ -0,0 +1,86 @@
|
||||
Start C:\Users\Rob\Desktop\WORK\Arduino\libraries\BitArray\examples\bitArrayDemo3\bitArrayDemo3.ino
|
||||
LIB VERSION: 0.1.8
|
||||
CAPACITY: 10000
|
||||
MEMORY: 1250
|
||||
BITS: 1
|
||||
SEGMENTS: 7
|
||||
|
||||
GET:
|
||||
DURATION: 113396
|
||||
DURATION: 222296
|
||||
X: 6792
|
||||
|
||||
SET:
|
||||
DURATION: 84468
|
||||
DURATION: 164444
|
||||
|
||||
CLEAR:
|
||||
DURATION: 548
|
||||
|
||||
TOGGLE:
|
||||
DURATION: 105244
|
||||
DURATION: 205948
|
||||
Done...
|
||||
CAPACITY: 5000
|
||||
MEMORY: 1250
|
||||
BITS: 2
|
||||
SEGMENTS: 7
|
||||
|
||||
GET:
|
||||
DURATION: 89184
|
||||
DURATION: 176084
|
||||
X: 51288
|
||||
|
||||
SET:
|
||||
DURATION: 73152
|
||||
DURATION: 144008
|
||||
|
||||
CLEAR:
|
||||
DURATION: 548
|
||||
|
||||
TOGGLE:
|
||||
DURATION: 86064
|
||||
DURATION: 169796
|
||||
Done...
|
||||
CAPACITY: 3333
|
||||
MEMORY: 1250
|
||||
BITS: 3
|
||||
SEGMENTS: 7
|
||||
|
||||
GET:
|
||||
DURATION: 81104
|
||||
DURATION: 160656
|
||||
X: 120501
|
||||
|
||||
SET:
|
||||
DURATION: 69368
|
||||
DURATION: 137184
|
||||
|
||||
CLEAR:
|
||||
DURATION: 548
|
||||
|
||||
TOGGLE:
|
||||
DURATION: 79660
|
||||
DURATION: 157720
|
||||
Done...
|
||||
CAPACITY: 2500
|
||||
MEMORY: 1250
|
||||
BITS: 4
|
||||
SEGMENTS: 7
|
||||
|
||||
GET:
|
||||
DURATION: 77084
|
||||
DURATION: 152972
|
||||
X: 231717
|
||||
|
||||
SET:
|
||||
DURATION: 67492
|
||||
DURATION: 133792
|
||||
|
||||
CLEAR:
|
||||
DURATION: 552
|
||||
|
||||
TOGGLE:
|
||||
DURATION: 76472
|
||||
DURATION: 151712
|
||||
Done...
|
82
libraries/BitArray/examples/fibonacci/fibonacci.ino
Normal file
82
libraries/BitArray/examples/fibonacci/fibonacci.ino
Normal file
@ -0,0 +1,82 @@
|
||||
// FILE: Fibonacci.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// DATE: 2018-03-05
|
||||
// PURPOSE: Generate Fibonaci numbers
|
||||
// URL: https://forum.arduino.cc/index.php?topic=532760.0
|
||||
|
||||
|
||||
#include "BitArray.h"
|
||||
|
||||
#define NR 70
|
||||
|
||||
BitArray a;
|
||||
BitArray b;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(230400);
|
||||
|
||||
// 10 bit can hold 3 digits 000..999 (1000 with overflow)
|
||||
// 10 bits give effective use of 1000/1024 = 97%
|
||||
int x = a.begin(10, NR);
|
||||
if (x != 0) Serial.println(x);
|
||||
x = b.begin(10, NR);
|
||||
if (x != 0) Serial.println(x);
|
||||
|
||||
a.clear();
|
||||
b.clear();
|
||||
|
||||
b.set(0, 1);
|
||||
|
||||
uint32_t start = millis();
|
||||
for (int x = 0; x <= 1000; x++)
|
||||
{
|
||||
{
|
||||
Serial.print(x);
|
||||
Serial.write('\t');
|
||||
for (int16_t i = NR - 1; i >= 0; i--)
|
||||
{
|
||||
uint32_t t = a.get(i);
|
||||
if (t < 100) Serial.write('0');
|
||||
if (t < 10) Serial.write('0');
|
||||
Serial.print(t);
|
||||
}
|
||||
Serial.write('\n');
|
||||
}
|
||||
add();
|
||||
}
|
||||
Serial.println(millis() - start);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{}
|
||||
|
||||
// add numbers in groups of 3 digits
|
||||
void add()
|
||||
{
|
||||
uint8_t carry = 0;
|
||||
|
||||
for (uint16_t i = 0; i <= NR; i++)
|
||||
{
|
||||
uint16_t ta = a.get(i);
|
||||
uint16_t tb = b.get(i);
|
||||
|
||||
// if there is nothing to add, skip column
|
||||
if (ta == 0 && tb == 0 && carry == 0) continue;
|
||||
|
||||
// do the add
|
||||
uint16_t tc = ta + tb + carry;
|
||||
// does column overflow? then correct
|
||||
if (tc > 999)
|
||||
{
|
||||
tc -= 1000;
|
||||
carry = 1; // carry for next column
|
||||
}
|
||||
else carry = 0;
|
||||
b.set(i, tc);
|
||||
a.set(i, tb);
|
||||
}
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "BitArray",
|
||||
"keywords": "Bit,Array,Boolean,bool",
|
||||
"description": "Library to make a compact array of objects with a size expressed in bits. typically 1..10",
|
||||
"description": "Arduino library for compact array of objects with a size expressed in bits. typically 1..10",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
@ -13,12 +13,9 @@
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Arduino.git"
|
||||
"url": "https://github.com/RobTillaart/BitArray.git"
|
||||
},
|
||||
"version":"0.1.8",
|
||||
"version":"0.2.0",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"export": {
|
||||
"include": "libraries/BitArray"
|
||||
}
|
||||
"platforms": "*"
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
name=BitArray
|
||||
version=0.1.8
|
||||
version=0.2.1
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library to make a compact array of objects with a size expressed in bits. typically 1..10
|
||||
paragraph=
|
||||
sentence=Arduino library for compact array of objects with a size expressed in bits.
|
||||
paragraph=Sizes are typically 1..10
|
||||
category=Data Processing
|
||||
url=https://github.com/RobTillaart/Arduino/tree/master/libraries/
|
||||
url=https://github.com/RobTillaart/BitArray
|
||||
architectures=*
|
||||
includes=BitArray.h
|
||||
depends=
|
||||
depends=
|
||||
|
@ -1,13 +1,14 @@
|
||||
//
|
||||
// FILE: BoolArray.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.3
|
||||
// VERSION: 0.2.1
|
||||
// PURPOSE: BoolArray library for Arduino
|
||||
// URL: http://forum.arduino.cc/index.php?topic=361167
|
||||
// URL: https://github.com/RobTillaart/BoolArray.git
|
||||
// http://forum.arduino.cc/index.php?topic=361167
|
||||
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
// 0.2.1 2020-06-05 FIx library.json
|
||||
// 0.2.0 2020-03-29 #pragma, readme.md,
|
||||
// 0.1.4 2017-07-16 added masks for performance
|
||||
// 0.1.3 - added toggle
|
||||
// 0.1.02 - added errorhandling
|
||||
// 0.1.01 - fixed constructor - Thanks WPD64 + error handling
|
||||
@ -42,8 +43,7 @@ uint8_t BoolArray::get(const uint16_t idx)
|
||||
if (idx >= _size) return BOOLARRAY_SIZE_ERROR;
|
||||
uint8_t by = idx / 8;
|
||||
uint8_t bi = idx & 7;
|
||||
uint8_t mask = 1 << bi;
|
||||
return (_ar[by] & mask) > 0;
|
||||
return (_ar[by] & masks[bi]) > 0;
|
||||
}
|
||||
|
||||
uint8_t BoolArray::set(const uint16_t idx, const uint8_t value)
|
||||
@ -52,9 +52,8 @@ uint8_t BoolArray::set(const uint16_t idx, const uint8_t value)
|
||||
if (idx >= _size) return BOOLARRAY_SIZE_ERROR;
|
||||
uint8_t by = idx / 8;
|
||||
uint8_t bi = idx & 7;
|
||||
uint8_t mask = 1 << bi;
|
||||
if (value == 0) _ar[by] &= ~mask;
|
||||
else _ar[by] |= mask;
|
||||
if (value == 0) _ar[by] &= ~masks[bi];
|
||||
else _ar[by] |= masks[bi];
|
||||
return BOOLARRAY_OK;
|
||||
}
|
||||
|
||||
@ -64,27 +63,25 @@ uint8_t BoolArray::toggle(const uint16_t idx)
|
||||
if (idx >= _size) return BOOLARRAY_SIZE_ERROR;
|
||||
uint8_t by = idx / 8;
|
||||
uint8_t bi = idx & 7;
|
||||
uint8_t mask = 1 << bi;
|
||||
_ar[by] ^= mask;
|
||||
_ar[by] ^= masks[bi];
|
||||
return BOOLARRAY_OK;
|
||||
}
|
||||
|
||||
uint8_t BoolArray::clear()
|
||||
{
|
||||
return setAll(0);
|
||||
}
|
||||
|
||||
// 32 bit is even faster,
|
||||
uint8_t BoolArray::setAll(const uint8_t value)
|
||||
{
|
||||
if (_ar == NULL) return BOOLARRAY_INIT_ERROR;
|
||||
uint8_t *p = _ar;
|
||||
uint8_t t = (_size + 7) / 8;
|
||||
uint8_t v = value?255:0;
|
||||
while(t--)
|
||||
uint16_t *p = (uint16_t *)_ar;
|
||||
uint8_t t = (_size + 15) / 16;
|
||||
if (value == 0)
|
||||
{
|
||||
*p++ = v;
|
||||
while(t--) *p++ = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
while(t--) *p++ = 0xFFFF; // set 16 bits at once
|
||||
}
|
||||
return BOOLARRAY_OK;
|
||||
}
|
||||
|
||||
// END OF FILE
|
||||
// -- END OF FILE --
|
||||
|
@ -1,25 +1,18 @@
|
||||
#ifndef BoolArray_H
|
||||
#define BoolArray_H
|
||||
#pragma once
|
||||
//
|
||||
// FILE: BoolArray.h
|
||||
// AUTHOR: Rob dot Tillaart at gmail dot com
|
||||
// VERSION: 0.1.3
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.1
|
||||
// PURPOSE: BoolArray library for Arduino
|
||||
// HISTORY: See BoolArray.cpp
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
// URL: https://github.com/RobTillaart/BoolArray.git
|
||||
|
||||
// BoolArray implement a compact array of booleans of max size 2000.
|
||||
// For larger arrays one need to modify the code, or use BitArray.
|
||||
//
|
||||
// Tested on AVR only
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#define BOOLARRAY_LIB_VERSION "0.1.3"
|
||||
#define BOOLARRAY_LIB_VERSION "0.2.0"
|
||||
#define BOOLARRAY_MAXSIZE (250*8)
|
||||
#define BOOLARRAY_OK 0x00
|
||||
#define BOOLARRAY_ERROR 0xFF
|
||||
@ -32,16 +25,19 @@ public:
|
||||
BoolArray();
|
||||
~BoolArray();
|
||||
|
||||
uint8_t begin(const uint16_t size);
|
||||
uint8_t clear();
|
||||
uint8_t setAll(const uint8_t value);
|
||||
uint8_t get(const uint16_t idx);
|
||||
uint8_t set(const uint16_t idx, const uint8_t value);
|
||||
uint8_t toggle(const uint16_t idx);
|
||||
uint8_t begin(const uint16_t size);
|
||||
uint8_t setAll(const uint8_t value);
|
||||
uint8_t clear() { return setAll(0); };
|
||||
uint16_t size() { return _size; };
|
||||
|
||||
uint8_t get(const uint16_t idx);
|
||||
uint8_t set(const uint16_t idx, const uint8_t value);
|
||||
uint8_t toggle(const uint16_t idx);
|
||||
|
||||
private:
|
||||
uint8_t masks[8] = {1,2,4,8,16,32,64,128};
|
||||
uint8_t * _ar;
|
||||
uint16_t _size;
|
||||
};
|
||||
|
||||
#endif
|
||||
// -- END OF FILE --
|
||||
|
21
libraries/BoolArray/LICENSE
Normal file
21
libraries/BoolArray/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2015-2020 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
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
38
libraries/BoolArray/README.md
Normal file
38
libraries/BoolArray/README.md
Normal file
@ -0,0 +1,38 @@
|
||||
|
||||
# BoolArray
|
||||
Arduino library for compact array of booleans of max size 2000 (UNO).
|
||||
|
||||
## Description
|
||||
The BoolArray class allows the user to instantiate an array of booleans, allocating only one bit per element.
|
||||
For example one could create an array of 1000 throws with a coin. Normally this would take 1000 bytes,
|
||||
but BoolArray can store one throw in 1 bit, so 1000 throws in approx 125 bytes.
|
||||
|
||||
The class is optimized for storage by packing 8 elements of the array in one byte.
|
||||
You need to check if your application needs more performance than this library can deliver.
|
||||
|
||||
The BoolArray library is one from a set of three:
|
||||
* BitArray for elements of user defined size in bits (values 0 .. 2^n-1)
|
||||
* BoolArray for elements of 1 bit (values 0 .. 1)
|
||||
* nybbleArray for elements of 4 bits (values 0 .. 15)
|
||||
|
||||
BoolArray is faster than BitArray as it only supports single bits and does not need to merge parts
|
||||
of different bytes to read/write a value. However BoolArray currently only supports 2000 bits while
|
||||
BitArray can support more.
|
||||
|
||||
## Operations
|
||||
In the function **begin(#elements)** the number of elements needs to be defined.
|
||||
|
||||
The basic functions of the class are
|
||||
* **set(index, value)**
|
||||
* **get(index)**
|
||||
* **toggle(index)**
|
||||
* **clear()**
|
||||
|
||||
Check out the examples.
|
||||
|
||||
## Notes
|
||||
The BoolArray class dynamicly allocates memory.
|
||||
The **BOOLARRAY_MAXSIZE** is set to 2000, this was chosen as **malloc()** can only allocate 255 bytes
|
||||
in one call on an UNO. This is not checked with the recent versions of the IDE anymore.
|
||||
|
||||
The library is tested on AVR architecture only.
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: boolArrayDemo2.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.00
|
||||
// VERSION: 0.2.0
|
||||
// PURPOSE: demo performance reading boolean array
|
||||
// DATE: 2015-12-06
|
||||
// URL: https://forum.arduino.cc/index.php?topic=361167.0
|
||||
@ -17,6 +17,8 @@ uint32_t start;
|
||||
uint32_t stop;
|
||||
volatile long x = 0;
|
||||
|
||||
uint32_t duration1, duration2;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -25,47 +27,20 @@ void setup()
|
||||
Serial.print("LIB VERSION:\t");
|
||||
Serial.println(BOOLARRAY_LIB_VERSION);
|
||||
|
||||
b.begin(10000);
|
||||
|
||||
start = micros();
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
x += b.get(i);
|
||||
}
|
||||
stop = micros();
|
||||
Serial.print("DURATION:\t");
|
||||
Serial.println(stop - start);
|
||||
int rv = b.begin(BOOLARRAY_MAXSIZE);
|
||||
Serial.print("SIZE:\t");
|
||||
Serial.println(b.size());
|
||||
|
||||
start = micros();
|
||||
for (int i = 0; i < 10000; i++)
|
||||
if (rv != BOOLARRAY_OK)
|
||||
{
|
||||
x += b.get(i);
|
||||
x += b.get(i);
|
||||
Serial.println("Boolarray alloc error");
|
||||
while (1);
|
||||
}
|
||||
stop = micros();
|
||||
Serial.print("DURATION:\t");
|
||||
Serial.println(stop - start);
|
||||
Serial.print(" X:\t");
|
||||
Serial.println(x);
|
||||
|
||||
start = micros();
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
b.set(i, 0);
|
||||
}
|
||||
stop = micros();
|
||||
Serial.print("DURATION:\t");
|
||||
Serial.println(stop - start);
|
||||
|
||||
start = micros();
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
b.set(i, 0);
|
||||
b.set(i, 0);
|
||||
}
|
||||
stop = micros();
|
||||
Serial.print("DURATION:\t");
|
||||
Serial.println(stop - start);
|
||||
test0();
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
|
||||
Serial.println("Done...");
|
||||
}
|
||||
@ -73,3 +48,122 @@ void setup()
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
void test0()
|
||||
{
|
||||
Serial.println();
|
||||
Serial.println("SET TEST0");
|
||||
|
||||
start = micros();
|
||||
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
|
||||
{
|
||||
b.set(i, 1);
|
||||
}
|
||||
duration1 = micros() - start;
|
||||
Serial.print("DURATION:\t");
|
||||
Serial.println(duration1);
|
||||
|
||||
start = micros();
|
||||
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
|
||||
{
|
||||
b.set(i, 1);
|
||||
b.set(i, 1);
|
||||
}
|
||||
duration2 = micros() - start;
|
||||
Serial.print("DURATION:\t");
|
||||
Serial.println(duration2);
|
||||
Serial.print("\t\t\t");
|
||||
Serial.println(duration2 - duration1);
|
||||
Serial.print(" X:\t");
|
||||
Serial.println(x);
|
||||
}
|
||||
|
||||
void test1()
|
||||
{
|
||||
Serial.println();
|
||||
Serial.println("SET TEST0");
|
||||
|
||||
start = micros();
|
||||
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
|
||||
{
|
||||
b.set(i, 0);
|
||||
}
|
||||
duration1 = micros() - start;
|
||||
Serial.print("DURATION:\t");
|
||||
Serial.println(duration1);
|
||||
|
||||
start = micros();
|
||||
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
|
||||
{
|
||||
b.set(i, 0);
|
||||
b.set(i, 0);
|
||||
}
|
||||
duration2 = micros() - start;
|
||||
Serial.print("DURATION:\t");
|
||||
Serial.println(duration2);
|
||||
Serial.print("\t\t\t");
|
||||
Serial.println(duration2 - duration1);
|
||||
Serial.print(" X:\t");
|
||||
Serial.println(x);
|
||||
}
|
||||
|
||||
void test2()
|
||||
{
|
||||
Serial.println();
|
||||
Serial.println("GET TEST");
|
||||
|
||||
start = micros();
|
||||
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
|
||||
{
|
||||
x += b.get(i);
|
||||
}
|
||||
duration1 = micros() - start;
|
||||
Serial.print("DURATION:\t");
|
||||
Serial.println(duration1);
|
||||
|
||||
start = micros();
|
||||
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
|
||||
{
|
||||
x += b.get(i);
|
||||
x += b.get(i);
|
||||
}
|
||||
duration2 = micros() - start;
|
||||
Serial.print("DURATION:\t");
|
||||
Serial.println(duration2);
|
||||
Serial.print("\t\t\t");
|
||||
Serial.println(duration2 - duration1);
|
||||
Serial.print(" X:\t");
|
||||
Serial.println(x);
|
||||
}
|
||||
|
||||
|
||||
void test3()
|
||||
{
|
||||
Serial.println();
|
||||
Serial.println("SET TEST");
|
||||
|
||||
start = micros();
|
||||
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
|
||||
{
|
||||
b.set(i, 0);
|
||||
}
|
||||
duration1 = micros();
|
||||
Serial.print("DURATION:\t");
|
||||
Serial.println(duration1);
|
||||
|
||||
start = micros();
|
||||
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
|
||||
{
|
||||
b.set(i, 0);
|
||||
b.set(i, 0);
|
||||
}
|
||||
duration2 = micros();
|
||||
Serial.print("DURATION:\t");
|
||||
Serial.println(duration2);
|
||||
Serial.print("\t\t\t");
|
||||
Serial.println(duration2 - duration1);
|
||||
Serial.print(" X:\t");
|
||||
Serial.println(x);
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -28,6 +28,9 @@ void setup()
|
||||
|
||||
b.begin(1000);
|
||||
|
||||
Serial.print("Bool array size:\t");
|
||||
Serial.println(b.size());
|
||||
|
||||
Serial.println("\nget");
|
||||
start = micros();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
@ -100,6 +103,11 @@ void setup()
|
||||
Serial.print("DURATION:\t");
|
||||
Serial.println(stop - start);
|
||||
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
if (b.get(i) == 0) Serial.println("Error in CLr()");
|
||||
}
|
||||
|
||||
start = micros();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
|
@ -0,0 +1,25 @@
|
||||
Start D:\Rob\WORK\Arduino\libraries\BoolArray\examples\boolArrayDemo2\boolArrayDemo2.ino
|
||||
BOOLARRAY_LIB_VERSION: 0.2.0
|
||||
Bool array size: 1000
|
||||
|
||||
get
|
||||
DURATION: 5652
|
||||
DURATION: 9960
|
||||
X: 0
|
||||
|
||||
set
|
||||
DURATION: 4180
|
||||
DURATION: 7572
|
||||
|
||||
clear
|
||||
DURATION: 31140
|
||||
DURATION: 61844
|
||||
|
||||
setAll
|
||||
DURATION: 35248
|
||||
DURATION: 69916
|
||||
|
||||
toggle
|
||||
DURATION: 3988
|
||||
DURATION: 7320
|
||||
Done...
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "BoolArray",
|
||||
"keywords": "Bool,Boolean,array,compact,compressed",
|
||||
"description": "Library to implement a compact array of booleans of max size 2000.",
|
||||
"description": "Arduino library for compact array of booleans of max size 2000 (UNO).",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
@ -13,12 +13,9 @@
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Arduino.git"
|
||||
"url": "https://github.com/RobTillaart/BoolArray.git"
|
||||
},
|
||||
"version":"0.1.3",
|
||||
"version":"0.2.0",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"export": {
|
||||
"include": "libraries/BoolArray"
|
||||
}
|
||||
"platforms": "*"
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
name=BoolArray
|
||||
version=0.1.3
|
||||
version=0.2.1
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library to implement a compact array of booleans of max size 2000.
|
||||
paragraph=
|
||||
sentence=Arduino library for compact array of booleans of max size 2000 (UNO).
|
||||
paragraph=tested on AVR only
|
||||
category=Data Processing
|
||||
url=https://github.com/RobTillaart/Arduino/tree/master/libraries
|
||||
architectures=*
|
||||
includes=BoolArray.h
|
||||
depends=
|
||||
depends=
|
21
libraries/Complex/LICENSE
Normal file
21
libraries/Complex/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2013-2020 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
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
28
libraries/Complex/README.md
Normal file
28
libraries/Complex/README.md
Normal file
@ -0,0 +1,28 @@
|
||||
# Complex
|
||||
|
||||
Arduino library for Complex math
|
||||
|
||||
## Description
|
||||
|
||||
This library defines the complex datatype and all the common math functions for it.
|
||||
|
||||
These functions include basic = - \* / but also power and gonio functions.
|
||||
|
||||
See Complex.h for all functions implemented.
|
||||
|
||||
|
||||
## Note
|
||||
The library has a big footprint so it fills up the memory of an UNO quite fast.
|
||||
|
||||
Issue found in version 0.1.9 - https://github.com/RobTillaart/Arduino/issues/90
|
||||
Class does not compile for DUE and TEENSY
|
||||
|
||||
Apparently the name "Complex" is already in use (reserved) by some non-AVR compilers
|
||||
so it won't include the Complex.h file. Problem seen on Due and Teensy3.5
|
||||
|
||||
Solution:
|
||||
- Make a copy of the Complex Library and rename the folder to CComplex
|
||||
- Rename Complex.h to CComplex.h
|
||||
- Rename Complex.cpp to CComplec.cpp
|
||||
- change one line in CComplex.cpp to include CComplex.h
|
||||
|
@ -1,12 +1,13 @@
|
||||
//
|
||||
// FILE: Complex.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.12
|
||||
// PURPOSE: library for Complex math for Arduino
|
||||
// URL: http://arduino.cc/playground/Main/ComplexMath
|
||||
//
|
||||
// Released to the public domain
|
||||
// VERSION: 0.2.1
|
||||
// PURPOSE: Arduino library for Complex math
|
||||
// URL: https://github.com/RobTillaart/Complex
|
||||
// http://arduino.cc/playground/Main/ComplexMath
|
||||
//
|
||||
// 0.2.1 2020-06-05 fix library.json
|
||||
// 0.2.0 2020-03-29 #pragma once, own repo
|
||||
// 0.1.12 - 2018-04-02 - fix issue #33 double -> float
|
||||
// 0.1.11 - 2018-01-29 - fix sin and cos formula - issue #91
|
||||
// 0.1.10 - 2018-01-15 - uppercase #define COMPLEX_H
|
||||
@ -14,7 +15,7 @@
|
||||
// 0.1.08 - 2015-06-03 - refactor
|
||||
// 0.1.07 - 2015-06-03 - refactor interfaces
|
||||
|
||||
#include "complex.h"
|
||||
#include "Complex.h"
|
||||
|
||||
// PRINTING
|
||||
size_t Complex::printTo(Print& p) const
|
||||
|
@ -1,26 +1,22 @@
|
||||
#pragma once
|
||||
//
|
||||
// FILE: Complex.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.12
|
||||
// PURPOSE: library for Complex math for Arduino
|
||||
// URL: http://arduino.cc/playground/Main/ComplexMath
|
||||
// VERSION: 0.2.1
|
||||
// PURPOSE: Arduino library for Complex math
|
||||
// URL: https://github.com/RobTillaart/Complex
|
||||
// http://arduino.cc/playground/Main/ComplexMath
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
#ifndef COMPLEX_H
|
||||
#define COMPLEX_H
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#include "Printable.h"
|
||||
|
||||
#define COMPLEX_LIB_VERSION "0.1.12"
|
||||
#define COMPLEX_LIB_VERSION "0.2.1"
|
||||
|
||||
class Complex: public Printable
|
||||
{
|
||||
public:
|
||||
Complex(const float r=0, const float i=0) : re(r), im(i) {};
|
||||
Complex(const float r = 0, const float i = 0) : re(r), im(i) {};
|
||||
Complex(const Complex &c) : re(c.re), im(c.im) {};
|
||||
|
||||
void set(const float r, const float i ) { re = r; im = i; };
|
||||
@ -97,5 +93,4 @@ protected:
|
||||
|
||||
static Complex one(1, 0);
|
||||
|
||||
#endif
|
||||
// --- END OF FILE ---
|
||||
// -- END OF FILE --
|
||||
|
110
libraries/Complex/examples/complex/referenceOutput_0.2.0.txt
Normal file
110
libraries/Complex/examples/complex/referenceOutput_0.2.0.txt
Normal file
@ -0,0 +1,110 @@
|
||||
Complex numbers test for Arduino: 0.2.0
|
||||
|
||||
1. Print Complex, set, real, imag
|
||||
1.000 0.000i
|
||||
10.000 -2.000i
|
||||
3.000 0.000i
|
||||
-10.000 4.000i
|
||||
-5.000 -5.000i
|
||||
0.000 0.000i
|
||||
0.00
|
||||
0.00
|
||||
|
||||
2. == !=
|
||||
ok :)
|
||||
ok :)
|
||||
ok :)
|
||||
|
||||
3. negation -
|
||||
-10.000 2.000i
|
||||
10.000 -2.000i
|
||||
ok :)
|
||||
|
||||
4. + -
|
||||
13.000 -2.000i
|
||||
13.000 -2.000i
|
||||
7.000 -2.000i
|
||||
7.000 -2.000i
|
||||
|
||||
5. * /
|
||||
30.000 -6.000i
|
||||
90.000 -18.000i
|
||||
30.000 -6.000i
|
||||
10.000 -2.000i
|
||||
10.000 -2.000i
|
||||
10.000 -2.000i
|
||||
|
||||
6. assign += -= *= /=
|
||||
20.000 -4.000i
|
||||
23.000 -4.000i
|
||||
13.000 -2.000i
|
||||
10.000 -2.000i
|
||||
96.000 -40.000i
|
||||
288.000 -120.000i
|
||||
30.000 -6.000i
|
||||
10.000 -2.000i
|
||||
|
||||
7. phase modulus polar
|
||||
10.000 -2.000i
|
||||
10.20
|
||||
-0.20
|
||||
10.000 -2.000i
|
||||
|
||||
8. conjugate reciprocal
|
||||
10.000 2.000i
|
||||
10.000 -2.000i
|
||||
0.096 0.019i
|
||||
10.000 -2.000i
|
||||
|
||||
9. power: exp log pow sqrt sqr logn log10
|
||||
96.000 -40.000i
|
||||
-9166.239 -20028.597i
|
||||
10.000 -2.000i
|
||||
96.000 -40.000i
|
||||
10.000 -2.000i
|
||||
96.000 -40.000i
|
||||
880.000 -592.000i
|
||||
10.000 -2.000i
|
||||
0.534 0.542i
|
||||
10.000 -2.000i
|
||||
1.009 -0.086i
|
||||
|
||||
10. gonio: sin cos tan asin acos atan
|
||||
0.541 0.457i
|
||||
0.500 0.500i
|
||||
0.990 -0.250i
|
||||
0.500 0.500i
|
||||
0.404 0.564i
|
||||
0.500 0.500i
|
||||
|
||||
11. gonio csc sec cot acsc asec acot
|
||||
1.078 -0.912i
|
||||
0.500 0.500i
|
||||
0.950 0.240i
|
||||
0.500 0.500i
|
||||
0.839 -1.172i
|
||||
0.500 0.500i
|
||||
|
||||
12. gonio hyperbolicus I
|
||||
0.457 0.541i
|
||||
0.500 0.500i
|
||||
0.990 0.250i
|
||||
0.500 0.500i
|
||||
0.564 0.404i
|
||||
0.500 0.500i
|
||||
|
||||
13. gonio hyperbolicus II
|
||||
0.912 -1.078i
|
||||
0.500 0.500i
|
||||
0.950 -0.240i
|
||||
0.500 0.500i
|
||||
1.172 -0.839i
|
||||
0.500 0.500i
|
||||
|
||||
14. gonio bug fix (minimal) test
|
||||
3.000 4.000i
|
||||
1.000 0.000i
|
||||
|
||||
.. Complex done
|
||||
521964
|
||||
1.000 0.000i
|
@ -0,0 +1,66 @@
|
||||
Complex numbers performance test for Arduino: 0.2.0
|
||||
|
||||
5 constructors 12
|
||||
set(0,0) 4
|
||||
c1 + 1 2024
|
||||
c1 + c2 2036
|
||||
+= c2 1616
|
||||
c5 = -c1 692
|
||||
c1 - 3 1440
|
||||
c1 - c2 2112
|
||||
c5 -= c2 1552
|
||||
c1 * 3 5728
|
||||
c1 * c2 5592
|
||||
c5 *= c2 4408
|
||||
c1 / 3 12356
|
||||
c1 / c2 12232
|
||||
c5 /= c2 6336
|
||||
|
||||
real() 4
|
||||
imag() 4
|
||||
modulus() 6000
|
||||
phase 204
|
||||
polar() 260
|
||||
conjugate() 676
|
||||
reciprocal(); 8160
|
||||
|
||||
c_sqr() 4672
|
||||
c_exp() 42588
|
||||
c_log() 39628
|
||||
c_pow(2) 88384
|
||||
c_sqrt() 8520
|
||||
c_logn(c4) 72644
|
||||
c_pow(c5) 61896
|
||||
c_log10() 40776
|
||||
|
||||
c_sin() 57968
|
||||
c_asin() 75552
|
||||
c_cos() 58076
|
||||
c_acos() 73968
|
||||
c_tan() 129156
|
||||
c_atan() 66864
|
||||
|
||||
c_csc() 70372
|
||||
c_acsc() 85828
|
||||
c_sec() 70412
|
||||
c_asec() 87528
|
||||
c_cot() 141652
|
||||
c_acot() 74420
|
||||
|
||||
c_sinh() 57964
|
||||
c_asinh() 64612
|
||||
c_cosh() 58060
|
||||
c_acosh() 62200
|
||||
c_tanh() 129148
|
||||
c_atanh() 91388
|
||||
|
||||
c_csch() 70452
|
||||
c_acsch() 66464
|
||||
c_sech() 70420
|
||||
c_asech() 77548
|
||||
c_coth() 141584
|
||||
c_acoth() 98544
|
||||
|
||||
2337184
|
||||
|
||||
.. Complex done
|
@ -13,12 +13,9 @@
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Arduino.git"
|
||||
"url": "https://github.com/RobTillaart/Complex.git"
|
||||
},
|
||||
"version":"0.1.12",
|
||||
"version":"0.2.1",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"export": {
|
||||
"include": "libraries/Complex"
|
||||
}
|
||||
"platforms": "*"
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
name=Complex
|
||||
version=0.1.12
|
||||
version=0.2.1
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library for Complex math.
|
||||
sentence=Arduino library for Complex math.
|
||||
paragraph=
|
||||
category=Data Processing
|
||||
url=https://github.com/RobTillaart/Arduino/tree/master/libraries
|
||||
architectures=*
|
||||
url=https://github.com/RobTillaart/Complex
|
||||
architectures=*
|
||||
includes=Complex.h
|
||||
depends=
|
||||
|
@ -1,10 +1,11 @@
|
||||
//
|
||||
// FILE: Correlation.cpp
|
||||
// AUTHOR: Rob dot Tillaart at gmail dot com
|
||||
// VERSION: 0.1.0
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: Arduino Library to determine correlation between X and Y dataset
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.1 2020-06-05 fix library.json
|
||||
// 0.1.0 2020-05-17 initial version
|
||||
//
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: Correlation.h
|
||||
// AUTHOR: Rob dot Tillaart at gmail dot com
|
||||
// VERSION: 0.1.0
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: Calculate Correlation from a small dataset.
|
||||
// HISTORY: See Correlation.cpp
|
||||
//
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user