Hi
Please help, I'm using a
Mega 2560
DHT11 temperature and humidity sensor
Analog pH meter
ITDB02 Shield
So, I've managed to connect everything together and it seems to be working, but I'm not able to get the screen to display the pH, temperature or humidity. I've copied all the codes together, but now I'm stuck!!!
/*
# this code is for fredpot hydroponic controller
# Editor : FredPot
# Date : 2014.1.20
# Ver : 0.1
# Product: Mega 2560, 3.2ITDB02, DHT11 and pH meter SEN0161
/*-----( Import needed libraries )-----*/
#include <dht11.h>
#include <UTFT.h>
#include <UTouch.h>
#include <UTFT_Buttons.h>
/*-----( Declare objects )-----*/
dht11 DHT11;
// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t Dingbats1_XL[];
/*-----( Declare Constants, Pin Numbers )-----*/
#define DHT11PIN 7
/*-----( Declare User-written Functions )-----*/
//
//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
}
//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
return celsius + 273.15;
}
// dewPoint function NOAA
// reference: http://wahiduddin.net/calc/density_algorithms.htm
double dewPoint(double celsius, double humidity)
{
double A0= 373.15/(273.15 + celsius);
double SUM = -7.90298 * (A0-1);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * humidity;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558-T);
}
// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity/100);
double Td = (b * temp) / (a - temp);
return Td;
}
/* ( THE END ) */
#define SensorPin 0 //pH meter Analog output to Arduino Analog Input 0
unsigned long int avgValue; //Store the average value of the sensor feedback
float b;
int buf[10],temp;
// Set up UTFT...
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino 2009/Uno/Leonardo shield : <display model>,19,18,17,16
// Standard Arduino Mega/Due shield : <display model>,38,39,40,41
// CTE TFT LCD/SD Shield for Arduino Due : <display model>,25,26,27,28
// Standard chipKit Uno32/uC32 : <display model>,34,35,36,37
// Standard chipKit Max32 : <display model>,82,83,84,85
// AquaLEDSource All in One Super Screw Shield : <display model>,82,83,84,85
//
// Remember to change the model parameter to suit your display module!
UTFT myGLCD(ITDB32S,38,39,40,41);
// Set up UTouch...
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino 2009/Uno/Leonardo shield : 15,10,14,9,8
// Standard Arduino Mega/Due shield : 6,5,4,3,2
// CTE TFT LCD/SD Shield for Arduino Due : 6,5,4,3,2
// Standard chipKit Uno32/uC32 : 20,21,22,23,24
// Standard chipKit Max32 : 62,63,64,65,66
// AquaLEDSource All in One Super Screw Shield : 62,63,64,65,66
UTouch myTouch(6,5,4,3,2);
// Finally we set up UTFT_Buttons :)
UTFT_Buttons myButtons(&myGLCD, &myTouch);
void setup()
{
pinMode(13,OUTPUT);
Serial.begin(9600);
Serial.println("Ready"); //Test the serial monitor
Serial.println("DHT11 TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT11LIB_VERSION);
Serial.println();
myGLCD.InitLCD();
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
myButtons.setTextFont(BigFont);
myButtons.setSymbolFont(Dingbats1_XL);
}
void loop()
{
for(int i=0;i<10;i++) //Get 10 sample value from the sensor for smooth the value
{
buf[i]=analogRead(SensorPin);
delay(10);
}
for(int i=0;i<9;i++) //sort the analog from small to large
{
for(int j=i+1;j<10;j++)
{
if(buf[i]>buf[j])
{
temp=buf[i];
buf[i]=buf[j];
buf[j]=temp;
}
}
}
avgValue=0;
for(int i=2;i<8;i++) //take the average value of 6 center sample
avgValue+=buf[i];
float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt
phValue=3.5*phValue; //convert the millivolt into pH value
Serial.print(" pH:");
Serial.print(phValue,2);
Serial.println(" ");
digitalWrite(13, HIGH);
delay(800);
digitalWrite(13, LOW);
Serial.println("\n");
int chk = DHT11.read(DHT11PIN);
Serial.print("Read sensor: ");
switch (chk)
{
case 0:
Serial.println("OK");
break;
case -1:
Serial.println("Checksum error");
break;
case -2:
Serial.println("Time out error");
break;
default:
Serial.println("Unknown error");
break;
}
{
int but1, but2, but3, but4, but5, butY, pressed_button;
boolean default_colors = true;
but1 = myButtons.addButton( 10, 20, 90, 30, "-");
but2 = myButtons.addButton( 115, 20, 90, 30, "pH", BUTTON_DISABLED);
but3 = myButtons.addButton( 220, 20, 90, 30, "+");
but4 = myButtons.addButton( 10, 60, 300, 30, "Temp", BUTTON_DISABLED);
but5 = myButtons.addButton( 10, 100, 300, 30, "Hum", BUTTON_DISABLED);
butY = myButtons.addButton( 0, 199, 100, 40, "I", BUTTON_SYMBOL | BUTTON_SYMBOL_REP_3X);
myButtons.drawButtons();
myGLCD.print("You pressed:", 110, 205);
myGLCD.setColor(VGA_BLACK);
myGLCD.setBackColor(VGA_WHITE);
myGLCD.print("None ", 110, 220);
while(1)
{
if (myTouch.dataAvailable() == true)
{
pressed_button = myButtons.checkButtons();
if (pressed_button==but5)
{
if (myButtons.buttonEnabled(but4))
myButtons.disableButton(but4, true);
else
myButtons.enableButton(but4, true);
}
else if (pressed_button==butY)
{
if (default_colors)
{
myButtons.setButtonColors(VGA_YELLOW, VGA_RED, VGA_YELLOW, VGA_BLUE, VGA_GRAY);
myButtons.relabelButton(butY, "_");
myButtons.drawButtons();
default_colors=false;
}
else
{
myButtons.setButtonColors(VGA_WHITE, VGA_GRAY, VGA_WHITE, VGA_RED, VGA_BLUE);
myButtons.relabelButton(butY, "I");
myButtons.drawButtons();
default_colors=true;
}
}
if (pressed_button==but1)
myGLCD.print("Button 1", 110, 220);
if (pressed_button==but2)
myGLCD.print("Button 2", 110, 220);
if (pressed_button==but3)
myGLCD.print("Button 3", 110, 220);
if (pressed_button==but4)
myGLCD.print("Button 4", 110, 220);
if (pressed_button==-1)
myGLCD.print("None ", 110, 220);
}
}
}
Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, 2);
Serial.print("Temperature (oC): ");
Serial.println((float)DHT11.temperature, 2);
//Serial.print("Temperature (oF): ");
//Serial.println(Fahrenheit(DHT11.temperature), 2);
//Serial.print("Temperature (K): ");
//Serial.println(Kelvin(DHT11.temperature), 2);
Serial.print("Dew Point (oC): ");
Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));
//Serial.print("Dew PointFast (oC): ");
//Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));
delay(5000);
}
Please HELP!!!