Go Down

Topic: Unable to display readings on arduino monitor and 2.4 inch tft lcd screen (Read 701 times) previous topic - next topic

shannonzchanz

Hello everyone! I am trying to display data via my esp8266 into my arduino com port monitor. Havent really figure out how to parse the json data to be displayed on my mcufriend 2.4inch tft lcd screen yet but that will come later.

Right now, I am unable to display these data on my arduino mega serial monitor. However, as I comment the void tftloop(), I am able to output the data on my arduino mega serial monitor. But, I have to now compromise the function of a tftloop().

Is this a memory problem? It says the sketch uses 12730 bytes (5%) of program storage space. Global variable uses 505 bytes (6%) of dynamic memory...

Code: [Select]


#include <Adafruit_GFX.h>    // Core graphics library
#include <SWTFT.h> // Hardware-specific library
#include <TouchScreen.h>
#include <Arduino.h>

#include "DHT.h"
#define DHTPIN 38 //MEGA2560 PIN 38
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

#define YP A2  // must be an analog pin, use "An" notation!
#define XM A1  // must be an analog pin, use "An" notation!
#define YM 6   // can be a digital pin
#define XP 7   // can be a digital pin

#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940

#define MINPRESSURE 10
#define MAXPRESSURE 1000

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);



// Assign human-readable names to some common 16-bit color values:
#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF


SWTFT tft;


int f1=0;
//DHT dht(DHTPIN, DHTTYPE);

// TFT FUNCTIONS----------------------------------------------------------------------------------------------------
//tft.setCursor(22,37) , tft.setTextSize(2) ~ 25 pixels in height , tft.setTextColor(RED)
/*
  tft.drawRect(x_start, y_start, width(x direction), height(y direction, COLOR)
  E.g. tft.drawRect(10,0,237,318,CYAN) , tft.fillRect 10,0,237,318,CYAN) */

/*
 tft.drawCircle(x_start, y_start, radius, COLOR)
 E.g. tft.drawCircle(180,140,10,BLACK) , tft.fillCircle(180,140,10,BLACK)
 */

 const int dht11=38, button=40;
long lastDebounceTime = 0, debounceDelay = 50;
int buttonState = LOW, ledState= -1;

void setup() {                                     
  // put your setup code here, to run once: LCD Code -------------------------------------------------------
 
  Serial.begin(115200);
  Serial1.begin(115200);
//  wifisetup();
  dht.begin();
 
   pinMode(button, OUTPUT);
   pinMode(dht11, INPUT);
   
  tft.reset();
uint16_t identifier = tft.readID();
  //tft.setRotation(0);
   tft.begin(identifier);
  tft.fillScreen(BLACK);
//BUTTON SETUP



  // SIGNATURE --------------------------------------------------------
  tft.fillRect(0,0,240,80,MAGENTA);
  tft.setCursor(50,20);
  tft.setTextSize(2);
  tft.setTextColor(BLACK);
  tft.println("ARCSTONE CORP");
  tft.setCursor(60,45);
  tft.print("BY SHANNON");

  //TOUCH CODE------------------------------------------------------------
TSPoint p = ts.getPoint();
  if (p.z >MINPRESSURE && p.z<MAXPRESSURE)
  {
    p.x = tft.width()-(map(p.x, TS_MINX, TS_MAXX, tft.width(), 0));
    p.y = tft.height()-(map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
   
  }

}

//TOUCH CODE---------------------------------------------------------------

void loop()
{
  if (Serial1.available())
  {
  Serial.write(Serial1.read());
  }

  //below if statement not important for printing output to mega monitor
  if (Serial.available())
  {
  char command=Serial.read();
  Serial1.write(command);

    }
   
 

tftloop();

   
//delay code------------------------------
   
}

void tftloop()
{

 //Touch code---------------------------------------------------------------------------------------
  digitalWrite(13, HIGH);
  // Recently Point was renamed TSPoint in the TouchScreen library
  // If you are using an older version of the library, use the
  // commented definition instead.
  // Point p = ts.getPoint();
  TSPoint p = ts.getPoint();
  digitalWrite(13, LOW);

  // if sharing pins, you'll need to fix the directions of the touchscreen pins
  //pinMode(XP, OUTPUT);
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  //pinMode(YM, OUTPUT);
 /* if (p.z >MINPRESSURE && p.z<MAXPRESSURE)
  {
    p.x = tft.width()-(map(p.x, TS_MINX, TS_MAXX, tft.width(), 0));
    p.y = tft.height()-(map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
   
  }

} */
//TOUCH CODE----------------------------------------------------------------------------

//DHT11---------------------------------------------------------------------------------------
// Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
 float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
 // float f = dht.readTemperature(true);
 
  //TEMP & HUMIDITY RECTANGLES--------------------------------------------------------
  //TEMP RECTANGLE
 
   tft.drawRect(0,80,240,80,BLACK);
  tft.fillRect(0,84, 240, 72, YELLOW);
   tft.setCursor(4,110);
   tft.setTextSize(2);
   tft.setTextColor(BLACK);
   tft.print("Temperature:");
   tft.print(t);
   tft.print("*C");
   Serial.print(t);

  //HUMIDITY RECTANGLE
 
 tft.drawRect(0,160,240,72,BLACK);
   tft.fillRect(0,160,240,72,CYAN);
   tft.setCursor(25,190);
   tft.setTextSize(2);
   tft.setTextColor(BLACK);
   tft.print("Humidity:");
   tft.print(h);
   tft.print(" %");
   Serial.println(h);
      // Wait a few seconds between measurements.
  //delay(2000);

 
  // Check if any reads failed and exit early (to try again).
/* if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
*/
//DHT11----------------------------------------------------------------------------------------

  int buttonState = digitalRead(button);   //sample the state of the button - is it pressed or not?
     
  if (buttonState == HIGH)
  {
    f1++;
  }
  //filter out any noise by setting a time buffer
  /* if ( (millis() - lastDebounceTime) > debounceDelay) {
 
    //if the button has been pressed, lets toggle the LED from "off to on" or "on to off"
    if ( (buttonState == HIGH) && (ledState < 0) ) {
 
      digitalWrite(led, HIGH); //turn LED on
      ledState = -ledState; //now the LED is on, we need to change the state
      lastDebounceTime = millis(); //set the current time
    }
    else if ( (buttonState == HIGH) && (ledState > 0) ) {
 
      digitalWrite(led, LOW); //turn LED off
      ledState = -ledState; //now the LED is off, we need to change the state
      lastDebounceTime = millis(); //set the current time
    }//close if/else
 
  }//close if(time buffer)
 */

 
   tft.drawRect(0,240,240,80, BLACK);
   tft.fillRect(0,236,120,72,RED);
   tft.setCursor(20, 270);
   tft.setTextSize(2);
   tft.setTextColor(BLACK);
   tft.print("FAIL:");
   tft.print(f1);
 
}


Go Up