Unable to Display variable's onto ILI9341 LCD

Hi.
I am constructing a simple clock using a ILI9341 as my screen. I am using the TFT_ILI9341-master Library. TFT_ILI9341 Master Lib
I have used Arduino Timezone Library Copyright (C) 2018 by Jack Christensen Example to pull most of the needed code from.Timezone Library
The clock and display are working great together.
My issue is not being able to print the Time Zone "tz" after the second. or anyware for that matter.

// format and print a time_t value, with a time zone appended.
void printDateTime(time_t t, const char *tz)
{
  char buf[32];
  char m[4];    // temporary storage for month string (DateStrings.cpp uses shared buffer)
  strcpy(m, monthShortStr(month(t)));
  sprintf(buf, "%.2d:%.2d:%.2d %s %.2d %s %d %s",
          hour(t), minute(t), second(t), dayShortStr(weekday(t)), day(t), m, year(t), tz);
  Serial.println(buf);
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    tft.setTextColor(TFT_GREEN, TFT_BLACK);// invisable text
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
    tft.setTextColor(TFT_BLACK, TFT_BLACK);// normal text
    if (pirState == HIGH) {
      // we have just turned of
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }
  tft.setTextSize(1);//                             = Chars 12.8 mm high MAX
  tft.drawNumber( hour(t), 40, 50, 7);// no decimal points
  tft.drawString(";", 1200, 50, 2);
  tft.drawNumber(minute(t), 118, 50, 7);// no decimal points
  tft.drawString(";", 188, 50, 2);
  tft.drawNumber(second(t), 195, 50, 7);// no decimal points
  //tft.drawString(tz), 40, 50, 7);// no decimal points    ******************Help here  **********
  hum = dht.readHumidity();
  temp = dht.readTemperature();
  tft.setTextSize(2);
  tft.drawString("Humidity : ", 10, 120, 2);
  tft.drawFloat(hum, 2, 140, 120, 2);// with decimal points
  tft.drawString("%", 220, 120, 2);
  tft.drawString("Tempature : ", 10, 150, 2);
  tft.drawFloat(temp, 2,165, 150, 2); // with  decimal points
  tft.drawString("C", 250, 150, 2);
}

The original code uses this part of the code to Serial print it.

 sprintf(buf, "%.2d:%.2d:%.2d %s %.2d %s %d %s",
          hour(t), minute(t), second(t), dayShortStr(weekday(t)), day(t), m, year(t), tz);

But I am unable to get it working.
The Library examples show no variable being used on the screen. Also looked at the Keywords and none seam to fit what I need to do.
Will post complete listing if wanted.
Advice please.

Regards Antony.

Since I can't see the parameters used in the call to the printDateTime() function, there's no way to answer your question. That's why posting code snippets is usually not a good idea.

Hi.
Ok will post the main code.

// Arduino Timezone Library Copyright (C) 2018 by Jack Christensen and
// licensed under GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html
//
// Arduino Timezone Library example sketch.
// Self-adjusting clock for one time zone using an external real-time
// clock, either a DS1307 or DS3231 (e.g. Chronodot).
// Assumes the RTC is set to UTC.
// TimeChangeRules can be hard-coded or read from EEPROM, see comments.
// Check out the Chronodot at http://www.macetech.com/store/
//
// Jack Christensen Aug 2012
#include <DHT.h>;
#include <DS1307RTC.h>   // https://github.com/PaulStoffregen/DS1307RTC
#include <Timezone.h>    // https://github.com/JChristensen/Timezone
#include <TFT_ILI9341.h> // Graphics and font library for ILI9341 driver chip  Adafruit_ILI9341
#include <SPI.h>
#define DHTPIN 8     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino

TFT_ILI9341 tft = TFT_ILI9341();  // Invoke library, pins defined in User_Setup.h
// United Kingdom (London, Belfast)
//TimeChangeRule BST = {"BST", Last, Sun, Mar, 1, 60};        // British Summer Time
//TimeChangeRule GMT = {"GMT", Last, Sun, Oct, 2, 0};         // Standard Time
//Timezone UK(BST, GMT);
// If TimeChangeRules are already stored in EEPROM, comment out the three
// lines above and uncomment the line below.
Timezone myTZ(100);       //assumes rules stored at EEPROM address 100

TimeChangeRule *tcr;        //pointer to the time change rule, use to get TZ abbrev
int inputPin = 2;
int val = 0;
int pirState = LOW;
int chk;
float hum;  //Stores humidity value
float temp; //Stores temperature value
void setup()
{
  Serial.begin(115200);
  tft.init();
  tft.setRotation(1);
  dht.begin();
  pinMode(inputPin, INPUT);
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  if (timeStatus() != timeSet)
    Serial.println("Unable to sync with the RTC");
  else
    Serial.println("RTC has set the system time");
  tft.fillScreen(TFT_BLACK);
}

void loop()
{
  time_t utc = now();
  time_t local = myTZ.toLocal(utc, &tcr);
  Serial.println();
  printDateTime(utc, "BST");
  // printDateTime(local, tcr -> abbrev);
  delay(100);



}//     ************************************************   End of Loop   **********************


// format and print a time_t value, with a time zone appended.
void printDateTime(time_t t, const char *tz)
{
  char buf[32];
  char m[4];    // temporary storage for month string (DateStrings.cpp uses shared buffer)
  strcpy(m, monthShortStr(month(t)));
  sprintf(buf, "%.2d:%.2d:%.2d %s %.2d %s %d %s",
          hour(t), minute(t), second(t), dayShortStr(weekday(t)), day(t), m, year(t), tz);
  Serial.println(buf);
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    tft.setTextColor(TFT_GREEN, TFT_BLACK);// invisable text
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
    tft.setTextColor(TFT_BLACK, TFT_BLACK);// normal text
    if (pirState == HIGH) {
      // we have just turned of
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }
  tft.setTextSize(1);//                             = Chars 12.8 mm high MAX
  tft.drawNumber( hour(t), 40, 50, 7);// no decimal points
  tft.drawString(";", 1200, 50, 2);
  tft.drawNumber(minute(t), 118, 50, 7);// no decimal points
  tft.drawString(";", 188, 50, 2);
  tft.drawNumber(second(t), 195, 50, 7);// no decimal points
  //tft.drawString(tz), 40, 50, 7);// no decimal points
  hum = dht.readHumidity();
  temp = dht.readTemperature();
  tft.setTextSize(2);
  tft.drawString("Humidity : ", 10, 120, 2);
  tft.drawFloat(hum, 2, 140, 120, 2);// with decimal points
  tft.drawString("%", 220, 120, 2);
  tft.drawString("Tempature : ", 10, 150, 2);
  tft.drawFloat(temp, 2,165, 150, 2); // with  decimal points
  tft.drawString("C", 250, 150, 2);
}

Many thanks.
Antony.

As long as you do this:

printDateTime(utc, "BST");

it should work. Try doing a Serial.println(tz) as well as 'tft.drawString(tz), 40, 50, 7);' just to check.

Neither of these two lines will work how you want:

time_t local = myTZ.toLocal(utc, &tcr);
printDateTime(local, tcr -> abbrev);

That's because you define 'tcr' as a pointer to a 'TimeChangeRule' struct, but then never assign it to point to anything.

EDIT:
Fix this:
tft.drawString(tz), 40, 50, 7);
^

Hi.
Still getting error
Arduino: 1.8.9 (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

C:\Users\Antony\Documents\Arduino\HardwareRTC_GMT\HardwareRTC_GMT.ino: In function 'void printDateTime(time_t, const char*)':

HardwareRTC_GMT:100:19: error: no matching function for call to 'TFT_ILI9341::drawString(const char*&)'

tft.drawString(tz), 40, 50, 7);

^

In file included from C:\Users\Antony\Documents\Arduino\HardwareRTC_GMT\HardwareRTC_GMT.ino:15:0:

C:\Users\Antony\Documents\Arduino\libraries\TFT_ILI9341-master/TFT_ILI9341.h:338:12: note: candidate: int16_t TFT_ILI9341::drawString(const char*, int, int, int)

drawString(const char *string, int poX, int poY, int font),

^

C:\Users\Antony\Documents\Arduino\libraries\TFT_ILI9341-master/TFT_ILI9341.h:338:12: note: candidate expects 4 arguments, 1 provided

exit status 1
no matching function for call to 'TFT_ILI9341::drawString(const char*&)'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

The serial print shows OK please see the screenshot. and is printing the" 20:36:11 Fri 10 May 2019 BST" time date year and BST as you can see.
I just cannot get the library to display it onto the screen.
My thoughts are … its got to be made into a string then IO can display it.
This line converts it into a string But I can not get it working … sprintf(buf, "%.2d:%.2d:%.2d %s %.2d %s %d %s",
hour(t), minute(t), second(t), dayShortStr(weekday(t)), day(t), m, year(t), tz);

But I am still trying other methods..

Regards Antony.

Post your code after making recommended modifications.

antony1876:
I just cannot get the library to display it onto the screen

gfvalvo:
That's because you define 'tcr' as a pointer to a 'TimeChangeRule' struct, but then never assign it to point to anything.

Hi.
Not quite sure what you are saying.

All the code you have pointed out comes unmodified from the original code.
The first part printDateTime(utc, "BST"); is at line 58
Serial printing works fine :slight_smile: But the 'tft.drawString(tz), 40, 50, 7); Gives me the error as in previous post.

The code time_t local = myTZ.toLocal(utc, &tcr); And printDateTime(local, tcr -> abbrev); are from the library example and are working.

With the line below
That's because you define 'tcr' as a pointer to a 'TimeChangeRule' struct, but then never assign it to point to anything. It is the original code and is working with Serial.print.

Thanks for your help.
Regards Antony.

antony1876:
Hi.
But the

'tft.drawString(tz), 40, 50, 7);

Gives me the error as in previous post.

Like I said in Reply #3, get rid of the extra ')':
tft.drawString(tz**)**, 40, 50, 7)

Never mind what I said about tcr. I see it's being given a value by:

time_t local = myTZ.toLocal(utc, &tcr);

HI.
Thank you so much.. Been looking at this most of the day but did not see the simple mistakes.
tft.drawString(tz, 10, 20, 2); Works a treat.
Also found that I can split most of the data that I need to display and add the missing zero's with the sprintf command.
Thanks again.

Regards Antony.