Loading...
Searching...
No Matches
Temperature.ino

Reads the on-board LMT84 temperature sensor once a second and prints the ADC reading, the signal voltage and the temperature in °C, °F and K, using AnalogShield::TempRaw(), AnalogShield::TempMillivolts(), AnalogShield::TempCelsius(), AnalogShield::TempFahrenheit() and AnalogShield::TempKelvin().

Jumpers
JP1 at Internal (on-board U1), JP2 at Internal (RP2040 ADC), JP3 at 3.3 V.
Output
Serial Monitor at 115200 baud, for example:
Raw: 1675 1350 mV 22.4 °C 72.3 °F 295.6 K
Notes
  • Change SOURCE to TempSource::SENSOR to read the sensor before the conditioning stage, or to TempSource::EXT to read the conditioned signal on A3 (move JP2 to External, the MAX11635 ADC).
  • Each reading averages SAMPLES ADC reads at 12-bit resolution (10 bits on an Uno R3), which steadies the value. Every column is its own reading, so they can differ slightly.
/*
* Temperature
* Reads the on-board LMT84 temperature sensor once a second and prints the
* ADC reading, the signal voltage and the temperature in °C, °F and K.
*
* Jumpers: JP1 at Internal (on-board U1), JP2 at Internal (RP2040 ADC), JP3 at 3.3 V.
* Output: Serial Monitor at 115200 baud, for example
* Raw: 1675 1350 mV 22.4 °C 72.3 °F 295.6 K
*
* Change SOURCE to TempSource::SENSOR to read the sensor before the
* conditioning stage, or to TempSource::EXT to read the conditioned signal on
* A3 (move JP2 to External, the MAX11635 ADC).
*
* Each reading averages SAMPLES ADC reads at 12-bit resolution, which steadies
* the value. Every column is its own reading, so they can differ slightly.
*/
#include <AnalogShield.h>
AnalogShield Shield;
constexpr TempSource SOURCE = TempSource::MCU;
constexpr uint8_t SAMPLES = 16;
void setup() {
Serial.begin(115200);
Shield.begin();
Shield.SetAdcResolution(12); // stays at 10 bits on an Uno R3
}
void loop() {
Serial.print("Raw: ");
Serial.print(Shield.TempRaw(SOURCE, SAMPLES));
Serial.print(" ");
Serial.print(Shield.TempMillivolts(SOURCE, SAMPLES));
Serial.print(" mV ");
Serial.print(Shield.TempCelsius(SOURCE, SAMPLES), 1);
Serial.print(" °C ");
Serial.print(Shield.TempFahrenheit(SOURCE, SAMPLES), 1);
Serial.print(" °F ");
Serial.print(Shield.TempKelvin(SOURCE, SAMPLES), 1);
Serial.println(" K");
delay(1000);
}
Library for the U of T Physics Analog Shield (Introduction to Electronics).
TempSource
Temperature signal to read with AnalogShield::TempRaw() or AnalogShield::TempMillivolts().
Definition AnalogShield.h:52
@ MCU
Conditioned signal on TEMP_SIG_MCU (A0, RP2040 ADC), JP2 at Internal.
Definition AnalogShield.h:54
Encoder, switch, temperature signals, potentiometer and LEDs on the Analog Shield.
Definition AnalogShield.h:64
int32_t TempMillivolts(TempSource source, uint8_t samples=1) const
Reads the voltage of a temperature signal.
Definition AnalogShield.cpp:216
float TempKelvin(TempSource source, uint8_t samples=1) const
Reads a temperature signal and converts it to kelvins.
Definition AnalogShield.cpp:248
float TempFahrenheit(TempSource source, uint8_t samples=1) const
Reads a temperature signal and converts it to degrees Fahrenheit.
Definition AnalogShield.cpp:244
float TempCelsius(TempSource source, uint8_t samples=1) const
Reads a temperature signal and converts it to degrees Celsius.
Definition AnalogShield.cpp:240
int TempRaw(TempSource source, uint8_t samples=1) const
Reads a temperature signal with the ADC.
Definition AnalogShield.cpp:212
bool SetAdcResolution(uint8_t bits)
Sets the ADC resolution used by analogRead() and by every reading below.
Definition AnalogShield.cpp:171
void begin()
Sets pin modes, turns both LEDs off and starts tracking the encoder and its switch.
Definition AnalogShield.cpp:56