From a19ec7f0253c69f6ecf30c7ce2bd0a9fb5357d96 Mon Sep 17 00:00:00 2001 From: rob tillaart Date: Fri, 27 Nov 2020 11:10:47 +0100 Subject: [PATCH] update libraries A-D --- README.md | 8 +- libraries/ACS712/ACS712.cpp | 64 +++- libraries/ACS712/ACS712.h | 19 +- libraries/ACS712/LICENSE | 21 ++ .../examples/ACS712_20_AC/ACS712_20_AC.ino | 13 +- .../ACS712_20_AC_DEMO/ACS712_20_AC_DEMO.ino | 3 + .../examples/ACS712_20_DC/ACS712_20_DC.ino | 3 + .../ACS712_20_DC_DEMO/ACS712_20_DC_DEMO.ino | 3 + libraries/ACS712/library.json | 15 +- libraries/ACS712/library.properties | 12 +- libraries/ACS712/readme.md | 50 ++- libraries/AD524X/AD524X.cpp | 8 +- libraries/AD524X/AD524X.h | 23 +- libraries/AD524X/library.json | 11 +- libraries/AD524X/library.properties | 10 +- libraries/AM232X/AM232X.cpp | 8 +- libraries/AM232X/AM232X.h | 10 +- libraries/AM232X/library.json | 7 +- libraries/AM232X/library.properties | 2 +- libraries/AnalogKeypad/AnalogKeypad.cpp | 20 +- libraries/AnalogKeypad/AnalogKeypad.h | 17 +- libraries/AnalogKeypad/LICENSE | 21 ++ libraries/AnalogKeypad/README.md | 31 ++ libraries/AnalogKeypad/keywords.txt | 13 - libraries/AnalogKeypad/library.json | 13 +- libraries/AnalogKeypad/library.properties | 12 +- libraries/AnalogPin/AnalogPin.cpp | 60 ++-- libraries/AnalogPin/AnalogPin.h | 59 ++-- libraries/AnalogPin/LICENSE | 21 ++ libraries/AnalogPin/README.md | 54 ++++ .../examples/AnalogPin/AnalogPin.ino | 85 +++++- .../AnalogPin_prescaler.ino | 49 +++ libraries/AnalogPin/library.json | 9 +- libraries/AnalogPin/library.properties | 8 +- libraries/Angle/Angle.cpp | 13 +- libraries/Angle/Angle.h | 20 +- libraries/Angle/LICENSE | 21 ++ libraries/Angle/README.md | 27 ++ libraries/Angle/library.json | 14 +- libraries/Angle/library.properties | 8 +- libraries/AverageAngle/AverageAngle.cpp | 18 +- libraries/AverageAngle/AverageAngle.h | 33 +- libraries/AverageAngle/LICENSE | 21 ++ libraries/AverageAngle/README.md | 49 +++ .../examples/AverageAngle2/AverageAngle2.ino | 285 ++++++++++++++++++ libraries/AverageAngle/library.json | 9 +- libraries/AverageAngle/library.properties | 10 +- libraries/AvrHeap/LICENSE | 21 ++ libraries/AvrHeap/README.md | 12 + libraries/AvrHeap/avrheap.cpp | 19 +- libraries/AvrHeap/avrheap.h | 24 +- .../AvrHeap/examples/heapdemo/heapdemo.ino | 91 ++++++ .../AvrHeap/examples/heapdemo2/heapdemo2.ino | 4 +- libraries/AvrHeap/library.json | 11 +- libraries/AvrHeap/library.properties | 10 +- libraries/BH1750FVI/BH1750FVI.cpp | 230 +++++++++++--- libraries/BH1750FVI/BH1750FVI.h | 148 +++++---- libraries/BH1750FVI/LICENSE | 21 ++ .../BH1750FVI_angle_measurement.ino | 94 ++++++ .../experimental.txt | 18 ++ .../BH1750FVI_async/BH1750FVI_async.ino | 65 ++++ .../BH1750FVI_cont_high_res.ino | 9 +- .../BH1750FVI_cont_low_res.ino | 4 +- .../BH1750FVI_setAngle/BH1750FVI_setAngle.ino | 43 +++ .../BH1750FVI_setCorrectionFactor.ino | 22 +- .../BH1750FVI_setTemperature.ino | 44 +++ .../BH1750FVI_setWaveLength.ino | 47 +++ .../BH1750FVI_single_shot_3_res.ino | 64 ++++ libraries/BH1750FVI/keywords.txt | 35 ++- libraries/BH1750FVI/library.json | 15 +- libraries/BH1750FVI/library.properties | 14 +- libraries/BH1750FVI/readme.md | 151 +++++++++- libraries/BitArray/BitArray.cpp | 58 +++- libraries/BitArray/BitArray.h | 32 +- libraries/BitArray/LICENSE | 21 ++ libraries/BitArray/README.md | 41 +++ .../examples/bitArrayDemo3/performance_1.8.0 | 86 ++++++ .../examples/bitArrayDemo3/performance_1.9.0 | 86 ++++++ .../BitArray/examples/fibonacci/fibonacci.ino | 82 +++++ libraries/BitArray/library.json | 11 +- libraries/BitArray/library.properties | 10 +- libraries/BoolArray/BoolArray.cpp | 43 ++- libraries/BoolArray/BoolArray.h | 38 ++- libraries/BoolArray/LICENSE | 21 ++ libraries/BoolArray/README.md | 38 +++ .../boolArrayDemo0/boolArrayDemo0.ino | 170 ++++++++--- .../boolArrayDemo2/boolArrayDemo2.ino | 8 + .../boolArrayDemo2/performance_0.2.0.txt | 25 ++ libraries/BoolArray/library.json | 11 +- libraries/BoolArray/library.properties | 8 +- libraries/Complex/LICENSE | 21 ++ libraries/Complex/README.md | 28 ++ libraries/Complex/complex.cpp | 13 +- libraries/Complex/complex.h | 21 +- .../complex/referenceOutput_0.2.0.txt | 110 +++++++ .../performance/preformanceOutput_0.2.0.txt | 66 ++++ libraries/Complex/library.json | 9 +- libraries/Complex/library.properties | 10 +- libraries/Correlation/Correlation.cpp | 3 +- libraries/Correlation/Correlation.h | 2 +- libraries/Correlation/library.json | 7 +- libraries/Correlation/library.properties | 2 +- libraries/CountDown/CountDown.cpp | 79 +++-- libraries/CountDown/CountDown.h | 41 ++- libraries/CountDown/LICENSE | 21 ++ libraries/CountDown/README.md | 53 ++++ .../countdown_demo1/countdown_demo1.ino | 41 ++- .../countdown_demo2/countdown_demo2.ino | 63 ++-- .../examples/demo_DHMS/demo_DHMS.ino | 2 +- libraries/CountDown/library.json | 13 +- libraries/CountDown/library.properties | 12 +- libraries/Cozir/LICENSE | 21 ++ libraries/Cozir/README.md | 25 ++ libraries/Cozir/cozir.cpp | 120 ++++---- libraries/Cozir/cozir.h | 111 ++++--- .../CozirDemoHWSerial/CozirDemoHWSerial.ino | 46 +++ .../CozirDemoSWSerial/CozirDemoSWSerial.ino | 45 +++ libraries/Cozir/library.json | 13 +- libraries/Cozir/library.properties | 14 +- libraries/DAC8551/DAC8551.cpp | 22 +- libraries/DAC8551/DAC8551.h | 19 +- libraries/DAC8551/LICENSE | 21 ++ libraries/DAC8551/README.md | 25 ++ .../DAC8551_hw_spi/DAC8551_hw_spi.ino | 15 +- .../DAC8551_powerdown/DAC8551_powerdown.ino | 9 +- .../DAC8551_sw_spi/DAC8551_sw_spi.ino | 15 +- libraries/DAC8551/library.json | 13 +- libraries/DAC8551/library.properties | 12 +- libraries/DAC8552/DAC8552.cpp | 26 +- libraries/DAC8552/DAC8552.h | 15 +- libraries/DAC8552/LICENSE | 21 ++ libraries/DAC8552/README.md | 31 ++ .../DAC8552_hw_spi/DAC8552_hw_spi.ino | 14 +- .../DAC8552_powerdown/DAC8552_powerdown.ino | 9 +- .../DAC8552_same_time_write.ino | 9 +- .../DAC8552_sequential_write.ino | 9 +- .../DAC8552_sw_spi/DAC8552_sw_spi.ino | 13 +- libraries/DAC8552/library.json | 13 +- libraries/DAC8552/library.properties | 10 +- libraries/DAC8554/DAC8554.cpp | 21 +- libraries/DAC8554/DAC8554.h | 18 +- libraries/DAC8554/LICENSE | 21 ++ libraries/DAC8554/README.md | 31 ++ .../DAC8554_broadcast/DAC8554_broadcast.ino | 11 +- .../DAC8554_hw_spi/DAC8554_hw_spi.ino | 10 +- .../DAC8554_powerdown/DAC8554_powerdown.ino | 10 +- .../DAC8554_same_time_write.ino | 10 +- .../DAC8554_sequential_write.ino | 10 +- .../DAC8554_sw_spi/DAC8554_sw_spi.ino | 10 +- libraries/DAC8554/library.json | 13 +- libraries/DAC8554/library.properties | 12 +- libraries/DHT12/DHT12.cpp | 61 ++-- libraries/DHT12/DHT12.h | 31 +- libraries/DHT12/LICENSE | 21 ++ libraries/DHT12/README.md | 19 ++ libraries/DHT12/examples/DHT12/DHT12.ino | 13 +- .../examples/DHT12_plotter/DHT12_plotter.ino | 32 ++ .../DHT12_test_esp/DHT12_test_esp.ino | 61 ++++ libraries/DHT12/keywords.txt | 13 +- libraries/DHT12/library.json | 13 +- libraries/DHT12/library.properties | 10 +- libraries/DHT2pin/LICENSE | 21 ++ libraries/DHT2pin/dht2pin.cpp | 8 +- libraries/DHT2pin/dht2pin.h | 13 +- .../DHT2pin/examples/dht2pin/dht2pin.ino | 4 +- libraries/DHT2pin/library.json | 9 +- libraries/DHT2pin/library.properties | 10 +- libraries/DHT2pin/readme.md | 27 +- libraries/DHTNEW/dhtnew.cpp | 262 +++++++++++----- libraries/DHTNEW/dhtnew.h | 122 +++++--- .../dhtnew_adaptive_delay.ino | 62 +++- .../examples/dhtnew_array/dhtnew_array.ino | 60 +++- .../dhtnew_endless/dhtnew_endless.ino | 130 ++++++++ .../dhtnew_minimum/dhtnew_minimum.ino | 28 +- .../dhtnew_powerDown/dhtnew_powerDown.ino | 75 +++++ .../dhtnew_pulse_diag/dhtnew_pulse_diag.ino | 179 +++++++++++ .../dhtnew_setReadDelay.ino | 126 ++++++++ .../dhtnew_suppressError.ino | 62 ++++ .../examples/dhtnew_test/dhtnew_test.ino | 64 ++-- .../dhtnew_waitForRead/dhtnew_waitForRead.ino | 44 ++- .../dhtnew_waitForRead_nonBlocking.ino | 95 ++++++ libraries/DHTNEW/keywords.txt | 20 +- libraries/DHTNEW/library.json | 23 +- libraries/DHTNEW/library.properties | 4 +- libraries/DHTNEW/readme.md | 65 +++- libraries/DHTlib/LICENSE | 21 ++ libraries/DHTlib/dht.cpp | 79 +++-- libraries/DHTlib/dht.h | 9 +- .../dht22_test_noIRQ/dht22_test.pde.txt | 95 ++++++ libraries/DHTlib/library.json | 9 +- libraries/DHTlib/library.properties | 10 +- libraries/DHTlib/readme.md | 47 ++- libraries/DHTstable/LICENSE | 21 ++ libraries/DHTstable/dht.cpp | 8 +- libraries/DHTstable/dht.h | 6 +- .../examples/dht11_test/dht11_test.ino | 8 +- .../examples/dht12_test/dht12_test.ino | 8 +- .../examples/dht22_test/dht22_test.ino | 8 +- libraries/DHTstable/keywords.txt | 2 +- libraries/DHTstable/library.json | 9 +- libraries/DHTstable/library.properties | 8 +- libraries/DHTstable/readme.md | 32 +- libraries/DS18B20/DS18B20.cpp | 73 +++-- libraries/DS18B20/DS18B20.h | 37 ++- libraries/DS18B20/LICENSE | 21 ++ .../DS18B20_diagnose/DS18B20_diagnose.ino | 68 +++++ .../DS18B20_getAddress/DS18B20_getAddress.ino | 2 - .../DS18B20_performance.ino | 2 +- .../DS18B20_test_disconnect.ino | 74 +++++ .../examples/oneWireSearch/oneWireSearch.ino | 67 ++++ libraries/DS18B20/keywords.txt | 15 +- libraries/DS18B20/library.json | 11 +- libraries/DS18B20/library.properties | 13 +- libraries/DS18B20/readme.md | 61 ++-- libraries/DS28CM00/DS28CM00.cpp | 61 ++-- libraries/DS28CM00/DS28CM00.h | 26 +- libraries/DS28CM00/LICENSE | 21 ++ libraries/DS28CM00/README.md | 20 ++ .../DS28CM00_test_ESP/DS28CM00_test_ESP.ino | 95 ++++++ libraries/DS28CM00/library.json | 13 +- libraries/DS28CM00/library.properties | 12 +- libraries/DistanceTable/DistanceTable.cpp | 25 +- libraries/DistanceTable/DistanceTable.h | 20 +- libraries/DistanceTable/LICENSE | 21 ++ libraries/DistanceTable/keywords.txt | 17 +- libraries/DistanceTable/library.json | 7 +- libraries/DistanceTable/library.properties | 8 +- libraries/DistanceTable/readme.md | 22 +- 228 files changed, 6104 insertions(+), 1680 deletions(-) create mode 100644 libraries/ACS712/LICENSE create mode 100644 libraries/AnalogKeypad/LICENSE create mode 100644 libraries/AnalogKeypad/README.md create mode 100644 libraries/AnalogPin/LICENSE create mode 100644 libraries/AnalogPin/README.md create mode 100644 libraries/AnalogPin/examples/AnalogPin_prescaler/AnalogPin_prescaler.ino create mode 100644 libraries/Angle/LICENSE create mode 100644 libraries/Angle/README.md create mode 100644 libraries/AverageAngle/LICENSE create mode 100644 libraries/AverageAngle/README.md create mode 100644 libraries/AverageAngle/examples/AverageAngle2/AverageAngle2.ino create mode 100644 libraries/AvrHeap/LICENSE create mode 100644 libraries/AvrHeap/README.md create mode 100644 libraries/AvrHeap/examples/heapdemo/heapdemo.ino create mode 100644 libraries/BH1750FVI/LICENSE create mode 100644 libraries/BH1750FVI/examples/BH1750FVI_angle_measurement/BH1750FVI_angle_measurement.ino create mode 100644 libraries/BH1750FVI/examples/BH1750FVI_angle_measurement/experimental.txt create mode 100644 libraries/BH1750FVI/examples/BH1750FVI_async/BH1750FVI_async.ino create mode 100644 libraries/BH1750FVI/examples/BH1750FVI_setAngle/BH1750FVI_setAngle.ino create mode 100644 libraries/BH1750FVI/examples/BH1750FVI_setTemperature/BH1750FVI_setTemperature.ino create mode 100644 libraries/BH1750FVI/examples/BH1750FVI_setWaveLength/BH1750FVI_setWaveLength.ino create mode 100644 libraries/BH1750FVI/examples/BH1750FVI_single_shot_3_res/BH1750FVI_single_shot_3_res.ino create mode 100644 libraries/BitArray/LICENSE create mode 100644 libraries/BitArray/README.md create mode 100644 libraries/BitArray/examples/bitArrayDemo3/performance_1.8.0 create mode 100644 libraries/BitArray/examples/bitArrayDemo3/performance_1.9.0 create mode 100644 libraries/BitArray/examples/fibonacci/fibonacci.ino create mode 100644 libraries/BoolArray/LICENSE create mode 100644 libraries/BoolArray/README.md create mode 100644 libraries/BoolArray/examples/boolArrayDemo2/performance_0.2.0.txt create mode 100644 libraries/Complex/LICENSE create mode 100644 libraries/Complex/README.md create mode 100644 libraries/Complex/examples/complex/referenceOutput_0.2.0.txt create mode 100644 libraries/Complex/examples/performance/preformanceOutput_0.2.0.txt create mode 100644 libraries/CountDown/LICENSE create mode 100644 libraries/CountDown/README.md create mode 100644 libraries/Cozir/LICENSE create mode 100644 libraries/Cozir/README.md create mode 100644 libraries/Cozir/examples/CozirDemoHWSerial/CozirDemoHWSerial.ino create mode 100644 libraries/Cozir/examples/CozirDemoSWSerial/CozirDemoSWSerial.ino create mode 100644 libraries/DAC8551/LICENSE create mode 100644 libraries/DAC8551/README.md create mode 100644 libraries/DAC8552/LICENSE create mode 100644 libraries/DAC8552/README.md create mode 100644 libraries/DAC8554/LICENSE create mode 100644 libraries/DAC8554/README.md create mode 100644 libraries/DHT12/LICENSE create mode 100644 libraries/DHT12/README.md create mode 100644 libraries/DHT12/examples/DHT12_plotter/DHT12_plotter.ino create mode 100644 libraries/DHT12/examples/DHT12_test_esp/DHT12_test_esp.ino create mode 100644 libraries/DHT2pin/LICENSE create mode 100644 libraries/DHTNEW/examples/dhtnew_endless/dhtnew_endless.ino create mode 100644 libraries/DHTNEW/examples/dhtnew_powerDown/dhtnew_powerDown.ino create mode 100644 libraries/DHTNEW/examples/dhtnew_pulse_diag/dhtnew_pulse_diag.ino create mode 100644 libraries/DHTNEW/examples/dhtnew_setReadDelay/dhtnew_setReadDelay.ino create mode 100644 libraries/DHTNEW/examples/dhtnew_suppressError/dhtnew_suppressError.ino create mode 100644 libraries/DHTNEW/examples/dhtnew_waitForRead_nonBlocking/dhtnew_waitForRead_nonBlocking.ino create mode 100644 libraries/DHTlib/LICENSE create mode 100644 libraries/DHTlib/examples/dht22_test_noIRQ/dht22_test.pde.txt create mode 100644 libraries/DHTstable/LICENSE create mode 100644 libraries/DS18B20/LICENSE create mode 100644 libraries/DS18B20/examples/DS18B20_diagnose/DS18B20_diagnose.ino create mode 100644 libraries/DS18B20/examples/DS18B20_test_disconnect/DS18B20_test_disconnect.ino create mode 100644 libraries/DS18B20/examples/oneWireSearch/oneWireSearch.ino create mode 100644 libraries/DS28CM00/LICENSE create mode 100644 libraries/DS28CM00/README.md create mode 100644 libraries/DS28CM00/examples/DS28CM00_test_ESP/DS28CM00_test_ESP.ino create mode 100644 libraries/DistanceTable/LICENSE diff --git a/README.md b/README.md index 84ed25d9..95454a5e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/libraries/ACS712/ACS712.cpp b/libraries/ACS712/ACS712.cpp index fc372dfb..1bad0e16 100644 --- a/libraries/ACS712/ACS712.cpp +++ b/libraries/ACS712/ACS712.cpp @@ -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 diff --git a/libraries/ACS712/ACS712.h b/libraries/ACS712/ACS712.h index 77128bd0..1407f1a4 100644 --- a/libraries/ACS712/ACS712.h +++ b/libraries/ACS712/ACS712.h @@ -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 diff --git a/libraries/ACS712/LICENSE b/libraries/ACS712/LICENSE new file mode 100644 index 00000000..3d51ae3b --- /dev/null +++ b/libraries/ACS712/LICENSE @@ -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. diff --git a/libraries/ACS712/examples/ACS712_20_AC/ACS712_20_AC.ino b/libraries/ACS712/examples/ACS712_20_AC/ACS712_20_AC.ino index b74612d5..b3e28333 100644 --- a/libraries/ACS712/examples/ACS712_20_AC/ACS712_20_AC.ino +++ b/libraries/ACS712/examples/ACS712_20_AC/ACS712_20_AC.ino @@ -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 diff --git a/libraries/ACS712/examples/ACS712_20_AC_DEMO/ACS712_20_AC_DEMO.ino b/libraries/ACS712/examples/ACS712_20_AC_DEMO/ACS712_20_AC_DEMO.ino index ae07b6e2..d589c7ae 100644 --- a/libraries/ACS712/examples/ACS712_20_AC_DEMO/ACS712_20_AC_DEMO.ino +++ b/libraries/ACS712/examples/ACS712_20_AC_DEMO/ACS712_20_AC_DEMO.ino @@ -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() diff --git a/libraries/ACS712/examples/ACS712_20_DC/ACS712_20_DC.ino b/libraries/ACS712/examples/ACS712_20_DC/ACS712_20_DC.ino index 9d99627e..9341e008 100644 --- a/libraries/ACS712/examples/ACS712_20_DC/ACS712_20_DC.ino +++ b/libraries/ACS712/examples/ACS712_20_DC/ACS712_20_DC.ino @@ -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() diff --git a/libraries/ACS712/examples/ACS712_20_DC_DEMO/ACS712_20_DC_DEMO.ino b/libraries/ACS712/examples/ACS712_20_DC_DEMO/ACS712_20_DC_DEMO.ino index d992b6af..3fb64ea2 100644 --- a/libraries/ACS712/examples/ACS712_20_DC_DEMO/ACS712_20_DC_DEMO.ino +++ b/libraries/ACS712/examples/ACS712_20_DC_DEMO/ACS712_20_DC_DEMO.ino @@ -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() diff --git a/libraries/ACS712/library.json b/libraries/ACS712/library.json index 4f59b5b6..3f8381f8 100644 --- a/libraries/ACS712/library.json +++ b/libraries/ACS712/library.json @@ -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": "*" } diff --git a/libraries/ACS712/library.properties b/libraries/ACS712/library.properties index 983a33ef..73bd1cc3 100644 --- a/libraries/ACS712/library.properties +++ b/libraries/ACS712/library.properties @@ -1,9 +1,11 @@ name=ACS712 -version=0.1.1 -author=Rob Tillaart +version=0.2.0 +author=Rob Tillaart , Pete Thompson maintainer=Rob Tillaart -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=* \ No newline at end of file +url=https://github.com/RobTillaart/ACS712 +architectures=* +includes=ACS712.h +depends= diff --git a/libraries/ACS712/readme.md b/libraries/ACS712/readme.md index 36b68bf7..db26c00c 100644 --- a/libraries/ACS712/readme.md +++ b/libraries/ACS712/readme.md @@ -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. - diff --git a/libraries/AD524X/AD524X.cpp b/libraries/AD524X/AD524X.cpp index 6127d78e..23068cc7 100644 --- a/libraries/AD524X/AD524X.cpp +++ b/libraries/AD524X/AD524X.cpp @@ -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 -- \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/AD524X/AD524X.h b/libraries/AD524X/AD524X.h index e421c3d3..11015a5d 100644 --- a/libraries/AD524X/AD524X.h +++ b/libraries/AD524X/AD524X.h @@ -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 - -#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 -- \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/AD524X/library.json b/libraries/AD524X/library.json index f13d4fd7..1ffa8977 100644 --- a/libraries/AD524X/library.json +++ b/libraries/AD524X/library.json @@ -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": "*" } diff --git a/libraries/AD524X/library.properties b/libraries/AD524X/library.properties index d2382989..2473b9af 100644 --- a/libraries/AD524X/library.properties +++ b/libraries/AD524X/library.properties @@ -1,9 +1,11 @@ name=AD524X -version=0.1.3 +version=0.2.1 author=Rob Tillaart maintainer=Rob Tillaart 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=* \ No newline at end of file +url=https://github.com/RobTillaart/AD524X +architectures=* +includes=AD524X.h +depends= \ No newline at end of file diff --git a/libraries/AM232X/AM232X.cpp b/libraries/AM232X/AM232X.cpp index ce72cf1f..ed819a05 100644 --- a/libraries/AM232X/AM232X.cpp +++ b/libraries/AM232X/AM232X.cpp @@ -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 @@ -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 -- diff --git a/libraries/AM232X/AM232X.h b/libraries/AM232X/AM232X.h index a02f1ac1..a969c4bc 100644 --- a/libraries/AM232X/AM232X.h +++ b/libraries/AM232X/AM232X.h @@ -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 -- diff --git a/libraries/AM232X/library.json b/libraries/AM232X/library.json index de202b05..6ad78ff1 100644 --- a/libraries/AM232X/library.json +++ b/libraries/AM232X/library.json @@ -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": "*" } diff --git a/libraries/AM232X/library.properties b/libraries/AM232X/library.properties index c46bb7c2..04b3e41e 100644 --- a/libraries/AM232X/library.properties +++ b/libraries/AM232X/library.properties @@ -1,5 +1,5 @@ name=AM232X -version=0.2.1 +version=0.2.3 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for AM2320 AM2321 and AM2323 I2C temperature and humidity sensor. diff --git a/libraries/AnalogKeypad/AnalogKeypad.cpp b/libraries/AnalogKeypad/AnalogKeypad.cpp index c1de6c7c..b9021fb3 100644 --- a/libraries/AnalogKeypad/AnalogKeypad.cpp +++ b/libraries/AnalogKeypad/AnalogKeypad.cpp @@ -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; diff --git a/libraries/AnalogKeypad/AnalogKeypad.h b/libraries/AnalogKeypad/AnalogKeypad.h index d0e84610..15c9134d 100644 --- a/libraries/AnalogKeypad/AnalogKeypad.h +++ b/libraries/AnalogKeypad/AnalogKeypad.h @@ -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 -- \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/AnalogKeypad/LICENSE b/libraries/AnalogKeypad/LICENSE new file mode 100644 index 00000000..ee06de04 --- /dev/null +++ b/libraries/AnalogKeypad/LICENSE @@ -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. diff --git a/libraries/AnalogKeypad/README.md b/libraries/AnalogKeypad/README.md new file mode 100644 index 00000000..d4592ff5 --- /dev/null +++ b/libraries/AnalogKeypad/README.md @@ -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. + + + + diff --git a/libraries/AnalogKeypad/keywords.txt b/libraries/AnalogKeypad/keywords.txt index 904eb85b..4142b3a0 100644 --- a/libraries/AnalogKeypad/keywords.txt +++ b/libraries/AnalogKeypad/keywords.txt @@ -1,24 +1,11 @@ -####################################### # Syntax Coloring Map For AnalogKeypad -####################################### -####################################### # Datatypes (KEYWORD1) -####################################### - AnalogKeypad KEYWORD1 -####################################### # Methods and Functions (KEYWORD2) -####################################### - read KEYWORD2 -####################################### # Instances (KEYWORD2) -####################################### -####################################### # Constants (LITERAL1) -####################################### - diff --git a/libraries/AnalogKeypad/library.json b/libraries/AnalogKeypad/library.json index c1619619..395723b1 100644 --- a/libraries/AnalogKeypad/library.json +++ b/libraries/AnalogKeypad/library.json @@ -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": "*" } diff --git a/libraries/AnalogKeypad/library.properties b/libraries/AnalogKeypad/library.properties index 50e357ec..cab6acf3 100644 --- a/libraries/AnalogKeypad/library.properties +++ b/libraries/AnalogKeypad/library.properties @@ -1,9 +1,11 @@ name=AnalogKeypad -version=0.1.2 +version=0.1.4 author=Rob Tillaart maintainer=Rob Tillaart -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=* \ No newline at end of file +url=https://github.com/RobTillaart/AnalogKeypad +architectures=* +includes=AnalogKeypad.h +depends= \ No newline at end of file diff --git a/libraries/AnalogPin/AnalogPin.cpp b/libraries/AnalogPin/AnalogPin.cpp index 861eff77..b71c3e41 100644 --- a/libraries/AnalogPin/AnalogPin.cpp +++ b/libraries/AnalogPin/AnalogPin.cpp @@ -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 -- \ No newline at end of file + +// -- END OF FILE -- diff --git a/libraries/AnalogPin/AnalogPin.h b/libraries/AnalogPin/AnalogPin.h index 56fd7718..f3d97028 100644 --- a/libraries/AnalogPin/AnalogPin.h +++ b/libraries/AnalogPin/AnalogPin.h @@ -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 -- \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/AnalogPin/LICENSE b/libraries/AnalogPin/LICENSE new file mode 100644 index 00000000..27679c12 --- /dev/null +++ b/libraries/AnalogPin/LICENSE @@ -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. diff --git a/libraries/AnalogPin/README.md b/libraries/AnalogPin/README.md new file mode 100644 index 00000000..e4add47c --- /dev/null +++ b/libraries/AnalogPin/README.md @@ -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. + diff --git a/libraries/AnalogPin/examples/AnalogPin/AnalogPin.ino b/libraries/AnalogPin/examples/AnalogPin/AnalogPin.ino index bc8f8716..199e4db2 100644 --- a/libraries/AnalogPin/examples/AnalogPin/AnalogPin.ino +++ b/libraries/AnalogPin/examples/AnalogPin/AnalogPin.ino @@ -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 -- diff --git a/libraries/AnalogPin/examples/AnalogPin_prescaler/AnalogPin_prescaler.ino b/libraries/AnalogPin/examples/AnalogPin_prescaler/AnalogPin_prescaler.ino new file mode 100644 index 00000000..cb9460dd --- /dev/null +++ b/libraries/AnalogPin/examples/AnalogPin_prescaler/AnalogPin_prescaler.ino @@ -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() +{ +} diff --git a/libraries/AnalogPin/library.json b/libraries/AnalogPin/library.json index dc7fd3e3..bfc112fb 100644 --- a/libraries/AnalogPin/library.json +++ b/libraries/AnalogPin/library.json @@ -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": "*" } diff --git a/libraries/AnalogPin/library.properties b/libraries/AnalogPin/library.properties index 24826fab..f6cf67e4 100644 --- a/libraries/AnalogPin/library.properties +++ b/libraries/AnalogPin/library.properties @@ -1,9 +1,11 @@ name=AnalogPin -version=0.1.4 +version=0.2.3 author=Rob Tillaart maintainer=Rob Tillaart 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=* \ No newline at end of file +url=https://github.com/RobTillaart/AnalogPin +architectures=* +includes=AnalogPin.h +depends= diff --git a/libraries/Angle/Angle.cpp b/libraries/Angle/Angle.cpp index 536bd0aa..c24dbb8d 100644 --- a/libraries/Angle/Angle.cpp +++ b/libraries/Angle/Angle.cpp @@ -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 --- \ No newline at end of file +// --- END OF FILE --- diff --git a/libraries/Angle/Angle.h b/libraries/Angle/Angle.h index 64b109f2..fc2b8341 100644 --- a/libraries/Angle/Angle.h +++ b/libraries/Angle/Angle.h @@ -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 - -#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 \ No newline at end of file + +// -- END OF FILE diff --git a/libraries/Angle/LICENSE b/libraries/Angle/LICENSE new file mode 100644 index 00000000..e563929f --- /dev/null +++ b/libraries/Angle/LICENSE @@ -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. diff --git a/libraries/Angle/README.md b/libraries/Angle/README.md new file mode 100644 index 00000000..194a7e28 --- /dev/null +++ b/libraries/Angle/README.md @@ -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. diff --git a/libraries/Angle/library.json b/libraries/Angle/library.json index 4149cce6..806409be 100644 --- a/libraries/Angle/library.json +++ b/libraries/Angle/library.json @@ -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": "*" } diff --git a/libraries/Angle/library.properties b/libraries/Angle/library.properties index d5b01cd3..6d27fac1 100644 --- a/libraries/Angle/library.properties +++ b/libraries/Angle/library.properties @@ -1,9 +1,11 @@ name=Angle -version=0.1.6 +version=0.1.8 author=Rob Tillaart maintainer=Rob Tillaart 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=* \ No newline at end of file +url=https://github.com/RobTillaart/Angle +architectures=* +includes=Angle.h +depends= diff --git a/libraries/AverageAngle/AverageAngle.cpp b/libraries/AverageAngle/AverageAngle.cpp index ef8c9391..8622eed9 100644 --- a/libraries/AverageAngle/AverageAngle.cpp +++ b/libraries/AverageAngle/AverageAngle.cpp @@ -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 \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/AverageAngle/AverageAngle.h b/libraries/AverageAngle/AverageAngle.h index eaf1304d..f5892566 100644 --- a/libraries/AverageAngle/AverageAngle.h +++ b/libraries/AverageAngle/AverageAngle.h @@ -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 - -#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 \ No newline at end of file + +// -- END OF FILE -- diff --git a/libraries/AverageAngle/LICENSE b/libraries/AverageAngle/LICENSE new file mode 100644 index 00000000..ed401f22 --- /dev/null +++ b/libraries/AverageAngle/LICENSE @@ -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. diff --git a/libraries/AverageAngle/README.md b/libraries/AverageAngle/README.md new file mode 100644 index 00000000..5afc050f --- /dev/null +++ b/libraries/AverageAngle/README.md @@ -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()); +``` + + + + + + + diff --git a/libraries/AverageAngle/examples/AverageAngle2/AverageAngle2.ino b/libraries/AverageAngle/examples/AverageAngle2/AverageAngle2.ino new file mode 100644 index 00000000..398de6ee --- /dev/null +++ b/libraries/AverageAngle/examples/AverageAngle2/AverageAngle2.ino @@ -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 \ No newline at end of file diff --git a/libraries/AverageAngle/library.json b/libraries/AverageAngle/library.json index fd4cc0e2..a36479a6 100644 --- a/libraries/AverageAngle/library.json +++ b/libraries/AverageAngle/library.json @@ -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": "*" } diff --git a/libraries/AverageAngle/library.properties b/libraries/AverageAngle/library.properties index 513779b5..61ba915e 100644 --- a/libraries/AverageAngle/library.properties +++ b/libraries/AverageAngle/library.properties @@ -1,9 +1,11 @@ name=AverageAngle -version=0.1.2 +version=0.1.4 author=Rob Tillaart maintainer=Rob Tillaart -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=* \ No newline at end of file +url=https://github.com/RobTillaart/AverageAngle +architectures=* +includes=AverageAngle.h +depends= diff --git a/libraries/AvrHeap/LICENSE b/libraries/AvrHeap/LICENSE new file mode 100644 index 00000000..e563929f --- /dev/null +++ b/libraries/AvrHeap/LICENSE @@ -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. diff --git a/libraries/AvrHeap/README.md b/libraries/AvrHeap/README.md new file mode 100644 index 00000000..24328016 --- /dev/null +++ b/libraries/AvrHeap/README.md @@ -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 diff --git a/libraries/AvrHeap/avrheap.cpp b/libraries/AvrHeap/avrheap.cpp index 4ba716d9..43168d37 100644 --- a/libraries/AvrHeap/avrheap.cpp +++ b/libraries/AvrHeap/avrheap.cpp @@ -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 --- \ No newline at end of file +// --- END OF FILE --- diff --git a/libraries/AvrHeap/avrheap.h b/libraries/AvrHeap/avrheap.h index 71a7ae86..6cc43e04 100644 --- a/libraries/AvrHeap/avrheap.h +++ b/libraries/AvrHeap/avrheap.h @@ -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 \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/AvrHeap/examples/heapdemo/heapdemo.ino b/libraries/AvrHeap/examples/heapdemo/heapdemo.ino new file mode 100644 index 00000000..92e9e7af --- /dev/null +++ b/libraries/AvrHeap/examples/heapdemo/heapdemo.ino @@ -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() +{} + diff --git a/libraries/AvrHeap/examples/heapdemo2/heapdemo2.ino b/libraries/AvrHeap/examples/heapdemo2/heapdemo2.ino index a23bb6cc..4c4a926c 100644 --- a/libraries/AvrHeap/examples/heapdemo2/heapdemo2.ino +++ b/libraries/AvrHeap/examples/heapdemo2/heapdemo2.ino @@ -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 diff --git a/libraries/AvrHeap/library.json b/libraries/AvrHeap/library.json index 5c123e1c..f6af0c95 100644 --- a/libraries/AvrHeap/library.json +++ b/libraries/AvrHeap/library.json @@ -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" } diff --git a/libraries/AvrHeap/library.properties b/libraries/AvrHeap/library.properties index 7350687c..afa1ff93 100644 --- a/libraries/AvrHeap/library.properties +++ b/libraries/AvrHeap/library.properties @@ -1,9 +1,11 @@ name=AvrHeap -version=0.1.5 +version=0.2.1 author=Rob Tillaart maintainer=Rob Tillaart 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 \ No newline at end of file +url=https://github.com/RobTillaart/avrheap +architectures=avr +includes=avrheap.h +depends= diff --git a/libraries/BH1750FVI/BH1750FVI.cpp b/libraries/BH1750FVI/BH1750FVI.cpp index 7ab47e0d..85a4c33e 100644 --- a/libraries/BH1750FVI/BH1750FVI.cpp +++ b/libraries/BH1750FVI/BH1750FVI.cpp @@ -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 --- diff --git a/libraries/BH1750FVI/BH1750FVI.h b/libraries/BH1750FVI/BH1750FVI.h index 6227dd08..a20afe70 100644 --- a/libraries/BH1750FVI/BH1750FVI.h +++ b/libraries/BH1750FVI/BH1750FVI.h @@ -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% / 60C ~~ 1% / 20C + // 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 -- diff --git a/libraries/BH1750FVI/LICENSE b/libraries/BH1750FVI/LICENSE new file mode 100644 index 00000000..3d51ae3b --- /dev/null +++ b/libraries/BH1750FVI/LICENSE @@ -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. diff --git a/libraries/BH1750FVI/examples/BH1750FVI_angle_measurement/BH1750FVI_angle_measurement.ino b/libraries/BH1750FVI/examples/BH1750FVI_angle_measurement/BH1750FVI_angle_measurement.ino new file mode 100644 index 00000000..87d83d2b --- /dev/null +++ b/libraries/BH1750FVI/examples/BH1750FVI_angle_measurement/BH1750FVI_angle_measurement.ino @@ -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 -- diff --git a/libraries/BH1750FVI/examples/BH1750FVI_angle_measurement/experimental.txt b/libraries/BH1750FVI/examples/BH1750FVI_angle_measurement/experimental.txt new file mode 100644 index 00000000..6c09860d --- /dev/null +++ b/libraries/BH1750FVI/examples/BH1750FVI_angle_measurement/experimental.txt @@ -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 + +*/ diff --git a/libraries/BH1750FVI/examples/BH1750FVI_async/BH1750FVI_async.ino b/libraries/BH1750FVI/examples/BH1750FVI_async/BH1750FVI_async.ino new file mode 100644 index 00000000..344f83d2 --- /dev/null +++ b/libraries/BH1750FVI/examples/BH1750FVI_async/BH1750FVI_async.ino @@ -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 -- diff --git a/libraries/BH1750FVI/examples/BH1750FVI_cont_high_res/BH1750FVI_cont_high_res.ino b/libraries/BH1750FVI/examples/BH1750FVI_cont_high_res/BH1750FVI_cont_high_res.ino index b3009426..949c220d 100644 --- a/libraries/BH1750FVI/examples/BH1750FVI_cont_high_res/BH1750FVI_cont_high_res.ino +++ b/libraries/BH1750FVI/examples/BH1750FVI_cont_high_res/BH1750FVI_cont_high_res.ino @@ -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 -- diff --git a/libraries/BH1750FVI/examples/BH1750FVI_cont_low_res/BH1750FVI_cont_low_res.ino b/libraries/BH1750FVI/examples/BH1750FVI_cont_low_res/BH1750FVI_cont_low_res.ino index 39a9a8e9..9ef5806b 100644 --- a/libraries/BH1750FVI/examples/BH1750FVI_cont_low_res/BH1750FVI_cont_low_res.ino +++ b/libraries/BH1750FVI/examples/BH1750FVI_cont_low_res/BH1750FVI_cont_low_res.ino @@ -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; diff --git a/libraries/BH1750FVI/examples/BH1750FVI_setAngle/BH1750FVI_setAngle.ino b/libraries/BH1750FVI/examples/BH1750FVI_setAngle/BH1750FVI_setAngle.ino new file mode 100644 index 00000000..d0d298e6 --- /dev/null +++ b/libraries/BH1750FVI/examples/BH1750FVI_setAngle/BH1750FVI_setAngle.ino @@ -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 -- diff --git a/libraries/BH1750FVI/examples/BH1750FVI_setCorrectionFactor/BH1750FVI_setCorrectionFactor.ino b/libraries/BH1750FVI/examples/BH1750FVI_setCorrectionFactor/BH1750FVI_setCorrectionFactor.ino index aa65ee20..687b38e1 100644 --- a/libraries/BH1750FVI/examples/BH1750FVI_setCorrectionFactor/BH1750FVI_setCorrectionFactor.ino +++ b/libraries/BH1750FVI/examples/BH1750FVI_setCorrectionFactor/BH1750FVI_setCorrectionFactor.ino @@ -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 \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/BH1750FVI/examples/BH1750FVI_setTemperature/BH1750FVI_setTemperature.ino b/libraries/BH1750FVI/examples/BH1750FVI_setTemperature/BH1750FVI_setTemperature.ino new file mode 100644 index 00000000..fdea9dcc --- /dev/null +++ b/libraries/BH1750FVI/examples/BH1750FVI_setTemperature/BH1750FVI_setTemperature.ino @@ -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 -- diff --git a/libraries/BH1750FVI/examples/BH1750FVI_setWaveLength/BH1750FVI_setWaveLength.ino b/libraries/BH1750FVI/examples/BH1750FVI_setWaveLength/BH1750FVI_setWaveLength.ino new file mode 100644 index 00000000..4a4a0669 --- /dev/null +++ b/libraries/BH1750FVI/examples/BH1750FVI_setWaveLength/BH1750FVI_setWaveLength.ino @@ -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 -- diff --git a/libraries/BH1750FVI/examples/BH1750FVI_single_shot_3_res/BH1750FVI_single_shot_3_res.ino b/libraries/BH1750FVI/examples/BH1750FVI_single_shot_3_res/BH1750FVI_single_shot_3_res.ino new file mode 100644 index 00000000..61282ebd --- /dev/null +++ b/libraries/BH1750FVI/examples/BH1750FVI_single_shot_3_res/BH1750FVI_single_shot_3_res.ino @@ -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 -- diff --git a/libraries/BH1750FVI/keywords.txt b/libraries/BH1750FVI/keywords.txt index 6caa58a1..663a8d62 100644 --- a/libraries/BH1750FVI/keywords.txt +++ b/libraries/BH1750FVI/keywords.txt @@ -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) -####################################### diff --git a/libraries/BH1750FVI/library.json b/libraries/BH1750FVI/library.json index 513e0c52..afe8bb8e 100644 --- a/libraries/BH1750FVI/library.json +++ b/libraries/BH1750FVI/library.json @@ -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": "*" } diff --git a/libraries/BH1750FVI/library.properties b/libraries/BH1750FVI/library.properties index 96f17e56..e4d65f19 100644 --- a/libraries/BH1750FVI/library.properties +++ b/libraries/BH1750FVI/library.properties @@ -1,9 +1,11 @@ -name=BH1750FVI -version=0.1.0 +name=BH1750FVI_RT +version=0.2.4 author=Rob Tillaart maintainer=Rob Tillaart -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=* \ No newline at end of file +url=https://github.com/RobTillaart/BH1750FVI_RT +architectures=* +includes=BH1750FVI.h +depends= diff --git a/libraries/BH1750FVI/readme.md b/libraries/BH1750FVI/readme.md index c552eeb7..f59e7eb8 100644 --- a/libraries/BH1750FVI/readme.md +++ b/libraries/BH1750FVI/readme.md @@ -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... diff --git a/libraries/BitArray/BitArray.cpp b/libraries/BitArray/BitArray.cpp index 92ccfe7c..2ed16507 100644 --- a/libraries/BitArray/BitArray.cpp +++ b/libraries/BitArray/BitArray.cpp @@ -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); diff --git a/libraries/BitArray/BitArray.h b/libraries/BitArray/BitArray.h index 99edf9bd..43881d43 100644 --- a/libraries/BitArray/BitArray.h +++ b/libraries/BitArray/BitArray.h @@ -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 -- diff --git a/libraries/BitArray/LICENSE b/libraries/BitArray/LICENSE new file mode 100644 index 00000000..e563929f --- /dev/null +++ b/libraries/BitArray/LICENSE @@ -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. diff --git a/libraries/BitArray/README.md b/libraries/BitArray/README.md new file mode 100644 index 00000000..0556cb85 --- /dev/null +++ b/libraries/BitArray/README.md @@ -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. + diff --git a/libraries/BitArray/examples/bitArrayDemo3/performance_1.8.0 b/libraries/BitArray/examples/bitArrayDemo3/performance_1.8.0 new file mode 100644 index 00000000..41f023cf --- /dev/null +++ b/libraries/BitArray/examples/bitArrayDemo3/performance_1.8.0 @@ -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... diff --git a/libraries/BitArray/examples/bitArrayDemo3/performance_1.9.0 b/libraries/BitArray/examples/bitArrayDemo3/performance_1.9.0 new file mode 100644 index 00000000..41f023cf --- /dev/null +++ b/libraries/BitArray/examples/bitArrayDemo3/performance_1.9.0 @@ -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... diff --git a/libraries/BitArray/examples/fibonacci/fibonacci.ino b/libraries/BitArray/examples/fibonacci/fibonacci.ino new file mode 100644 index 00000000..7f3b5803 --- /dev/null +++ b/libraries/BitArray/examples/fibonacci/fibonacci.ino @@ -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 -- diff --git a/libraries/BitArray/library.json b/libraries/BitArray/library.json index 81977899..28f850cb 100644 --- a/libraries/BitArray/library.json +++ b/libraries/BitArray/library.json @@ -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": "*" } diff --git a/libraries/BitArray/library.properties b/libraries/BitArray/library.properties index 193a1d1d..2bbd6561 100644 --- a/libraries/BitArray/library.properties +++ b/libraries/BitArray/library.properties @@ -1,11 +1,11 @@ name=BitArray -version=0.1.8 +version=0.2.1 author=Rob Tillaart maintainer=Rob Tillaart -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= \ No newline at end of file +depends= diff --git a/libraries/BoolArray/BoolArray.cpp b/libraries/BoolArray/BoolArray.cpp index 99c907bf..c3757872 100644 --- a/libraries/BoolArray/BoolArray.cpp +++ b/libraries/BoolArray/BoolArray.cpp @@ -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 -- diff --git a/libraries/BoolArray/BoolArray.h b/libraries/BoolArray/BoolArray.h index c7852a50..375bdbdb 100644 --- a/libraries/BoolArray/BoolArray.h +++ b/libraries/BoolArray/BoolArray.h @@ -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 -- diff --git a/libraries/BoolArray/LICENSE b/libraries/BoolArray/LICENSE new file mode 100644 index 00000000..e563929f --- /dev/null +++ b/libraries/BoolArray/LICENSE @@ -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. diff --git a/libraries/BoolArray/README.md b/libraries/BoolArray/README.md new file mode 100644 index 00000000..afeb886f --- /dev/null +++ b/libraries/BoolArray/README.md @@ -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. diff --git a/libraries/BoolArray/examples/boolArrayDemo0/boolArrayDemo0.ino b/libraries/BoolArray/examples/boolArrayDemo0/boolArrayDemo0.ino index d89f4942..96041ca6 100644 --- a/libraries/BoolArray/examples/boolArrayDemo0/boolArrayDemo0.ino +++ b/libraries/BoolArray/examples/boolArrayDemo0/boolArrayDemo0.ino @@ -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 -- diff --git a/libraries/BoolArray/examples/boolArrayDemo2/boolArrayDemo2.ino b/libraries/BoolArray/examples/boolArrayDemo2/boolArrayDemo2.ino index ebd1fdc8..69fabc2c 100644 --- a/libraries/BoolArray/examples/boolArrayDemo2/boolArrayDemo2.ino +++ b/libraries/BoolArray/examples/boolArrayDemo2/boolArrayDemo2.ino @@ -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++) { diff --git a/libraries/BoolArray/examples/boolArrayDemo2/performance_0.2.0.txt b/libraries/BoolArray/examples/boolArrayDemo2/performance_0.2.0.txt new file mode 100644 index 00000000..fb3172b9 --- /dev/null +++ b/libraries/BoolArray/examples/boolArrayDemo2/performance_0.2.0.txt @@ -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... diff --git a/libraries/BoolArray/library.json b/libraries/BoolArray/library.json index 1bde6966..17a0aadc 100644 --- a/libraries/BoolArray/library.json +++ b/libraries/BoolArray/library.json @@ -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": "*" } diff --git a/libraries/BoolArray/library.properties b/libraries/BoolArray/library.properties index 0260d0f3..28fc27c1 100644 --- a/libraries/BoolArray/library.properties +++ b/libraries/BoolArray/library.properties @@ -1,11 +1,11 @@ name=BoolArray -version=0.1.3 +version=0.2.1 author=Rob Tillaart maintainer=Rob Tillaart -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= \ No newline at end of file diff --git a/libraries/Complex/LICENSE b/libraries/Complex/LICENSE new file mode 100644 index 00000000..2fc1cc50 --- /dev/null +++ b/libraries/Complex/LICENSE @@ -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. diff --git a/libraries/Complex/README.md b/libraries/Complex/README.md new file mode 100644 index 00000000..11c29929 --- /dev/null +++ b/libraries/Complex/README.md @@ -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 + diff --git a/libraries/Complex/complex.cpp b/libraries/Complex/complex.cpp index 0c0762bb..0f6dc64b 100644 --- a/libraries/Complex/complex.cpp +++ b/libraries/Complex/complex.cpp @@ -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 diff --git a/libraries/Complex/complex.h b/libraries/Complex/complex.h index 2bdfe80d..38df2825 100644 --- a/libraries/Complex/complex.h +++ b/libraries/Complex/complex.h @@ -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 --- \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/Complex/examples/complex/referenceOutput_0.2.0.txt b/libraries/Complex/examples/complex/referenceOutput_0.2.0.txt new file mode 100644 index 00000000..a0b57039 --- /dev/null +++ b/libraries/Complex/examples/complex/referenceOutput_0.2.0.txt @@ -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 diff --git a/libraries/Complex/examples/performance/preformanceOutput_0.2.0.txt b/libraries/Complex/examples/performance/preformanceOutput_0.2.0.txt new file mode 100644 index 00000000..917f7dd9 --- /dev/null +++ b/libraries/Complex/examples/performance/preformanceOutput_0.2.0.txt @@ -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 diff --git a/libraries/Complex/library.json b/libraries/Complex/library.json index ab95f025..f79260d2 100644 --- a/libraries/Complex/library.json +++ b/libraries/Complex/library.json @@ -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": "*" } diff --git a/libraries/Complex/library.properties b/libraries/Complex/library.properties index f291ca88..6fafd194 100644 --- a/libraries/Complex/library.properties +++ b/libraries/Complex/library.properties @@ -1,9 +1,11 @@ name=Complex -version=0.1.12 +version=0.2.1 author=Rob Tillaart maintainer=Rob Tillaart -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=* \ No newline at end of file +url=https://github.com/RobTillaart/Complex +architectures=* +includes=Complex.h +depends= diff --git a/libraries/Correlation/Correlation.cpp b/libraries/Correlation/Correlation.cpp index 683cbcbd..5809479f 100644 --- a/libraries/Correlation/Correlation.cpp +++ b/libraries/Correlation/Correlation.cpp @@ -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 // diff --git a/libraries/Correlation/Correlation.h b/libraries/Correlation/Correlation.h index 12806c0d..e8648d42 100644 --- a/libraries/Correlation/Correlation.h +++ b/libraries/Correlation/Correlation.h @@ -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 // diff --git a/libraries/Correlation/library.json b/libraries/Correlation/library.json index 17bd5ad5..73b5a54a 100644 --- a/libraries/Correlation/library.json +++ b/libraries/Correlation/library.json @@ -15,10 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/Correlation.git" }, - "version":"0.1.0", + "version":"0.1.1", "frameworks": "arduino", - "platforms": "*", - "export": { - "include": "Correlation" - } + "platforms": "*" } diff --git a/libraries/Correlation/library.properties b/libraries/Correlation/library.properties index 7cc76e94..98c602fc 100644 --- a/libraries/Correlation/library.properties +++ b/libraries/Correlation/library.properties @@ -1,5 +1,5 @@ name=Correlation -version=0.1.0 +version=0.1.1 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino Library to determine correlation between X and Y dataset diff --git a/libraries/CountDown/CountDown.cpp b/libraries/CountDown/CountDown.cpp index 123ebcff..1b0c359e 100644 --- a/libraries/CountDown/CountDown.cpp +++ b/libraries/CountDown/CountDown.cpp @@ -1,18 +1,18 @@ // // FILE: CountDown.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.2 +// VERSION: 0.2.2 // PURPOSE: CountDown library for Arduino -// -// The library is based upon millis() and therefore -// has the same restrictions as millis() has wrt overflow. +// URL: https://github.com/RobTillaart/CountDown // // HISTORY: -// 0.1.2 - 2017-07-16 added start(days, hours, minutes, seconds) + cont() == continue countdown -// 0.1.1 - 2015-10-29 added start(h, m, s) -// 0.1.0 - 2015-10-27 initial version -// -// Released to the public domain +// 0.2.2 2020-07-08 add MINUTES; refactor +// 0.2.1 2020-06-05 fix library.json +// 0.2.0 2020-03-29 #pragma once, removed pre 1.0 support +// 0.1.3 2017-07-16 TODO improved seconds - OdoMeter see below ... TODO +// 0.1.2 2017-07-16 added start(days, hours, minutes, seconds) + cont() == continue countdown +// 0.1.1 2015-10-29 added start(h, m, s) +// 0.1.0 2015-10-27 initial version // #include "CountDown.h" @@ -26,30 +26,24 @@ CountDown::CountDown(const enum Resolution res) void CountDown::setResolution(const enum Resolution res) { _res = res; - switch(_res) - { - case MICROS: - _gettime = micros; - break; - case SECONDS: - _gettime = seconds; - break; - case MILLIS: - default: - _gettime = millis; - break; - } _ticks = 0; } void CountDown::start(uint32_t ticks) { - _state = CountDown::RUNNING; - _starttime = _gettime(); _ticks = ticks; + _state = CountDown::RUNNING; + if (_res == MICROS) + { + _starttime = micros(); + } + else + { + _starttime = millis(); + } } -void CountDown::start(uint8_t days, uint8_t hours, uint8_t minutes, uint8_t seconds) +void CountDown::start(uint8_t days, uint16_t hours, uint32_t minutes, uint32_t seconds) { uint32_t ticks = 86400UL * days + 3600UL * hours + 60UL * minutes + seconds; if (ticks > 4294967) ticks = 4294967; // prevent underlying millis() overflow @@ -57,6 +51,14 @@ void CountDown::start(uint8_t days, uint8_t hours, uint8_t minutes, uint8_t seco start(ticks); } +void CountDown::start(uint8_t days, uint16_t hours, uint32_t minutes) +{ + uint32_t ticks = 86400UL * days + 3600UL * hours + 60UL * minutes; + if (ticks > 4294967) ticks = 4294967; // prevent underlying millis() overflow + setResolution(MINUTES); + start(ticks); +} + void CountDown::stop() { calcRemaining(); @@ -74,19 +76,36 @@ void CountDown::cont() uint32_t CountDown::remaining() { calcRemaining(); + if (_remaining == 0) _state = CountDown::STOPPED; return _remaining; } void CountDown::calcRemaining() { + uint32_t t = 0; if (_state == CountDown::RUNNING) { - uint32_t t = _gettime() - _starttime; - _remaining = _ticks > t? _ticks - t: 0; - if (_remaining == 0) + switch(_res) { - _state = CountDown::STOPPED; + case MINUTES: + t = (millis() - _starttime) / 60000UL; + break; + case SECONDS: + t = (millis() - _starttime) / 1000UL;; + break; + case MICROS: + t = micros() - _starttime; + break; + case MILLIS: + default: + t = millis() - _starttime; + break; } + _remaining = _ticks > t ? _ticks - t: 0; + return; } + // do not change } -// END OF FILE \ No newline at end of file + + +// -- END OF FILE -- diff --git a/libraries/CountDown/CountDown.h b/libraries/CountDown/CountDown.h index 34ac530f..5c6627a3 100644 --- a/libraries/CountDown/CountDown.h +++ b/libraries/CountDown/CountDown.h @@ -1,33 +1,31 @@ -#ifndef CountDown_h -#define CountDown_h +#pragma once // // FILE: CountDown.h // AUTHOR: Rob Tillaart +// VERSION: 0.2.2 // PURPOSE: CountDown library for Arduino +// URL: https://github.com/RobTillaart/CountDown +// // HISTORY: See CountDown.cpp -// URL: -// -// Released to the public domain // -#define COUNTDOWN_LIB_VERSION "0.1.2" - -#if ARDUINO >= 100 #include "Arduino.h" -#else -#include "WProgram.h" -#endif + +#define COUNTDOWN_LIB_VERSION "0.2.2" class CountDown { public: - enum Resolution { MILLIS, MICROS, SECONDS }; + enum Resolution { MILLIS, MICROS, SECONDS, MINUTES }; explicit CountDown(const enum Resolution res = MILLIS); void setResolution(const enum Resolution res = MILLIS); void start(uint32_t ticks); - void start(uint8_t days, uint8_t hours, uint8_t minutes, uint8_t seconds); + // Implicit set resolution to SECONDS. + void start(uint8_t days, uint16_t hours, uint32_t minutes, uint32_t seconds); + // Implicit set resolution to MINUTES. + void start(uint8_t days, uint16_t hours, uint32_t minutes); void stop(); void cont(); @@ -36,19 +34,14 @@ public: enum Resolution resolution() const { return _res; }; private: - // ?? enum State { RUNNING, STOPPED }; - uint32_t _ticks; - uint32_t _remaining; - enum State _state; + uint32_t _ticks; + uint32_t _remaining; + enum State _state; enum Resolution _res; - unsigned long _starttime; - - void calcRemaining(); - unsigned long (*_gettime)(void); - static unsigned long seconds() { return millis() / 1000; }; + uint32_t _starttime; + void calcRemaining(); }; -#endif -// END OF FILE \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/CountDown/LICENSE b/libraries/CountDown/LICENSE new file mode 100644 index 00000000..e563929f --- /dev/null +++ b/libraries/CountDown/LICENSE @@ -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. diff --git a/libraries/CountDown/README.md b/libraries/CountDown/README.md new file mode 100644 index 00000000..f23d4c88 --- /dev/null +++ b/libraries/CountDown/README.md @@ -0,0 +1,53 @@ +# CountDown + +Arduino Library to implement a CountDown clock (in SW polling, no HW timer). + +## Description + +The main functions of the CountDown clock are: + +* **void start(ticks);** +* **void start(days, hours, minutes, seconds);** +* **void start(days, hours, minutes);** +* **void stop();** +* **void cont();** *(continue is a C-Keyword)* +* **uint32_t remaining();** +* **bool isRunning();** + +These functions work straightforward. + +The function **start(days, hours, minutes, seconds)** has changed its +parameters type to minimize them, given that the total time may not exceed 2^32 milliseconds. +This allows the user to call **start()** with e.g. four hundred minutes **start(0, 0, 400, 0)** +or a million seconds **start(0, 0, 0, 1000000)** as parameter. +The resolution is implicitly set to *SECONDS*. + +Note: the function **start()** does not check if the parameters cause an overflow +in the underlying math. That is responsibility of the user. + +The function **start(days, hours, minutes)** is new since 0.2.2. +It also uses **millis()** under the hood. The resolution is implicitly set to *MINUTES*. + +Total amount of time to countdown for **MICROS** may not exceed 2\^32 micros ~ 1hr 10 minutes. +Total amount of time to countdown for **MILLIS**, **SECONDS** and **MINUTES** +may not exceed 2\^32 millis ~49 days + +## Operation + +The Countdown clock uses by default **millis()** to do the time keeping, +although this can be changed runtime by **setResolution(res)**. The parameter +**res** can be: +- *MICROS* +- *MILLIS* +- *SECONDS* // based upon millis() +- *MINUTES* // based upon millis() + +Although possible one should not change the resolution of the CountDown +clock while it is running as you mix up different timescales. + +One can call **start(...)** at any time to reset the running clock to +a new value. This allows to implement a sort of watchdog clock in which e.g. +the user must press a button at least once per minute to show he is still +awake. + + diff --git a/libraries/CountDown/examples/countdown_demo1/countdown_demo1.ino b/libraries/CountDown/examples/countdown_demo1/countdown_demo1.ino index c45cd7d2..11358301 100644 --- a/libraries/CountDown/examples/countdown_demo1/countdown_demo1.ino +++ b/libraries/CountDown/examples/countdown_demo1/countdown_demo1.ino @@ -1,36 +1,45 @@ // // FILE: countdown_demo.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.0 +// VERSION: 0.1.1 // PURPOSE: demo // DATE: 2015-10-28 // URL: http://forum.arduino.cc/index.php?topic=356253 // -// Released to the public domain -// #include "CountDown.h" -CountDown CD(CountDown::SECONDS); +CountDown CD(CountDown::MINUTES); + +uint32_t start, stop; void setup() { - Serial.begin(115200); - Serial.println(__FILE__); - Serial.print("COUNTDOWN_LIB_VERSION: "); - Serial.println(COUNTDOWN_LIB_VERSION); + Serial.begin(115200); + Serial.println(__FILE__); + Serial.print("COUNTDOWN_LIB_VERSION: "); + Serial.println(COUNTDOWN_LIB_VERSION); - CD.start(5); + delay(random(2000)); + start = millis(); + CD.start(3); + Serial.println(start); - while (CD.remaining() > 0 && CD.isRunning() ) - { - Serial.println(CD.remaining() ); - if (CD.remaining() < 2) CD.stop(); - } - Serial.println(CD.remaining()); - Serial.println("done..."); + while (CD.remaining() > 0 ) + { + // Serial.print(millis()); + // Serial.print("\t"); + // Serial.println(CD.remaining() ); + // delay(100); + } + Serial.println(millis() - start); // SHOULD PRINT 180000 + + Serial.println(CD.remaining()); + Serial.println("done..."); } void loop() { } + +// -- END OF FILE -- diff --git a/libraries/CountDown/examples/countdown_demo2/countdown_demo2.ino b/libraries/CountDown/examples/countdown_demo2/countdown_demo2.ino index 6816ca90..d4e28db1 100644 --- a/libraries/CountDown/examples/countdown_demo2/countdown_demo2.ino +++ b/libraries/CountDown/examples/countdown_demo2/countdown_demo2.ino @@ -13,40 +13,51 @@ CountDown CD[5]; +uint8_t lines = 0; + void setup() { - Serial.begin(115200); - Serial.println(__FILE__); - Serial.print("COUNTDOWN_LIB_VERSION: "); - Serial.println(COUNTDOWN_LIB_VERSION); + Serial.begin(115200); + Serial.println(__FILE__); + Serial.print("COUNTDOWN_LIB_VERSION: "); + Serial.println(COUNTDOWN_LIB_VERSION); - for (int i = 0; i < 5; i++) - { - CD[i].start(10000UL * i); - } - delay(1234); - CD[3].stop(); + for (int i = 0; i < 5; i++) + { + CD[i].start(10000UL * i); + } + delay(1234); + CD[3].stop(); } void loop() { - for (int i = 0; i < 5; i++) - { - Serial.print("\t"); - Serial.print(CD[i].remaining()); - } - for (int i = 0; i < 5; i++) - { - Serial.print("\t"); - Serial.print(CD[i].isRunning()); - } + if (lines == 10) + { + lines = 0; Serial.println(); + } + lines++; - if (CD[1].isRunning() == false && CD[3].isRunning() == false) - { - uint32_t x = CD[3].remaining(); - CD[3].start(x); - } + for (int i = 0; i < 5; i++) + { + Serial.print("\t"); + Serial.print(CD[i].remaining()); + } + for (int i = 0; i < 5; i++) + { + Serial.print("\t"); + Serial.print(CD[i].isRunning()); + } + Serial.println(); - delay(250); + if (CD[1].isRunning() == false && CD[3].isRunning() == false) + { + uint32_t x = CD[3].remaining(); + CD[3].start(x); + } + + delay(250); } + +// -- END OF FILE -- diff --git a/libraries/CountDown/examples/demo_DHMS/demo_DHMS.ino b/libraries/CountDown/examples/demo_DHMS/demo_DHMS.ino index e70f167f..ead76794 100644 --- a/libraries/CountDown/examples/demo_DHMS/demo_DHMS.ino +++ b/libraries/CountDown/examples/demo_DHMS/demo_DHMS.ino @@ -27,7 +27,7 @@ void setup() void loop() { static uint32_t last_remaining = 0; - if (last_remaining != CD.remaining()) + if (last_remaining != CD.remaining() || CD.remaining() == 0 ) { Serial.println(); last_remaining = CD.remaining(); diff --git a/libraries/CountDown/library.json b/libraries/CountDown/library.json index 2cf6f868..fd5f41d9 100644 --- a/libraries/CountDown/library.json +++ b/libraries/CountDown/library.json @@ -1,7 +1,7 @@ { "name": "CountDown", - "keywords": "Count,down,stopwatch,timer,millis,micros,seconds", - "description": "Library to implement a CountDown clock (in SW no HW).", + "keywords": "Count,down,stopwatch,timer,millis,micros,seconds,minutes", + "description": "Arduino library to implement a CountDown clock (in SW no HW).", "authors": [ { @@ -13,12 +13,9 @@ "repository": { "type": "git", - "url": "https://github.com/RobTillaart/Arduino.git" + "url": "https://github.com/RobTillaart/CountDown.git" }, - "version":"0.1.2", + "version":"0.2.2", "frameworks": "arduino", - "platforms": "*", - "export": { - "include": "libraries/CountDown" - } + "platforms": "*" } diff --git a/libraries/CountDown/library.properties b/libraries/CountDown/library.properties index 6f6c89b9..fc6ba946 100644 --- a/libraries/CountDown/library.properties +++ b/libraries/CountDown/library.properties @@ -1,9 +1,11 @@ name=CountDown -version=0.1.2 +version=0.2.2 author=Rob Tillaart maintainer=Rob Tillaart -sentence=Library to implement a CountDown clock (in SW no HW). -paragraph= +sentence=Arduino library to implement a CountDown clock in SW. +paragraph=Polling, no HW timer used. category=Data Processing -url=https://github.com/RobTillaart/Arduino/tree/master/libraries/ -architectures=* \ No newline at end of file +url=https://github.com/RobTillaart/CountDown +architectures=* +includes=CountDown.h +depends= \ No newline at end of file diff --git a/libraries/Cozir/LICENSE b/libraries/Cozir/LICENSE new file mode 100644 index 00000000..4c3eaf9b --- /dev/null +++ b/libraries/Cozir/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2012-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. diff --git a/libraries/Cozir/README.md b/libraries/Cozir/README.md new file mode 100644 index 00000000..95ab39bf --- /dev/null +++ b/libraries/Cozir/README.md @@ -0,0 +1,25 @@ +# Cozir + +Arduino library for COZIR range of temperature, humidity and CO2 sensors + +## Description +The Cozir library is still experimental as I do not have a sensor to test the library. +The polling mode as used in the examples seem to work quite well. + +Note that the **CozirDemoHWSerial.ino** example needs to run on a MEGA or a Teensy, +at least a board with more than one Serial port. + +## Operation + +See examples. + +There are functions commented that are **NOT RECOMMENDED** by the datasheet. +Feel free to uncomment but use at your own risk. + +## Notes + +Note: the 0.2.0 library is still experimental, see several TODO's in the code. +That said, the default polling mode used in the examples works stable (last version tested). + +## Test sensor +People who have a spare sensor for me, or are willing to run tests, please contact me. diff --git a/libraries/Cozir/cozir.cpp b/libraries/Cozir/cozir.cpp index 603be095..66f53bee 100644 --- a/libraries/Cozir/cozir.cpp +++ b/libraries/Cozir/cozir.cpp @@ -1,39 +1,40 @@ // // FILE: Cozir.cpp // AUTHOR: DirtGambit & Rob Tillaart -// VERSION: 0.1.05 +// VERSION: 0.2.1 // PURPOSE: library for COZIR range of sensors for Arduino // Polling Mode -// URL: http://forum.arduino.cc/index.php?topic=91467.0 +// URL: https://github.com/RobTillaart/Cozir +// http://forum.arduino.cc/index.php?topic=91467.0 // // HISTORY: -// 0.1.05 fixed bug: uint16_t request() to uint32_t request() in .h file (Rob T) -// 0.1.04 changed CO2 to support larger values (Rob T) -// 0.1.03 added setOperatingMode -// 0.1.02 added support Arduino 1.x -// 0.1.01 initial version +// 0.2.1 2020-06-05 fix library.json +// 0.2.0 2020-03-30 some refactor and own repo +// 0.1.06 added support for HardwareSerial for MEGA (Rob T) +// removed support for NewSoftSerial ==> stop pre 1.0 support) +// 0.1.05 fixed bug: uint16_t request() to uint32_t request() in .h file (Rob T) +// 0.1.04 changed CO2 to support larger values (Rob T) +// 0.1.03 added setOperatingMode +// 0.1.02 added support Arduino 1.x +// 0.1.01 initial version // // READ DATASHEET BEFORE USE OF THIS LIB ! // -// Released to the public domain -// -#include "Cozir.h" +#include "cozir.h" -//////////////////////////////////////////////////////////// -// -// CONSTRUCTOR -// -#if defined(ARDUINO) && ARDUINO >= 100 -COZIR::COZIR(SoftwareSerial& nss) : CZR_Serial(nss) -#else -COZIR::COZIR(NewSoftSerial& nss) : CZR_Serial(nss) -#endif +COZIR::COZIR(Stream * str) { - nss.begin(9600); - // overide default streaming (takes too much perf + ser = str; + buffer[0] = '\0'; +} + +void COZIR::init() +{ + // overide default streaming (takes too much performance) SetOperatingMode(CZR_POLLING); - // delay for initialization + // delay for initialization TODO should be timestamp based + // with an isInitialized function. Non blocking. delay(1200); } @@ -60,16 +61,10 @@ void COZIR::SetOperatingMode(uint8_t mode) // this is the default behaviour of this Class but // not of the sensor!! // -float COZIR::Fahrenheit() -{ - return (Celsius() * 1.8) + 32; -} - float COZIR::Celsius() { uint16_t rv = Request("T"); - float f = 0.1 * (rv - 1000.0); - return f; + return 0.1 * (rv - 1000.0); // TODO verify negative values } float COZIR::Humidity() @@ -77,7 +72,7 @@ float COZIR::Humidity() return 0.1 * Request("H"); } -// TODO UNITS UNKNOWN +// TODO UNITS UNKNOWN lux?? float COZIR::Light() { return 1.0 * Request("L"); @@ -118,32 +113,25 @@ uint16_t COZIR::CalibrateKnownGas(uint16_t value) return Request(buffer); } -// NOT RECOMMENDED, see datasheet -uint16_t COZIR::CalibrateManual(uint16_t value) -{ - return 0; + +//uint16_t COZIR::CalibrateManual(uint16_t value) +//{ //sprintf(buffer, "u %u", value); //return Request(buffer); -} +//} -// NOT RECOMMENDED, see datasheet -uint16_t COZIR::SetSpanCalibrate(uint16_t value) -{ - return 0; +//uint16_t COZIR::SetSpanCalibrate(uint16_t value) +//{ //sprintf(buffer, "S %u", value); //return Request(buffer); -} +//} + +//uint16_t COZIR::GetSpanCalibrate() +//{ +// return Request("s"); +//} -// NOT RECOMMENDED, see datasheet -uint16_t COZIR::GetSpanCalibrate() -{ - return Request("s"); -} -// DIGIFILTER, use with care -// default value = 32, -// 1=fast (noisy) 255=slow (smoothed) -// 0 = special. details see datasheet void COZIR::SetDigiFilter(uint8_t value) { sprintf(buffer, "A %u", value); @@ -155,6 +143,7 @@ uint8_t COZIR::GetDigiFilter() return Request("a"); } + //////////////////////////////////////////////////////////// // // STREAMING MODE @@ -219,29 +208,30 @@ void COZIR::GetConfiguration() Command("*"); } -///////////////////////////////////////////////////////// -// PRIVATE -void COZIR::Command(const char* s) +///////////////////////////////////////////////////////// +// +// PRIVATE +// +void COZIR::Command(const char* str) { - // TODO - // CZR_Serial.println(s); - CZR_Serial.print(s); - CZR_Serial.print("\r\n"); + ser->print(str); + ser->print("\r\n"); } -uint32_t COZIR::Request(const char* s) +uint32_t COZIR::Request(const char* str) { - Command(s); - // empty buffer - buffer[0] = '\0'; + Command(str); + // read answer; there may be a 100ms delay! - // TODO: PROPER TIMEOUT CODE. + // TODO: PROPER TIMEOUT CODE. - what is longest answer possible? delay(200); - int idx = 0; - while(CZR_Serial.available()) + + // start with empty buffer + uint8_t idx = 0; + while(ser->available()) { - buffer[idx++] = CZR_Serial.read(); + buffer[idx++] = ser->read(); } buffer[idx] = '\0'; @@ -249,7 +239,7 @@ uint32_t COZIR::Request(const char* s) switch(buffer[0]) { case 'T' : - rv = atoi(&buffer[5]); + rv = atol(&buffer[5]); if (buffer[4] == 1) rv += 1000; // negative values are mapped above 1000..1250 => capture this in Celsius() break; diff --git a/libraries/Cozir/cozir.h b/libraries/Cozir/cozir.h index ec5b1fe1..98039d68 100644 --- a/libraries/Cozir/cozir.h +++ b/libraries/Cozir/cozir.h @@ -1,106 +1,101 @@ +#pragma once // // FILE: Cozir.h // AUTHOR: DirtGambit & Rob Tillaart -// VERSION: 0.1.05 +// VERSION: 0.2.1 // PURPOSE: library for COZIR range of sensors for Arduino // Polling Mode -// URL: http://forum.arduino.cc/index.php?topic=91467.0 +// URL: https://github.com/RobTillaart/Cozir +// http://forum.arduino.cc/index.php?topic=91467.0 // // READ DATASHEET BEFORE USE OF THIS LIB ! // -// Released to the public domain -// -#ifndef Cozir_h -#define Cozir_h - -#if defined(ARDUINO) && ARDUINO >= 100 #include "Arduino.h" #include "SoftwareSerial.h" -#else -#include "WProgram.h" -#include "NewSoftSerial.h" -#endif -#define COZIR_LIB_VERSION "0.1.05" +#define COZIR_LIB_VERSION "0.2.1" // OUTPUTFIELDS // See datasheet for details. // These defines can be OR-ed for the SetOutputFields command -#define CZR_LIGHT 0x2000 -#define CZR_HUMIDITY 0x1000 -#define CZR_FILTLED 0x0800 -#define CZR_RAWLED 0x0400 -#define CZR_MAXLED 0x0200 -#define CZR_ZEROPOINT 0x0100 -#define CZR_RAWTEMP 0x0080 -#define CZR_FILTTEMP 0x0040 -#define CZR_FILTLEDSIGNAL 0x0020 -#define CZR_RAWLEDSIGNAL 0x0010 -#define CZR_SENSTEMP 0x0008 -#define CZR_FILTCO2 0x0004 -#define CZR_RAWCO2 0x0002 -#define CZR_NONE 0x0001 +#define CZR_LIGHT 0x2000 +#define CZR_HUMIDITY 0x1000 +#define CZR_FILTLED 0x0800 +#define CZR_RAWLED 0x0400 +#define CZR_MAXLED 0x0200 +#define CZR_ZEROPOINT 0x0100 +#define CZR_RAWTEMP 0x0080 +#define CZR_FILTTEMP 0x0040 +#define CZR_FILTLEDSIGNAL 0x0020 +#define CZR_RAWLEDSIGNAL 0x0010 +#define CZR_SENSTEMP 0x0008 +#define CZR_FILTCO2 0x0004 +#define CZR_RAWCO2 0x0002 + +#define CZR_NONE 0x0001 // easy default setting for streaming -#define CZR_HTC (CZR_HUMIDITY | CZR_RAWTEMP | CZR_RAWCO2) +#define CZR_HTC (CZR_HUMIDITY | CZR_RAWTEMP | CZR_RAWCO2) // not in datasheet for debug only -#define CZR_ALL 0x3FFE +#define CZR_ALL 0x3FFE // OPERATING MODES -#define CZR_COMMAND 0x00 -#define CZR_STREAMING 0x01 -#define CZR_POLLING 0x02 +#define CZR_COMMAND 0x00 +#define CZR_STREAMING 0x01 +#define CZR_POLLING 0x02 + class COZIR { public: -#if defined(ARDUINO) && ARDUINO >= 100 - COZIR(SoftwareSerial&); -#else - COZIR(NewSoftSerial&); -#endif + COZIR(Stream *); + void init(); // sets operatingMode to CZR_POLLING + + // warning: CZR_STREAMING is experimental, minimal tested. + void SetOperatingMode(uint8_t mode); float Celsius(); - float Fahrenheit(); + float Fahrenheit() { return (Celsius() * 1.8) + 32; }; float Humidity(); float Light(); uint32_t CO2(); + // Callibration function, read datasheet before use uint16_t FineTuneZeroPoint(uint16_t , uint16_t); uint16_t CalibrateFreshAir(); uint16_t CalibrateNitrogen(); uint16_t CalibrateKnownGas(uint16_t ); - uint16_t CalibrateManual(uint16_t ); - uint16_t SetSpanCalibrate(uint16_t ); - uint16_t GetSpanCalibrate(); - void SetDigiFilter(uint8_t ); + // following 3 functions are NOT RECOMMENDED, read datasheet before use + // uint16_t CalibrateManual(uint16_t ); + // uint16_t SetSpanCalibrate(uint16_t ); + // uint16_t GetSpanCalibrate(); + + // DIGIFILTER, use with care, read datasheet before use + // default value = 32, + // 1 = fast (noisy) 255 = slow (smoothed) + // 0 = special. details see datasheet + void SetDigiFilter(uint8_t value); uint8_t GetDigiFilter(); - void SetOutputFields(uint16_t ); - void GetRecentFields(); + // STREAMING MODE - needs testing... + void SetOutputFields(uint16_t fields); + // void ClrOutputFields(); { SetOutputFields(CZR_NONE); } ; // TODO test + void GetRecentFields(); // TODO test; - void SetEEPROM(uint8_t , uint8_t ); - uint8_t GetEEPROM(uint8_t ); + void SetEEPROM(uint8_t address, uint8_t value); + uint8_t GetEEPROM(uint8_t address); void GetVersionSerial(); void GetConfiguration(); private: -#if defined(ARDUINO) && ARDUINO >= 100 - SoftwareSerial& CZR_Serial; -#else - NewSoftSerial& CZR_Serial; -#endif - - void SetOperatingMode(uint8_t mode); - - void Command(const char* ); - uint32_t Request(const char* ); - + Stream *ser; char buffer[20]; + + void Command(const char* str); + uint32_t Request(const char* str); }; -#endif // -- END OF FILE -- diff --git a/libraries/Cozir/examples/CozirDemoHWSerial/CozirDemoHWSerial.ino b/libraries/Cozir/examples/CozirDemoHWSerial/CozirDemoHWSerial.ino new file mode 100644 index 00000000..a4df5b2e --- /dev/null +++ b/libraries/Cozir/examples/CozirDemoHWSerial/CozirDemoHWSerial.ino @@ -0,0 +1,46 @@ +// +// FILE: CozirDemoHardwareSerial.ino +// AUTHOR: Rob Tillaart +// VERSION: 0.1.1 +// PURPOSE: demo of Cozir lib (>= 0.1.06) +// DATE: 2015-jan-17 +// URL: http://forum.arduino.cc/index.php?topic=91467.0 +// + +// Note: this sketch needs a MEGA or a Teensy that supports a second +// Serial port named Serial1 + +#include + +COZIR czr(&Serial1); + +void setup() +{ + Serial1.begin(9600); + czr.init(); + + Serial.begin(115200); + Serial.print("Cozir HardwareSerial: "); + Serial.println(COZIR_LIB_VERSION); + Serial.println(); + + delay(1000); +} + +void loop() +{ + float t = czr.Celsius(); + float f = czr.Fahrenheit(); + float h = czr.Humidity(); + uint32_t c = czr.CO2(); + + Serial.print("Celcius =\t"); Serial.println(t); + Serial.print("Fahrenheit =\t"); Serial.println(f); + Serial.print("Humidity =\t"); Serial.println(h); + Serial.print("CO2 =\t"); Serial.println(c); + Serial.println(); + + delay(3000); +} + +// -- END OF FILE -- diff --git a/libraries/Cozir/examples/CozirDemoSWSerial/CozirDemoSWSerial.ino b/libraries/Cozir/examples/CozirDemoSWSerial/CozirDemoSWSerial.ino new file mode 100644 index 00000000..ef94d185 --- /dev/null +++ b/libraries/Cozir/examples/CozirDemoSWSerial/CozirDemoSWSerial.ino @@ -0,0 +1,45 @@ +// +// FILE: CozirDemoSoftwareSerial.ino +// AUTHOR: Rob Tillaart +// VERSION: 0.1.1 +// PURPOSE: demo of Cozir lib +// DATE: 2015-jan-17 +// URL: http://forum.arduino.cc/index.php?topic=91467.0 +// + +#include + +SoftwareSerial sws(3, 2); + +COZIR czr(&sws); + +void setup() +{ + sws.begin(9600); + czr.init(); + + Serial.begin(9600); + Serial.print("Cozir SoftwareSerial: "); + Serial.println(COZIR_LIB_VERSION); + Serial.println(); + + delay(1000); +} + +void loop() +{ + float t = czr.Celsius(); + float f = czr.Fahrenheit(); + float h = czr.Humidity(); + uint32_t c = czr.CO2(); + + Serial.print("Celcius =\t"); Serial.println(t); + Serial.print("Fahrenheit =\t"); Serial.println(f); + Serial.print("Humidity =\t"); Serial.println(h); + Serial.print("CO2 =\t"); Serial.println(c); + Serial.println(); + + delay(3000); +} + +// -- END OF FILE -- diff --git a/libraries/Cozir/library.json b/libraries/Cozir/library.json index 042d5991..810bd67b 100644 --- a/libraries/Cozir/library.json +++ b/libraries/Cozir/library.json @@ -1,7 +1,7 @@ { "name": "Cozir", - "keywords": "Cozir,CO2,sensor,polling", - "description": "Library for COZIR range of CO2 sensors for Arduino. Polling mode only.", + "keywords": "Cozir, CO2, sensor, polling", + "description": "Arduino library for COZIR range of CO2 sensors. Polling mode only.", "authors": [ { @@ -16,12 +16,9 @@ "repository": { "type": "git", - "url": "https://github.com/RobTillaart/Arduino.git" + "url": "https://github.com/RobTillaart/Cozir.git" }, - "version":"0.1.5", + "version":"0.2.1", "frameworks": "arduino", - "platforms": "*", - "export": { - "include": "libraries/Cozir" - } + "platforms": "*" } diff --git a/libraries/Cozir/library.properties b/libraries/Cozir/library.properties index 4ebf7fee..57c30c20 100644 --- a/libraries/Cozir/library.properties +++ b/libraries/Cozir/library.properties @@ -1,9 +1,11 @@ name=Cozir -version=0.1.5 -author=Rob Tillaart +version=0.2.1 +author=Rob Tillaart , DirtGambit maintainer=Rob Tillaart -sentence=Library for COZIR range of CO2 sensors for Arduino. Polling mode only. -paragraph= +sentence=Arduino library for COZIR range of CO2 sensors. Polling mode only. +paragraph=Still experimental category=Sensors -url=https://github.com/RobTillaart/Arduino/tree/master/libraries/ -architectures=* \ No newline at end of file +url=https://github.com/RobTillaart/Cozir +architectures=* +includes=Cozir.h +depends= diff --git a/libraries/DAC8551/DAC8551.cpp b/libraries/DAC8551/DAC8551.cpp index a6bdd749..eacd1f2b 100644 --- a/libraries/DAC8551/DAC8551.cpp +++ b/libraries/DAC8551/DAC8551.cpp @@ -1,21 +1,20 @@ // // FILE: DAC8551.cpp // AUTHOR: Rob Tillaart -// PURPOSE: DAC8550 DAC8551 library for Arduino -// VERSION: 0.1.1 -// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/DAC8551 +// PURPOSE: Arduino library for DAC8551 SPI Digital Analog Convertor +// VERSION: 0.1.3 +// URL: https://github.com/RobTillaart/DAC8551 +// // HISTORY: // 0.1.0: 2017-12-18 initial version // 0.1.1: 2017-12-19 fix begin() bug -// -// Released to the public domain +// 0.1.2 2020-04-06 minor refactor, readme.md +// 0.1.3 2020-06-07 fix library.json // #include #include -#define MAXVALUE 0xFFFF - DAC8551::DAC8551() { _hwSPI = true; @@ -43,6 +42,9 @@ void DAC8551::begin() pinMode(_spiData, OUTPUT); pinMode(_spiClock, OUTPUT); pinMode(_slaveSelect, OUTPUT); + digitalWrite(_slaveSelect, HIGH); + digitalWrite(_spiData, LOW); + digitalWrite(_spiClock, LOW); } _register = 0; @@ -84,7 +86,7 @@ void DAC8551::updateDevice() SPI.transfer(configRegister); SPI.transfer(_value >> 8); SPI.transfer(_value & 0xFF); - digitalWrite(_slaveSelect, LOW); + digitalWrite(_slaveSelect, HIGH); SPI.endTransaction(); } else // Software SPI @@ -93,7 +95,7 @@ void DAC8551::updateDevice() swSPI_transfer(configRegister); swSPI_transfer(_value >> 8); swSPI_transfer(_value & 0xFF); - digitalWrite(_slaveSelect, LOW); + digitalWrite(_slaveSelect, HIGH); } } @@ -108,4 +110,4 @@ void DAC8551::swSPI_transfer(uint8_t value) } } -// END OF FILE \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/DAC8551/DAC8551.h b/libraries/DAC8551/DAC8551.h index 53725c82..9041d3b7 100644 --- a/libraries/DAC8551/DAC8551.h +++ b/libraries/DAC8551/DAC8551.h @@ -1,12 +1,12 @@ +#pragma once // // FILE: DAC8551.h // AUTHOR: Rob Tillaart -// PURPOSE: DAC8550 DAC8551 library for Arduino -// VERSION: 0.1.1 +// PURPOSE: Arduino library for DAC8551 SPI Digital Analog Convertor +// could work with DAC8550, not tested +// VERSION: 0.1.3 // HISTORY: See DAC8551.cpp -// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/DAC8551 -// -// Released to the public domain +// URL: https://github.com/RobTillaart/DAC8551 // #include @@ -16,14 +16,13 @@ #define DAC8551_POWERDOWN_100K 2 #define DAC8551_POWERDOWN_HIGH_IMP 3 -#define DAC8551_LIB_VERSION (F("0.1.1 experimental")) +#define DAC8551_LIB_VERSION "0.1.3" class DAC8551 { public: - // type = 0,1,2,4 8550, 8551, 8552, 8554 - DAC8551(); - DAC8551(uint8_t spiData, uint8_t spiClock, uint8_t slaveSelect); + DAC8551(); + DAC8551(uint8_t spiData, uint8_t spiClock, uint8_t slaveSelect); void begin(); @@ -45,4 +44,4 @@ private: void swSPI_transfer(uint8_t value); }; -// END OF FILE \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/DAC8551/LICENSE b/libraries/DAC8551/LICENSE new file mode 100644 index 00000000..ed401f22 --- /dev/null +++ b/libraries/DAC8551/LICENSE @@ -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. diff --git a/libraries/DAC8551/README.md b/libraries/DAC8551/README.md new file mode 100644 index 00000000..8297f383 --- /dev/null +++ b/libraries/DAC8551/README.md @@ -0,0 +1,25 @@ +# DAC8551 +Arduino library for DAC8551 SPI Digital Analog Convertor + +## Description + +not tested extensively + +## Operation + +See examples + +**demo_hw_spi.ino** +write a sawtooth to channel A followed by a sinus +uses HW SPI + +**demo_sw_spi.ino** +write a sawtooth to channel A followed by a sinus +uses SW SPI + +**demo_powerdown.ino** +idem + +## TODO + +more testing diff --git a/libraries/DAC8551/examples/DAC8551_hw_spi/DAC8551_hw_spi.ino b/libraries/DAC8551/examples/DAC8551_hw_spi/DAC8551_hw_spi.ino index eb0fe1bc..e15a4067 100644 --- a/libraries/DAC8551/examples/DAC8551_hw_spi/DAC8551_hw_spi.ino +++ b/libraries/DAC8551/examples/DAC8551_hw_spi/DAC8551_hw_spi.ino @@ -2,11 +2,8 @@ // FILE: DAC8551_hw_spi.ino // AUTHOR: Rob Tillaart // PURPOSE: demo DAC8551 library Arduino with hardware SPI -// VERSION: 0.1.0 -// HISTORY: -// URL: -// -// Released to the public domain +// VERSION: 0.1.1 +// URL: https://github.com/RobTillaart/DAC8551 // #include @@ -25,7 +22,7 @@ void setup() void loop() { // minimal sawtooth - for (uint16_t val = 0; val < 65500; val+= 30) + for (uint16_t val = 0; val < 65500; val += 30) { DAC.setValue(val); int av = analogRead(A0); @@ -33,7 +30,9 @@ void loop() Serial.print(val); Serial.print("\t ==> \t"); Serial.print(av); + if (val % 300 == 0) Serial.println(); } + Serial.println(); // minimal sinus for (long i = 0; i < 360; i++ ) @@ -45,7 +44,9 @@ void loop() Serial.print("\t ==> \t"); Serial.print(av); delay(100); + if (i % 30 == 0) Serial.println(); } + Serial.println(); } -// END OF FILE \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/DAC8551/examples/DAC8551_powerdown/DAC8551_powerdown.ino b/libraries/DAC8551/examples/DAC8551_powerdown/DAC8551_powerdown.ino index 722afab6..92d355bd 100644 --- a/libraries/DAC8551/examples/DAC8551_powerdown/DAC8551_powerdown.ino +++ b/libraries/DAC8551/examples/DAC8551_powerdown/DAC8551_powerdown.ino @@ -2,11 +2,8 @@ // FILE: DAC8551_powerdown.ino // AUTHOR: Rob Tillaart // PURPOSE: demo DAC8551 library Arduino -// VERSION: 0.1.0 -// HISTORY: -// URL: -// -// Released to the public domain +// VERSION: 0.1.1 +// URL: https://github.com/RobTillaart/DAC8551 // #include @@ -50,4 +47,4 @@ void loop() DAC.setPowerDown(DAC8551_POWERDOWN_NORMAL); } -// END OF FILE \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/DAC8551/examples/DAC8551_sw_spi/DAC8551_sw_spi.ino b/libraries/DAC8551/examples/DAC8551_sw_spi/DAC8551_sw_spi.ino index 6adb01e0..2c9adc73 100644 --- a/libraries/DAC8551/examples/DAC8551_sw_spi/DAC8551_sw_spi.ino +++ b/libraries/DAC8551/examples/DAC8551_sw_spi/DAC8551_sw_spi.ino @@ -2,11 +2,8 @@ // FILE: DAC8551_sw_spi.ino // AUTHOR: Rob Tillaart // PURPOSE: demo DAC8551 library Arduino with software SPI -// VERSION: 0.1.0 -// HISTORY: -// URL: -// -// Released to the public domain +// VERSION: 0.1.1 +// URL: https://github.com/RobTillaart/DAC8551 // #include @@ -34,8 +31,10 @@ void loop() Serial.print(val); Serial.print("\t ==> \t"); Serial.print(av); + if (val % 300 == 0) Serial.println(); } - + Serial.println(); + // minimal sinus for (long i = 0; i < 360; i++ ) { @@ -46,7 +45,9 @@ void loop() Serial.print("\t ==> \t"); Serial.print(av); delay(100); + if (i % 30 == 0) Serial.println(); } + Serial.println(); } -// END OF FILE \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/DAC8551/library.json b/libraries/DAC8551/library.json index a91b559c..c2f8611b 100644 --- a/libraries/DAC8551/library.json +++ b/libraries/DAC8551/library.json @@ -1,7 +1,7 @@ { "name": "DAC8551", - "keywords": "DAC8551,DAC8550,digital,analog,convertor", - "description": "DAC8550 DAC8551 library for Arduino", + "keywords": "DAC8551, SPI, digital, analog, convertor", + "description": "Arduino library for DAC8551 SPI Digital Analog Convertor", "authors": [ { @@ -13,12 +13,9 @@ "repository": { "type": "git", - "url": "https://github.com/RobTillaart/Arduino.git" + "url": "https://github.com/RobTillaart/DAC8551" }, - "version":"0.1.0", + "version":"0.1.3", "frameworks": "arduino", - "platforms": "*", - "export": { - "include": "libraries/DAC8551" - } + "platforms": "*" } diff --git a/libraries/DAC8551/library.properties b/libraries/DAC8551/library.properties index bbd79553..74ab8a1d 100644 --- a/libraries/DAC8551/library.properties +++ b/libraries/DAC8551/library.properties @@ -1,9 +1,11 @@ name=DAC8551 -version=0.1.0 +version=0.1.3 author=Rob Tillaart maintainer=Rob Tillaart -sentence=DAC8550 DAC8551 library for Arduino -paragraph= +sentence=Arduino library for DAC8551 SPI Digital Analog Convertor +paragraph=could work with DAC8550 (not tested) category=Sensors -url=https://github.com/RobTillaart/Arduino/tree/master/libraries/ -architectures=* \ No newline at end of file +url=https://github.com/RobTillaart/DAC8551 +architectures=* +includes=DAC8551.h +depends=SPI.h diff --git a/libraries/DAC8552/DAC8552.cpp b/libraries/DAC8552/DAC8552.cpp index 83ff646b..a2804dfc 100644 --- a/libraries/DAC8552/DAC8552.cpp +++ b/libraries/DAC8552/DAC8552.cpp @@ -1,15 +1,16 @@ // // FILE: DAC8552.cpp // AUTHOR: Rob Tillaart -// PURPOSE: DAC8552 library for Arduino -// VERSION: 0.1.1 -// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/DAC8552 +// PURPOSE: Arduino library for DAC8552 SPI Digital Analog Convertor +// VERSION: 0.1.3 +// URL: https://github.com/RobTillaart/DAC8552 +// // HISTORY: // 0.1.0: 2017-12-14 initial version // 0.1.1: 2017-12-19 fix begin() bug -// -// Released to the public domain -// +// 0.1.2 2020-04-06 minor refactor, readme.md +// 0.1.3 2020-06-07 fix library.json + #include #include @@ -17,13 +18,11 @@ #define MAXVOLTAGE 5.0 #define MAXVALUE 0xFFFF -// 0,1,2,4 resp 8550 8551 8552 8554 DAC8552::DAC8552() { _hwSPI = true; } -// 0,1,2,4 resp 8550 8551 8552 8554 DAC8552::DAC8552(uint8_t spiData, uint8_t spiClock, uint8_t slaveSelect) { _hwSPI = false; @@ -46,6 +45,9 @@ void DAC8552::begin() pinMode(_spiData, OUTPUT); pinMode(_spiClock, OUTPUT); pinMode(_slaveSelect, OUTPUT); + digitalWrite(_slaveSelect, HIGH); + digitalWrite(_spiData, LOW); + digitalWrite(_spiClock, LOW); } for (uint8_t i = 0; i < 2; i++) @@ -94,7 +96,7 @@ void DAC8552::setPowerDown(uint8_t DAC, uint8_t powerDownMode) uint8_t DAC8552::getPowerDownMode(uint8_t DAC) { - return _register[DAC] & 0x03;; + return _register[DAC] & 0x03; } // DAC = 0, 1, 2, 3 depending on type @@ -112,7 +114,7 @@ void DAC8552::updateDevice(uint8_t DAC, bool directWrite) SPI.transfer(configRegister); SPI.transfer(_value[DAC] >> 8); SPI.transfer(_value[DAC] & 0xFF); - digitalWrite(_slaveSelect, LOW); + digitalWrite(_slaveSelect, HIGH); SPI.endTransaction(); } else // Software SPI @@ -121,7 +123,7 @@ void DAC8552::updateDevice(uint8_t DAC, bool directWrite) swSPI_transfer(configRegister); swSPI_transfer(_value[DAC] >> 8); swSPI_transfer(_value[DAC] & 0xFF); - digitalWrite(_slaveSelect, LOW); + digitalWrite(_slaveSelect, HIGH); } } @@ -136,4 +138,4 @@ void DAC8552::swSPI_transfer(uint8_t value) } } -// END OF FILE \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/DAC8552/DAC8552.h b/libraries/DAC8552/DAC8552.h index 64a9c168..815a386b 100644 --- a/libraries/DAC8552/DAC8552.h +++ b/libraries/DAC8552/DAC8552.h @@ -1,12 +1,11 @@ +#pragma once // -// FILE: DAC8552.h +// FILE: DAC8552.h // AUTHOR: Rob Tillaart -// PURPOSE: DAC8552 library for Arduino -// VERSION: 0.1.1 +// PURPOSE: Arduino library for DAC8552 SPI Digital Analog Convertor +// VERSION: 0.1.3 // HISTORY: See DAC8552.cpp -// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/DAC8552 -// -// Released to the public domain +// URL: https://github.com/RobTillaart/DAC8552 // #include @@ -16,7 +15,7 @@ #define DAC8552_POWERDOWN_100K 2 #define DAC8552_POWERDOWN_HIGH_IMP 3 -#define DAC8552_LIB_VERSION (F("0.1.1 experimental")) +#define DAC8552_LIB_VERSION "0.1.3" class DAC8552 { @@ -47,4 +46,4 @@ private: void swSPI_transfer(uint8_t value); }; -// END OF FILE \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/DAC8552/LICENSE b/libraries/DAC8552/LICENSE new file mode 100644 index 00000000..ed401f22 --- /dev/null +++ b/libraries/DAC8552/LICENSE @@ -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. diff --git a/libraries/DAC8552/README.md b/libraries/DAC8552/README.md new file mode 100644 index 00000000..287e21a6 --- /dev/null +++ b/libraries/DAC8552/README.md @@ -0,0 +1,31 @@ +# DAC8552 +Arduino library for DAC8552 SPPI Digital Analog Convertor + +## Description + +not tested extensively + +## Operation + +See examples + +**demo_hw_spi.ino** +write a sawtooth to channel A followed by a sinus +uses HW SPI + +**demo_sw_spi.ino** +write a sawtooth to channel A followed by a sinus +uses SW SPI + +**demo_same_time_write.ino** +writes two square waves that trigger at the same time + +**demo_sequential_write.ino** +writes two square waves sequentially (slight time difference) + +**demo_powerdown.ino** +idem + +## TODO + +more testing diff --git a/libraries/DAC8552/examples/DAC8552_hw_spi/DAC8552_hw_spi.ino b/libraries/DAC8552/examples/DAC8552_hw_spi/DAC8552_hw_spi.ino index 7a4860f4..c2433b33 100644 --- a/libraries/DAC8552/examples/DAC8552_hw_spi/DAC8552_hw_spi.ino +++ b/libraries/DAC8552/examples/DAC8552_hw_spi/DAC8552_hw_spi.ino @@ -2,11 +2,8 @@ // FILE: DAC8552_hw_spi.ino // AUTHOR: Rob Tillaart // PURPOSE: demo DAC8552 library Arduino with hardware SPI -// VERSION: 0.1.0 -// HISTORY: -// URL: -// -// Released to the public domain +// VERSION: 0.1.1 +// URL: https://github.com/RobTillaart/DAC8552 // #include @@ -36,7 +33,9 @@ void loop() Serial.print(val); Serial.print("\t ==> \t"); Serial.print(av); + if (val % 300 == 0) Serial.println(); } + Serial.println(); // minimal sinus for (long i = 0; i < 360; i++ ) @@ -48,7 +47,10 @@ void loop() Serial.print("\t ==> \t"); Serial.print(av); delay(100); + if (i % 30 == 0) Serial.println(); } + Serial.println(); + } -// END OF FILE \ No newline at end of file +// -- END OF FILE -- \ No newline at end of file diff --git a/libraries/DAC8552/examples/DAC8552_powerdown/DAC8552_powerdown.ino b/libraries/DAC8552/examples/DAC8552_powerdown/DAC8552_powerdown.ino index 08f6af20..7f0bffc2 100644 --- a/libraries/DAC8552/examples/DAC8552_powerdown/DAC8552_powerdown.ino +++ b/libraries/DAC8552/examples/DAC8552_powerdown/DAC8552_powerdown.ino @@ -2,11 +2,8 @@ // FILE: DAC8552_powerdown.ino // AUTHOR: Rob Tillaart // PURPOSE: demo DAC8552 library Arduino -// VERSION: 0.1.0 -// HISTORY: -// URL: -// -// Released to the public domain +// VERSION: 0.1.1 +// URL: https://github.com/RobTillaart/DAC8552 // #include @@ -56,4 +53,4 @@ void loop() DAC.setPowerDown(chanA, DAC8552_POWERDOWN_NORMAL); } -// END OF FILE \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/DAC8552/examples/DAC8552_same_time_write/DAC8552_same_time_write.ino b/libraries/DAC8552/examples/DAC8552_same_time_write/DAC8552_same_time_write.ino index 5183a0c1..cb701572 100644 --- a/libraries/DAC8552/examples/DAC8552_same_time_write/DAC8552_same_time_write.ino +++ b/libraries/DAC8552/examples/DAC8552_same_time_write/DAC8552_same_time_write.ino @@ -2,11 +2,8 @@ // FILE: DAC8552_same_time_write.ino // AUTHOR: Rob Tillaart // PURPOSE: demo DAC8552 library Arduino with hardware SPI -// VERSION: 0.1.0 -// HISTORY: -// URL: -// -// Released to the public domain +// VERSION: 0.1.1 +// URL: https://github.com/RobTillaart/DAC8552 // #include @@ -52,4 +49,4 @@ void loop() } } -// END OF FILE \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/DAC8552/examples/DAC8552_sequential_write/DAC8552_sequential_write.ino b/libraries/DAC8552/examples/DAC8552_sequential_write/DAC8552_sequential_write.ino index 78aa508d..54afd9fa 100644 --- a/libraries/DAC8552/examples/DAC8552_sequential_write/DAC8552_sequential_write.ino +++ b/libraries/DAC8552/examples/DAC8552_sequential_write/DAC8552_sequential_write.ino @@ -2,11 +2,8 @@ // FILE: DAC8552_sequential_write.ino // AUTHOR: Rob Tillaart // PURPOSE: demo DAC8552 library Arduino -// VERSION: 0.1.0 -// HISTORY: -// URL: -// -// Released to the public domain +// VERSION: 0.1.1 +// URL: https://github.com/RobTillaart/DAC8552 // #include @@ -52,4 +49,4 @@ void loop() } } -// END OF FILE \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/DAC8552/examples/DAC8552_sw_spi/DAC8552_sw_spi.ino b/libraries/DAC8552/examples/DAC8552_sw_spi/DAC8552_sw_spi.ino index 7287821f..9443c0e4 100644 --- a/libraries/DAC8552/examples/DAC8552_sw_spi/DAC8552_sw_spi.ino +++ b/libraries/DAC8552/examples/DAC8552_sw_spi/DAC8552_sw_spi.ino @@ -2,11 +2,8 @@ // FILE: DAC8552_sw_spi.ino // AUTHOR: Rob Tillaart // PURPOSE: demo DAC8552 library Arduino with software SPI -// VERSION: 0.1.0 -// HISTORY: -// URL: -// -// Released to the public domain +// VERSION: 0.1.1 +// URL: https://github.com/RobTillaart/DAC8552 // #include @@ -36,7 +33,9 @@ void loop() Serial.print(val); Serial.print("\t ==> \t"); Serial.print(av); + if (val % 300 == 0) Serial.println(); } + Serial.println(); // minimal sinus for (long i = 0; i < 360; i++ ) @@ -48,7 +47,11 @@ void loop() Serial.print("\t ==> \t"); Serial.print(av); delay(100); + if (i % 30 == 0) Serial.println(); } + Serial.println(); + + } // END OF FILE \ No newline at end of file diff --git a/libraries/DAC8552/library.json b/libraries/DAC8552/library.json index 70ca876f..6ace3033 100644 --- a/libraries/DAC8552/library.json +++ b/libraries/DAC8552/library.json @@ -1,7 +1,7 @@ { "name": "DAC8552", - "keywords": "DAC8552,digital,analog,convertor ", - "description": "DAC8552 library for Arduino", + "keywords": "DAC8552, SPI, digital, analog, convertor", + "description": "Arduino library for DAC8552 SPI Digital Analog Convertor", "authors": [ { @@ -13,12 +13,9 @@ "repository": { "type": "git", - "url": "https://github.com/RobTillaart/Arduino.git" + "url": "https://github.com/RobTillaart/DAC8552" }, - "version":"0.1.1", + "version":"0.1.3", "frameworks": "arduino", - "platforms": "*", - "export": { - "include": "libraries/DAC8552" - } + "platforms": "*" } diff --git a/libraries/DAC8552/library.properties b/libraries/DAC8552/library.properties index 395b5f78..46737040 100644 --- a/libraries/DAC8552/library.properties +++ b/libraries/DAC8552/library.properties @@ -1,9 +1,11 @@ name=DAC8552 -version=0.1.1 +version=0.1.3 author=Rob Tillaart maintainer=Rob Tillaart -sentence=DAC8552 library for Arduino +sentence=Arduino library for DAC8552 SPI Digital Analog Convertor paragraph=experimental category=Sensors -url=https://github.com/RobTillaart/Arduino/tree/master/libraries/ -architectures=* \ No newline at end of file +url=https://github.com/RobTillaart/DAC8552 +architectures=* +includes=DAC8552.h +depends=SPI.h diff --git a/libraries/DAC8554/DAC8554.cpp b/libraries/DAC8554/DAC8554.cpp index 7f57b560..243bedc3 100644 --- a/libraries/DAC8554/DAC8554.cpp +++ b/libraries/DAC8554/DAC8554.cpp @@ -1,13 +1,15 @@ // // FILE: DAC8554.cpp // AUTHOR: Rob Tillaart -// PURPOSE: DAC8554 library for Arduino -// VERSION: 0.1.0 -// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/DAC8554 +// PURPOSE: Arduino library for DAC8554 SPI Digital Analog Convertor +// VERSION: 0.1.4 experimental +// URL: https://github.com/RobTillaart/DAC8554 +// // HISTORY: // 0.1.0: 2017-12-19 initial version -// -// Released to the public domain +// 0.1.2 2020-04-06 minor refactor, readme.md +// 0.1.3 2020-06-07 fix library.json +// 0.1.4 2020-07-20 fix URL's in demo's; MIT license; minor edits // #include @@ -48,6 +50,9 @@ void DAC8554::begin() pinMode(_spiData, OUTPUT); pinMode(_spiClock, OUTPUT); pinMode(_slaveSelect, OUTPUT); + digitalWrite(_slaveSelect, HIGH); + digitalWrite(_spiData, LOW); + digitalWrite(_spiClock, LOW); } } @@ -154,7 +159,7 @@ void DAC8554::writeDevice(uint8_t configRegister, uint16_t value) SPI.transfer(configRegister); SPI.transfer(value >> 8); SPI.transfer(value & 0xFF); - digitalWrite(_slaveSelect, LOW); + digitalWrite(_slaveSelect, HIGH); SPI.endTransaction(); } else // Software SPI @@ -163,7 +168,7 @@ void DAC8554::writeDevice(uint8_t configRegister, uint16_t value) swSPI_transfer(configRegister); swSPI_transfer(value >> 8); swSPI_transfer(value & 0xFF); - digitalWrite(_slaveSelect, LOW); + digitalWrite(_slaveSelect, HIGH); } } @@ -178,4 +183,4 @@ void DAC8554::swSPI_transfer(uint8_t value) } } -// END OF FILE \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/DAC8554/DAC8554.h b/libraries/DAC8554/DAC8554.h index 9d058bfa..f333098f 100644 --- a/libraries/DAC8554/DAC8554.h +++ b/libraries/DAC8554/DAC8554.h @@ -1,22 +1,21 @@ +#pragma once // // FILE: DAC8554.h // AUTHOR: Rob Tillaart -// PURPOSE: DAC8554 library for Arduino -// VERSION: 0.1.0 -// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/DAC8554 +// PURPOSE: Arduino library for DAC8554 SPI Digital Analog Convertor +// VERSION: 0.1.4 experimental // HISTORY: See DAC8554.cpp -// -// Released to the public domain +// URL: https://github.com/RobTillaart/DAC8554 // -#include +#include "SPI.h" #define DAC8554_POWERDOWN_NORMAL 0x00 #define DAC8554_POWERDOWN_1K 0x40 #define DAC8554_POWERDOWN_100K 0x80 #define DAC8554_POWERDOWN_HIGH_IMP 0xC0 -#define DAC8554_LIB_VERSION (F("0.1.0 experimental")) +#define DAC8554_LIB_VERSION "0.1.4" class DAC8554 { @@ -29,14 +28,11 @@ public: void begin(); - // writes the value for DAC in a buffer void bufferValue(uint8_t DAC, uint16_t value); - // writes all values including buffered ones to the DAC's void setValue(uint8_t DAC, uint16_t value); //writes the value to the DAC but does not affect buffered ones void setSingleValue(uint8_t DAC, uint16_t value); - // same as above but now for power down. void bufferPowerDown(uint8_t DAC, uint8_t powerDownMode); void setPowerDown(uint8_t DAC, uint8_t powerDownMode); void setSinglePowerDown(uint8_t DAC, uint8_t powerDownMode); @@ -59,4 +55,4 @@ private: void swSPI_transfer(uint8_t value); }; -// END OF FILE \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/DAC8554/LICENSE b/libraries/DAC8554/LICENSE new file mode 100644 index 00000000..ed401f22 --- /dev/null +++ b/libraries/DAC8554/LICENSE @@ -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. diff --git a/libraries/DAC8554/README.md b/libraries/DAC8554/README.md new file mode 100644 index 00000000..8718e7b0 --- /dev/null +++ b/libraries/DAC8554/README.md @@ -0,0 +1,31 @@ +# DAC8554 +Arduino library for DAC8554 Digital Analog Convertor + +## Description + +not tested extensively + +## Operation + +See examples + +**demo_hw_spi.ino** +write a sawtooth to channel A followed by a sinus +uses HW SPI + +**demo_sw_spi.ino** +write a sawtooth to channel A followed by a sinus +uses SW SPI + +**demo_same_time_write.ino** +writes two square waves that trigger at the same time + +**demo_sequential_write.ino** +writes two square waves sequentially (slight time difference) + +**demo_powerdown.ino** +idem + +## TODO + +more testing diff --git a/libraries/DAC8554/examples/DAC8554_broadcast/DAC8554_broadcast.ino b/libraries/DAC8554/examples/DAC8554_broadcast/DAC8554_broadcast.ino index df764b89..ec3c38cb 100644 --- a/libraries/DAC8554/examples/DAC8554_broadcast/DAC8554_broadcast.ino +++ b/libraries/DAC8554/examples/DAC8554_broadcast/DAC8554_broadcast.ino @@ -2,14 +2,13 @@ // FILE: DAC8554_broadcast.ino // AUTHOR: Rob Tillaart // PURPOSE: demo DAC8554 library Arduino with hardware SPI -// VERSION: 0.1.0 -// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/DAC8554 +// VERSION: 0.1.1 +// URL: https://github.com/RobTillaart/Arduino/DAC8554 + // HISTORY: // 0.1.0: 2017-12-19 initial version -// -// Released to the public domain -// -#include +// 0.1.1 2020-07-20 fix URL; minor edits + #include "DAC8554.h" // note address as param diff --git a/libraries/DAC8554/examples/DAC8554_hw_spi/DAC8554_hw_spi.ino b/libraries/DAC8554/examples/DAC8554_hw_spi/DAC8554_hw_spi.ino index 33a12d38..f3a3cf93 100644 --- a/libraries/DAC8554/examples/DAC8554_hw_spi/DAC8554_hw_spi.ino +++ b/libraries/DAC8554/examples/DAC8554_hw_spi/DAC8554_hw_spi.ino @@ -2,15 +2,13 @@ // FILE: DAC8554_hw_spi.ino // AUTHOR: Rob Tillaart // PURPOSE: demo DAC8554 library Arduino with hardware SPI -// VERSION: 0.1.0 -// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/DAC8554 +// VERSION: 0.1.1 +// URL: https://github.com/RobTillaart/Arduino/DAC8554 +// // HISTORY: // 0.1.0: 2017-12-19 initial version -// -// Released to the public domain -// +// 0.1.1 2020-07-20 fix URL; minor edits -#include #include "DAC8554.h" DAC8554 DAC; diff --git a/libraries/DAC8554/examples/DAC8554_powerdown/DAC8554_powerdown.ino b/libraries/DAC8554/examples/DAC8554_powerdown/DAC8554_powerdown.ino index 1d9d80da..e40fb17e 100644 --- a/libraries/DAC8554/examples/DAC8554_powerdown/DAC8554_powerdown.ino +++ b/libraries/DAC8554/examples/DAC8554_powerdown/DAC8554_powerdown.ino @@ -2,15 +2,13 @@ // FILE: DAC8554_powerdown.ino // AUTHOR: Rob Tillaart // PURPOSE: demo DAC8554 library Arduino -// VERSION: 0.1.0 -// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/DAC8554 +// VERSION: 0.1.1 +// URL: https://github.com/RobTillaart/Arduino/DAC8554 +// // HISTORY: // 0.1.0: 2017-12-19 experimental version - NOT tested - from data sheet -// -// Released to the public domain -// +// 0.1.1 2020-07-20 fix URL; minor edits -#include #include "DAC8554.h" // HW SPI diff --git a/libraries/DAC8554/examples/DAC8554_same_time_write/DAC8554_same_time_write.ino b/libraries/DAC8554/examples/DAC8554_same_time_write/DAC8554_same_time_write.ino index 5253843b..ad872bde 100644 --- a/libraries/DAC8554/examples/DAC8554_same_time_write/DAC8554_same_time_write.ino +++ b/libraries/DAC8554/examples/DAC8554_same_time_write/DAC8554_same_time_write.ino @@ -2,15 +2,13 @@ // FILE: DAC8554_same_time_write.ino // AUTHOR: Rob Tillaart // PURPOSE: demo DAC8554 library Arduino with hardware SPI -// VERSION: 0.1.0 -// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/DAC8554 +// VERSION: 0.1.1 +// URL: https://github.com/RobTillaart/Arduino/DAC8554 +// // HISTORY: // 0.1.0: 2017-12-19 initial version -// -// Released to the public domain -// +// 0.1.1 2020-07-20 fix URL; minor edits -#include #include "DAC8554.h" // HW SPI diff --git a/libraries/DAC8554/examples/DAC8554_sequential_write/DAC8554_sequential_write.ino b/libraries/DAC8554/examples/DAC8554_sequential_write/DAC8554_sequential_write.ino index f4bb1b2b..8a252693 100644 --- a/libraries/DAC8554/examples/DAC8554_sequential_write/DAC8554_sequential_write.ino +++ b/libraries/DAC8554/examples/DAC8554_sequential_write/DAC8554_sequential_write.ino @@ -2,15 +2,13 @@ // FILE: DAC8554_sequential_write.ino // AUTHOR: Rob Tillaart // PURPOSE: demo DAC8554 library Arduino -// VERSION: 0.1.0 -// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/DAC8554 +// VERSION: 0.1.1 +// URL: https://github.com/RobTillaart/DAC8554 +// // HISTORY: // 0.1.0: 2017-12-19 initial version -// -// Released to the public domain -// +// 0.1.1 2020-07-20 fix URL; minor edits -#include #include "DAC8554.h" // HW SPI diff --git a/libraries/DAC8554/examples/DAC8554_sw_spi/DAC8554_sw_spi.ino b/libraries/DAC8554/examples/DAC8554_sw_spi/DAC8554_sw_spi.ino index 068ac903..5bac249d 100644 --- a/libraries/DAC8554/examples/DAC8554_sw_spi/DAC8554_sw_spi.ino +++ b/libraries/DAC8554/examples/DAC8554_sw_spi/DAC8554_sw_spi.ino @@ -2,15 +2,13 @@ // FILE: DAC8554_sw_spi.ino // AUTHOR: Rob Tillaart // PURPOSE: demo DAC8554 library Arduino with software SPI -// VERSION: 0.1.0 -// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/DAC8554 +// VERSION: 0.1.1 +// URL: https://github.com/RobTillaart/Arduino/DAC8554 +// // HISTORY: // 0.1.0: 2017-12-19 initial version -// -// Released to the public domain -// +// 0.1.1 2020-07-20 fix URL; minor edits -#include #include "DAC8554.h" // SW SPI pins 4,5,6 diff --git a/libraries/DAC8554/library.json b/libraries/DAC8554/library.json index 738db9d7..b0347e8e 100644 --- a/libraries/DAC8554/library.json +++ b/libraries/DAC8554/library.json @@ -1,7 +1,7 @@ { "name": "DAC8554", - "keywords": "DAC8554,digital,analog,convertor", - "description": "DAC8554 library for Arduino", + "keywords": "DAC8554, SPI, digital, analog, convertor", + "description": "Arduino library for DAC8554 SPI Digital Analog Convertor", "authors": [ { @@ -13,12 +13,9 @@ "repository": { "type": "git", - "url": "https://github.com/RobTillaart/Arduino.git" + "url": "https://github.com/RobTillaart/DAC8554" }, - "version":"0.1.0", + "version":"0.1.4", "frameworks": "arduino", - "platforms": "*", - "export": { - "include": "libraries/DAC8554" - } + "platforms": "*" } diff --git a/libraries/DAC8554/library.properties b/libraries/DAC8554/library.properties index 894f93ec..2b947832 100644 --- a/libraries/DAC8554/library.properties +++ b/libraries/DAC8554/library.properties @@ -1,9 +1,11 @@ name=DAC8554 -version=0.1.0 +version=0.1.4 author=Rob Tillaart maintainer=Rob Tillaart -sentence=DAC8554 library for Arduino -paragraph= +sentence=Arduino library for DAC8554 SPI Digital Analog Convertor +paragraph=experimental category=Sensors -url=https://github.com/RobTillaart/Arduino/tree/master/libraries/ -architectures=* \ No newline at end of file +url=https://github.com/RobTillaart/DAC8554 +architectures=* +includes=DAC8554.h +depends=SPI.h diff --git a/libraries/DHT12/DHT12.cpp b/libraries/DHT12/DHT12.cpp index 2a9edb69..a513e377 100644 --- a/libraries/DHT12/DHT12.cpp +++ b/libraries/DHT12/DHT12.cpp @@ -1,7 +1,7 @@ // // FILE: DHT12.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.2 +// VERSION: 0.2.0 // PURPOSE: I2C library for DHT12 for Arduino. // // HISTORY: @@ -9,33 +9,46 @@ // 0.1.1: 2017-12-19 added ESP8266 - issue #86 // Verified by Viktor Balint // 0.1.2: 2018-09-02 fix negative temperature DHT12 - issue #111 -// -// -// Released to the public domain +// 0.2.0 2020-04-11 explicit constructors, select other Wire interface, #pragma once +// 0.2.1 2020-06-07 fix library.json // -#include #include #define DHT12_ADDRESS ((uint8_t)0x5C) -//////////////////////////////////////////////////////////////////// -// -// PUBLIC -// -#ifdef ESP8266 -void DHT12::begin(uint8_t sda, uint8_t scl) +DHT12::DHT12() { - Wire.begin(sda, scl); + DHT12(Wire); } -#endif + + +DHT12::DHT12(TwoWire *wire) +{ + _wire = wire; +} + void DHT12::begin() { - Wire.begin(); + _wire->begin(); } + +#if defined(ESP8266) || defined(ESP32) +void DHT12::begin(const uint8_t dataPin, const uint8_t clockPin) +{ + if ((dataPin < 255) && (clockPin < 255)) + { + _wire->begin(dataPin, clockPin); + } else { + _wire->begin(); + } +} +#endif + + int8_t DHT12::read() { // READ SENSOR @@ -60,33 +73,27 @@ int8_t DHT12::read() return DHT12_OK; } -//////////////////////////////////////////////////////////////////// -// -// PRIVATE -// -// negative is error in communication -// 5 is OK -// 0..4 is too few bytes. int DHT12::_readSensor() { // GET CONNECTION - Wire.beginTransmission(DHT12_ADDRESS); - Wire.write(0); - int rv = Wire.endTransmission(); + _wire->beginTransmission(DHT12_ADDRESS); + _wire->write(0); + int rv = _wire->endTransmission(); if (rv < 0) return rv; // GET DATA const uint8_t length = 5; - int bytes = Wire.requestFrom(DHT12_ADDRESS, length); + int bytes = _wire->requestFrom(DHT12_ADDRESS, length); if (bytes == 0) return DHT12_ERROR_CONNECT; if (bytes < length) return DHT12_MISSING_BYTES; for (int i = 0; i < bytes; i++) { - bits[i] = Wire.read(); + bits[i] = _wire->read(); } return bytes; } -// END OF FILE \ No newline at end of file + +// -- END OF FILE -- diff --git a/libraries/DHT12/DHT12.h b/libraries/DHT12/DHT12.h index 5d2f445b..005b30a3 100644 --- a/libraries/DHT12/DHT12.h +++ b/libraries/DHT12/DHT12.h @@ -1,20 +1,16 @@ -#ifndef DHT12_H -#define DHT12_H +#pragma once // // FILE: DHT12.h // AUTHOR: Rob Tillaart // PURPOSE: DHT_I2C library for Arduino . -// VERSION: 0.1.2 +// VERSION: 0.2.1 // HISTORY: See DHT12.cpp -// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/ -// -// Released to the public domain +// URL: https://github.com/RobTillaart/DHT12 // -#include "Wire.h" -#include "Arduino.h" +#include -#define DHT12_VERSION "0.1.2" +#define DHT12_LIB_VERSION "0.2.1" #define DHT12_OK 0 #define DHT12_ERROR_CHECKSUM -10 @@ -24,21 +20,28 @@ class DHT12 { public: + explicit DHT12(); + explicit DHT12(TwoWire *wire); // to be tested explicitly - #ifdef ESP8266 - void begin(uint8_t sda, uint8_t scl); - #endif +#if defined(ESP8266) || defined(ESP32) + void begin(const uint8_t dataPin, const uint8_t clockPin); +#endif void begin(); int8_t read(); + // preferred interface + float getHumidity() { return humidity; }; + float getTemperature() { return temperature; }; + + // members will become private in the future. float humidity; float temperature; private: uint8_t bits[5]; int _readSensor(); + TwoWire* _wire; }; -#endif -// END OF FILE \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/DHT12/LICENSE b/libraries/DHT12/LICENSE new file mode 100644 index 00000000..ed401f22 --- /dev/null +++ b/libraries/DHT12/LICENSE @@ -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. diff --git a/libraries/DHT12/README.md b/libraries/DHT12/README.md new file mode 100644 index 00000000..bbde09e0 --- /dev/null +++ b/libraries/DHT12/README.md @@ -0,0 +1,19 @@ +# DHT12 + +Arduino library for I2C DHT12 temperature and humidity sensor. + +## Description + +The library should be initiated by calling the **begin()** function, +optionally with datapin and clockpin for **ESP** and other platforms. + +Thereafter one has to call the **read()** function to do the actual reading, +and with **getTemperature()** and **getHumidity()** to get the read values. +Calling these latter again will return the same values until a new **read()** is called. + +### note +The two members **temperature** and **humidity** will become private in the future. + +## Operation + +See examples diff --git a/libraries/DHT12/examples/DHT12/DHT12.ino b/libraries/DHT12/examples/DHT12/DHT12.ino index 50ba9758..022b19b8 100644 --- a/libraries/DHT12/examples/DHT12/DHT12.ino +++ b/libraries/DHT12/examples/DHT12/DHT12.ino @@ -1,11 +1,12 @@ // // FILE: DHT12.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.0 +// VERSION: 0.1.1 // PURPOSE: Demo for DHT12 I2C humidity & temperature sensor // // HISTORY: // 0.1.0 - 2017-12-11 initial version +// 0.1.1 2020-04-11 minor changes // // Released to the public domain // @@ -16,12 +17,12 @@ DHT12 DHT; void setup() { - Wire.begin(); + DHT.begin(); Serial.begin(115200); Serial.println(__FILE__); Serial.print("DHT12 LIBRARY VERSION: "); - Serial.println(DHT12_VERSION); + Serial.println(DHT12_LIB_VERSION); Serial.println(); delay(2000); @@ -53,11 +54,11 @@ void loop() break; } // DISPLAY DATA, sensor has only one decimal. - Serial.print(DHT.humidity, 1); + Serial.print(DHT.getHumidity(), 1); Serial.print(",\t"); - Serial.println(DHT.temperature, 1); + Serial.println(DHT.getTemperature(), 1); delay(2000); } -// END OF FILE \ No newline at end of file +// -- END OF FILE -- \ No newline at end of file diff --git a/libraries/DHT12/examples/DHT12_plotter/DHT12_plotter.ino b/libraries/DHT12/examples/DHT12_plotter/DHT12_plotter.ino new file mode 100644 index 00000000..3f881550 --- /dev/null +++ b/libraries/DHT12/examples/DHT12_plotter/DHT12_plotter.ino @@ -0,0 +1,32 @@ +// +// FILE: DHT12 _plotter.ino +// AUTHOR: Rob Tillaart +// VERSION: 0.1.0 +// PURPOSE: Demo for DHT12 I2C humidity & temperature sensor +// +// HISTORY: +// 0.1.0 - 2020-04-11 initial version +// + +#include + +DHT12 DHT; + +void setup() +{ + DHT.begin(); + Serial.begin(115200); + Serial.println("Humidity, Temperature"); +} + +void loop() +{ + // note no error checking + DHT.read(); + Serial.print(DHT.getHumidity(), 1); + Serial.print(", "); + Serial.println(DHT.getTemperature(), 1); + delay(1000); +} + +// -- END OF FILE -- diff --git a/libraries/DHT12/examples/DHT12_test_esp/DHT12_test_esp.ino b/libraries/DHT12/examples/DHT12_test_esp/DHT12_test_esp.ino new file mode 100644 index 00000000..288227c5 --- /dev/null +++ b/libraries/DHT12/examples/DHT12_test_esp/DHT12_test_esp.ino @@ -0,0 +1,61 @@ +// +// FILE: DHT12_test_esp.ino +// AUTHOR: Rob Tillaart +// VERSION: 0.1.0 +// PURPOSE: Demo for DHT12 I2C humidity & temperature sensor +// +// HISTORY: +// 0.1.0 2020-04-11 initial version +// + +#include + +DHT12 DHT; + +void setup() +{ + DHT.begin(12, 13); // select your pin numbers here + + Serial.begin(115200); + Serial.println(__FILE__); + Serial.print("DHT12 LIBRARY VERSION: "); + Serial.println(DHT12_LIB_VERSION); + Serial.println(); + + delay(2000); + + Serial.println("Type,\tStatus,\tHumidity (%),\tTemperature (C)"); +} + +void loop() +{ + // READ DATA + Serial.print("DHT12, \t"); + int status = DHT.read(); + switch (status) + { + case DHT12_OK: + Serial.print("OK,\t"); + break; + case DHT12_ERROR_CHECKSUM: + Serial.print("Checksum error,\t"); + break; + case DHT12_ERROR_CONNECT: + Serial.print("Connect error,\t"); + break; + case DHT12_MISSING_BYTES: + Serial.print("Missing bytes,\t"); + break; + default: + Serial.print("Unknown error,\t"); + break; + } + // DISPLAY DATA, sensor has only one decimal. + Serial.print(DHT.getHumidity(), 1); + Serial.print(",\t"); + Serial.println(DHT.getTemperature(), 1); + + delay(2000); +} + +// -- END OF FILE -- diff --git a/libraries/DHT12/keywords.txt b/libraries/DHT12/keywords.txt index ae604ae4..a462a7e7 100644 --- a/libraries/DHT12/keywords.txt +++ b/libraries/DHT12/keywords.txt @@ -1,25 +1,16 @@ -####################################### # Syntax Coloring Map For DHT_I2C -####################################### -####################################### # Datatypes (KEYWORD1) -####################################### - DHT12 KEYWORD1 -####################################### # Methods and Functions (KEYWORD2) -####################################### - read KEYWORD2 +getHumidity KEYWORD2 +getTemperature KEYWORD2 humidity KEYWORD2 temperature KEYWORD2 -####################################### # Constants (LITERAL1) -####################################### - DHT12_VERSION LITERAL2 DHT12_OK LITERAL2 DHT12_ERROR_CHECKSUM LITERAL1 diff --git a/libraries/DHT12/library.json b/libraries/DHT12/library.json index 97582b56..aaa9582a 100644 --- a/libraries/DHT12/library.json +++ b/libraries/DHT12/library.json @@ -1,7 +1,7 @@ { "name": "DHT12", - "keywords": "Temperature,Humidity,DHT12,I2C", - "description": "I2C Library for DHT12", + "keywords": "Temperature, Humidity, DHT12, I2C", + "description": "Arduino library for I2C DHT12 temperature and humidity sensor. ", "authors": [ { @@ -13,12 +13,9 @@ "repository": { "type": "git", - "url": "https://github.com/RobTillaart/Arduino.git" + "url": "https://github.com/RobTillaart/DHT12.git" }, - "version":"0.1.2", + "version":"0.2.1", "frameworks": "arduino", - "platforms": "*", - "export": { - "include": "libraries/DHT12" - } + "platforms": "*" } diff --git a/libraries/DHT12/library.properties b/libraries/DHT12/library.properties index be5e61c2..0f5f7afc 100644 --- a/libraries/DHT12/library.properties +++ b/libraries/DHT12/library.properties @@ -1,9 +1,11 @@ name=DHT12 -version=0.1.2 +version=0.2.1 author=Rob Tillaart maintainer=Rob Tillaart -sentence=I2C Library for DHT12 Temperature and Humidity. +sentence=Arduino library for I2C DHT12 temperature and humidity sensor. paragraph=DHT12 category=Sensors -url=https://github.com/RobTillaart/Arduino/tree/master/libraries/ -architectures=* \ No newline at end of file +url=https://github.com/RobTillaart/DHT12 +architectures=* +includes=DHT12.h +depends=Wire diff --git a/libraries/DHT2pin/LICENSE b/libraries/DHT2pin/LICENSE new file mode 100644 index 00000000..9aa72bbc --- /dev/null +++ b/libraries/DHT2pin/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016-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. diff --git a/libraries/DHT2pin/dht2pin.cpp b/libraries/DHT2pin/dht2pin.cpp index 09f6db7f..40f8aa5a 100644 --- a/libraries/DHT2pin/dht2pin.cpp +++ b/libraries/DHT2pin/dht2pin.cpp @@ -1,19 +1,19 @@ // // FILE: DHT2pin.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.0.3 +// VERSION: 0.1.0 // PURPOSE: Experimental DHT Temperature & Humidity Sensor library for Arduino -// URL: +// URL: https://github.com/RobTillaart/DHT2pin +// http://arduino.cc/playground/Main/DHTLib // // HISTORY: +// 0.1.0 2020-06-30 own repository; #pragma once // 0.0.3 Fix issue #33 // 0.0.2 support for non "F_CPU" boards especially Galileo // Tested and verified by Maria Emanuella Moura Silva (thanks) // changed name to DHT2pin // 0.0.1 initial version - 2016 SEP 05 (based upon 0.1.13 DHT) // -// Released to the public domain -// #include "DHT2pin.h" diff --git a/libraries/DHT2pin/dht2pin.h b/libraries/DHT2pin/dht2pin.h index ae0ec3b0..b67c528d 100644 --- a/libraries/DHT2pin/dht2pin.h +++ b/libraries/DHT2pin/dht2pin.h @@ -1,20 +1,19 @@ +#pragma once // // FILE: dht2pin.h // AUTHOR: Rob Tillaart -// VERSION: 0.0.3 +// VERSION: 0.1.0 // PURPOSE: DHT Temperature & Humidity Sensor library for Arduino -// URL: http://arduino.cc/playground/Main/DHTLib +// URL: https://github.com/RobTillaart/DHT2pin +// http://arduino.cc/playground/Main/DHTLib // // HISTORY: // see dht.cpp file // -#ifndef dht_h -#define dht_h - #include -#define DHT2PIN_LIB_VERSION "0.0.3" +#define DHT2PIN_LIB_VERSION "0.1.0" #define DHTLIB_OK 0 #define DHTLIB_ERROR_CHECKSUM -1 @@ -74,7 +73,7 @@ private: uint8_t bits[5]; // buffer to receive data int _readSensor(uint8_t wakeupDelay); }; -#endif + // // END OF FILE // \ No newline at end of file diff --git a/libraries/DHT2pin/examples/dht2pin/dht2pin.ino b/libraries/DHT2pin/examples/dht2pin/dht2pin.ino index 4f1565a8..32017daf 100644 --- a/libraries/DHT2pin/examples/dht2pin/dht2pin.ino +++ b/libraries/DHT2pin/examples/dht2pin/dht2pin.ino @@ -4,7 +4,9 @@ // VERSION: 0.1.01 // PURPOSE: demo reading an DHT with 2 pins iso 1 // DATE: 2016 sep 5 -// URL: - +// URL: https://github.com/RobTillaart/DHT2pin +// http://arduino.cc/playground/Main/DHTLib +// // HISTORY: // 0.1.01 changed name to DHT2pin // 0.1.00 initial version diff --git a/libraries/DHT2pin/library.json b/libraries/DHT2pin/library.json index 895342d1..d8c60344 100644 --- a/libraries/DHT2pin/library.json +++ b/libraries/DHT2pin/library.json @@ -13,12 +13,9 @@ "repository": { "type": "git", - "url": "https://github.com/RobTillaart/Arduino.git" + "url": "https://github.com/RobTillaart/DHT2pin" }, - "version":"0.0.3", + "version":"0.1.0", "frameworks": "arduino", - "platforms": "*", - "export": { - "include": "libraries/DHT2pin" - } + "platforms": "*" } diff --git a/libraries/DHT2pin/library.properties b/libraries/DHT2pin/library.properties index a95cfe76..d2b096ac 100644 --- a/libraries/DHT2pin/library.properties +++ b/libraries/DHT2pin/library.properties @@ -1,9 +1,11 @@ name=DHT2pin -version=0.0.3 +version=0.1.0 author=Rob Tillaart maintainer=Rob Tillaart -sentence=Experimental library of the DHT library that uses 2 pins instead of 3. +sentence=Experimental library of the DHT library that uses 2 pins. paragraph= category=Sensors -url=https://github.com/RobTillaart/Arduino/tree/master/libraries/ -architectures=* \ No newline at end of file +url=https://github.com/RobTillaart/DHT2pin +architectures=* +includes=DHT2pin.h +depends= diff --git a/libraries/DHT2pin/readme.md b/libraries/DHT2pin/readme.md index 098fc5fd..9d1d89fe 100644 --- a/libraries/DHT2pin/readme.md +++ b/libraries/DHT2pin/readme.md @@ -1,22 +1,35 @@ +# DHT2pin -# DHT2PIN library +Arduino library for experimental 2 pin DHT library ## Description -NOTE: THIS LIB IS NOT TESTED EXTENSIVELY YET SO ALL DISCLAIMERS APPLY +**NOTE: THIS LIB IS NOT TESTED EXTENSIVELY YET SO USE WITH CARE** -This library is an experimental version of the DHT library that uses 2 pins instead of 1. -One pin for all read actions and one pin for write actions. +This library is an experimental version of the DHT library that uses 2 pins. +One pin for all read actions and one pin for write actions. This way one does +not need to switch a pin between **INPUT** and **OUTPUT**. + +Note: It needs a diode in the hardware between the input pin of the MCU +and the datapin of the DHT sensor. +The output pin of the MCU is directly connected to the datapin of the DHT sensor. It was made after a request which also refered to the links below. https://communities.intel.com/thread/53869 + +(this link looks dead) http://bigdinotech.com/tutorials/galileo-tutorials/using-1-wire-device-with-intel-galileo/ -## Credits +**NOTE: THIS LIB IS NOT TESTED EXTENSIVELY YET SO USE WITH CARE** -Maria Emanuella Moura Silva for testing and verifying this experimental code on a Galileo. +## Credits & testing -## NOTE: THIS LIB IS NOT TESTED EXTENSIVELY YET SO ALL DISCLAIMERS APPLY +Maria Emanuella Moura Silva for testing and verifying this experimental +code on a Galileo. + +## Operation + +See examples diff --git a/libraries/DHTNEW/dhtnew.cpp b/libraries/DHTNEW/dhtnew.cpp index 30f9bebd..7f6ca20e 100644 --- a/libraries/DHTNEW/dhtnew.cpp +++ b/libraries/DHTNEW/dhtnew.cpp @@ -1,7 +1,7 @@ // // FILE: dhtnew.cpp // AUTHOR: Rob.Tillaart@gmail.com -// VERSION: 0.2.0 +// VERSION: 0.4.1 // PURPOSE: DHT Temperature & Humidity Sensor library for Arduino // URL: https://github.com/RobTillaart/DHTNEW // @@ -13,49 +13,101 @@ // 0.1.4 2018-04-03 add get-/setDisableIRQ(bool b) // 0.1.5 2019-01-20 fix negative temperature DHT22 - issue #120 // 0.1.6 2020-04-09 #pragma once, readme.md, own repo -// 0.1.7 2020-05-01 prevent premature read; add waitForReading flag (Kudo's to Mr-HaleYa), -// 0.2.0 2020-05-02 made temperature and humidity private (Kudo's to Mr-HaleYa), +// 0.1.7 2020-05-01 prevent premature read; add waitForReading flag (Kudo's to Mr-HaleYa), +// 0.2.0 2020-05-02 made temperature and humidity private (Kudo's to Mr-HaleYa), +// 0.2.1 2020-05-27 Fix #11 - Adjust bit timing threshold +// 0.2.2 2020-06-08 added ERROR_SENSOR_NOT_READY and differentiate timeout errors +// 0.3.0 2020-06-12 added getReadDelay & setReadDelay to tune reading interval +// removed get/setDisableIRQ; adjusted wakeup timing; refactor +// 0.3.1 2020-07-08 added powerUp() powerDown(); +// 0.3.2 2020-07-17 fix #23 added get/setSuppressError(); overrulable DHTLIB_INVALID_VALUE +// 0.3.3 2020-08-18 fix #29, create explicit delay between pulling line HIGH and +// waiting for LOW in handshake to trigger the sensor. +// On fast ESP32 this fails because the capacity / voltage of the long wire +// cannot rise fast enough to be read back as HIGH. +// 0.3.4 2020-09-23 Added **waitFor(state, timeout)** to follow timing from datasheet. +// Restored disableIRQ flag as problems occured on AVR. The default of +// this flag on AVR is false so interrupts are allowed. +// This need some investigation +// Fix wake up timing for DHT11 as it does not behave according datasheet. +// fix wakeupDelay bug in setType(); +// 0.4.0 2020-11-10 added DHTLIB_WAITING_FOR_READ as return value of read (minor break of interface) +// 0.4.1 2020-11-11 getType() attempts to detect sensor type #include "dhtnew.h" -// these defines are implementation only, not for user +// these defines are not for user to adjust #define DHTLIB_DHT11_WAKEUP 18 #define DHTLIB_DHT_WAKEUP 1 -// datasheet state 1000 and 2000,// experiments [Mr-HaleYa] indicate a bit larger value to be robust. -#define DHTLIB_DHT11_READ_DELAY 1250 -#define DHTLIB_DHT22_READ_DELAY 2250 - -// max timeout is 100usec. -// For a 16Mhz proc that is max 1600 clock cycles -// loops using TIMEOUT use at least 4 clock cycli -// so 100 us takes max 400 loops -// so by dividing F_CPU by 40000 we "fail" as fast as possible - -#define DHTLIB_TIMEOUT (F_CPU/40000) +// READ_DELAY for blocking read +// datasheet: DHT11 = 1000 and DHT22 = 2000 +// use setReadDelay() to overrule (at own risk) +// as individual sensors can be read faster. +// see example DHTnew_setReadDelay.ino +#define DHTLIB_DHT11_READ_DELAY 1000 +#define DHTLIB_DHT22_READ_DELAY 2000 ///////////////////////////////////////////////////// // // PUBLIC // -DHTNEW::DHTNEW(uint8_t pin) { _pin = pin; }; +DHTNEW::DHTNEW(uint8_t pin) +{ + _dataPin = pin; + // Data-bus's free status is high voltage level. + pinMode(_dataPin, OUTPUT); + digitalWrite(_dataPin, HIGH); + _readDelay = 0; + #if defined(__AVR__) + _disableIRQ = false; + #endif +}; + +uint8_t DHTNEW::getType() +{ + if (_type == 0) read(); + return _type; +} + +void DHTNEW::setType(uint8_t type) +{ + if ((type == 0) || (type == 11)) + { + _type = type; + _wakeupDelay = DHTLIB_DHT11_WAKEUP; + } + if (type == 22) + { + _type = type; + _wakeupDelay = DHTLIB_DHT_WAKEUP; + } +} // return values: // DHTLIB_OK +// DHTLIB_WAITING_FOR_READ // DHTLIB_ERROR_CHECKSUM -// DHTLIB_ERROR_TIMEOUT +// DHTLIB_ERROR_BIT_SHIFT +// DHTLIB_ERROR_SENSOR_NOT_READY +// DHTLIB_ERROR_TIMEOUT_A +// DHTLIB_ERROR_TIMEOUT_B +// DHTLIB_ERROR_TIMEOUT_C +// DHTLIB_ERROR_TIMEOUT_D int DHTNEW::read() { + if (_readDelay == 0) + { + _readDelay = DHTLIB_DHT22_READ_DELAY; + if (_type == 11) _readDelay = DHTLIB_DHT11_READ_DELAY; + } if (_type != 0) { - uint16_t readDelay = DHTLIB_DHT22_READ_DELAY; // assume DHT22 compatible - if (_type == 11) readDelay = DHTLIB_DHT11_READ_DELAY; - - while (millis() - _lastRead < readDelay) - { - if (!_waitForRead) return DHTLIB_OK; - yield(); - } + while (millis() - _lastRead < _readDelay) + { + if (!_waitForRead) return DHTLIB_WAITING_FOR_READ; + yield(); + } return _read(); } @@ -76,39 +128,50 @@ int DHTNEW::read() // return values: // DHTLIB_OK // DHTLIB_ERROR_CHECKSUM -// DHTLIB_ERROR_TIMEOUT +// DHTLIB_ERROR_BIT_SHIFT +// DHTLIB_ERROR_SENSOR_NOT_READY +// DHTLIB_ERROR_TIMEOUT_A +// DHTLIB_ERROR_TIMEOUT_B +// DHTLIB_ERROR_TIMEOUT_C +// DHTLIB_ERROR_TIMEOUT_D int DHTNEW::_read() { // READ VALUES - if (_disableIRQ) noInterrupts(); int rv = _readSensor(); - if (_disableIRQ) interrupts(); - _lastRead = millis(); + interrupts(); + + // Data-bus's free status is high voltage level. + pinMode(_dataPin, OUTPUT); + digitalWrite(_dataPin, HIGH); + _lastRead = millis(); if (rv != DHTLIB_OK) { - humidity = DHTLIB_INVALID_VALUE; - temperature = DHTLIB_INVALID_VALUE; - return rv; // propagate error value + if (_suppressError == false) + { + _humidity = DHTLIB_INVALID_VALUE; + _temperature = DHTLIB_INVALID_VALUE; + } + return rv; // propagate error value } if (_type == 22) // DHT22, DHT33, DHT44, compatible { - humidity = (_bits[0] * 256 + _bits[1]) * 0.1; - temperature = ((_bits[2] & 0x7F) * 256 + _bits[3]) * 0.1; + _humidity = (_bits[0] * 256 + _bits[1]) * 0.1; + _temperature = ((_bits[2] & 0x7F) * 256 + _bits[3]) * 0.1; } else // if (_type == 11) // DHT11, DH12, compatible { - humidity = _bits[0] + _bits[1] * 0.1; - temperature = _bits[2] + _bits[3] * 0.1; + _humidity = _bits[0] + _bits[1] * 0.1; + _temperature = _bits[2] + _bits[3] * 0.1; } if (_bits[2] & 0x80) // negative temperature { - temperature = -temperature; + _temperature = -_temperature; } - humidity = constrain(humidity + _humOffset, 0, 100); - temperature += _tempOffset; + _humidity = constrain(_humidity + _humOffset, 0, 100); + _temperature += _tempOffset; // TEST CHECKSUM uint8_t sum = _bits[0] + _bits[1] + _bits[2] + _bits[3]; @@ -119,6 +182,19 @@ int DHTNEW::_read() return DHTLIB_OK; } +void DHTNEW::powerUp() +{ + digitalWrite(_dataPin, HIGH); + // do a dummy read to sync the sensor + read(); +}; + +void DHTNEW::powerDown() +{ + digitalWrite(_dataPin, LOW); +} + + ///////////////////////////////////////////////////// // // PRIVATE @@ -126,57 +202,74 @@ int DHTNEW::_read() // return values: // DHTLIB_OK -// DHTLIB_ERROR_TIMEOUT +// DHTLIB_ERROR_CHECKSUM +// DHTLIB_ERROR_BIT_SHIFT +// DHTLIB_ERROR_SENSOR_NOT_READY +// DHTLIB_ERROR_TIMEOUT_A +// DHTLIB_ERROR_TIMEOUT_B +// DHTLIB_ERROR_TIMEOUT_C +// DHTLIB_ERROR_TIMEOUT_D int DHTNEW::_readSensor() { // INIT BUFFERVAR TO RECEIVE DATA - uint8_t mask = 128; + uint8_t mask = 0x80; uint8_t idx = 0; // EMPTY BUFFER for (uint8_t i = 0; i < 5; i++) _bits[i] = 0; - // REQUEST SAMPLE - pinMode(_pin, OUTPUT); - digitalWrite(_pin, LOW); - delay(_wakeupDelay); - pinMode(_pin, INPUT); - delayMicroseconds(40); + // HANDLE PENDING IRQ + yield(); - // GET ACKNOWLEDGE or TIMEOUT - uint16_t loopCnt = DHTLIB_TIMEOUT; - while(digitalRead(_pin) == LOW) - { - if (--loopCnt == 0) return DHTLIB_ERROR_TIMEOUT; - } + // REQUEST SAMPLE - SEND WAKEUP TO SENSOR + pinMode(_dataPin, OUTPUT); + digitalWrite(_dataPin, LOW); + // add 10% extra for timing inaccuracies in sensor. + delayMicroseconds(_wakeupDelay * 1100UL); - loopCnt = DHTLIB_TIMEOUT; - while(digitalRead(_pin) == HIGH) - { - if (--loopCnt == 0) return DHTLIB_ERROR_TIMEOUT; - } + // HOST GIVES CONTROL TO SENSOR + digitalWrite(_dataPin, HIGH); + delayMicroseconds(2); + pinMode(_dataPin, INPUT_PULLUP); + + // DISABLE INTERRUPTS when clock in the bits + if (_disableIRQ) { noInterrupts(); } + + // DHT22 + // SENSOR PULLS LOW after 20-40 us => if stays HIGH ==> device not ready + // timeout is 20 us less due to delay() above + // DHT11 + // SENSOR PULLS LOW after 6000-10000 us + uint32_t WAITFORSENSOR = 50; + if (_type == 11) WAITFORSENSOR = 15000UL; + if (_waitFor(LOW, WAITFORSENSOR)) return DHTLIB_ERROR_SENSOR_NOT_READY; + + // SENSOR STAYS LOW for ~80 us => or TIMEOUT + if (_waitFor(HIGH, 90)) return DHTLIB_ERROR_TIMEOUT_A; + + // SENSOR STAYS HIGH for ~80 us => or TIMEOUT + if (_waitFor(LOW, 90)) return DHTLIB_ERROR_TIMEOUT_B; + + // SENSOR HAS NOW SEND ACKNOWLEDGE ON WAKEUP + // NOW IT SENDS THE BITS // READ THE OUTPUT - 40 BITS => 5 BYTES for (uint8_t i = 40; i != 0; i--) { - loopCnt = DHTLIB_TIMEOUT; - while(digitalRead(_pin) == LOW) - { - if (--loopCnt == 0) return DHTLIB_ERROR_TIMEOUT; - } + // EACH BIT START WITH ~50 us LOW + if (_waitFor(HIGH, 70)) return DHTLIB_ERROR_TIMEOUT_C; + // DURATION OF HIGH DETERMINES 0 or 1 + // 26-28 us ==> 0 + // 70 us ==> 1 uint32_t t = micros(); - - loopCnt = DHTLIB_TIMEOUT; - while(digitalRead(_pin) == HIGH) - { - if (--loopCnt == 0) return DHTLIB_ERROR_TIMEOUT; - } - - if ((micros() - t) > 40) + if (_waitFor(LOW, 90)) return DHTLIB_ERROR_TIMEOUT_D; + if ((micros() - t) > DHTLIB_BIT_THRESHOLD) { _bits[idx] |= mask; } + + // PREPARE FOR NEXT BIT mask >>= 1; if (mask == 0) // next byte? { @@ -184,8 +277,35 @@ int DHTNEW::_readSensor() idx++; } } + // After 40 bits the sensor pulls the line LOW for 50 us + // No functional need to wait for this one + // if (_waitFor(HIGH, 60)) return DHTLIB_ERROR_TIMEOUT_E; + + // CATCH RIGHTSHIFT BUG ESP (only 1 single bit shift) + // humidity is max 1000 = 0x03E8 for DHT22 and 0x6400 for DHT11 + // so most significant bit may never be set. + if (_bits[0] & 0x80) return DHTLIB_ERROR_BIT_SHIFT; return DHTLIB_OK; } + +// returns true if timeout has passed. +// returns false if timeout is not reached and state is seen. +bool DHTNEW::_waitFor(uint8_t state, uint32_t timeout) +{ + uint32_t start = micros(); + uint8_t count = 2; + while ((micros() - start) < timeout) + { + // delayMicroseconds(1); // less # reads ==> minimizes # glitch reads + if (digitalRead(_dataPin) == state) + { + count--; + if (count == 0) return false; // requested state seen count times + } + } + return true; +} + // -- END OF FILE -- diff --git a/libraries/DHTNEW/dhtnew.h b/libraries/DHTNEW/dhtnew.h index 5347c61f..43cbe19d 100644 --- a/libraries/DHTNEW/dhtnew.h +++ b/libraries/DHTNEW/dhtnew.h @@ -2,69 +2,111 @@ // // FILE: dhtnew.h // AUTHOR: Rob Tillaart -// VERSION: 0.2.0 +// VERSION: 0.4.1 // PURPOSE: DHT Temperature & Humidity Sensor library for Arduino // URL: https://github.com/RobTillaart/DHTNEW // // HISTORY: // see dhtnew.cpp file -// -#include +// DHT PIN layout from left to right +// ================================= +// FRONT : DESCRIPTION +// pin 1 : VCC +// pin 2 : DATA +// pin 3 : Not Connected +// pin 4 : GND -#define DHTNEW_LIB_VERSION "0.2.0" +#include "Arduino.h" -#define DHTLIB_OK 0 -#define DHTLIB_ERROR_CHECKSUM -1 -#define DHTLIB_ERROR_TIMEOUT -2 -#define DHTLIB_INVALID_VALUE -999 +#define DHTNEW_LIB_VERSION "0.4.0" + +#define DHTLIB_OK 0 +#define DHTLIB_ERROR_CHECKSUM -1 +#define DHTLIB_ERROR_TIMEOUT_A -2 +#define DHTLIB_ERROR_BIT_SHIFT -3 +#define DHTLIB_ERROR_SENSOR_NOT_READY -4 +#define DHTLIB_ERROR_TIMEOUT_C -5 +#define DHTLIB_ERROR_TIMEOUT_D -6 +#define DHTLIB_ERROR_TIMEOUT_B -7 +#define DHTLIB_WAITING_FOR_READ -8 + +#ifndef DHTLIB_INVALID_VALUE +#define DHTLIB_INVALID_VALUE -999 +#endif + + +// bits are timing based (datasheet) +// 26-28us ==> 0 +// 70 us ==> 1 +// See https://github.com/RobTillaart/DHTNew/issues/11 +#ifndef DHTLIB_BIT_THRESHOLD +#define DHTLIB_BIT_THRESHOLD 50 +#endif class DHTNEW { public: - DHTNEW(uint8_t pin); + DHTNEW(uint8_t pin); - // 0 = unknown, 11 or 22 - int getType() { return _type; }; - int read(); + // 0 = unknown, 11 or 22 + uint8_t getType(); + void setType(uint8_t type = 0); + int read(); - // lastRead is in MilliSeconds since start sketch - uint32_t lastRead() { return _lastRead; }; + // lastRead is in MilliSeconds since start sketch + uint32_t lastRead() { return _lastRead; }; - // preferred interface - float getHumidity() { return humidity; }; - float getTemperature() { return temperature; }; + // preferred interface + float getHumidity() { return _humidity; }; + float getTemperature() { return _temperature; }; - // adding offsets works well in normal range - // might introduce under- or overflow at the ends of the sensor range - void setHumOffset(float offset) { _humOffset = offset; }; - void setTempOffset(float offset) { _tempOffset = offset; }; - float getHumOffset() { return _humOffset; }; - float getTempOffset() { return _tempOffset; }; + // adding offsets works well in normal range + // might introduce under- or overflow at the ends of the sensor range + void setHumOffset(float offset) { _humOffset = offset; }; + void setTempOffset(float offset) { _tempOffset = offset; }; + float getHumOffset() { return _humOffset; }; + float getTempOffset() { return _tempOffset; }; - bool getDisableIRQ() { return _disableIRQ; }; - void setDisableIRQ(bool b ) { _disableIRQ = b; }; + bool getDisableIRQ() { return _disableIRQ; }; + void setDisableIRQ(bool b ) { _disableIRQ = b; }; - bool getWaitForReading() { return _waitForRead; }; - void setWaitForReading(bool b ) { _waitForRead = b; }; + bool getWaitForReading() { return _waitForRead; }; + void setWaitForReading(bool b ) { _waitForRead = b; }; + + // set readDelay to 0 will reset to datasheet values + uint16_t getReadDelay() { return _readDelay; }; + void setReadDelay(uint16_t rd = 0) { _readDelay = rd; }; + + // minimal support for low power applications. + // after powerUp one must wait up to two seconds. + void powerUp(); + void powerDown(); + + // suppress error values of -999 => check return value of read() instead + bool getSuppressError() { return _suppressError; }; + void setSuppressError(bool b) { _suppressError = b; }; private: - uint8_t _pin = 0; - uint8_t _wakeupDelay = 0; - uint8_t _type = 0; - float _humOffset = 0.0; - float _tempOffset = 0.0; - float humidity; - float temperature; - uint32_t _lastRead = 0; - bool _disableIRQ = false; - bool _waitForRead = false; + uint8_t _dataPin = 0; + uint8_t _wakeupDelay = 0; + uint8_t _type = 0; + float _humOffset = 0.0; + float _tempOffset = 0.0; + float _humidity; + float _temperature; + uint32_t _lastRead = 0; + bool _disableIRQ = true; + bool _waitForRead = false; + bool _suppressError = false; + uint16_t _readDelay = 0; - uint8_t _bits[5]; // buffer to receive data - int _read(); - int _readSensor(); + uint8_t _bits[5]; // buffer to receive data + int _read(); + int _readSensor(); + bool _waitFor(uint8_t state, uint32_t timeout); }; // -- END OF FILE -- diff --git a/libraries/DHTNEW/examples/dhtnew_adaptive_delay/dhtnew_adaptive_delay.ino b/libraries/DHTNEW/examples/dhtnew_adaptive_delay/dhtnew_adaptive_delay.ino index 81f36a24..d7a2bc20 100644 --- a/libraries/DHTNEW/examples/dhtnew_adaptive_delay/dhtnew_adaptive_delay.ino +++ b/libraries/DHTNEW/examples/dhtnew_adaptive_delay/dhtnew_adaptive_delay.ino @@ -1,23 +1,34 @@ // // FILE: dhtnew_adaptive_delay.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.1 +// VERSION: 0.1.3 // PURPOSE: DHTNEW library test sketch for Arduino // URL: https://github.com/RobTillaart/DHTNew -// HISTORY: // +// HISTORY: // 0.1.0 2018-08-06 initial version // 0.1.1 2020-04-30 replaced humidity and temperature with functions +// 0.1.2 2020-06-08 redid 0.1.1 testing and fix + improved error handling +// 0.1.3 2020-06-15 match 0.3.0 error handling // -// FRONT left 2 right +// DHT PIN layout from left to right +// ================================= +// FRONT : DESCRIPTION // pin 1 : VCC // pin 2 : DATA -// pin 3 : NC -// PIN 4 : GND +// pin 3 : Not Connected +// pin 4 : GND + +// Note: +// Adaptive delay makes no sense anymore as the DHTNEW lib catches reads that +// are done faster than READ_DELAY apart (see dhtnew.cpp file). +// that said it is the goal to get this adaptibility into the library one day. +// A way to do this is to add a function auto_calibrate() that finds the timing +// where reading fails and use that value + safety margin (20%?) #include -DHTNEW mySensor(6); +DHTNEW mySensor(16); void setup() { @@ -76,12 +87,12 @@ void setup() void loop() { - + test(); } void test() { - static uint16_t dht_delay = 1000; + static uint16_t dht_delay = 600; // READ DATA uint32_t start = micros(); int chk = mySensor.read(); @@ -97,21 +108,42 @@ void test() Serial.print("Checksum error,\t"); dht_delay += 10; break; - case DHTLIB_ERROR_TIMEOUT: - Serial.print("Time out error,\t"); + case DHTLIB_ERROR_TIMEOUT_A: + Serial.print("Time out A error,\t"); + dht_delay += 10; + break; + case DHTLIB_ERROR_TIMEOUT_B: + Serial.print("Time out B error,\t"); + break; + case DHTLIB_ERROR_TIMEOUT_C: + Serial.print("Time out C error,\t"); + dht_delay += 10; + break; + case DHTLIB_ERROR_TIMEOUT_D: + Serial.print("Time out D error,\t"); + dht_delay += 10; + break; + case DHTLIB_ERROR_SENSOR_NOT_READY: + Serial.print("Sensor not ready,\t"); + dht_delay += 10; + break; + case DHTLIB_ERROR_BIT_SHIFT: + Serial.print("Bit shift error,\t"); dht_delay += 10; break; default: - Serial.print("Unknown error,\t"); - dht_delay += 10; + Serial.print("Unknown: "); + Serial.print(chk); + Serial.print(",\t"); + dht_delay += 100; break; } dht_delay = constrain(dht_delay, 100, 5000); // DISPLAY DATA - Serial.print(mySensor.humidity, 1); + Serial.print(mySensor.getHumidity(), 1); Serial.print(",\t"); - Serial.print(mySensor.temperature, 1); + Serial.print(mySensor.getTemperature(), 1); Serial.print(",\t"); uint32_t duration = stop - start; Serial.print(duration); @@ -123,4 +155,4 @@ void test() } -// END OF FILE \ No newline at end of file +// END OF FILE diff --git a/libraries/DHTNEW/examples/dhtnew_array/dhtnew_array.ino b/libraries/DHTNEW/examples/dhtnew_array/dhtnew_array.ino index f6cdea0d..7871fcd7 100644 --- a/libraries/DHTNEW/examples/dhtnew_array/dhtnew_array.ino +++ b/libraries/DHTNEW/examples/dhtnew_array/dhtnew_array.ino @@ -1,32 +1,37 @@ // // FILE: dhtnew_array.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.1 +// VERSION: 0.1.4 // PURPOSE: DHTNEW library test sketch for Arduino // URL: https://github.com/RobTillaart/DHTNew + // HISTORY: -// // 0.1.0 2020-04-25 initial version // 0.1.1 2020-04-30 replaced humidity and temperature with functions -// -// FRONT left to right +// 0.1.2 2020-06-08 improved error handling +// 0.1.3 2020-06-15 match 0.3.0 error handling +// 0.1.4 2020-11-09 wait for read handling +// +// DHT PIN layout from left to right +// ================================= +// FRONT : DESCRIPTION // pin 1 : VCC // pin 2 : DATA -// pin 3 : NC -// PIN 4 : GND +// pin 3 : Not Connected +// pin 4 : GND #include -DHTNEW kitchen(2); -DHTNEW living(3); -DHTNEW outside(4); +DHTNEW kitchen(4); +DHTNEW living(5); +DHTNEW outside(6); DHTNEW ar[3] = { kitchen, living, outside }; void setup() { Serial.begin(115200); - Serial.println("dhtnew_test.ino"); + Serial.println("dhtnew_array.ino"); Serial.print("LIBRARY VERSION: "); Serial.println(DHTNEW_LIB_VERSION); Serial.println(); @@ -39,6 +44,11 @@ void setup() void loop() { + for (int idx = 0; idx < 3; idx++) + { + test(idx); + } + Serial.println(); } void test(int idx) @@ -48,6 +58,9 @@ void test(int idx) int chk = ar[idx].read(); uint32_t stop = micros(); + Serial.print(idx); + Serial.print(",\t"); + switch (chk) { case DHTLIB_OK: @@ -56,13 +69,34 @@ void test(int idx) case DHTLIB_ERROR_CHECKSUM: Serial.print("Checksum error,\t"); break; - case DHTLIB_ERROR_TIMEOUT: - Serial.print("Time out error,\t"); + case DHTLIB_ERROR_TIMEOUT_A: + Serial.print("Time out A error,\t"); + break; + case DHTLIB_ERROR_TIMEOUT_B: + Serial.print("Time out B error,\t"); + break; + case DHTLIB_ERROR_TIMEOUT_C: + Serial.print("Time out C error,\t"); + break; + case DHTLIB_ERROR_TIMEOUT_D: + Serial.print("Time out D error,\t"); + break; + case DHTLIB_ERROR_SENSOR_NOT_READY: + Serial.print("Sensor not ready,\t"); + break; + case DHTLIB_ERROR_BIT_SHIFT: + Serial.print("Bit shift error,\t"); + break; + case DHTLIB_WAITING_FOR_READ: + Serial.print("Waiting for read,\t"); break; default: - Serial.print("Unknown error,\t"); + Serial.print("Unknown: "); + Serial.print(chk); + Serial.print(",\t"); break; } + // DISPLAY DATA Serial.print(ar[idx].getHumidity(), 1); Serial.print(",\t"); diff --git a/libraries/DHTNEW/examples/dhtnew_endless/dhtnew_endless.ino b/libraries/DHTNEW/examples/dhtnew_endless/dhtnew_endless.ino new file mode 100644 index 00000000..45c251a3 --- /dev/null +++ b/libraries/DHTNEW/examples/dhtnew_endless/dhtnew_endless.ino @@ -0,0 +1,130 @@ +// +// FILE: DHT_endless.ino +// AUTHOR: Rob Tillaart +// VERSION: 0.1.3 +// PURPOSE: demo +// DATE: 2020-06-04 +// (c) : MIT +// +// 0.1.0 2020-06-04 initial version +// 0.1.1 2020-06-15 match 0.3.0 error handling +// 0.1.2 2020-09-22 fix typo +// 0.1.3 2020-11-09 wait for read handling +// +// DHT PIN layout from left to right +// ================================= +// FRONT : DESCRIPTION +// pin 1 : VCC +// pin 2 : DATA +// pin 3 : Not Connected +// pin 4 : GND + +#include + +DHTNEW mySensor(16); // ESP 16 UNO 6 + +uint32_t count = 0; +uint32_t start, stop; + +uint32_t errors[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + +void setup() +{ + Serial.begin(115200); + Serial.println("DHT_endless.ino"); + Serial.print("LIBRARY VERSION: "); + Serial.println(DHTNEW_LIB_VERSION); + Serial.println(); +} + +void loop() +{ + count++; + // show counters for OK and errors. + if (count % 50 == 0) + { + Serial.println(); + Serial.println("OK \tCRC \tTOA \tTOB \tTOC \tTOD \tSNR \tBS \tWFR \tUNK"); + for (uint8_t i = 0; i < 10; i++) + { + Serial.print(errors[i]); + Serial.print('\t'); + } + Serial.println(); + Serial.println(); + } + + if (count % 10 == 0) + { + Serial.println(); + Serial.println("TIM\tCNT\tSTAT\tHUMI\tTEMP\tTIME\tTYPE"); + } + Serial.print(millis()); + Serial.print("\t"); + Serial.print(count); + Serial.print("\t"); + + start = micros(); + int chk = mySensor.read(); + stop = micros(); + + switch (chk) + { + case DHTLIB_OK: + Serial.print("OK,\t"); + errors[0]++; + break; + case DHTLIB_ERROR_CHECKSUM: + Serial.print("CRC,\t"); + errors[1]++; + break; + case DHTLIB_ERROR_TIMEOUT_A: + Serial.print("TOA,\t"); + errors[2]++; + break; + case DHTLIB_ERROR_TIMEOUT_B: + Serial.print("TOB,\t"); + errors[3]++; + break; + case DHTLIB_ERROR_TIMEOUT_C: + Serial.print("TOC,\t"); + errors[4]++; + break; + case DHTLIB_ERROR_TIMEOUT_D: + Serial.print("TOD,\t"); + errors[5]++; + break; + case DHTLIB_ERROR_SENSOR_NOT_READY: + Serial.print("SNR,\t"); + errors[6]++; + break; + case DHTLIB_ERROR_BIT_SHIFT: + Serial.print("BS,\t"); + errors[7]++; + break; + case DHTLIB_WAITING_FOR_READ: + Serial.print("WFR,\t"); + errors[8]++; + break; + default: + Serial.print("U"); + Serial.print(chk); + Serial.print(",\t"); + errors[9]++; + break; + } + // DISPLAY DATA + Serial.print(mySensor.getHumidity(), 1); + Serial.print(",\t"); + Serial.print(mySensor.getTemperature(), 1); + Serial.print(",\t"); + Serial.print(stop - start); + Serial.print(",\t"); + Serial.println(mySensor.getType()); + + delay(1000); +} + + +// -- END OF FILE -- diff --git a/libraries/DHTNEW/examples/dhtnew_minimum/dhtnew_minimum.ino b/libraries/DHTNEW/examples/dhtnew_minimum/dhtnew_minimum.ino index 40c5cdf7..49a5d915 100644 --- a/libraries/DHTNEW/examples/dhtnew_minimum/dhtnew_minimum.ino +++ b/libraries/DHTNEW/examples/dhtnew_minimum/dhtnew_minimum.ino @@ -1,22 +1,26 @@ // // FILE: dhtnew_minimum.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.1 -// PURPOSE: DHTNEW library test sketch for Arduino +// VERSION: 0.1.2 +// PURPOSE: DHTNEW library test sketch // URL: https://github.com/RobTillaart/DHTNew +// // HISTORY: // 0.1.0 2018-01-08 initial version // 0.1.1 2020-04-30 replaced humidity and temperature with functions +// 0.1.2 2020-06-15 match 0.3.0 error handling // -// FRONT left 2 right +// DHT PIN layout from left to right +// ================================= +// FRONT : DESCRIPTION // pin 1 : VCC // pin 2 : DATA -// pin 3 : NC -// PIN 4 : GND +// pin 3 : Not Connected +// pin 4 : GND #include -DHTNEW mySensor(6); +DHTNEW mySensor(16); void setup() { @@ -24,8 +28,16 @@ void setup() Serial.println(__FILE__); Serial.println(); + Serial.println("BEFORE OFFSET"); + mySensor.read(); + Serial.print(mySensor.getHumidity(), 1); + Serial.print("\t"); + Serial.println(mySensor.getTemperature(), 1); + mySensor.setHumOffset(10); - mySensor.setTempOffset(-1.5); + mySensor.setTempOffset(-3.5); + + Serial.println("AFTER OFFSET"); } void loop() @@ -39,4 +51,4 @@ void loop() } } -// END OF FILE \ No newline at end of file +// END OF FILE diff --git a/libraries/DHTNEW/examples/dhtnew_powerDown/dhtnew_powerDown.ino b/libraries/DHTNEW/examples/dhtnew_powerDown/dhtnew_powerDown.ino new file mode 100644 index 00000000..adc52700 --- /dev/null +++ b/libraries/DHTNEW/examples/dhtnew_powerDown/dhtnew_powerDown.ino @@ -0,0 +1,75 @@ +// +// FILE: dhtnew_powerDown.ino +// AUTHOR: Rob Tillaart +// VERSION: 0.1.0 +// PURPOSE: DHTNEW library test sketch for Arduino +// URL: https://github.com/RobTillaart/DHTNew +// +// DHT PIN layout from left to right +// ================================= +// FRONT : DESCRIPTION +// pin 1 : VCC +// pin 2 : DATA +// pin 3 : Not Connected +// pin 4 : GND + +// to see the effect one must apply a voltmeter to the datapin of the sensor +// during the low power mode. Measuring during communication will disrupt the +// data transfer. + +#include + +DHTNEW mySensor(16); + +void setup() +{ + Serial.begin(115200); + Serial.println("dhtnew_test.ino"); + Serial.print("LIBRARY VERSION: "); + Serial.println(DHTNEW_LIB_VERSION); + + Serial.println("\nstartup"); + delay(2000); + + Serial.println("read sensor with 2 second interval"); + for (int i = 0; i < 3; i++) + { + int rv = mySensor.read(); + if (rv != DHTLIB_OK) + { + Serial.println(rv); // will print -7 when measuring voltage + } + Serial.print(mySensor.getHumidity(), 1); + Serial.print(",\t"); + Serial.println(mySensor.getTemperature(), 1); + delay(2000); + } + + Serial.println("switch to low power (~ 5 seconds )"); + Serial.println("measure voltage"); + mySensor.powerDown(); + delay(5000); + + Serial.println("switch sensor on (and wait 2 seconds)"); + mySensor.powerUp(); + // wait for 2 seconds. + delay(2000); + + Serial.println("read sensor with 2 second interval"); + for (int i = 0; i < 3; i++) + { + mySensor.read(); + Serial.print(mySensor.getHumidity(), 1); + Serial.print(",\t"); + Serial.println(mySensor.getTemperature(), 1); + delay(2000); + } + + Serial.println("\nDone..."); +} + +void loop() +{ +} + +// END OF FILE \ No newline at end of file diff --git a/libraries/DHTNEW/examples/dhtnew_pulse_diag/dhtnew_pulse_diag.ino b/libraries/DHTNEW/examples/dhtnew_pulse_diag/dhtnew_pulse_diag.ino new file mode 100644 index 00000000..f473b521 --- /dev/null +++ b/libraries/DHTNEW/examples/dhtnew_pulse_diag/dhtnew_pulse_diag.ino @@ -0,0 +1,179 @@ +// +// FILE: dhtnew_pulse_diag.ino +// AUTHOR: Rob Tillaart +// VERSION: 0.1.1 +// PURPOSE: DHTNEW library pulse measurement tool - diagnostics +// URL: https://github.com/RobTillaart/DHTNew +// +// HISTORY: +// 0.1.0 2020-08-15 initial version +// 0.1.1 2020-09-23 commented noInterrupts as it corrupts timing on AVR. + +// +// DHT PIN layout from left to right +// ================================= +// FRONT : DESCRIPTION +// pin 1 : VCC +// pin 2 : DATA +// pin 3 : Not Connected +// pin 4 : GND + +#include "Arduino.h" + +#define DHTLIB_DHT11_WAKEUP 18 +#define DHTLIB_DHT_WAKEUP 1 + +uint8_t _dataPin = 16; +uint8_t _wakeupDelay = DHTLIB_DHT_WAKEUP; + +uint16_t count = 0; +uint32_t times[100], t = 0; +uint8_t idx = 0; + +void setup() +{ + Serial.begin(115200); + Serial.println("dhtnew_pulse_diag.ino"); + Serial.println(); + + // default should be HIGH + pinMode(_dataPin, OUTPUT); + digitalWrite(_dataPin, HIGH); +} + +void loop() +{ + measure(); + dump(); + delay(5000); +} + +void dump() +{ + int i = 1; + Serial.println(); + Serial.print("RUN:\t"); Serial.println(count); + Serial.print("IDX:\t"); Serial.println(idx); + + Serial.println("WAKEUP"); + for (int n = 0; n < 6; n++) + { + Serial.print("\t"); + Serial.print(times[i++]); + } + Serial.println(); + + Serial.println("HUM"); + for (int n = 0; n < 32; n++) + { + Serial.print("\t"); + Serial.print(times[i++]); + if ((n & 15) == 15) Serial.println(); + } + Serial.println(); + + Serial.println("TEMP"); + for (int n = 0; n < 32; n++) + { + Serial.print("\t"); + Serial.print(times[i++]); + if ((n & 15) == 15) Serial.println(); + } + Serial.println(); + + Serial.println("CRC"); + for (int n = 0; n < 16; n++) + { + Serial.print("\t"); + Serial.print(times[i++]); + if ((n & 7) == 7) Serial.println(); + } + Serial.println(); + + Serial.println("BYE"); + for (int n = 0; n < 2; n++) + { + Serial.print("\t"); + Serial.print(times[i++]); + } + Serial.println(); + Serial.println(); +} + + +void measure() +{ + count++; + yield(); // handle pending interrupts + + // reset measurements table + idx = 0; + t = micros(); + for (int i = 0; i < 100; i++) times[i] = 0; + + times[idx++] = micros(); + // REQUEST SAMPLE - SEND WAKEUP TO SENSOR + pinMode(_dataPin, OUTPUT); + digitalWrite(_dataPin, LOW); + // add 10% extra for timing inaccuracies in sensor. + delayMicroseconds(_wakeupDelay * 1100UL); + + + times[idx++] = micros(); + // HOST GIVES CONTROL TO SENSOR + pinMode(_dataPin, INPUT_PULLUP); + + // DISABLE INTERRUPTS when clock in the bits + // noInterrupts(); // gives problems on AVR + + + times[idx++] = micros(); + // SENSOR PULLS LOW after 20-40 us => if stays HIGH ==> device not ready + while (digitalRead(_dataPin) == HIGH); + + + times[idx++] = micros(); + // SENSOR STAYS LOW for ~80 us => or TIMEOUT + while (digitalRead(_dataPin) == LOW); + + + times[idx++] = micros(); + // SENSOR STAYS HIGH for ~80 us => or TIMEOUT + while (digitalRead(_dataPin) == HIGH); + times[idx++] = micros(); + + + // SENSOR HAS NOW SEND ACKNOWLEDGE ON WAKEUP + // NOW IT SENDS THE BITS + + // READ THE OUTPUT - 40 BITS => 5 BYTES + for (uint8_t i = 40; i != 0; i--) + { + times[idx++] = micros(); + // EACH BIT START WITH ~50 us LOW + while (digitalRead(_dataPin) == LOW); + + times[idx++] = micros(); + // DURATION OF HIGH DETERMINES 0 or 1 + // 26-28 us ==> 0 + // 70 us ==> 1 + while (digitalRead(_dataPin) == HIGH); + } + + + times[idx++] = micros(); + // After 40 bits the sensor pulls the line LOW for 50 us + // TODO: should we wait? + while (digitalRead(_dataPin) == LOW); + + times[idx++] = micros(); + times[idx++] = micros(); + + for (int n = 100; n > 0; n--) + { + times[n] -= times[n - 1]; + } +} + + +// -- END OF FILE -- \ No newline at end of file diff --git a/libraries/DHTNEW/examples/dhtnew_setReadDelay/dhtnew_setReadDelay.ino b/libraries/DHTNEW/examples/dhtnew_setReadDelay/dhtnew_setReadDelay.ino new file mode 100644 index 00000000..53efa65e --- /dev/null +++ b/libraries/DHTNEW/examples/dhtnew_setReadDelay/dhtnew_setReadDelay.ino @@ -0,0 +1,126 @@ +// +// FILE: dhtnew_setReadDelay.ino +// AUTHOR: Rob Tillaart +// VERSION: 0.1.2 +// PURPOSE: DHTNEW library waitForRead example sketch for Arduino +// URL: https://github.com/RobTillaart/DHTNew +// +// HISTORY: +// 0.1.0 2020-06-12 initial version +// 0.1.1 2020-06-15 match 0.3.0 error handling +// 0.1.2 2020-11-09 fix + wait for read handling +// +// DHT PIN layout from left to right +// ================================= +// FRONT : DESCRIPTION +// pin 1 : VCC +// pin 2 : DATA +// pin 3 : Not Connected +// pin 4 : GND + +#include + +DHTNEW mySensor(16); + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.print("LIBRARY VERSION: "); + Serial.println(DHTNEW_LIB_VERSION); + Serial.println(); + + delay(2000); // boot time + + mySensor.setWaitForReading(true); + + uint16_t rd = 2000; + uint16_t step = 2000; + + while (step) + { + step /= 2; + mySensor.setReadDelay(rd); + int chk = mySensor.read(); + + Serial.print("ReadDelay (ms): "); + Serial.print(mySensor.getReadDelay()); + Serial.print("\t T: "); + Serial.print(mySensor.getTemperature(), 1); + Serial.print("\t H: "); + Serial.print(mySensor.getHumidity(), 1); + Serial.print("\t"); + printStatus(chk); + + if (chk == DHTLIB_OK) rd -= step; + else { + rd += step; + mySensor.read(); + } + } + + // safety margin of 100 uSec + rd += 100; + mySensor.setReadDelay(rd); + Serial.print("\nreadDelay set to (ms) : "); + Serial.print(mySensor.getReadDelay()); + Serial.println("\n\nDuration test started"); +} + +void loop() +{ + // Note: the library prevents reads faster than readDelay... + // it will return previous values for T & H + int chk = mySensor.read(); + Serial.print(millis()); + Serial.print("\t"); + Serial.print(mySensor.getReadDelay()); + Serial.print("\t T: "); + Serial.print(mySensor.getTemperature(), 1); + Serial.print("\t H: "); + Serial.print(mySensor.getHumidity(), 1); + Serial.print("\t"); + printStatus(chk); +} + +void printStatus(int chk) +{ + switch (chk) + { + case DHTLIB_OK: + Serial.print("OK,\t"); + break; + case DHTLIB_ERROR_CHECKSUM: + Serial.print("Checksum error,\t"); + break; + case DHTLIB_ERROR_TIMEOUT_A: + Serial.print("Time out A error,\t"); + break; + case DHTLIB_ERROR_TIMEOUT_B: + Serial.print("Time out B error,\t"); + break; + case DHTLIB_ERROR_TIMEOUT_C: + Serial.print("Time out C error,\t"); + break; + case DHTLIB_ERROR_TIMEOUT_D: + Serial.print("Time out D error,\t"); + break; + case DHTLIB_ERROR_SENSOR_NOT_READY: + Serial.print("Sensor not ready,\t"); + break; + case DHTLIB_ERROR_BIT_SHIFT: + Serial.print("Bit shift error,\t"); + break; + case DHTLIB_WAITING_FOR_READ: + Serial.print("Waiting for read,\t"); + break; + default: + Serial.print("Unknown: "); + Serial.print(chk); + Serial.print(",\t"); + break; + } + Serial.println(); +} + +// -- END OF FILE -- diff --git a/libraries/DHTNEW/examples/dhtnew_suppressError/dhtnew_suppressError.ino b/libraries/DHTNEW/examples/dhtnew_suppressError/dhtnew_suppressError.ino new file mode 100644 index 00000000..d4c0b6c9 --- /dev/null +++ b/libraries/DHTNEW/examples/dhtnew_suppressError/dhtnew_suppressError.ino @@ -0,0 +1,62 @@ +// +// FILE: dhtnew_suppressError.ino +// AUTHOR: Rob Tillaart +// VERSION: 0.1.0 +// PURPOSE: DHTNEW library test sketch +// URL: https://github.com/RobTillaart/DHTNew +// +// HISTORY: +// 0.1.0 2020-07-17 initial version +// +// DHT PIN layout from left to right +// ================================= +// FRONT : DESCRIPTION +// pin 1 : VCC +// pin 2 : DATA +// pin 3 : Not Connected +// pin 4 : GND + + +// run sketch without connected sensor to see effect + +#include + +DHTNEW mySensor(16); + +uint32_t count = 0; + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.println(); + + // test flag working => prints 010 + Serial.print(mySensor.getSuppressError()); + mySensor.setSuppressError(true); + Serial.print(mySensor.getSuppressError()); + mySensor.setSuppressError(false); + Serial.print(mySensor.getSuppressError()); + + // change to false to see difference + mySensor.setSuppressError(true); + Serial.println(); +} + +void loop() +{ + if (millis() - mySensor.lastRead() > 2000) + { + if ((count % 10) == 0) Serial.println("\nERR\tHUM\tTEMP"); + count++; + + int errcode = mySensor.read(); + Serial.print(errcode); + Serial.print("\t"); + Serial.print(mySensor.getHumidity(), 1); + Serial.print("\t"); + Serial.println(mySensor.getTemperature(), 1); + } +} + +// -- END OF FILE -- \ No newline at end of file diff --git a/libraries/DHTNEW/examples/dhtnew_test/dhtnew_test.ino b/libraries/DHTNEW/examples/dhtnew_test/dhtnew_test.ino index ab8e6451..9d762c52 100644 --- a/libraries/DHTNEW/examples/dhtnew_test/dhtnew_test.ino +++ b/libraries/DHTNEW/examples/dhtnew_test/dhtnew_test.ino @@ -1,21 +1,30 @@ // // FILE: dhtnew_test.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.2 +// VERSION: 0.1.6 // PURPOSE: DHTNEW library test sketch for Arduino -// URL: +// URL: https://github.com/RobTillaart/DHTNew +// // HISTORY: +// 0.1.0 2017-07-24 initial version +// 0.1.1 2017-07-29 added begin(); +// 0.1.2 2018-01-08 removed begin(); +// 0.1.3 2020-04-30 replaced humidity and temperature with functions +// 0.1.4 2020-06-08 improved error handling +// 0.1.5 2020-06-15 match 0.3.0 error handling +// 0.1.6 2020-11-09 wait for read handling // -// 0.1.0 - 2017-07-24 initial version -// 0.1.1 - 2017-07-29 added begin(); -// 0.1.2 - 2018-01-08 removed begin(); -// -// Released to the public domain -// +// DHT PIN layout from left to right +// ================================= +// FRONT : DESCRIPTION +// pin 1 : VCC +// pin 2 : DATA +// pin 3 : Not Connected +// pin 4 : GND #include -DHTNEW mySensor(6); +DHTNEW mySensor(16); void setup() { @@ -63,9 +72,9 @@ void setup() mySensor.read(); Serial.println("actual read"); } - Serial.print(mySensor.humidity, 1); + Serial.print(mySensor.getHumidity(), 1); Serial.print(",\t"); - Serial.println(mySensor.temperature, 1); + Serial.println(mySensor.getTemperature(), 1); delay(250); } @@ -92,17 +101,38 @@ void test() case DHTLIB_ERROR_CHECKSUM: Serial.print("Checksum error,\t"); break; - case DHTLIB_ERROR_TIMEOUT: - Serial.print("Time out error,\t"); + case DHTLIB_ERROR_TIMEOUT_A: + Serial.print("Time out A error,\t"); + break; + case DHTLIB_ERROR_TIMEOUT_B: + Serial.print("Time out B error,\t"); + break; + case DHTLIB_ERROR_TIMEOUT_C: + Serial.print("Time out C error,\t"); + break; + case DHTLIB_ERROR_TIMEOUT_D: + Serial.print("Time out D error,\t"); + break; + case DHTLIB_ERROR_SENSOR_NOT_READY: + Serial.print("Sensor not ready,\t"); + break; + case DHTLIB_ERROR_BIT_SHIFT: + Serial.print("Bit shift error,\t"); + break; + case DHTLIB_WAITING_FOR_READ: + Serial.print("Waiting for read,\t"); break; default: - Serial.print("Unknown error,\t"); + Serial.print("Unknown: "); + Serial.print(chk); + Serial.print(",\t"); break; } + // DISPLAY DATA - Serial.print(mySensor.humidity, 1); + Serial.print(mySensor.getHumidity(), 1); Serial.print(",\t"); - Serial.print(mySensor.temperature, 1); + Serial.print(mySensor.getTemperature(), 1); Serial.print(",\t"); uint32_t duration = stop - start; Serial.print(duration); @@ -112,4 +142,4 @@ void test() } -// END OF FILE \ No newline at end of file +// END OF FILE diff --git a/libraries/DHTNEW/examples/dhtnew_waitForRead/dhtnew_waitForRead.ino b/libraries/DHTNEW/examples/dhtnew_waitForRead/dhtnew_waitForRead.ino index 76d8af78..43469693 100644 --- a/libraries/DHTNEW/examples/dhtnew_waitForRead/dhtnew_waitForRead.ino +++ b/libraries/DHTNEW/examples/dhtnew_waitForRead/dhtnew_waitForRead.ino @@ -1,22 +1,26 @@ // // FILE: dhtnew_waitForRead.ino // AUTHOR: Mr-HaleYa -// VERSION: 0.1.0 +// VERSION: 0.1.2 // PURPOSE: DHTNEW library waitForRead example sketch for Arduino // URL: https://github.com/RobTillaart/DHTNew +// // HISTORY: -// // 0.1.0 2020-05-03 initial version +// 0.1.1 2020-06-08 updated error handling +// 0.1.2 2020-06-15 match 0.3.0 error handling // -// FRONT left 2 right +// DHT PIN layout from left to right +// ================================= +// FRONT : DESCRIPTION // pin 1 : VCC // pin 2 : DATA -// pin 3 : NC -// PIN 4 : GND +// pin 3 : Not Connected +// pin 4 : GND #include -DHTNEW mySensor(6); +DHTNEW mySensor(16); void setup() { @@ -81,18 +85,36 @@ void test() switch (chk) { case DHTLIB_OK: - Serial.println("OK"); + Serial.print("OK,\t"); break; case DHTLIB_ERROR_CHECKSUM: - Serial.println("Checksum error"); + Serial.print("Checksum error,\t"); break; - case DHTLIB_ERROR_TIMEOUT: - Serial.println("Time out error"); + case DHTLIB_ERROR_TIMEOUT_A: + Serial.print("Time out A error,\t"); + break; + case DHTLIB_ERROR_TIMEOUT_B: + Serial.print("Time out B error,\t"); + break; + case DHTLIB_ERROR_TIMEOUT_C: + Serial.print("Time out C error,\t"); + break; + case DHTLIB_ERROR_TIMEOUT_D: + Serial.print("Time out D error,\t"); + break; + case DHTLIB_ERROR_SENSOR_NOT_READY: + Serial.print("Sensor not ready,\t"); + break; + case DHTLIB_ERROR_BIT_SHIFT: + Serial.print("Bit shift error,\t"); break; default: - Serial.println("Unknown error"); + Serial.print("Unknown: "); + Serial.print(chk); + Serial.print(",\t"); break; } + Serial.println(); delay(100); } diff --git a/libraries/DHTNEW/examples/dhtnew_waitForRead_nonBlocking/dhtnew_waitForRead_nonBlocking.ino b/libraries/DHTNEW/examples/dhtnew_waitForRead_nonBlocking/dhtnew_waitForRead_nonBlocking.ino new file mode 100644 index 00000000..9bb398fd --- /dev/null +++ b/libraries/DHTNEW/examples/dhtnew_waitForRead_nonBlocking/dhtnew_waitForRead_nonBlocking.ino @@ -0,0 +1,95 @@ +// +// FILE: dhtnew_waitForRead_nonBlocking.ino +// AUTHOR: Budulinek +// VERSION: 0.1.0 +// PURPOSE: DHTNEW non-blocking wait for read example sketch for Arduino +// URL: https://github.com/RobTillaart/DHTNew +// +// HISTORY: +// 0.1.0 2020-11-09 initial version +// +// DHT PIN layout from left to right +// ================================= +// FRONT : DESCRIPTION +// pin 1 : VCC +// pin 2 : DATA +// pin 3 : Not Connected +// pin 4 : GND + +#include + +DHTNEW mySensor(16); + +void setup() +{ + Serial.begin(115200); + Serial.println("\n"); + Serial.println("dhtnew_waitForRead_nonBlocking.ino"); + Serial.print("LIBRARY VERSION: "); + Serial.println(DHTNEW_LIB_VERSION); + Serial.println(); + Serial.println("This example shows how you can use the output of the read() function to implement non-blocking waiting for read."); + Serial.println("In this example, Arduino continuously polls the read() function and returns fresh data (or an error) only when the read delay is over."); + Serial.println("Infinite loop."); + Serial.println(); + Serial.println("STAT\tHUMI\tTEMP\tTIME\tTYPE"); +} + +void loop() +{ + // READ DATA + uint32_t start = micros(); + int chk = mySensor.read(); + uint32_t stop = micros(); + + if (chk != DHTLIB_WAITING_FOR_READ) { + switch (chk) + { + case DHTLIB_OK: + Serial.print("OK,\t"); + break; + case DHTLIB_ERROR_CHECKSUM: + Serial.print("Checksum error,\t"); + break; + case DHTLIB_ERROR_TIMEOUT_A: + Serial.print("Time out A error,\t"); + break; + case DHTLIB_ERROR_TIMEOUT_B: + Serial.print("Time out B error,\t"); + break; + case DHTLIB_ERROR_TIMEOUT_C: + Serial.print("Time out C error,\t"); + break; + case DHTLIB_ERROR_TIMEOUT_D: + Serial.print("Time out D error,\t"); + break; + case DHTLIB_ERROR_SENSOR_NOT_READY: + Serial.print("Sensor not ready,\t"); + break; + case DHTLIB_ERROR_BIT_SHIFT: + Serial.print("Bit shift error,\t"); + break; + default: + Serial.print("Unknown: "); + Serial.print(chk); + Serial.print(",\t"); + break; + } + + // DISPLAY DATA + Serial.print(mySensor.getHumidity(), 1); + Serial.print(",\t"); + Serial.print(mySensor.getTemperature(), 1); + Serial.print(",\t"); + uint32_t duration = stop - start; + Serial.print(duration); + Serial.print(",\t"); + Serial.println(mySensor.getType()); + } + + // do some other stuff + delay(100); +} + + +// END OF FILE diff --git a/libraries/DHTNEW/keywords.txt b/libraries/DHTNEW/keywords.txt index cccd1715..b328429f 100644 --- a/libraries/DHTNEW/keywords.txt +++ b/libraries/DHTNEW/keywords.txt @@ -5,7 +5,7 @@ DHTNEW KEYWORD1 # Methods and Functions (KEYWORD2) getType KEYWORD2 - +setType() KEYWORD2 read KEYWORD2 lastRead KEYWORD2 @@ -17,10 +17,16 @@ setTempOffset KEYWORD2 getHumOffset KEYWORD2 getTempOffset KEYWORD2 -getDisableIRQ KEYWORD2 -setDisableIRQ KEYWORD2 getWaitForReading KEYWORD2 setWaitForReading KEYWORD2 +getSuppressError KEYWORD2 +setSuppressError KEYWORD2 + +getReadDelay KEYWORD2 +setReadDelay KEYWORD2 + +powerUp KEYWORD2 +powerDown KEYWORD2 # Instances (KEYWORD2) @@ -28,6 +34,12 @@ setWaitForReading KEYWORD2 DHTNEW_LIB_VERSION LITERAL1 DHTLIB_OK LITERAL1 DHTLIB_ERROR_CHECKSUM LITERAL1 -DHTLIB_ERROR_TIMEOUT LITERAL1 +DHTLIB_ERROR_BIT_SHIFT LITERAL1 DHTLIB_INVALID_VALUE LITERAL1 DHTLIB_TIMEOUT LITERAL1 +DHTLIB_ERROR_TIMEOUT_A LITERAL1 +DHTLIB_ERROR_TIMEOUT_B LITERAL1 +DHTLIB_ERROR_TIMEOUT_C LITERAL1 +DHTLIB_ERROR_TIMEOUT_D LITERAL1 +DHTLIB_ERROR_SENSOR_NOT_READY LITERAL1 +DHTLIB_WAITING_FOR_READ LITERAL1 diff --git a/libraries/DHTNEW/library.json b/libraries/DHTNEW/library.json index 021efebd..94de0f29 100644 --- a/libraries/DHTNEW/library.json +++ b/libraries/DHTNEW/library.json @@ -1,24 +1,19 @@ { "name": "DHTNEW", - "keywords": "DHT11, DHT22, DHT33, DHT44, AM2301, AM2302, AM2303, autodetect, offset", + "keywords": "DHT11, DHT22, DHT33, DHT44, AM2301, AM2302, AM2303, autodetect, offset, interrupt, powerDown", "description": "Arduino library for DHT temperature and humidity sensor, with automatic sensortype recognition.", - "authors": - [ - { - "name": "Rob Tillaart", - "email": "Rob.Tillaart@gmail.com", - "maintainer": true - } - ], + "authors": + { + "name": "Rob Tillaart", + "email": "Rob.Tillaart@gmail.com", + "maintainer": true + }, "repository": { "type": "git", "url": "https://github.com/RobTillaart/DHTNEW.git" }, - "version":"0.2.0", + "version":"0.4.0", "frameworks": "arduino", - "platforms": "*", - "export": { - "include": "dhtnew" - } + "platforms": "*" } diff --git a/libraries/DHTNEW/library.properties b/libraries/DHTNEW/library.properties index ffcf0691..e0e61818 100644 --- a/libraries/DHTNEW/library.properties +++ b/libraries/DHTNEW/library.properties @@ -1,9 +1,9 @@ name=DHTNEW -version=0.2.0 +version=0.4.0 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for DHT temperature and humidity sensor, with automatic sensortype recognition. -paragraph=Types supported: DHT11, DHT22, DHT33, DHT44, AM2301, AM2302, AM2303, autodetect, offset, interrup +paragraph=Types supported: DHT11, DHT22, DHT33, DHT44, AM2301, AM2302, AM2303, autodetect, offset, interrupt, powerDown category=Sensors url=https://github.com/RobTillaart/DHTNEW architectures=* diff --git a/libraries/DHTNEW/readme.md b/libraries/DHTNEW/readme.md index 86b6da5d..15b5738d 100644 --- a/libraries/DHTNEW/readme.md +++ b/libraries/DHTNEW/readme.md @@ -23,15 +23,74 @@ DHTNEW has some new features compared to the DHTlib code. should have 1-2 seconds between reads according to specification. In the future, this functionality could be inside the library by setting a time threshold (e.g. 1 second by default) to give more stable results. -5. Added **interrupt enable / disable flag** to prevent interrupts disturb timing of DHT protocol. +5. Added **interrupt enable/disable flag** to prevent interrupts disturb timing of DHT protocol. Be aware that this may affect other parts of your application. - 6. (0.1.7) added an automatic check of lastRead in the read call. If request a read to fast it will just return OK. 7. (0.1.7) added **waitForReading flag** (kudos to Mr-HaleYa) to let the sensor explicitly wait until a new value can be read. - 8. (0.2.0) Temperature and humidity are private now, use **getTemperature()** and **getHumidity()** +9. (0.2.1) Adjusted the bit timing threshold to work around issue #11 +10. (0.2.2) added **ERROR_SENSOR_NOT_READY** and differentiated timeout errors. +11. (0.3.0) +removed interrupt flag, now the library always disables interrupts during +the clocking of the bits. +Added getReadDelay & setReadDelay to tune reading interval. Check the example code. +Adjusted the timing in the wake-up part of the protocol. +Added more comments to describe the protocol. +12. (0.3.1) +added **powerDown()** and **powerUp()** for low power applications. Note that after **powerUp()** +the user must wait for two seconds before doing a read(). Just like after a (re)boot. +Note: The lib does not (yet) control the power pin of the sensor. +Discussion see https://github.com/RobTillaart/DHTNew/issues/13 +13. (0.3.2) +Added **setSuppressError()** and **getSuppressError()** so the library will not output -999 +but the last known valid value for temperature and humidity. +This flag is usefull to suppress 'negative spikes' in graphs or logs. +Default the error values are not suppressed to be backwards compaible. +Added **#ifndef** around **DHTLIB_INVALID_VALUE** so the default -999 can be overruled +compile time to set another error value e.g. -127 or -1 whatever suits the project. +14. (0.3.3) +Refactored the low level **readSensor()** as the **BIT SHIFT ERROR** issue #29 and issue #11 popped up again. +It was reproduced "efficiently" with an ESP32 and by using long wires. +Fixed with an explicit digitalWrite(datapin, HIGH) + delayMicroseconds() to have enough time between +pulling the line HIGH and poiling for the line LOW. +15. (0.3.4) +Added **waitFor(state, timeout)** to more precisely follow the datasheet in terms of timing. +Reintroduced the **interrupt enable/disable flag** as forced noInterrupts() +could break the timing of the DHT protocol / micros() - seen on AVR. + + +## DHT PIN layout from left to right + +| FRONT | | DESCRIPTION | +|:----|:----:|:----| +| pin 1 | | VCC | +| pin 2 | | DATA | +| pin 3 | | Not Connected | +| pin 4 | | GND | + +## Specification DHT22 + +| | | | +|:----|:----|:----| +| Model | DHT22 | +| Power supply | 3.3 - 6 V DC | +| Output signal | digital signal via single-bus | +| Sensing element | Polymer capacitor | +| Operating range | humidity 0-100% RH | temperature -40~80 Celsius | +| Accuracy humidity | ±2% RH(Max ±5% RH) | temperature < ±0.5 Celsius | +| Resolution or sensitivity | humidity 0.1% RH | temperature 0.1 Celsius | +| Repeatability humidity | ±1% RH | temperature ±0.2 Celsius | +| Humidity hysteresis | ±0.3% RH | +| Long-term Stability | ±0.5% RH/year | +| Sensing period | Average: 2s | +| Interchangeability | fully interchangeable | +| Dimensions | small size 14 x 18 x 5.5 mm; | big size 22 x 28 x 5 mm | + ## Operation See examples + +If consistent problems occur with reading a sensor, one should allow interrupts +**DHT.setDisableIRQ(true)** diff --git a/libraries/DHTlib/LICENSE b/libraries/DHTlib/LICENSE new file mode 100644 index 00000000..95ba2177 --- /dev/null +++ b/libraries/DHTlib/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2011-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. diff --git a/libraries/DHTlib/dht.cpp b/libraries/DHTlib/dht.cpp index 4eef33a4..8f5d2f0e 100644 --- a/libraries/DHTlib/dht.cpp +++ b/libraries/DHTlib/dht.cpp @@ -1,50 +1,49 @@ // // FILE: dht.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.29 -// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino -// URL: http://arduino.cc/playground/Main/DHTLib +// VERSION: 0.1.30 +// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino, AVR optimized +// URL: https://github.com/RobTillaart/DHTlib +// http://arduino.cc/playground/Main/DHTLib // // HISTORY: -// 0.1.29 2018-09-02 fix negative temperature DHT12 - issue #111 -// 0.1.28 2018-04-03 refactor -// 0.1.27 2018-03-26 added _disableIRQ flag -// 0.1.26 2017-12-12 explicit support for AM23XX series and DHT12 -// 0.1.25 2017-09-20 FIX https://github.com/RobTillaart/Arduino/issues/80 -// 0.1.24 2017-07-27 FIX https://github.com/RobTillaart/Arduino/issues/33 double -> float -// 0.1.23 2017-07-24 FIX https://github.com/RobTillaart/Arduino/issues/31 -// 0.1.22 undo delayMicroseconds() for wakeups larger than 8 -// 0.1.21 replace delay with delayMicroseconds() + small fix -// 0.1.20 Reduce footprint by using uint8_t as error codes. (thanks to chaveiro) -// 0.1.19 masking error for DHT11 - FIXED (thanks Richard for noticing) -// 0.1.18 version 1.16/17 broke the DHT11 - FIXED -// 0.1.17 replaced micros() with adaptive loopcount -// removed DHTLIB_INVALID_VALUE -// added DHTLIB_ERROR_CONNECT -// added DHTLIB_ERROR_ACK_L DHTLIB_ERROR_ACK_H -// 0.1.16 masking unused bits (less errors); refactored bits[] -// 0.1.15 reduced # micros calls 2->1 in inner loop. -// 0.1.14 replace digital read with faster (~3x) code => more robust low MHz machines. -// -// 0.1.13 fix negative temperature -// 0.1.12 support DHT33 and DHT44 initial version -// 0.1.11 renamed DHTLIB_TIMEOUT -// 0.1.10 optimized faster WAKEUP + TIMEOUT -// 0.1.09 optimize size: timeout check + use of mask -// 0.1.08 added formula for timeout based upon clockspeed -// 0.1.07 added support for DHT21 -// 0.1.06 minimize footprint (2012-12-27) -// 0.1.05 fixed negative temperature bug (thanks to Roseman) -// 0.1.04 improved readability of code using DHTLIB_OK in code -// 0.1.03 added error values for temp and humidity when read failed -// 0.1.02 added error codes -// 0.1.01 added support for Arduino 1.0, fixed typos (31/12/2011) -// 0.1.00 by Rob Tillaart (01/04/2011) +// 0.1.30 2020-06-30 own repo; +// 0.1.29 2018-09-02 fix negative temperature DHT12 - issue #111 +// 0.1.28 2018-04-03 refactor +// 0.1.27 2018-03-26 added _disableIRQ flag +// 0.1.26 2017-12-12 explicit support for AM23XX series and DHT12 +// 0.1.25 2017-09-20 FIX https://github.com/RobTillaart/Arduino/issues/80 +// 0.1.24 2017-07-27 FIX https://github.com/RobTillaart/Arduino/issues/33 double -> float +// 0.1.23 2017-07-24 FIX https://github.com/RobTillaart/Arduino/issues/31 +// 0.1.22 undo delayMicroseconds() for wakeups larger than 8 +// 0.1.21 replace delay with delayMicroseconds() + small fix +// 0.1.20 Reduce footprint by using uint8_t as error codes. (thanks to chaveiro) +// 0.1.19 masking error for DHT11 - FIXED (thanks Richard for noticing) +// 0.1.18 version 1.16/17 broke the DHT11 - FIXED +// 0.1.17 replaced micros() with adaptive loopcount +// removed DHTLIB_INVALID_VALUE +// added DHTLIB_ERROR_CONNECT +// added DHTLIB_ERROR_ACK_L DHTLIB_ERROR_ACK_H +// 0.1.16 masking unused bits (less errors); refactored bits[] +// 0.1.15 reduced # micros calls 2->1 in inner loop. +// 0.1.14 replace digital read with faster (~3x) code => more robust low MHz machines. +// +// 0.1.13 fix negative temperature +// 0.1.12 support DHT33 and DHT44 initial version +// 0.1.11 renamed DHTLIB_TIMEOUT +// 0.1.10 optimized faster WAKEUP + TIMEOUT +// 0.1.09 optimize size: timeout check + use of mask +// 0.1.08 added formula for timeout based upon clockspeed +// 0.1.07 added support for DHT21 +// 0.1.06 minimize footprint (2012-12-27) +// 0.1.05 fixed negative temperature bug (thanks to Roseman) +// 0.1.04 improved readability of code using DHTLIB_OK in code +// 0.1.03 added error values for temp and humidity when read failed +// 0.1.02 added error codes +// 0.1.01 added support for Arduino 1.0, fixed typos (31/12/2011) +// 0.1.00 by Rob Tillaart (01/04/2011) // // inspired by DHT11 library -// -// Released to the public domain -// #include "dht.h" diff --git a/libraries/DHTlib/dht.h b/libraries/DHTlib/dht.h index 66c9db6d..a3339b76 100644 --- a/libraries/DHTlib/dht.h +++ b/libraries/DHTlib/dht.h @@ -1,9 +1,10 @@ - // +// // FILE: dht.h // AUTHOR: Rob Tillaart -// VERSION: 0.1.29 -// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino -// URL: http://arduino.cc/playground/Main/DHTLib +// VERSION: 0.1.30 +// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino. AVR optimized +// URL: https://github.com/RobTillaart/DHTlib +// http://arduino.cc/playground/Main/DHTLib // // HISTORY: // see dht.cpp file diff --git a/libraries/DHTlib/examples/dht22_test_noIRQ/dht22_test.pde.txt b/libraries/DHTlib/examples/dht22_test_noIRQ/dht22_test.pde.txt new file mode 100644 index 00000000..26f8307b --- /dev/null +++ b/libraries/DHTlib/examples/dht22_test_noIRQ/dht22_test.pde.txt @@ -0,0 +1,95 @@ +// +// FILE: dht22_test.ino +// AUTHOR: Rob Tillaart +// VERSION: 0.1.02 +// PURPOSE: DHT library test sketch for DHT22 && Arduino +// URL: +// HISTORY: +// 0.1.02 added counters for error-regression testing. +// 0.1.01 +// 0.1.00 initial version +// +// Released to the public domain +// + +#include + +dht DHT; + +#define DHT22_PIN 5 + +struct +{ + uint32_t total; + uint32_t ok; + uint32_t crc_error; + uint32_t time_out; + uint32_t unknown; +} stat = { 0,0,0,0,0 }; + +void setup() +{ + Serial.begin(115200); + Serial.println("dht22_test.ino"); + Serial.print("LIBRARY VERSION: "); + Serial.println(DHT_LIB_VERSION); + Serial.println(); + Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)\tTime (us)"); +} + +void loop() +{ + // READ DATA + Serial.print("DHT22, \t"); + + uint32_t start = micros(); + int chk = DHT.read22(DHT22_PIN); + uint32_t stop = micros(); + + stat.total++; + switch (chk) + { + case DHTLIB_OK: + stat.ok++; + Serial.print("OK,\t"); + break; + case DHTLIB_ERROR_CHECKSUM: + stat.crc_error++; + Serial.print("Checksum error,\t"); + break; + case DHTLIB_ERROR_TIMEOUT: + stat.time_out++; + Serial.print("Time out error,\t"); + break; + default: + stat.unknown++; + Serial.print("Unknown error,\t"); + break; + } + // DISPLAY DATA + Serial.print(DHT.humidity, 1); + Serial.print(",\t"); + Serial.print(DHT.temperature, 1); + Serial.print(",\t"); + Serial.print(stop - start); + Serial.println(); + + if (stat.total % 20 == 0) + { + Serial.println("\nTOT\tOK\tCRC\tTO\tUNK"); + Serial.print(stat.total); + Serial.print("\t"); + Serial.print(stat.ok); + Serial.print("\t"); + Serial.print(stat.crc_error); + Serial.print("\t"); + Serial.print(stat.time_out); + Serial.print("\t"); + Serial.print(stat.unknown); + Serial.println("\n"); + } + delay(2000); +} +// +// END OF FILE +// \ No newline at end of file diff --git a/libraries/DHTlib/library.json b/libraries/DHTlib/library.json index 6e418dc1..4d9a2836 100644 --- a/libraries/DHTlib/library.json +++ b/libraries/DHTlib/library.json @@ -13,12 +13,9 @@ "repository": { "type": "git", - "url": "https://github.com/RobTillaart/Arduino.git" + "url": "https://github.com/RobTillaart/DHTlib.git" }, - "version":"0.1.29", + "version":"0.1.30", "frameworks": "arduino", - "platforms": "*", - "export": { - "include": "libraries/DHTlib" - } + "platforms": "*" } diff --git a/libraries/DHTlib/library.properties b/libraries/DHTlib/library.properties index f67b7518..cba00156 100644 --- a/libraries/DHTlib/library.properties +++ b/libraries/DHTlib/library.properties @@ -1,9 +1,11 @@ name=DHTlib -version=0.1.29 +version=0.1.30 author=Rob Tillaart maintainer=Rob Tillaart -sentence=Optimized Library for DHT Temperature & Humidity Sensor on AVR only. -paragraph= +sentence=AVR Optimized Library for DHT Temperature & Humidity Sensor on AVR only. +paragraph= category=Sensors -url=https://github.com/RobTillaart/Arduino/tree/master/libraries +url=https://github.com/RobTillaart/DHTlib architectures=avr +includes=dht.h +depends= diff --git a/libraries/DHTlib/readme.md b/libraries/DHTlib/readme.md index b484a2a2..12261278 100644 --- a/libraries/DHTlib/readme.md +++ b/libraries/DHTlib/readme.md @@ -1,4 +1,6 @@ -# DHT Library +# DHTlib + +Arduino library for DHT temperature and humidity sensor. AVR optimized ## Description @@ -11,20 +13,32 @@ The hardware pins of the sensors and handshake are identical so ideal to combine The library (0.1.13 version) is confirmed to work on: -*UNO (tested myself) -*2009 (tested myself) -*MEGA2560 -*DUE -*attiny85 @8MHz -*Digistump Digix @ 84 MHz +* UNO (tested myself) +* 2009 (tested myself) +* MEGA2560 +* DUE +* attiny85 @8MHz +* Digistump Digix @ 84 MHz -Later 0.1.xx versions are optimized for AVR. +Later 0.1.xx versions are optimized for AVR only. More information - http://playground.arduino.cc/Main/DHTLib - +For latest version for the DHT, check https://github.com/RobTillaart/DHTNEW + +## DHT PIN layout from left to right + +| FRONT | | DESCRIPTION | +|:----|:----:|:----| +| pin 1 | | VCC | +| pin 2 | | DATA | +| pin 3 | | Not Connected | +| pin 4 | | GND | + | + ## Operational -TODO pin description +See examples ## Versions: @@ -32,8 +46,8 @@ TODO pin description ==> See DHTStable library for latest stable version for all platforms. * version 0.1.13 is the last stable version for both AVR and ARM -* version 0.1.14 and up are not compatible anymore with pre 1.0 Arduino -* version 0.1.14 and up have breaking changes wrt ARM based arduino's e.g DUE. +* version 0.1.14 and up are not compatible anymore with pre 1.0 Arduino. +These have breaking changes wrt ARM based arduino's e.g DUE. * version 0.1.15 is stable version for AVR only * version 0.1.16 and 0.1.17 have breaking changes for DHT11 * version 0.1.18 works again for DHT11 (avr only) @@ -41,7 +55,12 @@ TODO pin description * version 0.1.20 Reduce footprint (34 bytes) by using int8_t as error codes. (thanks to chaveiro) * version 0.1.21 replace delay with delayMicroseconds() + small fix (thanks to codingforfun) * version 0.1.22 undo delayMicroseconds() for wakeups larger than 8 -* version 0.1.23 FIX https://github.com/RobTillaart/Arduino/issues/31 -* version 0.1.24 FIX https://github.com/RobTillaart/Arduino/issues/33 -* version 0.1.25 FIX https://github.com/RobTillaart/Arduino/issues/80 +* version 0.1.23 fix https://github.com/RobTillaart/Arduino/issues/31 +* version 0.1.24 fix https://github.com/RobTillaart/Arduino/issues/33 +* version 0.1.25 fix https://github.com/RobTillaart/Arduino/issues/80 * version 0.1.26 Explicit support for AM23XX series and DHT12 +* version 0.1.27 added _disableIRQ flag +* version 0.1.28 refactor +* version 0.1.29 fix negative temperature DHT12 - issue #111 +* version 0.1.30 own repo version + diff --git a/libraries/DHTstable/LICENSE b/libraries/DHTstable/LICENSE new file mode 100644 index 00000000..27679c12 --- /dev/null +++ b/libraries/DHTstable/LICENSE @@ -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. diff --git a/libraries/DHTstable/dht.cpp b/libraries/DHTstable/dht.cpp index 204159dc..13b1077e 100644 --- a/libraries/DHTstable/dht.cpp +++ b/libraries/DHTstable/dht.cpp @@ -1,11 +1,13 @@ // // FILE: dht.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.2.4 +// VERSION: 0.2.6 // PURPOSE: DHT Temperature & Humidity Sensor library for Arduino -// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTstable +// URL: https://github.com/RobTillaart/DHTstable // // HISTORY: +// 0.2.6 2020-07-20 update URL in .cpp +// 0.2.5 2020-06-30 move to own repository; update headers mainly. // 0.2.4 2018-04-03 add get-/setDisableIRQ(bool b) // 0.2.3 2018-02-21 change #defines in const int to enforce return types. // https://github.com/RobTillaart/Arduino/issues/94 @@ -29,8 +31,6 @@ // // inspired by DHT11 library // -// Released to the public domain -// #include "dht.h" diff --git a/libraries/DHTstable/dht.h b/libraries/DHTstable/dht.h index dde78a0c..b14c3c0a 100644 --- a/libraries/DHTstable/dht.h +++ b/libraries/DHTstable/dht.h @@ -1,9 +1,9 @@ // // FILE: dht.h // AUTHOR: Rob Tillaart -// VERSION: 0.2.4 +// VERSION: 0.2.6 // PURPOSE: DHT Temperature & Humidity Sensor library for Arduino -// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTstable +// URL: https://github.com/RobTillaart/DHTstable // // HISTORY: // see dht.cpp file @@ -18,7 +18,7 @@ #include #endif -#define DHT_LIB_VERSION "0.2.3 - dhtstable" +#define DHT_LIB_VERSION "0.2.6 - dhtstable" const int DHTLIB_OK = 0; const int DHTLIB_ERROR_CHECKSUM = -1; diff --git a/libraries/DHTstable/examples/dht11_test/dht11_test.ino b/libraries/DHTstable/examples/dht11_test/dht11_test.ino index 9308139c..ce0f2d4a 100644 --- a/libraries/DHTstable/examples/dht11_test/dht11_test.ino +++ b/libraries/DHTstable/examples/dht11_test/dht11_test.ino @@ -1,12 +1,12 @@ // // FILE: dht11_test.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.01 +// VERSION: 0.1.2 // PURPOSE: DHT library test sketch for DHT11 && Arduino -// URL: -// -// Released to the public domain +// URL: https://github.com/RobTillaart/DHTstable // +// HISTORY: +// 0.1.2 add URL in header #include diff --git a/libraries/DHTstable/examples/dht12_test/dht12_test.ino b/libraries/DHTstable/examples/dht12_test/dht12_test.ino index 8d100a4c..57344722 100644 --- a/libraries/DHTstable/examples/dht12_test/dht12_test.ino +++ b/libraries/DHTstable/examples/dht12_test/dht12_test.ino @@ -1,12 +1,12 @@ // // FILE: dht12_test.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.0 +// VERSION: 0.1.1 // PURPOSE: DHT library test sketch for DHT12 && Arduino -// URL: -// -// Released to the public domain +// URL: https://github.com/RobTillaart/DHTstable // +// HISTORY: +// 0.1.1 add URL in header #include diff --git a/libraries/DHTstable/examples/dht22_test/dht22_test.ino b/libraries/DHTstable/examples/dht22_test/dht22_test.ino index 0c7cbfae..401689a6 100644 --- a/libraries/DHTstable/examples/dht22_test/dht22_test.ino +++ b/libraries/DHTstable/examples/dht22_test/dht22_test.ino @@ -1,17 +1,17 @@ // // FILE: dht22_test.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.03 +// VERSION: 0.1.4 // PURPOSE: DHT library test sketch for DHT22 && Arduino -// URL: +// URL: https://github.com/RobTillaart/DHTstable +// // HISTORY: +// 0.1.4 add URL in header // 0.1.03 extended stats for all errors // 0.1.02 added counters for error-regression testing. // 0.1.01 // 0.1.00 initial version // -// Released to the public domain -// #include diff --git a/libraries/DHTstable/keywords.txt b/libraries/DHTstable/keywords.txt index 77c388e3..482f45d1 100644 --- a/libraries/DHTstable/keywords.txt +++ b/libraries/DHTstable/keywords.txt @@ -1,5 +1,5 @@ ####################################### -# Syntax Coloring Map For DHT +# Syntax Coloring Map For DHTStable ####################################### ####################################### diff --git a/libraries/DHTstable/library.json b/libraries/DHTstable/library.json index e904e2d5..27c9f21e 100644 --- a/libraries/DHTstable/library.json +++ b/libraries/DHTstable/library.json @@ -13,12 +13,9 @@ "repository": { "type": "git", - "url": "https://github.com/RobTillaart/Arduino.git" + "url": "https://github.com/RobTillaart/DHTstable }, - "version":"0.2.4", + "version":"0.2.6", "frameworks": "arduino", - "platforms": "atmelavr", - "export": { - "include": "libraries/DHTstable" - } + "platforms": "atmelavr" } diff --git a/libraries/DHTstable/library.properties b/libraries/DHTstable/library.properties index a3879418..8db2391e 100644 --- a/libraries/DHTstable/library.properties +++ b/libraries/DHTstable/library.properties @@ -1,9 +1,11 @@ name=DHTStable -version=0.2.4 +version=0.2.6 author=Rob Tillaart maintainer=Rob Tillaart sentence=Stable version of library for DHT Temperature & Humidity Sensor paragraph= category=Sensors -url=https://github.com/RobTillaart/Arduino/tree/master/libraries/ -architectures=* \ No newline at end of file +url=https://github.com/RobTillaart/DHTstable +architectures=atmelavr +includes=DHT.h +depends= diff --git a/libraries/DHTstable/readme.md b/libraries/DHTstable/readme.md index 6795b33e..8bc33ea4 100644 --- a/libraries/DHTstable/readme.md +++ b/libraries/DHTstable/readme.md @@ -1,13 +1,29 @@ +# DHTstable -This is the 0.2.3 version of the DHTlib. +Arduino Library for the DHT temperature and humidity sensor. + +## Description + +The DHTstable library is a "frozen" version of the DHTlib. This version is stable for both ARM and AVR. -You can use most examples from https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTlib/examples +0.2.5 is a migration to its own repository. +0.2.6 fixed URL to new repro -update 2015-10-12: -For multithreading environments for Arduino one could replace - delay(wakeupDelay); -with - delayMicroseconds(wakeupDelay * 1000UL); -see also - https://github.com/RobTillaart/Arduino/pull/25 - +The latest developments for the DHT sensors are done in https://github.com/RobTillaart/DHTNEW +which is also tested on an ESP32. +There are some interface differences but these are relative small. +It is adviced to upgrade to the DHTNEW library if one needs new functionality. + +## Multiple DHT.h includes + +Note that the include file is called dht.h (for compatibily reasons) +this might need a rename in sketch and library if there is a conflict. + +## TODO (optional) +* rename it to dhtstable.h + dhtstable.cpp ( 0.3.0 version some day ) + +## Operational + +See examples. diff --git a/libraries/DS18B20/DS18B20.cpp b/libraries/DS18B20/DS18B20.cpp index 82e23489..5b51777a 100644 --- a/libraries/DS18B20/DS18B20.cpp +++ b/libraries/DS18B20/DS18B20.cpp @@ -1,16 +1,19 @@ // // FILE: DS18B20.cpp // AUTHOR: Rob.Tillaart@gmail.com -// VERSION: 0.1.1 +// VERSION: 0.1.6 // DATE: 2017-07-25 -// // PUPROSE: library for DS18B20 temperature sensor with minimal footprint // // HISTORY: // 0.1.0 2017-07-25 initial version // 0.1.1 2020-02-18 added getAddress() +// 0.1.2 2020-04-11 #pragma once, refactor +// 0.1.3 2020-04-22 #1 fix library.json file +// 0.1.4 2020-04-23 #2 add retry in begin() to support Wemos +// 0.1.5 2020-04-29 #4 added set/getConfig + DEVICE_CRC_ERROR + example +// 0.1.6 2020-06-07 fix library.json -#include "Arduino.h" #include "DS18B20.h" // OneWire commands @@ -21,13 +24,13 @@ // Scratchpad locations #define TEMP_LSB 0 #define TEMP_MSB 1 -// #define HIGH_ALARM_TEMP 2 -// #define LOW_ALARM_TEMP 3 -// #define CONFIGURATION 4 -// #define INTERNAL_BYTE 5 -// #define COUNT_REMAIN 6 -// #define COUNT_PER_C 7 -// #define SCRATCHPAD_CRC 8 +#define HIGH_ALARM_TEMP 2 +#define LOW_ALARM_TEMP 3 +#define CONFIGURATION 4 +#define INTERNAL_BYTE 5 +#define COUNT_REMAIN 6 +#define COUNT_PER_C 7 +#define SCRATCHPAD_CRC 8 // Device resolution #define TEMP_9_BIT 0x1F // 9 bit @@ -39,25 +42,32 @@ DS18B20::DS18B20(OneWire* _oneWire) { _wire = _oneWire; - configured = false; + _addresFound = false; + _config = DS18B20_CLEAR; } bool DS18B20::begin(void) { - _wire->reset_search(); - _wire->search(deviceAddress); - configured = _wire->crc8(deviceAddress, 7) == deviceAddress[7] - && deviceAddress[0] != 0x00; - return configured; + _config = DS18B20_CLEAR; + _addresFound = false; + for (uint8_t retries = 3; (retries > 0) && (_addresFound == false); retries--) + { + _wire->reset_search(); + _deviceAddress[0] = 0x00; + _wire->search(_deviceAddress); + _addresFound = _deviceAddress[0] != 0x00 && + _wire->crc8(_deviceAddress, 7) == _deviceAddress[7]; + } + return _addresFound; } void DS18B20::readScratchPad(uint8_t *scratchPad, uint8_t fields) { _wire->reset(); - _wire->select(deviceAddress); + _wire->select(_deviceAddress); _wire->write(READSCRATCH); - for(uint8_t i=0; i < fields; i++) + for (uint8_t i = 0; i < fields; i++) { scratchPad[i] = _wire->read(); } @@ -79,10 +89,19 @@ void DS18B20::requestTemperatures(void) float DS18B20::getTempC(void) { ScratchPad scratchPad; - readScratchPad(scratchPad, 2); - + if (_config & DS18B20_CRC) + { + readScratchPad(scratchPad, 9); + if (_wire->crc8(scratchPad, 8) != scratchPad[SCRATCHPAD_CRC]) + { + return DEVICE_CRC_ERROR; + } + } + else + { + readScratchPad(scratchPad, 2); + } int16_t rawTemperature = (((int16_t)scratchPad[TEMP_MSB]) << 8) | scratchPad[TEMP_LSB]; - float temp = 0.0625 * rawTemperature; if (temp < -55) return DEVICE_DISCONNECTED; return temp; @@ -91,7 +110,7 @@ float DS18B20::getTempC(void) void DS18B20::setResolution(uint8_t newResolution) { _wire->reset(); - _wire->select(deviceAddress); + _wire->select(_deviceAddress); _wire->write(WRITESCRATCH); // two dummy values for LOW & HIGH ALARM _wire->write(0); @@ -117,14 +136,14 @@ void DS18B20::setResolution(uint8_t newResolution) bool DS18B20::getAddress(uint8_t* buf) { - if (configured) + if (_addresFound) { - for (uint8_t i = 0; i< 8; i++) + for (uint8_t i = 0; i < 8; i++) { - buf[i] = deviceAddress[i]; + buf[i] = _deviceAddress[i]; } } - return configured; + return _addresFound; } -// END OF FILE +// -- END OF FILE -- diff --git a/libraries/DS18B20/DS18B20.h b/libraries/DS18B20/DS18B20.h index c2b37ff4..39529d05 100644 --- a/libraries/DS18B20/DS18B20.h +++ b/libraries/DS18B20/DS18B20.h @@ -1,35 +1,40 @@ +#pragma once // // FILE: DS18B20.h // AUTHOR: Rob.Tillaart@gmail.com -// VERSION: 0.1.1 +// VERSION: 0.1.6 // DATE: 2017-07-25 -// // PUPROSE: library for DS18B20 temperature sensor with minimal footprint // // // BOTTOM VIEW // +// PIN MEANING // /---+ -// / o | GND -// | o | DATA -// \ o | VCC +// / o | 1 GND +// | o | 2 DATA +// \ o | 3 VCC // \---+ // -#ifndef DS18B20_H -#define DS18B20_H - -#define DS18B20_LIB_VERSION "0.1.1" +#define DS18B20_LIB_VERSION "0.1.6" #include // Error Code -#define DEVICE_DISCONNECTED -127 +#define DEVICE_DISCONNECTED -127 +#define DEVICE_CRC_ERROR -128 + +// config codes +#define DS18B20_CLEAR 0x00 +#define DS18B20_CRC 0x01 + typedef uint8_t DeviceAddress[8]; typedef uint8_t ScratchPad[9]; + class DS18B20 { public: @@ -41,13 +46,15 @@ public: bool isConversionComplete(void); bool getAddress(uint8_t*); + void setConfig(uint8_t config) { _config = config; }; + uint8_t getConfig() { return _config; }; + private: void readScratchPad(uint8_t *, uint8_t); - DeviceAddress deviceAddress; + DeviceAddress _deviceAddress; OneWire* _wire; - bool configured; + bool _addresFound; + uint8_t _config; }; -#endif - -// END OF FILE \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/DS18B20/LICENSE b/libraries/DS18B20/LICENSE new file mode 100644 index 00000000..ed401f22 --- /dev/null +++ b/libraries/DS18B20/LICENSE @@ -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. diff --git a/libraries/DS18B20/examples/DS18B20_diagnose/DS18B20_diagnose.ino b/libraries/DS18B20/examples/DS18B20_diagnose/DS18B20_diagnose.ino new file mode 100644 index 00000000..3df9213c --- /dev/null +++ b/libraries/DS18B20/examples/DS18B20_diagnose/DS18B20_diagnose.ino @@ -0,0 +1,68 @@ +// +// FILE: DS18B20_diagnose.ino +// AUTHOR: Rob Tillaart +// VERSION: 0.0.1 +// PURPOSE: Minimal DS18B20 lib with async support. +// +// HISTORY: +// 0.0.1 = 2020-04-23 initial version + +#include +#include + +#define ONE_WIRE_BUS 2 + +OneWire oneWire(ONE_WIRE_BUS); +DS18B20 sensor(&oneWire); + +uint32_t start, stop; + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.print("DS18B20 Library version: "); + Serial.println(DS18B20_LIB_VERSION); + + if (sensor.begin() == false) + { + Serial.println("Error: Could not find sensor."); + while (1); + } + sensor.setResolution(12); + sensor.requestTemperatures(); + + start = millis(); + while (!sensor.isConversionComplete()); + stop = millis(); + + Serial.print(stop - start); + Serial.print("\t"); + Serial.println(sensor.getTempC(), 2); + Serial.println(); +} + + +void loop() +{ + for (int res = 9; res < 13; res++) + { + sensor.setResolution(res); + + start = millis(); + sensor.requestTemperatures(); + while (!sensor.isConversionComplete()); + float temperature = sensor.getTempC(); + stop = millis(); + + Serial.print(res); + Serial.print("\t"); + Serial.print(stop - start); + Serial.print("\t"); + Serial.println(temperature, 1); // 1 decimal makes perfect sense + } + Serial.println(); + delay(1000); +} + +// -- END OF FILE -- diff --git a/libraries/DS18B20/examples/DS18B20_getAddress/DS18B20_getAddress.ino b/libraries/DS18B20/examples/DS18B20_getAddress/DS18B20_getAddress.ino index 9a848241..d56296bd 100644 --- a/libraries/DS18B20/examples/DS18B20_getAddress/DS18B20_getAddress.ino +++ b/libraries/DS18B20/examples/DS18B20_getAddress/DS18B20_getAddress.ino @@ -15,8 +15,6 @@ OneWire oneWire(ONE_WIRE_BUS); DS18B20 sensor(&oneWire); -uint32_t start, stop; - DeviceAddress da; void setup() diff --git a/libraries/DS18B20/examples/DS18B20_performance/DS18B20_performance.ino b/libraries/DS18B20/examples/DS18B20_performance/DS18B20_performance.ino index 79ccfab6..292efd6c 100644 --- a/libraries/DS18B20/examples/DS18B20_performance/DS18B20_performance.ino +++ b/libraries/DS18B20/examples/DS18B20_performance/DS18B20_performance.ino @@ -34,7 +34,7 @@ void loop() float ti[4] = { 94, 188, 375, 750 }; Serial.println(); - Serial.println("Test takes about 30 seconds for 4 resolutions"); + Serial.println("Test takes about 30 seconds for 4 resolutions, 20 measurements"); Serial.println("RES\tTIME\tACTUAL\tGAIN"); for (int r = 9; r < 13; r++) { diff --git a/libraries/DS18B20/examples/DS18B20_test_disconnect/DS18B20_test_disconnect.ino b/libraries/DS18B20/examples/DS18B20_test_disconnect/DS18B20_test_disconnect.ino new file mode 100644 index 00000000..ef4aa3ff --- /dev/null +++ b/libraries/DS18B20/examples/DS18B20_test_disconnect/DS18B20_test_disconnect.ino @@ -0,0 +1,74 @@ +// +// FILE: DS18B20_test_disconnect.ino +// AUTHOR: Rob Tillaart +// VERSION: 0.0.1 +// PURPOSE: Minimal DS18B20 lib with async support. +// +// HISTORY: +// 0.0.1 = 2020-04-29 initial version + +#include +#include + +#define ONE_WIRE_BUS 2 + +OneWire oneWire(ONE_WIRE_BUS); +DS18B20 sensor(&oneWire); + +uint32_t start, stop; +uint8_t res = 12; + + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.print("DS18B20 Library version: "); + Serial.println(DS18B20_LIB_VERSION); + + // wait until address found + if (sensor.begin() == false) + { + Serial.println("ERROR: No device found"); + while (!sensor.begin()); // wait until device comes available. + } + + sensor.setResolution(12); + sensor.setConfig(DS18B20_CRC); // or 1 + sensor.requestTemperatures(); +} + + +void loop() +{ + start = millis(); + sensor.requestTemperatures(); + + // wait for data AND detect disconnect + uint32_t timeout = millis(); + while (!sensor.isConversionComplete()) + { + if (millis() - timeout >= 800) // check for timeout + { + Serial.println("ERROR: timeout or disconnect"); + break; + } + } + + float t = sensor.getTempC(); + + if (t == DEVICE_CRC_ERROR) + { + Serial.println("ERROR: CRC error"); + } + stop = millis(); + + Serial.print(res); + Serial.print("\t"); + Serial.print(stop - start); + Serial.print("\t"); + Serial.println( t, 1); // 1 decimal makes perfect sense + delay(1000); +} + +// -- END OF FILE -- diff --git a/libraries/DS18B20/examples/oneWireSearch/oneWireSearch.ino b/libraries/DS18B20/examples/oneWireSearch/oneWireSearch.ino new file mode 100644 index 00000000..44da6192 --- /dev/null +++ b/libraries/DS18B20/examples/oneWireSearch/oneWireSearch.ino @@ -0,0 +1,67 @@ +// +// FILE: oneWireSearch.ino +// AUTHOR: Rob Tillaart +// VERSION: 0.1.02 +// PURPOSE: scan for 1-Wire devices + code snippet generator +// DATE: 2015-june-30 +// URL: http://forum.arduino.cc/index.php?topic=333923 +// +// inspired by http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html +// +// Released to the public domain +// +// 0.1.00 initial version +// 0.1.01 first published version +// 0.1.02 small output changes + +#include + +void setup() +{ + Serial.begin(115200); + Serial.println("//\n// Start oneWireSearch.ino \n//"); + + for (uint8_t pin = 2; pin < 13; pin++) + { + findDevices(pin); + } + Serial.println("\n//\n// End oneWireSearch.ino \n//"); +} + +void loop() +{ +} + +uint8_t findDevices(int pin) +{ + OneWire ow(pin); + + uint8_t address[8]; + uint8_t count = 0; + + + if (ow.search(address)) + { + Serial.print("\nuint8_t pin"); + Serial.print(pin, DEC); + Serial.println("[][8] = {"); + do { + count++; + Serial.println(" {"); + for (uint8_t i = 0; i < 8; i++) + { + Serial.print("0x"); + if (address[i] < 0x10) Serial.print("0"); + Serial.print(address[i], HEX); + if (i < 7) Serial.print(", "); + } + Serial.println(" },"); + } while (ow.search(address)); + + Serial.println("};"); + Serial.print("// nr devices found: "); + Serial.println(count); + } + + return count; +} diff --git a/libraries/DS18B20/keywords.txt b/libraries/DS18B20/keywords.txt index e0f232fe..277fb09b 100644 --- a/libraries/DS18B20/keywords.txt +++ b/libraries/DS18B20/keywords.txt @@ -1,24 +1,23 @@ -####################################### # Syntax Coloring Map For DS18B20 -####################################### -####################################### # Datatypes (KEYWORD1) -####################################### DS18B20 KEYWORD1 OneWire KEYWORD1 DeviceAddress KEYWORD1 -####################################### # Methods and Functions (KEYWORD2) -####################################### begin KEYWORD2 setResolution KEYWORD2 getTempC KEYWORD2 requestTemperatures KEYWORD2 isConversionComplete KEYWORD2 +getAddress KEYWORD2 +setConfig KEYWORD2 +getConfig KEYWORD2 -####################################### # Constants (LITERAL1) -####################################### DS18B20_LIB_VERSION LITERAL1 +DEVICE_DISCONNECTED LITERAL1 +DEVICE_CRC_ERROR LITERAL1 +DS18B20_CLEAR LITERAL1 +DS18B20_CRC LITERAL1 diff --git a/libraries/DS18B20/library.json b/libraries/DS18B20/library.json index e3ef99b8..78cbe3ac 100644 --- a/libraries/DS18B20/library.json +++ b/libraries/DS18B20/library.json @@ -1,7 +1,7 @@ { "name": "DS18B20", "keywords": "DS18B20,Dallas,Semiconductor,Temperature,sensor,asynchronuous", - "description": "Library for DS18B20 restricted to a single sensor per pin. Rewritten minimalistic version of Dallas Temperature Control Library of Miles Burton.", + "description": "Arduino library for the DS18B20 temperature sensor. Restricted to a single sensor per pin. Minimalistic version.", "authors": [ { @@ -13,12 +13,9 @@ "repository": { "type": "git", - "url": "https://github.com/RobTillaart/Arduino.git" + "url": "https://github.com/RobTillaart/DS18B20" }, - "version":"0.1.1", + "version":"0.1.6", "frameworks": "arduino", - "platforms": "*", - "export": { - "include": "libraries/DS18B20" - } + "platforms": "*" } diff --git a/libraries/DS18B20/library.properties b/libraries/DS18B20/library.properties index 18ead860..93075956 100644 --- a/libraries/DS18B20/library.properties +++ b/libraries/DS18B20/library.properties @@ -1,10 +1,11 @@ -name=DS18B20 -version=0.1.1 +name=DS18B20_RT +version=0.1.6 author=Rob Tillaart maintainer=Rob Tillaart -sentence=Library for DS18B20 restricted to a single sensor per pin. Rewritten minimalistic version of Dallas Temperature Control Library of Miles Burton. -paragraph= +sentence=Arduino library for the DS18B20 temperature sensor. +paragraph=Minimalistic version, restricted to one sensor per pin, asynchronuous mode only. category=Sensors -url=https://github.com/RobTillaart/Arduino/tree/master/libraries/ +url=https://github.com/RobTillaart/DS18B20 architectures=* -depends=OneWire \ No newline at end of file +includes=OneWire.h,DS18B20.h +depends=OneWire diff --git a/libraries/DS18B20/readme.md b/libraries/DS18B20/readme.md index 41ed23b0..2f8f6073 100644 --- a/libraries/DS18B20/readme.md +++ b/libraries/DS18B20/readme.md @@ -1,8 +1,12 @@ -# DS18B20 Library +# DS18B20 + +Arduino library for the DS18B20 sensor - restricted to one sensor per pin. ## Arduino Temperature Control Library (ATCL) This DS18B20 library is not a full featured library for the DS18B20 family. +This library supports only one DS18B20 per Arduino/ MCU pin. + If you need more functions or control over the DS18B20 family I refer to the library of Miles Burton - https://github.com/milesburton/Arduino-Temperature-Control-Library @@ -16,13 +20,14 @@ The DS18B20 library supports only the DS18B20, only one sensor per pin, no paras mode, no Fahrenheit and no alarm functions. The only feature the class supports is the asynchronous reading of the temperature by means of three core functions: -* requestTemperatures() -* isConversionComplete() -* readTempC() - -Version 0.1.1 added getAddress() as this info is available as private data. -* getAddress(uint8_t*) +* void requestTemperatures() +* bool isConversionComplete() +* float readTempC() +The other main functions are +* bool begin(void); *// returns true if the sensor is configured (available)* +* void setResolution(uint8_t); +* bool getAddress(uint8_t*) *// returns true if the sensor is configured (available)* This allowed the class to be both minimal in size and non-blocking. In fact the class has no support for a synchronous read in one call. This choice will teach people @@ -37,22 +42,44 @@ boards or IC's with small memory footprint. ## Operation +``` +// BOTTOM VIEW +// +// PIN MEANING +// /---+ +// / o | 1 GND +// | o | 2 DATA +// \ o | 3 VCC +// \---+ +``` + This library supports only one DS18B20 per Arduino/ MCU pin. -Pin1 = Ground -Pin2 = Data -Pin3 = VCC Connect a pull-up resistor 4.7 KOhm between pin3 and pin2. When the wires are longer -this resistor needs to be smaller. +this resistor needs to be smaller. + +### Pull up resistor + +An **indicative** table for pull up resistors, (E12 series), to get started. + +Note: thicker wires require smaller resistors (typically 1 step in E12 series) + + +| Length | - 5.0 Volt | - 3.3 Volt | +|--------------:|------------:|----------:| +| 10cm (4") | 10K0 | 6K8 | +| 20cm (8") | 8K2 | 4K7 | +| 50cm (20") | 4K7 | 3K3 | +| 100cm (3'4") | 3K3 | 2K2 | +| 200cm (6'8") | 2K2 | 1K0 | +| 500cm (16'8") | 1K0 | * | +| longer | * | * | + +\* = no info, smaller + ## Credits Miles Burton who originally developed the Arduino Temperature Control Library. and all people who contributed to that lib. -## 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. - diff --git a/libraries/DS28CM00/DS28CM00.cpp b/libraries/DS28CM00/DS28CM00.cpp index 924ac94f..803eabc6 100644 --- a/libraries/DS28CM00/DS28CM00.cpp +++ b/libraries/DS28CM00/DS28CM00.cpp @@ -2,13 +2,13 @@ // FILE: DS28CM00.cpp // AUTHOR: Rob Tillaart // PURPOSE: Library for the DS28CM00 unique identification chip. -// VERSION: 0.1.0 -// URL: +// VERSION: 0.2.1 +// URL: https://github.com/RobTillaart/DS28CM00 // // HISTORY: // 0.1.0 2017-07-15 initial version -// -// Released to the public domain +// 0.2.0 2020-04-11 refactor, #pragma once, ESP support, multiple Wire, ESP support (start) +// 0.2.1 2020-06-07 fix library.json // #include "DS28CM00.h" @@ -20,52 +20,71 @@ DS28CM00::DS28CM00() { + DS28CM00(Wire); } +DS28CM00::DS28CM00(TwoWire *wire) +{ + _wire = wire; +} + +#if defined(ESP8266) || defined(ESP32) +DS28CM00::DS28CM00(const uint8_t dataPin, const uint8_t clockPin) +{ + _wire = &Wire; + if ((dataPin < 255) && (clockPin < 255)) + { + _wire->begin(dataPin, clockPin); + } else { + _wire->begin(); + } +} +#endif + + void DS28CM00::begin() { - Wire.begin(); + _wire->begin(); setI2CMode(); } bool DS28CM00::setMode(uint8_t mode) { - Wire.beginTransmission(DS28CM00_DEVICEADDRESS); - Wire.write(DS28CM00_CONTROLREGISTER); - Wire.write(mode); - int rv = Wire.endTransmission(); + _wire->beginTransmission(DS28CM00_DEVICEADDRESS); + _wire->write(DS28CM00_CONTROLREGISTER); + _wire->write(mode); + int rv = _wire->endTransmission(); return rv == 0; } bool DS28CM00::getMode(uint8_t &mode) { - Wire.beginTransmission(DS28CM00_DEVICEADDRESS); - Wire.write(DS28CM00_CONTROLREGISTER); - int rv = Wire.endTransmission(); + _wire->beginTransmission(DS28CM00_DEVICEADDRESS); + _wire->write(DS28CM00_CONTROLREGISTER); + int rv = _wire->endTransmission(); if (rv != 0) return false; - uint8_t read = Wire.requestFrom(DS28CM00_DEVICEADDRESS, 1); + uint8_t read = _wire->requestFrom(DS28CM00_DEVICEADDRESS, 1); if (read < 1) return false; - mode = Wire.read(); + mode = _wire->read(); return true; } bool DS28CM00::getUID(uint8_t *buffer) { - Wire.beginTransmission(DS28CM00_DEVICEADDRESS); - Wire.write(DS28CM00_UIDREGISTER); - int rv = Wire.endTransmission(); + _wire->beginTransmission(DS28CM00_DEVICEADDRESS); + _wire->write(DS28CM00_UIDREGISTER); + int rv = _wire->endTransmission(); if (rv != 0) return false; - uint8_t read = Wire.requestFrom(DS28CM00_DEVICEADDRESS, 8); + uint8_t read = _wire->requestFrom(DS28CM00_DEVICEADDRESS, 8); if (read < 8) return false; - for (uint8_t i = 0; i < 8; i++) buffer[i] = Wire.read(); - // if (buffer[0] != 0x70) return false + for (uint8_t i = 0; i < 8; i++) buffer[i] = _wire->read(); return true; } -// END OF FILE \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/DS28CM00/DS28CM00.h b/libraries/DS28CM00/DS28CM00.h index dcb81d36..bad2e6a0 100644 --- a/libraries/DS28CM00/DS28CM00.h +++ b/libraries/DS28CM00/DS28CM00.h @@ -1,21 +1,16 @@ -#ifndef DS28CM00_H -#define DS28CM00_H +#pragma once // // FILE: DS28CM00.h // AUTHOR: Rob Tillaart // PURPOSE: Library for the DS28CM00 unique identification chip. -// VERSION: 0.1.0 +// VERSION: 0.2.1 // HISTORY: See DS28CM00.cpp -// URL: -// -// Released to the public domain +// URL: https://github.com/RobTillaart/DS28CM00 // #include -#include "Arduino.h" - -#define DS28CM00_LIB_VERSION "0.1.0" +#define DS28CM00_LIB_VERSION "0.2.1" #define DS28CM00_I2C_MODE 0x00 #define DS28CM00_SMBUS_MODE 0x01 @@ -23,8 +18,12 @@ class DS28CM00 { public: explicit DS28CM00(); - - void begin(); + explicit DS28CM00(TwoWire *wire); +#if defined(ESP8266) || defined(ESP32) + explicit DS28CM00(const uint8_t dataPin, const uint8_t clockPin); +#endif + + void begin(); // default DS28CM00_I2C_MODE bool getUID(uint8_t *); bool setI2CMode() { return setMode(DS28CM00_I2C_MODE); }; @@ -33,8 +32,7 @@ public: private: bool setMode(uint8_t m); + TwoWire* _wire; }; -#endif - -// END OF FILE \ No newline at end of file +// -- END OF FILE -- diff --git a/libraries/DS28CM00/LICENSE b/libraries/DS28CM00/LICENSE new file mode 100644 index 00000000..ed401f22 --- /dev/null +++ b/libraries/DS28CM00/LICENSE @@ -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. diff --git a/libraries/DS28CM00/README.md b/libraries/DS28CM00/README.md new file mode 100644 index 00000000..61162511 --- /dev/null +++ b/libraries/DS28CM00/README.md @@ -0,0 +1,20 @@ +# DS28CM00 +Arduino library for I2C DS28CM00 unique identification chip. \[48 bit\] + +## Description +THe DS28CM00 IC has a 64 bit address consisting of one type byte, 0x50, 6 bytes unique serial and a CRC +over the previous 7 bytes. This results in an 48 bits unique ID giving 281.474.976.710.656 combinations. +If that number is not unique enough, you could use 2 or more of them with an I2C multiplexer. + +The DS28CM00 IC has the same addressing scheme as the better known DS18B20, except for the type byte. +Therefor one could use an DS18B20 as an unique ID chip in a similar way and getting a temperature sensor +as bonus. + +The DS28CM00 can work in 2 modes, I2C and SMBus mode. check datasheet for details. + +## Operation + +See examples. + +The class is not tested with ESP32 / ESP8266 yet, but an example sketch exist and compiles. +(feedback welcome) diff --git a/libraries/DS28CM00/examples/DS28CM00_test_ESP/DS28CM00_test_ESP.ino b/libraries/DS28CM00/examples/DS28CM00_test_ESP/DS28CM00_test_ESP.ino new file mode 100644 index 00000000..94be7bd6 --- /dev/null +++ b/libraries/DS28CM00/examples/DS28CM00_test_ESP/DS28CM00_test_ESP.ino @@ -0,0 +1,95 @@ +// +// FILE: DS28CM00_test.ino +// AUTHOR: Rob Tillaart +// VERSION: 0.1.0 +// PURPOSE: test DS28CM00 lib +// DATE: 2020-04-10 +// URL: https://github.com/RobTillaart/DS28CM00 +// + +#include +#include + +#include // ESP32 specific + + +uint8_t uid[8]; + +DS28CM00 DS28(10, 12); + +void setup() +{ + Serial.begin(115200); + + Serial.println(__FILE__); + Serial.print(F("DS28CM00 library: ")); + Serial.println(DS28CM00_LIB_VERSION); + + DS28.begin(); + + Serial.println(); +} + +void loop() +{ + test(); + delay(1000); +} + + +void test() +{ + bool b = DS28.getUID(uid); + + if (b == false) + { + Serial.println(F("Error communicating with DS28CM00.")); + } + else + { + // PRINT UID + Serial.print(F("UID:\t")); + for (uint8_t i = 0; i < 8; i++) + { + if (uid[i] < 0x10) Serial.print('0'); + Serial.print(uid[i], HEX); + Serial.print(' '); + } + Serial.println(); + + // GET MODE + uint8_t mode = 0; + DS28.getMode(mode); + Serial.print(F("MODE:\t")); + Serial.println(mode); + + // TOGGLE MODE + if (mode == DS28CM00_I2C_MODE) + { + DS28.setSMBusMode(); + } + else + { + DS28.setI2CMode(); + } + + // CRC GENERATION + // TODO VERIFY WHICH CRC + // uint8_t crc8_le(uint8_t crc, uint8_t const *buf, uint32_t len); + // uint8_t crc8_be(uint8_t crc, uint8_t const *buf, uint32_t len); + + uint8_t crc = crc8_le(0, uid, 7); + if (crc == uid[7]) + { + Serial.println(F("CRC:\tOK")); + } + else + { + Serial.println(F("CRC:\tFAIL")); + } + + Serial.println(); + } +} + +// -- END OF FILE -- diff --git a/libraries/DS28CM00/library.json b/libraries/DS28CM00/library.json index 590551de..61eee0b1 100644 --- a/libraries/DS28CM00/library.json +++ b/libraries/DS28CM00/library.json @@ -1,7 +1,7 @@ { "name": "DS28CM00", - "keywords": "DS28CM00,identification,ID,unique", - "description": "Library for the DS28CM00 unique identification chip.", + "keywords": "DS28CM00, identification, ID, UID, unique", + "description": "Arduino library for I2C DS28CM00 unique identification chip.", "authors": [ { @@ -13,12 +13,9 @@ "repository": { "type": "git", - "url": "https://github.com/RobTillaart/Arduino.git" + "url": "https://github.com/RobTillaart/DS28CM00.git" }, - "version":"0.1.0", + "version":"0.2.1", "frameworks": "arduino", - "platforms": "*", - "export": { - "include": "libraries/DS28CM00" - } + "platforms": "*" } diff --git a/libraries/DS28CM00/library.properties b/libraries/DS28CM00/library.properties index 07a49911..5dfc4001 100644 --- a/libraries/DS28CM00/library.properties +++ b/libraries/DS28CM00/library.properties @@ -1,9 +1,11 @@ name=DS28CM00 -version=0.1.0 +version=0.2.1 author=Rob Tillaart maintainer=Rob Tillaart -sentence=Library for the DS28CM00 unique identification chip. -paragraph= +sentence=Arduino library for I2C DS28CM00 unique identification chip. +paragraph=48 bit unique ID, + type + CRC => 64 bit. category=Sensors -url=https://github.com/RobTillaart/Arduino/tree/master/libraries/ -architectures=* \ No newline at end of file +url=https://github.com/RobTillaart/DS28CM00 +architectures=* +includes=Wire.h,DS28CM00 +depends=Wire diff --git a/libraries/DistanceTable/DistanceTable.cpp b/libraries/DistanceTable/DistanceTable.cpp index 1e82acf3..5ac59bb9 100644 --- a/libraries/DistanceTable/DistanceTable.cpp +++ b/libraries/DistanceTable/DistanceTable.cpp @@ -1,12 +1,12 @@ // // FILE: DistanceTable.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.3 -// PURPOSE: library for a memory efficient DistanceTable for Arduino -// URL: -// -// Released to the public domain +// VERSION: 0.1.5 +// PURPOSE: Arduino library to store a symmetrical distance table in less memory +// URL: https://github.com/RobTillaart/DistanceTable // +// 0.1.5 2020-06-07 fix library.json, minor edits +// 0.1.4 2019-01-10 add size() // 0.1.3 2017-07-27 Fix issue #33 // 0.1.2 - fix overflow; add some error detection; revert float to float to memory // 0.1.01 - refactor @@ -43,7 +43,6 @@ void DistanceTable::set(uint8_t x, uint8_t y, float value ) // comment next line to skip rangecheck (squeeze performance) if ( x >= _size || y >= _size) return; - // uint16_t index = getIndex(uint8_t x, uint8_t y); if ( x < y ) { uint8_t t = x; x = y; y = t; @@ -60,7 +59,6 @@ float DistanceTable::get (uint8_t x, uint8_t y) // comment next line to skip rangecheck (squeeze performance) if ( x >= _size || y >= _size) return -1; - // uint16_t index = getIndex(uint8_t x, uint8_t y); if ( x < y ) { uint8_t t = x; x = y; y = t; @@ -70,18 +68,6 @@ float DistanceTable::get (uint8_t x, uint8_t y) return _distanceTable[index]; }; -// TODO remove identical code -// int DistanceTable::getIndex(uint8_t x, uint8_t y) -// { - // if ( x < y ) - // { - // uint8_t t = x; x = y; y = t; - // } - // uint16_t index = x; - // index = (index * (index-1))/2 + y; - // return index; -// } - // triangular dump void DistanceTable::dump() { @@ -98,5 +84,4 @@ void DistanceTable::dump() Serial.println(); }; - // --- END OF FILE --- \ No newline at end of file diff --git a/libraries/DistanceTable/DistanceTable.h b/libraries/DistanceTable/DistanceTable.h index f2e7df89..1d48ee70 100644 --- a/libraries/DistanceTable/DistanceTable.h +++ b/libraries/DistanceTable/DistanceTable.h @@ -1,19 +1,15 @@ +#pragma once // // FILE: DistanceTable.h // AUTHOR: Rob Tillaart -// VERSION: 0.1.3 -// PURPOSE: memory efficient DistanceTable for Arduino -// URL: +// VERSION: 0.1.5 +// PURPOSE: Arduino library to store a symmetrical distance table in less memory +// URL: https://github.com/RobTillaart/DistanceTable // -// Released to the public domain -// - -#ifndef DistanceTable_h -#define DistanceTable_h #include "Arduino.h" -#define DISTANCETABLE_LIB_VERSION "0.1.3" +#define DISTANCETABLE_LIB_VERSION "0.1.5" class DistanceTable { @@ -25,12 +21,14 @@ public: void set(uint8_t x, uint8_t y, float value ); float get(uint8_t x, uint8_t y); void dump(); + uint16_t size() { return _store; }; protected: + int getIndex(uint8_t, uint8_t); + uint8_t _size; uint16_t _store; float * _distanceTable; }; -#endif -// --- END OF FILE --- \ No newline at end of file +// --- END OF FILE --- diff --git a/libraries/DistanceTable/LICENSE b/libraries/DistanceTable/LICENSE new file mode 100644 index 00000000..e563929f --- /dev/null +++ b/libraries/DistanceTable/LICENSE @@ -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. diff --git a/libraries/DistanceTable/keywords.txt b/libraries/DistanceTable/keywords.txt index 8e933f86..a7178de9 100644 --- a/libraries/DistanceTable/keywords.txt +++ b/libraries/DistanceTable/keywords.txt @@ -1,28 +1,15 @@ -####################################### # Syntax Coloring Map For DistanceTable -####################################### -####################################### # Datatypes (KEYWORD1) -####################################### - DistanceTable KEYWORD1 -####################################### # Methods and Functions (KEYWORD2) -####################################### - clear KEYWORD2 set KEYWORD2 get KEYWORD2 -dump KEYWORD2 +size KEYWORD2 +dump KEYWORD2 -####################################### # Instances (KEYWORD2) -####################################### - -####################################### # Constants (LITERAL1) -####################################### - diff --git a/libraries/DistanceTable/library.json b/libraries/DistanceTable/library.json index 17e703f3..f6533aca 100644 --- a/libraries/DistanceTable/library.json +++ b/libraries/DistanceTable/library.json @@ -15,10 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/Arduino.git" }, - "version":"0.1.3", + "version":"0.1.5", "frameworks": "arduino", - "platforms": "*", - "export": { - "include": "libraries/DistanceTable" - } + "platforms": "*" } diff --git a/libraries/DistanceTable/library.properties b/libraries/DistanceTable/library.properties index 8039b11e..da17f3be 100644 --- a/libraries/DistanceTable/library.properties +++ b/libraries/DistanceTable/library.properties @@ -1,9 +1,11 @@ name=DistanceTable -version=0.1.3 +version=0.1.5 author=Rob Tillaart maintainer=Rob Tillaart sentence=Library for a memory efficient DistanceTable for Arduino. paragraph= category=Data Processing -url=https://github.com/RobTillaart/Arduino/tree/master/libraries/ -architectures=* \ No newline at end of file +url=https://github.com/RobTillaart/DistanceTable +architectures=* +includes=DIstanceTable.h +depends= diff --git a/libraries/DistanceTable/readme.md b/libraries/DistanceTable/readme.md index dd94b9ad..97dcd80a 100644 --- a/libraries/DistanceTable/readme.md +++ b/libraries/DistanceTable/readme.md @@ -1,16 +1,20 @@ -# DistanceTable Library +# Distancetable + +Arduino library to store a symmetrical distance table in less memory ## Description -The DistanceTable library is a class that stores a distance table which is typically x * x entries -in less memory space. It uses x * (x-1)/2 ("in a triangle") as an eucledian distance table is -symmetrical around its main diagonal. Furthermore the main diagonal are all zero. +The DistanceTable library is a class that stores a symmetrical distance table +which is typically N x N entries in less memory space. +It uses (N x (N-1))/2 ("in a triangle") as an eucledian distance table is +symmetrical around its main diagonal. +Furthermore as the main diagonal are all zero it does not need to be stored either. -An ATMEL328 (Arduino) can store a 30x30 matrix = 900 floats in 1740 bytes. Normally this amount -would approx hold a 21x21 matrix (1764 bytes). +An ATMEL328 (Arduino) can store a 30 x 30 matrix = 900 floats in 1740 bytes, +where it typically would take 900 x 4 = 3600 bytes. + +Within the 2K RAM of an Arduino one could store normally a 21 x 21 matrix (1764 bytes). ## Operational -Trivial, see examples. - - +See examples.