0

Temperature Sensor on CPB
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Temperature Sensor on CPB

by Physicsteacher on Thu Feb 04, 2021 12:08 am

Hello,

I have tried to read the temperature sensor of the CPB without using a library. I thought the folllowing code should work:

int sensorwert;
...
sensorwert=analogRead{A9};

However, the compiler (Arduino IDE 1.8.13) aborts at the analogRead line with the following error message:

invalid conversion from 'uint32_t (*)(uint32_t)' {aka 'long unsigned int (*)(long unsigned int)'} to 'int' [-fpermissive]

I have tried to change the variable to long or float, but it didn't make any difference. The output of analogRead should be between 0 and 1023, so I do not understand why there is a problem with the int variable.

Any help or advice appreciated.

Physicsteacher
 
Posts: 9
Joined: Mon Nov 09, 2020 5:24 pm

Re: Temperature Sensor on CPB

by adafruit_support_bill on Thu Feb 04, 2021 8:41 am

Are you able to compile the standard "AnalogInput" example sketch from the IDE?

Please post your complete code.

adafruit_support_bill
 
Posts: 81321
Joined: Sat Feb 07, 2009 10:11 am

Re: Temperature Sensor on CPB

by Physicsteacher on Thu Feb 04, 2021 9:06 am

Hello adafruit_support_bill,

thank you for your quick reply. Yes, AnalogInput is compiled correctly and can be uploaded (doesn't do anything because no potentiometer attached to A0).

Here is the complete code (comments in German for my students but the code should be self-explaining):

Code: Select all | TOGGLE FULL SIZE
int sensorwert; // Diese Variable wird die ausgelesene Spannung aufnehmen.
float R;  // Für den Widerstand des Thermistors
float Temperatur=0;
float R0=10000; // R0 = 10 kOhm
float T0=25;  // T0 = 25°C
float Bfactor=3950;  // B-Faktor laut Datenblatt
int t=500;  // Abstand zwischen den Messungen

void setup()
{

Serial.begin(9600);  // Die serielle Kommunikation muss festgelegt werden, damit wir mit dem seriellen Monitor der Arduino-IDE die Temperaturwerte verfolgen können.
pinMode (A9, INPUT); // I have tried both with and without the pinMode command

}

void loop()
{

sensorwert=analogRead{A9};  // Spannung am Thermistor auslesen
Serial.print(sensorwert);  // U (0 - 1023) ausgeben
Serial.print(" entspricht ");

// Umrechnung von U über R in T

R=R0/(1023/sensorwert-1);
Temperatur=1/(log(R/R0)/Bfactor+1/(t0+273,15))-273,15  // T0 in K

Serial.print(Temperatur);
Serial.println(" °C")  // Serial.println ergibt die nächste Zeile

delay(t);
}


Thanks for your help
Last edited by adafruit_support_bill on Thu Feb 04, 2021 9:21 am, edited 1 time in total.
Reason: Pleas use [code] tags when posting code to the forums

Physicsteacher
 
Posts: 9
Joined: Mon Nov 09, 2020 5:24 pm

Re: Temperature Sensor on CPB

by adafruit_support_bill on Thu Feb 04, 2021 9:28 am

A subtle, but fatal syntax error. You used curly braces rather than parentheses. That caused the compiler to think you were assigning the address of the analogRead function to an integer variable.

This:

Code: Select all | TOGGLE FULL SIZE
sensorwert=analogRead{A9};

should be:
Code: Select all | TOGGLE FULL SIZE
sensorwert=analogRead(A9);


There are further errors below regarding undeclared variables. But those should be straightforward to fix.

adafruit_support_bill
 
Posts: 81321
Joined: Sat Feb 07, 2009 10:11 am

Re: Temperature Sensor on CPB

by Physicsteacher on Thu Feb 04, 2021 10:12 am

Thank you very much, I just couldn't see the difference between the difference between the parantheses. I have a new laptop and I'm still fighting with the keyboard layout.

Yours sincerely

Physicsteacher
 
Posts: 9
Joined: Mon Nov 09, 2020 5:24 pm

Re: Temperature Sensor on CPB

by Physicsteacher on Thu Feb 04, 2021 12:36 pm

Hi adafruit_support_bill,

thanks to your advice, I have fixed the typos and variables and the programme is running. One more question in order to understand what I_m doing:

The readout at A9 INcreases with increasing temperature. Since it is (according to the documentation) a NTC thermistor, the resistance and therefore the voltage should DEcrease with increasing temperature. The only explanation I can think of is that the readout at A9 is the voltage across the pull-down resistor, which should INcrease if the resistance of the NTC DEcreases.

Can you confirm this or am I completely wrong?

Physicsteacher
 
Posts: 9
Joined: Mon Nov 09, 2020 5:24 pm

Re: Temperature Sensor on CPB

by adafruit_support_bill on Thu Feb 04, 2021 12:43 pm

The temperature sensing circuit is as shown below. The thermistor forms the variable upper part of a voltage divider circuit. As the temperature increases, the voltage drop across the NTC thermistor decreases, and the drop across the fixed resistor increases.

Full schematics can be found on the Downloads page of the documentation: https://learn.adafruit.com/adafruit-cir ... /downloads
Attachments
temp sense.gif
temp sense.gif (7.9 KiB) Viewed 2226 times

adafruit_support_bill
 
Posts: 81321
Joined: Sat Feb 07, 2009 10:11 am

Re: Temperature Sensor on CPB

by Physicsteacher on Thu Feb 04, 2021 12:51 pm

Thank you for the link to the schematic diagram in the documentation. Therefore, if the output at A9 is the voltage between GND and TEMP SENSE (not between VCC and TEMP SENSE), it is indeed the voltage across the pull-down resistor, which agrees with my measurement.

Thank you very much for your rapid help

Physicsteacher
 
Posts: 9
Joined: Mon Nov 09, 2020 5:24 pm

Re: Temperature Sensor on CPB

by kevinjwalters on Thu Mar 04, 2021 11:23 am

I've been doing a bit of investigation work with temperature sensors including NTC thermistors (but not the CPB one). I was interested in the difference between the onboard sensors that are heavily affected by heating effects of surrounding components and the extra heat generated by the backlight on the CLUE's TFT LCD display. The CircuitPython code is in https://github.com/kevinjwalters/circui ... templogger

I can dig out the (slightly messy) R code too if you're interested in the empirical coefficient determination for NTCs.

kevinjwalters
 
Posts: 960
Joined: Sun Oct 01, 2017 3:15 pm

Please be positive and constructive with your questions and comments.