Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "U8glib.h"
- #include <SPI.h>
- #include <Wire.h>
- #include "max6675.h"
- // -------------------------------------------
- // Thermometer using Thermocouple Type-K with Arduino Uno
- // www.ardukode.blogspot.com
- // -------------------------------------------
- boolean centigrade = true; //Uncomment for Centigrade and Comment the line below
- // boolean centigrade = false; // Uncomment for Fahrenheit and Comment the line above
- // setup u8g object
- U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); // I2C
- double max = 215; // Maximum temperature
- double min = -215; // Minimum temperature
- float currentTemp = 0.00;
- String thisTemp = "";
- int maxTemp = 0; // Maximum temperature reached
- int minTemp = 0; // Minimum temperature reached
- int pad = 0;
- // Thermocouple MAX 6675 Module
- int thermoSO = 11;
- int thermoCS = 12;
- int thermoSCK = 13;
- MAX6675 thermocouple(thermoSCK, thermoCS, thermoSO);
- int vccPin = 20; // Vcc pin for MAX6675 module = D3
- int gndPin = 22; // Gnd pin for MAX6675 = D2
- void draw(void) {
- u8g.setFont(u8g_font_profont12);
- u8g.drawStr(31, 10, "Temperature");
- u8g.setFont(u8g_font_profont12);
- // Show maximum temperature reached
- u8g.drawStr(10, 25, "max");
- if (maxTemp <= int(currentTemp)) {
- maxTemp = int(currentTemp);
- }
- thisTemp = String(maxTemp);
- if (centigrade) {
- thisTemp = thisTemp + "\260C";
- }
- else {
- thisTemp = thisTemp + "\260F";
- }
- const char* maxTempC = (const char*) thisTemp.c_str();
- u8g.drawStr(30, 25, maxTempC);
- // Show the minimum temperature reached
- u8g.drawStr(80, 25, "min");
- if (minTemp >= int(currentTemp)) {
- minTemp = int(currentTemp);
- }
- thisTemp = String(minTemp);
- if (centigrade) {
- thisTemp = thisTemp + "\260C";
- }
- else {
- thisTemp = thisTemp + "\260F";
- }
- const char* minTempC = (const char*) thisTemp.c_str();
- u8g.drawStr(100, 25, minTempC);
- u8g.setFont(u8g_font_profont29);
- if (currentTemp > 99) {
- pad = 2;
- }
- if (currentTemp > 9 && currentTemp < 100) {
- pad = 10;
- }
- if (currentTemp < 10) {
- pad = 18;
- }
- thisTemp = String(currentTemp);
- if (centigrade) {
- thisTemp = thisTemp + "\260C";
- }
- else {
- }
- const char* newDispC = (const char*) thisTemp.c_str();
- u8g.drawStr(pad, 50, newDispC);
- }
- void setup(void) {
- pinMode(vccPin, OUTPUT); digitalWrite(vccPin, HIGH); // D3 @5V/Vcc
- pinMode(gndPin, OUTPUT); digitalWrite(gndPin, LOW); // D2@0V/GND
- Serial.begin(9600); // Serial Begin
- Wire.begin();
- delay(500); // Stabilization Time
- if (centigrade) {
- currentTemp = thermocouple.readCelsius();
- minTemp = int(thermocouple.readCelsius());
- maxTemp = int(thermocouple.readCelsius());
- }
- else {
- currentTemp = thermocouple.readFahrenheit();
- minTemp = int(thermocouple.readFahrenheit());
- maxTemp = int(thermocouple.readFahrenheit());
- }
- }
- void loop(void) {
- currentTemp = 0;
- for (int f = 0; f < 25; f++) {
- if (centigrade) {
- currentTemp = thermocouple.readCelsius() + currentTemp;
- }
- else {
- currentTemp = thermocouple.readFahrenheit() + currentTemp;
- }
- }
- currentTemp = currentTemp / 25; //Average 25 readings
- // Draw
- u8g.firstPage();
- do {
- draw();
- } while ( u8g.nextPage() );
- delay(50); // Refresh Time
- }
- // avrdude -DV -patmega328p -Pnet:192.168.4.1:23 -carduino -b115200 -U flash:w:firmware.hex:i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement