New Internal Temperature Library

Hi everyone!
I tested this library, and noticed shortcomings:
Together with temperature measurements of a kernel I make the analysis of ATsP on other channels. Almost always it uses resolution of 12 bits (default) and voltage reference of Aref - too default. Your code leads to the fact that the ATsP settings and to the incorrect indication of other analog signals get off.
Why you use resolution of 16 bits and internal voltage reference?
Perhaps it is necessary to save the previous settings at measurement and after temperature measurement to recover them or to use current settings which were set for measurement of other channels? It will result in correctness of reading of other measurements.
Perhaps, this function needs to be added to a kernel of Arduino in the future?

Forgive for my English.
 
Last edited:
Thank you for your comments. When I wrote this, I was not thinking about also using the ADC for other measurements. This was the first time I had used the ADC for anything.

Why you use resolution of 16 bits and internal voltage reference?

I think it can use any settings, I chose these from other examples I saw.

Perhaps it is necessary to save the previous settings at measurement and after temperature measurement to recover them or to use current settings which were set for measurement of other channels?

I will change it to either use the current settings, or save and restore the settings.

Thanks for helping me make this library better. :)
 
Hello! I think you need to use the current settings, as a rule - for measurements, the settings are made at the beginning and do not change later.
If the library is fixed, maybe I can use it in my new project. I will need to do continuous multichannel measurements from 8 to 10 + temperature.
 
I just released a new version of the temperature library (https://github.com/LAtimes2/InternalTemperature).

It uses the current ADC settings when reading the temperature, so it won't interfere with other ADC readings.

By default it still sets the ADC settings for maximum accuracy. But if you don't want it to change any ADC settings, add a pass parameter to begin:

Code:
temperature.begin(TEMPERATURE_NO_ADC_SETTING_CHANGES);

This should make it useful in more applications.
 
You don't need a library.
Code:
void setup() {}
void loop() { Serial.println(tempmonGetTemp()); }
 
If you are already using the ADC library you can get the voltage of the temperature sensor with
Code:
int temp_volt = adc->analogRead(ADC_INTERNAL_SOURCE::TEMP_SENSOR);
You can convert it to the temperature in ºC with
Code:
int temp = 25 - (temp_volt - volts_25C)/slope;
Where the volts_25C and slope depend on the board: 0.719 V at 25ºC and slope of 1.715 mV/ºC for Teensy 3.x and 0.716 V, 1.62 mV/ºC for Teensy LC, 3.5 and 3.6.

This works for Teensy 3.x and LC, for Teensy 4 you can use tempmonGetTemp() like Frank B pointed out.
 
I have added support for Teensy 4, so you can have common routines for both T3 and T4. Also added overtemp and undertemp alarms that you can attach ISR functions that are called when the temperature exceeds the limit. There is an example for T4 that performs CPU throttling when the temperature exceeds a value.

Library is at https://github.com/LAtimes2/InternalTemperature.

Documentation is here.
 
The library is now available via the Arduino library manager:

Tools -> Manage Libraries ...
Search for InternalTemperature
Install
 
Back
Top