Good Day To All,
Need help on my current project, I have done a Weather station project and have been able to Display all the reading nicely on the serial Print.(as per attached pic). Currrently im trying to print the available data to my newly bought 1.8 tft display. I have managed to wired the stuff as per
The screen flikers and i cant seem to get the right code to display the value on my tft SCREEN.
I would appreciate if there is any guru out there who can help me on the matter. It would be very great.
/*
Pin Configuration
Rain Drop A0
Soil Humidity A1
SDA A4
SCL A5
DHT22 Data D7
*/
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
// For the breakout, you can use any 2 or 3 pins
// These pins will also work for the 1.8" TFT shield
#define TFT_CS 10
#define TFT_RST 9 // you can also connect this to the Arduino reset
// in which case, set this #define pin to 0!
#define TFT_DC 8
// Option 1 (recommended): must use the hardware SPI pins
// (for UNO thats sclk = 13 and sid = 11) and pin 10 must be
// an output. This is much faster - also required if you want
// to use the microSD card (see the image drawing example)
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
// Option 2: use any pins but a little slower!
#define TFT_SCLK 13 // set these to be whatever pins you like!
#define TFT_MOSI 11 // set these to be whatever pins you like!
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
float p = 3.1415926;
int result [5]; //Sensor result array
#include <Wire.h> //Including wire library
#include <SFE_BMP180.h> //Including BMP180 library
#define ALTITUDE 50 //Altitude Taman Melawati KL
SFE_BMP180 pressure; //Creating an object
#include <DHT.h> //Including DHT22 library
#define DHTPIN 7 //Define DHT22 digital pin
#define DHTTYPE DHT22 //Define DHT TYPE which is DHT11
DHT dht(DHTPIN, DHTTYPE); //Execute DHT22 library
void setup() {
Serial.begin(9600); //Starting serial communication
Serial.println("Program started");
//Analog setup
pinMode(A0, INPUT); //Soil
pinMode(A1, INPUT); //Rain
//BMP180 Setup
if (pressure.begin()) //If initialization was successful, continue
{ Serial.println("BMP180 Functions Success");
}
else //Else, stop code forever
{
Serial.println("BMP180 Sensor Fail ");
while (1);
}
//DHT22 setup
dht.begin();
}
void loop() {
//analog setup
int A_Rain = analogRead(A0);
int A_Soil = analogRead(A1);
A_Rain = map(A_Rain, 800, 1023, 100, 0);
A_Soil = map(A_Soil, 400, 1023, 100, 0);
result[0] = A_Soil;
result[1] = A_Rain;
//bmp180 setup
char status;
double T, P, p0, a;
status = pressure.startTemperature();
if (status != 0) {
delay(status);
status = pressure.getTemperature(T);
if (status != 0) {
status = pressure.startPressure(3);
if (status != 0) {
delay(status);
status = pressure.getPressure(P, T);
if (status != 0) {
p0 = pressure.sealevel(P, ALTITUDE);
result[2] = p0;
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.println();
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" Degrees Celcius ");
Serial.println();
Serial.print("Humidity: ");
Serial.print(h);
Serial.print("%");
Serial.println();
//--- extra---- you can measure dew point with the temperature and the humidity
double gamma = log(h/100) + ((17.62*t) / (243.5+t));
double dp = 243.5*gamma / (17.62-gamma);
Serial.print("Dew point: ");
Serial.print(dp);
Serial.print(" Degrees Celcius ");
Serial.println();
}
}
}
}
result[3] = dht.readHumidity();
result[4] = dht.readTemperature();
Serial.println();
Serial.print("Soil Humidity : ");
Serial.print(" \t");
Serial.print(result[0]);
Serial.print(" %\t");
Serial.print("Rain Drop Percentage : ");
Serial.print("\t");
Serial.print(result[1]);
Serial.print(" %\t");
Serial.print("Presssure : ");
Serial.print("\t");
Serial.print(result[2]);
Serial.print(" hPa \t");
Serial.print("Air Humidity : ");
Serial.print(result[3]);
Serial.print(" %\t");
Serial.print("\t");
Serial.print("Temperature : ");
Serial.print(result[4]);
Serial.println(" C \t");
Serial.println();
Serial.print ("BMP 180 Readings");
Serial.println("");
Serial.print("Provided Altitude: ");
Serial.print(ALTITUDE, 0);
Serial.print(" meters, ");
Serial.print(ALTITUDE * 3.28084, 0);
Serial.println(" feet");
status = pressure.startTemperature();
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
// Retrieve the completed temperature measurement:
// Note that the measurement is stored in the variable T.
// Function returns 1 if successful, 0 if failure.
status = pressure.getTemperature(T);
if (status != 0)
{
// Print out the measurement:
Serial.print("Temperature: ");
Serial.print(T,2);
Serial.print(" deg C, ");
Serial.print((9.0/5.0)*T+32.0,2);
Serial.println(" deg F");
// Start a pressure measurement:
// The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.
status = pressure.startPressure(3);
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
// Retrieve the completed pressure measurement:
// Note that the measurement is stored in the variable P.
// Note also that the function requires the previous temperature measurement (T).
// (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
// Function returns 1 if successful, 0 if failure.
status = pressure.getPressure(P, T);
if (status != 0)
{
// Print out the measurement:
Serial.print("Absolute Pressure: ");
Serial.print(P, 2);
Serial.print(" hPa, ");
Serial.print(P * 0.0295333727, 2);
Serial.println(" inHg");
// The pressure sensor returns abolute pressure, which varies with altitude.
// To remove the effects of altitude, use the sealevel function and your current altitude.
// This number is commonly used in weather reports.
// Parameters: P = absolute pressure in mb, ALTITUDE = current altitude in m.
// Result: p0 = sea-level compensated pressure in mb
p0 = pressure.sealevel(P, ALTITUDE); // we're at 1655 meters (Boulder, CO)
Serial.print("Relative (Sea-Level) Pressure: ");
Serial.print(p0, 2);
Serial.print(" hPa, ");
Serial.print(p0 * 0.0295333727, 2);
Serial.println(" inHg");
// On the other hand, if you want to determine your altitude from the pressure reading,
// use the altitude function along with a baseline pressure (sea-level or other).
// Parameters: P = absolute pressure in mb, p0 = baseline pressure in mb.
// Result: a = altitude in m.
a = pressure.altitude(P, p0);
Serial.print("Computed Altitude: ");
Serial.print(a, 0);
Serial.print(" meters, ");
Serial.print(a * 3.28084, 0);
Serial.println(" feet");
}
else Serial.println("error retrieving pressure measurement\n");
}
else Serial.println("error starting pressure measurement\n");
}
else Serial.println("error retrieving temperature measurement\n");
}
else Serial.println("error starting temperature measurement\n");
delay(5000);
}