Tri-Temp Standard Code v1.0

This is the first version of the Tri-Temp code. If you find any errors or add any features let me know so I can update it.

[php]

// v1.0 Tri-Temp Standard
// Copyright 2012 Jeff Williams @ http://www.arduinoeverything.com
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/&gt;.
#include “SoftwareSerial.h”
#include “DHT.h”
#define rxPin 4 // rxPin is immaterial – not used – just make this an unused Arduino pin number
#define txPin 0 // set display to digital pin 0
SoftwareSerial myDisplay = SoftwareSerial(rxPin, txPin);
int intTempPin = 0; //set internal temp analog pin
#define DHTPIN1 2
#define DHTPIN2 3
#define DHTPIN3 5
#define DHTTYPE DHT22
int pinButton1 = 1; //button pin assignments
int pinButton2 = 6;
int pinButton3 = 4;
int pinButton4 = 7;
int valButton1 = 0;
int valButton2 = 0;
int valButton3 = 0;
int valButton4 = 0;
int old_valButton3 = 0;
int old_valButton4 = 0;
int stateButton3 = 0;
int stateButton4 = 0;
int displayInfo = 1;

DHT dht1(DHTPIN1, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE);
DHT dht3(DHTPIN3, DHTTYPE);
void setup(){
pinMode(txPin, OUTPUT);

myDisplay.begin(9600); // 9600 baud is chip comm speed
myDisplay.print(“?f”); // clear the LCD

myDisplay.print(“?G216”); // set display geometry, 2 x 16 characters in this case
delay(500); // pause to allow LCD EEPROM to program

myDisplay.print(“?Bff”); // set backlight to ff hex, maximum brightness
delay(500); // pause to allow LCD EEPROM to program

myDisplay.print(“?f”); // clear the LCD
delay(10);

myDisplay.print(“?c0”); // turn cursor off
myDisplay.print(“..Starting Up..”);
delay(500);
dht1.begin(); //initialize the dht sensors
dht2.begin();
dht3.begin();
pinMode(pinButton1, INPUT); //setup the button pins
pinMode(pinButton2, INPUT);
pinMode(pinButton3, INPUT);
pinMode(pinButton4, INPUT);
myDisplay.print(“?f”);
}

void loop(){
delay(60);
checkButton1();
checkButton2();
//checkButton3();
checkButton4();
delay(60);

switch (displayInfo){
case 1:
//display DHT1
displayDHT1();
//myDisplay.print(displayInfo);
break;

case 2:
//display DHT2
displayDHT2();
//myDisplay.print(displayInfo);
break;

case 3:
//display DHT3
displayDHT3();
//myDisplay.print(displayInfo);
break;

case 4:
//display internal temp
displayInternalTemp();
//myDisplay.print(displayInfo);
break;

default:
myDisplay.print(“?f”);
break;

}

}

void displayDHT1(){

myDisplay.print(“?x00?y0”); // cursor to first character of line 0
float h1 = dht1.readHumidity();
float t1 = dht1.readTemperature();

// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t1) || isnan(h1)) {
myDisplay.print(“No read on DHT1”);
} else {
myDisplay.print(“#1 H:”);
myDisplay.print(h1);
myDisplay.print(“%”);
myDisplay.print(“?x00?y1”);
myDisplay.print(“Temp:”);
t1 = (t1 * 9.0 / 5.0) + 32.0;
myDisplay.print(t1);
myDisplay.print(“F”);
// myDisplay.println(” *C”);
}
}

void displayDHT2(){

myDisplay.print(“?x00?y0”); // cursor to first character of line 0
float h2 = dht2.readHumidity();
float t2 = dht2.readTemperature();

// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t2) || isnan(h2)) {
myDisplay.print(“No read on DHT2”);
} else {
myDisplay.print(“#2 H:”);
myDisplay.print(h2);
myDisplay.print(“%”);
myDisplay.print(“?x00?y1”);
myDisplay.print(“Temp:”);
t2 = (t2 * 9.0 / 5.0) + 32.0;
myDisplay.print(t2);
myDisplay.print(“F”);
// myDisplay.println(” *C”);
}
}

void displayDHT3(){

myDisplay.print(“?x00?y0”); // cursor to first character of line 0
float h3 = dht3.readHumidity();
float t3 = dht3.readTemperature();

// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t3) || isnan(h3)) {
myDisplay.print(“No read on DHT3”);
} else {
myDisplay.print(“#3 H:”);
myDisplay.print(h3);
myDisplay.print(“%”);
myDisplay.print(“?x00?y1”);
myDisplay.print(“Temp:”);
t3 = (t3 * 9.0 / 5.0) + 32.0;
myDisplay.print(t3);
myDisplay.print(“F”);
// myDisplay.println(” *C”);
}
}
void displayInternalTemp(){

int intTempReading = analogRead(intTempPin); //get temp from the internal sensor
// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = intTempReading * 5.0;
voltage /= 1024.0;
float intTemperatureC = (voltage – 0.5) * 100 ;
float intTemperatureF = (intTemperatureC * 9.0 / 5.0) + 32.0;

myDisplay.print(“?x00?y0”);
myDisplay.print(“#4 Int Temp:”);
myDisplay.print(“?x00?y1”);
myDisplay.print(intTemperatureF);
}
void checkButton1(){

valButton1 = digitalRead(pinButton1);

if (valButton1 == HIGH ) {
//do something here
displayInfo += 1;
myDisplay.print(“?f”);
if (displayInfo > 4)
{
displayInfo = 4;
}
} else {
//do something else

}
}

void checkButton2(){

valButton2 = digitalRead(pinButton2);

if (valButton2 == HIGH ) {
//do something here
myDisplay.print(“?f”);
displayInfo -= 1;
if (displayInfo < 1)
{
displayInfo = 1;
}
} else {
//do something else
}
}
void checkButton4(){
//turn the back light on/off
valButton4 = digitalRead(pinButton4);

if ((valButton4 == HIGH ) && (old_valButton4 == LOW)){
stateButton4 = 1 – stateButton4;
delay(50);
}
old_valButton4 = valButton4;

if (stateButton4 == 1) {
//do something here
myDisplay.print(“?Bff”); // set backlight to ff hex, maximum brightness
delay(50); // pause to allow LCD EEPROM to program

} else {
//do something else
myDisplay.print(“?B00”); // set backlight to ff hex, maximum brightness
delay(50); // pause to allow LCD EEPROM to program
}
}

[/php]

Author: Helicopter Jeff

I'm a vinyl decal cutting and designing, Astrophotography and general photography capturing, RC helicopter/quad copter pilot, Arduino and Raspberry Pi hardware/software developer, network, scripting and troubleshooting ninja living in the metro NY area. I am passionate about my hobbies so much I do them for a living. There's nothing better than getting paid to do what you love.

1 thought on “Tri-Temp Standard Code v1.0”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s