Ja, som det kan ses af nedenstående, så skriver jeg nogle gange på Engelsk.
Teksten til højre for // er en kort beskrivelse af hvad hver linje gør.
/* * Read out of Atmel ATmega328P's Internal temperature in temp scale centigrade */ void setup() // Run once, when the sketch starts { Serial.begin(9600); Serial.write(0xFE); // Special Command Extended Serial.write(0x01); // Clear Display delay(10); // Delay for clearing the Display Serial.write(0x7C); // Special Command Serial.write(150); // Backlight brightness level (128 = Off, 140 = 40%, 150 = 73%, 157 = Fully On) delay(10); // Delay for changing Backlight brightness Serial.write(0xFE); // Special Command Serial.write(0x80+0x02); // Move to Row 1 Column 3 Serial.write("Atmel ATMega328P"); // Pretext Serial.write(0xFE); // Special Command Serial.write(0x80+0x40); // Move to Row 2 Column 1 Serial.write("Internal Temperature"); // Pretext Serial.write(0xFE); // Special Command Serial.write(0x80+0x18); // Move to Row 3 Column 5 Serial.write("Sensor"); // Pretext Serial.write(0xFE); // Special Command Serial.write(0x80+0x22); // Move to Row 3 Column 15 Serial.write(0xDF); // Symbol ° Serial.print("C"); // Temp Scale Centigrade } void loop() // Run over and over again { Serial.write(0xFE); // Special Command Serial.write(0x80+0x1F); // Move to Row 3 Column 12 Serial.print(GetTemp(),0); // Show the temperature in degrees Celcius. delay(1000); } double GetTemp(void) { unsigned int wADC; double t; // The internal temperature has to be used // with the internal reference of 1.1V. // Channel 8 can not be selected with // the analogRead function yet. // Set the internal reference and mux. ADMUX = (_BV(REFS1) | _BV(REFS0) | _BV(MUX3)); ADCSRA |= _BV(ADEN); // enable the ADC delay(20); // wait for voltages to become stable. ADCSRA |= _BV(ADSC); // Start the ADC // Detect end-of-conversion while (bit_is_set(ADCSRA,ADSC)); // Reading register "ADCW" takes care of how to read ADCL and ADCH. wADC = ADCW; // Minus 289 are a result of 1,1 Vref, 1024 bit and the temperature conversion scale t = (wADC-289); // The returned temperature is in degrees Celcius. return (t); }
Ja, jeg har ændret lidt i den originale sketch som jeg fandt da den ikke lavede korrekt udlæsning af temperaturen, forskel på cirka 40 grader!
Man kan læse mere om den Internal Temperature Sensor i denne http://www.atmel.com/Images/doc8271.pdf under punktet 24.8 Temperature Measurement på side 263.
HUSK at der kan være op til +/- 10°C nøjagtighed!