Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Internal Temperature Sensor
- // Example sketch for ATmega328 types.
- //
- // https://playground.arduino.cc/Main/InternalTemperatureSensor/
- //
- // April 2012, Arduino 1.0
- #include <U8g2lib.h>
- U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);
- void setup()
- {
- Serial.begin(9600);
- Serial.println(F("Internal Temperature Sensor"));
- u8g2.begin();
- u8g2.clearBuffer();
- u8g2.setDrawColor(1);
- u8g2.setFontPosTop();
- u8g2.setFontDirection(2);
- u8g2.setFont(u8g2_font_timB12_tr);
- u8g2.drawStr(127,32, "NAGYLOFASZ");
- u8g2.sendBuffer();
- delay(2000);
- }
- void loop()
- {
- // Show the temperature in degrees Celsius.
- Serial.println(GetTemp(),1);
- u8g2.clearBuffer();
- u8g2.setDrawColor(1);
- u8g2.setFontPosTop();
- u8g2.setFontDirection(2);
- u8g2.setFont(u8g2_font_timB12_tr);
- u8g2.setCursor (127,32);
- u8g2.print(GetTemp(),1);
- u8g2.sendBuffer();
- 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;
- // The offset of 324.31 could be wrong. It is just an indication.
- t = (wADC - 324.31 ) / 1.22;
- // The returned temperature is in degrees Celsius.
- return (t);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement