From 1c486ef719903d87a247806834b3899de6695017 Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Sat, 26 Nov 2022 13:10:43 +0100 Subject: [PATCH] add RP2040 to build-CI (#18) --- .arduino-ci.yml | 18 ++++++++- CHANGELOG.md | 32 +++++----------- README.md | 74 +++++++++++++++++++---------------- library.json | 2 +- library.properties | 4 +- temperature.cpp | 96 +++++++++++++++++++++++----------------------- temperature.h | 68 ++++++++++++++++---------------- 7 files changed, 153 insertions(+), 141 deletions(-) diff --git a/.arduino-ci.yml b/.arduino-ci.yml index cecf585..b4ab412 100644 --- a/.arduino-ci.yml +++ b/.arduino-ci.yml @@ -1,3 +1,18 @@ +platforms: + rpipico: + board: rp2040:rp2040:rpipico + package: rp2040:rp2040 + gcc: + features: + defines: + - ARDUINO_ARCH_RP2040 + warnings: + flags: + +packages: + rp2040:rp2040: + url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json + compile: # Choosing to run compilation tests on 2 different Arduino platforms platforms: @@ -7,5 +22,6 @@ compile: # - leonardo - m4 - esp32 - # - esp8266 + - esp8266 # - mega2560 + - rpipico diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bda659..1c7aed7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,44 +6,32 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## [0.3.4] - 2022-04-15 - -### Added +## [0.3.5] - 2022-11-26 +- added RP2040 to build-CI +- simplified changelog +- optimized Steadman's formula (HeatIndex). +- update readme.md -### Changed -### Fixed +## [0.3.4] - 2022-04-15 - fix #16 Split .h in .h and .cpp - ## [0.3.3] - 2022-01-09 - -### Added -- added working limits to windchill() and heatIndex() - +- added working limits to windChill() and heatIndex() ## [0.3.2] - 2022-01-08 - -### Added - added a TempConvertor class for more exotic scales. - added baroToSeaLevel() - kudos to RobertDB59 - -### Fixed -- Renamed Celcius to Celsius. - +- Renamed Celcius to Celsius. ## [0.3.1] - 2022-01-07 - -### Fixed -- fix adjustments +- fix adjustments which were incorrectly added. ## [0.3.0] - 2022-01-05 - -### Fixed - fix #10 update HeatIndex function compared with https://www.calculator.net/heat-index-calculator.html - +---- ## [0.2.5] - 2021-12-28 - Arduino-CI, library.json, readme.md, license, minor edits diff --git a/README.md b/README.md index 0eb8ca5..ddf48c4 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ # Temperature -Arduino library with dewPoint, humidex, heatIndex and wind-chill functions. +Arduino library with temperature conversion and weather functions including dewPoint, humidex, heatIndex and wind-chill. ## Description @@ -31,7 +31,7 @@ Note: pre-0.3.1 versions have incorrect heat-index. - **float Celsius(float Fahrenheit)** idem. - **float Kelvin(float Celsius)** idem. -More converters are implemented in tne **temperatureConverter()** below. +More converters are implemented in the **temperatureConverter** class below. ### DewPoint, humidex @@ -51,22 +51,18 @@ More converters are implemented in tne **temperatureConverter()** below. The formula for the **heatIndex()** was taken from https://en.wikipedia.org/wiki/Heat_index. Since version 0.3.0 the more elaborated version of https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml -will be used. Note: there will be performance differences. +will be used. +Note: there will be performance differences. Indicative table -| Fahrenheit | Celsius | description | colour code | -|:----------:|:-------:|:------------|------------:| -| 70-79 | 21-26 | warm | green | -| 80-89 | 26-32 | very warm | yellow | -| 90-104 | 32-40 | hot | orange | -| 105-129 | 40-54 | very hot | red | -| > 130 | > 54 | extreme hot | purple | - - -#### 0.3.1 - -Fixed the adjustment which was incorrectly added. +| Fahrenheit | Celsius | description | colour code | +|:------------:|:---------:|:--------------|--------------:| +| 70-79 | 21-26 | warm | green | +| 80-89 | 26-32 | very warm | yellow | +| 90-104 | 32-40 | hot | orange | +| 105-129 | 40-54 | very hot | red | +| > 130 | > 54 | extreme hot | purple | ### WindChill @@ -81,15 +77,17 @@ else ==> formula assumes wind speed @ 1.5 meter Indicative table (subjective). -| wind chill °C | description | -|:-------------:|:---------------------| -| > -10 | cold | -| -10 .. -25 | very cold ! | -| -25 .. -35 | very very cold ! | -| -35 .. -55 | chance of frostbite | -| < -55 | serious dangerous | +| wind chill °C | description | +|:---------------:|:-----------------------| +| > -10 | cold | +| -10 .. -25 | very cold ! | +| -25 .. -35 | very very cold ! | +| -35 .. -55 | chance of frostbite | +| < -55 | serious dangerous | +---- + # temperatureConverter class Since version 0.3.2 a temperature convertor class is added to convert to and from @@ -101,16 +99,16 @@ See example. The scales are typically named after their inventor. Check Wikipedia for details about the scales. -| Name | units | 1° in °K | 0°C | 100°C | notes | -|:------------|:-----:|:--------:|--------:|--------:|:------| -| Celsius | °C | 1.000000 | 0.00 | 100.00 | -| Delisle | °De | 0.666666 | -100.00 | 50.00 | -| Fahrenheit | °F | 0.555556 | 32.00 | 212.00 | -| Kelvin | °K | 1.000000 | 273.15 | 373.15 | -| Newton | -- | 3.030303 | 0.00 | 33.00 | not the force. -| Rankine | °Ra | 0.555556 | 491.76 | 671.67 | 0°Ra == 0°K, steps == Fahrenheit. -| Reamur | °Re | 1.250000 | 0.00 | 80.00 | -| Romer | °Ro | 1.904762 | 7.50 | 60.00 | +| Name | units | 1° in °K | 0°C | 100°C | notes | +|:--------------|:-------:|:----------:|----------:|----------:|:--------| +| Celsius | °C | 1.000000 | 0.00 | 100.00 | +| Delisle | °De | 0.666666 | -100.00 | 50.00 | +| Fahrenheit | °F | 0.555556 | 32.00 | 212.00 | +| Kelvin | °K | 1.000000 | 273.15 | 373.15 | +| Newton | -- | 3.030303 | 0.00 | 33.00 | not the force. +| Rankine | °Ra | 0.555556 | 491.76 | 671.67 | 0°Ra == 0°K, steps == Fahrenheit. +| Reamur | °Re | 1.250000 | 0.00 | 80.00 | +| Romer | °Ro | 1.904762 | 7.50 | 60.00 | Note: units to be verified. @@ -118,6 +116,8 @@ Note: this class is slightly slower than direct conversion, but it prevents to have 8 x 7 optimized functions. +## Interface + #### Constructor - **temperatureConverter()** Constructor sets the default to zero degrees C. @@ -158,6 +158,14 @@ See examples for typical usage. # Future +#### must + +#### should - improve documentation - add short explanation? -- +- add formula for water boiling height + - https://en.wikipedia.org/wiki/High-altitude_cooking + - multiMap needed? + +#### could + diff --git a/library.json b/library.json index 54dd7c3..7ffdeab 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/Temperature" }, - "version": "0.3.4", + "version": "0.3.5", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/library.properties b/library.properties index 93d1a4a..5c6809c 100644 --- a/library.properties +++ b/library.properties @@ -1,8 +1,8 @@ name=Temperature -version=0.3.4 +version=0.3.5 author=Rob Tillaart maintainer=Rob Tillaart -sentence=Library with weather related functions. +sentence=Library with weather and temperature conversion functions. paragraph=Kelvin Celsius Fahrenheit dewPoint humidex heatIndex windChill category=Data Processing url=https://github.com/RobTillaart/Temperature diff --git a/temperature.cpp b/temperature.cpp index 90322e7..2ed37bb 100644 --- a/temperature.cpp +++ b/temperature.cpp @@ -1,10 +1,8 @@ // // FILE: temperature.cpp -// VERSION: 0.3.4 +// VERSION: 0.3.5 // DATE: 2015-03-29 // PURPOSE: collection temperature functions -// -// HISTORY: see CHANGELOG.md #include "temperature.h" @@ -12,13 +10,13 @@ float Fahrenheit(float celsius) { - return 1.8 * celsius + 32; // 5.0 / 9.0 = 1.8 + return 1.8 * celsius + 32; // 5.0 / 9.0 = 1.8 } float Celsius(float Fahrenheit) { - return (Fahrenheit - 32) * 0.55555555555; // 5.0 / 9.0 = 0.555... + return (Fahrenheit - 32) * 0.55555555555; // 5.0 / 9.0 = 0.555... } @@ -28,35 +26,35 @@ float Kelvin(float celsius) } -// reference: -// [1] https://wahiduddin.net/calc/density_algorithms.htm -// [2] https://web.archive.org/web/20100528030817/https://www.colorado.edu/geography/weather_station/Geog_site/about.htm -// dewPoint function based on code of [2] -// calculation of the saturation vapour pressure part is based upon NOAA ESGG(temp) +// reference: +// [1] https://wahiduddin.net/calc/density_algorithms.htm +// [2] https://web.archive.org/web/20100528030817/https://www.colorado.edu/geography/weather_station/Geog_site/about.htm +// dewPoint function based on code of [2] +// calculation of the saturation vapour pressure part is based upon NOAA ESGG(temp) float dewPoint(float celsius, float humidity) { - // Calculate saturation vapour pressure - // ratio 100C and actual temp in Kelvin + // Calculate saturation vapour pressure + // ratio 100C and actual temp in Kelvin float A0 = 373.15 / (273.15 + celsius); - // SVP = Saturation Vapor Pressure - based on ESGG() NOAA + // SVP = Saturation Vapor Pressure - based on ESGG() NOAA float SVP = -7.90298 * (A0 - 1.0); SVP += 5.02808 * log10(A0); SVP += -1.3816e-7 * (pow(10, (11.344 * ( 1.0 - 1.0/A0))) - 1.0 ); SVP += 8.1328e-3 * (pow(10, (-3.49149 * (A0 - 1.0 ))) - 1.0 ) ; SVP += log10(1013.246); - // calculate actual vapour pressure VP; - // note to convert to KPa the -3 is used + // calculate actual vapour pressure VP; + // note to convert to KPa the -3 is used float VP = pow(10, SVP - 3) * humidity; float T = log( VP / 0.61078); // temp var return (241.88 * T) / (17.558 - T); } -// dewPointFast() is > 5x faster than dewPoint() - run dewpoint_test.ino -// delta mdewPointFastax with dewPoint() - run dewpoint_test.ino ==> ~0.347 -// (earlier version mentions ~0.6544 but that test code is gone :( -// http://en.wikipedia.org/wiki/Dew_point +// dewPointFast() is > 5x faster than dewPoint() - run dewpoint_test.ino +// delta mdewPointFastax with dewPoint() - run dewpoint_test.ino ==> ~0.347 +// (earlier version mentions ~0.6544 but that test code is gone :( +// http://en.wikipedia.org/wiki/Dew_point float dewPointFast(float celsius, float humidity) { float a = 17.271; @@ -67,7 +65,7 @@ float dewPointFast(float celsius, float humidity) } -// https://en.wikipedia.org/wiki/Humidex +// https://en.wikipedia.org/wiki/Humidex float humidex(float celsius, float dewPoint) { float e = 19.833625 - 5417.753 /(273.16 + dewPoint); @@ -76,14 +74,16 @@ float humidex(float celsius, float dewPoint) } -// 0.3.0 => https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml -// previous https://en.wikipedia.org/wiki/Heat_index -// TF = temp in Fahrenheit -// RH = relative humidity in % +// 0.3.0 => https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml +// previous https://en.wikipedia.org/wiki/Heat_index +// TF = temp in Fahrenheit +// RH = relative humidity in % float heatIndex(float TF, float RH) { - // Steadman's formula ==> can be optimized :: HI = TF * 1.1 - 10.3 + RH * 0.047 - float HI = 0.5 * (TF + 61.0 + ((TF - 68.0) * 1.2) + (RH * 0.094)); + // Steadman's formula + // float HI = 0.5 * (TF + 61.0 + ((TF - 68.0) * 1.2) + (RH * 0.094)); + // optimized to: + float HI = TF * 1.1 - 10.3 + RH * 0.047; // Rothfusz regression @@ -118,10 +118,10 @@ float heatIndex(float TF, float RH) } -// 0.3.0 => https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml -// previous https://en.wikipedia.org/wiki/Heat_index -// TC = temp in Celsius -// RH = relative humidity in % +// 0.3.0 => https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml +// previous https://en.wikipedia.org/wiki/Heat_index +// TC = temp in Celsius +// RH = relative humidity in % float heatIndexC(float TC, float RH) { if ( (TC < 27) || (RH < 40)) return TC; @@ -148,15 +148,15 @@ float heatIndexC(float TC, float RH) } -// https://en.wikipedia.org/wiki/Wind_chill -// US = Fahrenheit / miles / hour -// METRIC = Celsius / meter / hour (sec) -// wind speed @ 10 meter, -// if convert is true => wind speed will be converted to 1.5 meter -// else ==> formula assumes wind speed @ 1.5 meter +// https://en.wikipedia.org/wiki/Wind_chill +// US = Fahrenheit / miles / hour +// METRIC = Celsius / meter / hour (sec) +// wind speed @ 10 meter, +// if convert is true => wind speed will be converted to 1.5 meter +// else ==> formula assumes wind speed @ 1.5 meter -// US +// US float WindChill_F_mph(const float Fahrenheit, const float milesPerHour, const bool convert) { if ((milesPerHour < 3.0) || (Fahrenheit > 50)) return Fahrenheit; @@ -166,7 +166,7 @@ float WindChill_F_mph(const float Fahrenheit, const float milesPerHour, const bo } -// METRIC - standard wind chill formula for Environment Canada +// METRIC - standard wind chill formula for Environment Canada float WindChill_C_kmph(const float Celsius, const float kilometerPerHour, const bool convert) { if ((kilometerPerHour < 4.8) || (Celsius > 10)) return Celsius; @@ -182,12 +182,12 @@ float WindChill_C_mps(const float Celsius, const float meterPerSecond, const boo } -// https://www.engineeringtoolbox.com/air-altitude-pressure-d_462.html -// Does not have the temperature correction ==> it has almost the -5.257 exponent -// https://www.omnicalculator.com/physics/air-pressure-at-altitude -// similar to https://en.wikipedia.org/wiki/Barometric_formula +// https://www.engineeringtoolbox.com/air-altitude-pressure-d_462.html +// Does not have the temperature correction ==> it has almost the -5.257 exponent +// https://www.omnicalculator.com/physics/air-pressure-at-altitude +// similar to https://en.wikipedia.org/wiki/Barometric_formula // -// Note: altitude in meters. +// Note: altitude in meters. float baroToSeaLevelC( float pressure, float celsius, float altitude) { float altitudeFactor = 0.0065 * altitude; @@ -196,12 +196,12 @@ float baroToSeaLevelC( float pressure, float celsius, float altitude) } -// https://www.omnicalculator.com/physics/air-pressure-at-altitude -// temperature (Celsius) at altitude (meter) +// https://www.omnicalculator.com/physics/air-pressure-at-altitude +// temperature (Celsius) at altitude (meter) float seaLevelToAltitude( float pressureSeaLevel, float celsius, float altitude) { float kelvin = celsius + 273.15; - // P = P0 * exp( -g.M.h / (R.T)); + // P = P0 * exp( -g.M.h / (R.T)); float factor = -9.80655 * 0.0289644 / 8.31432; factor /= kelvin; return pressureSeaLevel * exp(factor * abs(altitude)); @@ -210,12 +210,12 @@ float seaLevelToAltitude( float pressureSeaLevel, float celsius, float altitude) float altitudeToSeaLevel( float pressure, float celsius, float altitude) { float kelvin = celsius + 273.15; - // P = P0 * exp( -g.M.h / (R.T)); + // P = P0 * exp( -g.M.h / (R.T)); float factor = 9.80655 * 0.0289644 / 8.31432; factor /= kelvin; return pressure / exp(factor * abs(altitude)); } -// -- END OF FILE -- +// -- END OF FILE -- diff --git a/temperature.h b/temperature.h index 94c6801..a7e284a 100644 --- a/temperature.h +++ b/temperature.h @@ -1,7 +1,7 @@ #pragma once // // FILE: temperature.h -// VERSION: 0.3.4 +// VERSION: 0.3.5 // DATE: 2015-03-29 // PURPOSE: collection temperature functions @@ -19,19 +19,19 @@ float Celsius(float Fahrenheit); float Kelvin(float celsius); -// reference: -// [1] https://wahiduddin.net/calc/density_algorithms.htm -// [2] https://web.archive.org/web/20100528030817/https://www.colorado.edu/geography/weather_station/Geog_site/about.htm -// dewPoint function based on code of [2] -// calculation of the saturation vapour pressure part is based upon NOAA ESGG(temp) +// reference: +// [1] https://wahiduddin.net/calc/density_algorithms.htm +// [2] https://web.archive.org/web/20100528030817/https://www.colorado.edu/geography/weather_station/Geog_site/about.htm +// dewPoint function based on code of [2] +// calculation of the saturation vapour pressure part is based upon NOAA ESGG(temp) float dewPoint(float celsius, float humidity); -// dewPointFast() is > 5x faster than dewPoint() - run dewpoint_test.ino -// delta mdewPointFastax with dewPoint() - run dewpoint_test.ino ==> ~0.347 -// (earlier version mentions ~0.6544 but that test code is gone :( -// http://en.wikipedia.org/wiki/Dew_point +// dewPointFast() is > 5x faster than dewPoint() - run dewpoint_test.ino +// delta mdewPointFastax with dewPoint() - run dewpoint_test.ino ==> ~0.347 +// (earlier version mentions ~0.6544 but that test code is gone :( +// http://en.wikipedia.org/wiki/Dew_point float dewPointFast(float celsius, float humidity); @@ -41,49 +41,49 @@ float humidex(float celsius, float dewPoint); -// 0.3.0 => https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml -// previous https://en.wikipedia.org/wiki/Heat_index -// TF = temp in Fahrenheit -// RH = relative humidity in % +// 0.3.0 => https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml +// previous https://en.wikipedia.org/wiki/Heat_index +// TF = temp in Fahrenheit +// RH = relative humidity in % float heatIndex(float TF, float RH); -// 0.3.0 => https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml -// previous https://en.wikipedia.org/wiki/Heat_index -// TC = temp in Celsius -// RH = relative humidity in % +// 0.3.0 => https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml +// previous https://en.wikipedia.org/wiki/Heat_index +// TC = temp in Celsius +// RH = relative humidity in % float heatIndexC(float TC, float RH); -// https://en.wikipedia.org/wiki/Wind_chill -// US = Fahrenheit / miles / hour -// METRIC = Celsius / meter / hour (sec) -// wind speed @ 10 meter, -// if convert is true => wind speed will be converted to 1.5 meter -// else ==> formula assumes wind speed @ 1.5 meter +// https://en.wikipedia.org/wiki/Wind_chill +// US = Fahrenheit / miles / hour +// METRIC = Celsius / meter / hour (sec) +// wind speed @ 10 meter, +// if convert is true => wind speed will be converted to 1.5 meter +// else ==> formula assumes wind speed @ 1.5 meter -// US +// US float WindChill_F_mph(const float Fahrenheit, const float milesPerHour, const bool convert = true); -// METRIC - standard wind chill formula for Environment Canada +// METRIC - standard wind chill formula for Environment Canada float WindChill_C_kmph(const float Celsius, const float kilometerPerHour, const bool convert = true); float WindChill_C_mps(const float Celsius, const float meterPerSecond, const bool convert = true); -// https://www.engineeringtoolbox.com/air-altitude-pressure-d_462.html -// Does not have the temperature correction ==> it has almost the -5.257 exponent -// https://www.omnicalculator.com/physics/air-pressure-at-altitude -// similar to https://en.wikipedia.org/wiki/Barometric_formula +// https://www.engineeringtoolbox.com/air-altitude-pressure-d_462.html +// Does not have the temperature correction ==> it has almost the -5.257 exponent +// https://www.omnicalculator.com/physics/air-pressure-at-altitude +// similar to https://en.wikipedia.org/wiki/Barometric_formula // -// Note: altitude in meters. +// Note: altitude in meters. float baroToSeaLevelC( float pressure, float celsius, float altitude); -// https://www.omnicalculator.com/physics/air-pressure-at-altitude -// temperature (Celsius) at altitude (meter) +// https://www.omnicalculator.com/physics/air-pressure-at-altitude +// temperature (Celsius) at altitude (meter) float seaLevelToAltitude( float pressureSeaLevel, float celsius, float altitude); float altitudeToSeaLevel( float pressure, float celsius, float altitude); @@ -123,5 +123,5 @@ class temperatureConverter }; -// -- END OF FILE -- +// -- END OF FILE --