Go Down

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


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

#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;

// 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 -------------------------------------------------------
//  wifisetup();
   pinMode(button, OUTPUT);
   pinMode(dht11, INPUT);
uint16_t identifier = tft.readID();

  // SIGNATURE --------------------------------------------------------
  tft.println("ARCSTONE CORP");
  tft.print("BY SHANNON");

  //TOUCH CODE------------------------------------------------------------
TSPoint p = ts.getPoint();
    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())

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



//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----------------------------------------------------------------------------

// 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--------------------------------------------------------
  tft.fillRect(0,84, 240, 72, YELLOW);

   tft.print(" %");
      // Wait a few seconds between measurements.

  // 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!");

  int buttonState = digitalRead(button);   //sample the state of the button - is it pressed or not?
  if (buttonState == HIGH)
  //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.setCursor(20, 270);

Go Up