Go Down

Topic: Adafruit_ILI9341: 2.8inch TFT LCD resistiv Touchplatine (Read 519 times) previous topic - next topic

Pass6

Hello everybody,

I started working with Arduino a month ago. And I would like to first create a real time with Arduino. For this I have Arduino Mega 2560, a 2.8 inch TFT resistive touch board and a PmodRTCC. Until here I managed to spend the real time on the display. I ran my RTC the night, but this morning the time was not right anymore. I was forced to upload my code again to have the right time. In order to avoid ever uploading my code I would like to set the time directly on the display. For this I thought to create a botton on the display, so if you press on it comes another window and so far until I come in the window where I want to set the time. But my code does not work somehow.
Please can you check my code and tell me what to do?


Thanks a lot

Passy.

Pass6

Here is my code

Code: [Select]

// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_ILI9341.h>
#include <TouchScreen.h>
#define MINPRESSURE 200
#define MAXPRESSURE 1000

#include <Arduino.h>
#include <Wire.h>         // this #include still required because the RTClib depends on it
#include "RTClib.h"

//Touchscreen X+ X- Y+ Y- pins
#define YP A3  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 5   // can be a digital pin
#define XP 4   // can be a digital pin

// This is calibration data for the raw touch data to the screen coordinates
#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940

#define TFT_CS 10
#define TFT_DC 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
   #define Serial SerialUSB
#endif

RTC_Millis rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

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



#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

boolean buttonStart = true;
boolean buttonFenster = true;
boolean buttonErweiterungen = true;
boolean buttonFenster1 = true;
boolean buttonSensordatenEinstellungen = true;
boolean buttonFenster2 = true;
boolean buttonFenster3 = true;
//boolean buttonFenster4 = true;

void setup () {
  Serial.begin(9600);
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));

  tft.begin();  // this returns the above results. below you can see how I replaced all this once i know which one I have...
  tft.setRotation(1); // 3=landscape mode -w- row pins on right...
  tft.fillScreen(BLACK);  //Set's LCD Back Ground as Black

  tft.fillRect(60,180, 201, 40,RED);
  tft.setCursor(120,188);
  tft.setTextColor(BLACK);
  tft.setTextSize(3);
  tft.print("Start");
  delay(10);
}

void loop () {

  TSPoint p = ts.getPoint(); //checks touch x/y min-max



  // if you're sharing pins, you'll need to fix the directions of the touchscreen pins!
  //pinMode(XP, OUTPUT);    //normally not needed..when used as defualt setup..
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  //pinMode(YM, OUTPUT);   //normally not needed..when used as defualt setup..

   digitalWrite(YP, HIGH);   //because TFT control pins
   digitalWrite(XM, HIGH);



     // turn from 0->1023 to tft.width
    p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240);//default is (240, 0) [default puts touch cord. 0=x/y upper right.
    p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320);//default is (320, 0) [I change these cause i like 0=xy bottom left.
   

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {    //checks IF theres any touch action then continues
  }
 
    DateTime now = rtc.now();
   
    tft.setTextSize(3);
    tft.setTextColor(WHITE, BLACK);
    tft.setCursor(30, 20);
    tft.println(now.year(), DEC);
    Serial.print(now.year(), DEC);

    tft.setTextSize(3);
    tft.setTextColor(WHITE, BLACK);
    tft.setCursor(110, 20);
    tft.println('/');
    Serial.print('/');

    tft.setTextSize(3);
    tft.setTextColor(WHITE, BLACK);
    tft.setCursor(140, 20);
    tft.println(now.month(), DEC);
    Serial.print(now.month(), DEC);

    tft.setTextSize(3);
    tft.setTextColor(WHITE, BLACK);
    tft.setCursor(170, 20);
    tft.println('/');
    Serial.print('/');

    tft.setTextSize(3);
    tft.setTextColor(WHITE, BLACK);
    tft.setCursor(200, 20);
    tft.println(now.day(), DEC);
    Serial.print(now.day(), DEC);

    tft.setTextSize(3);
    tft.setTextColor(WHITE, BLACK);
    tft.setCursor(30, 70);
    tft.println("(");
    Serial.print("(");

    tft.setTextSize(3);
    tft.setTextColor(WHITE, BLACK);
    tft.setCursor(70, 70);
    tft.println(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
   
    tft.setTextSize(3);
    tft.setTextColor(WHITE, BLACK);
    tft.setCursor(230, 70);
    tft.println(" )");
    Serial.print(") ");

    tft.setTextSize(3);
    tft.setTextColor(WHITE, BLACK);
    tft.setCursor(30, 120);
    tft.println(now.hour(), DEC);
    Serial.print(now.hour(), DEC);

    tft.setTextSize(3);
    tft.setTextColor(WHITE, BLACK);
    tft.setCursor(70, 120);
    tft.println(':');
    Serial.print(':');

    tft.setTextSize(3);
    tft.setTextColor(WHITE, BLACK);
    tft.setCursor(90, 120);
    tft.println(now.minute(), DEC);
    Serial.print(now.minute(), DEC);

    tft.setTextSize(3);
    tft.setTextColor(WHITE, BLACK);
    tft.setCursor(130, 120);
    tft.println(':');
    Serial.print(':');
   
    tft.setTextSize(3);
    tft.setTextColor(WHITE, BLACK);
    tft.setCursor(150, 120);
    tft.println(now.second(), DEC);
    Serial.print(now.second(), DEC);
    Serial.println();
 
    delay(1000);

   if(p.x>60 && p.x<260 && p.y>180 && p.y<220)
   {
    Fenster();
    Serial.println("taster_Start");
   }
}

Pass6

Following my Code

Code: [Select]

//Touch Botton
void StartToutch()
{
 digitalWrite(13, HIGH);
TSPoint p = ts.getPoint();
digitalWrite(13, LOW);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);

   digitalWrite(YP, HIGH);   //because TFT control pins
   digitalWrite(XM, HIGH);

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
  {
   p.x = map(p.x, TS_MAXX, TS_MINX, 0, 320);
   p.y = map(p.y, TS_MAXY, TS_MINY, 0, 240);
     
   if(p.x>60 && p.x<260 && p.y>180 && p.y<220 && buttonStart)
   {
    Fenster();
   }
  }
}

void ErweiterungenToutch()
{
    while(buttonErweiterungen = true)
{
   Timerfunktion();
  buttonFenster = false;
 digitalWrite(13, HIGH);
TSPoint p = ts.getPoint();
digitalWrite(13, LOW);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);

   digitalWrite(YP, HIGH);   //because TFT control pins
   digitalWrite(XM, HIGH);

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
  {
   p.x = map(p.x, TS_MAXX, TS_MINX, 0, 320);
   p.y = map(p.y, TS_MAXY, TS_MINY, 0, 240);
if(p.x>10 && p.x<290 && p.y>150 && p.y<205 && buttonErweiterungen)
  {
    Fenster1();
  }
 }
delay(0);
}
}

void SensordatenToutch()
{
buttonFenster1 = false;
 digitalWrite(13, HIGH);
TSPoint p = ts.getPoint();
digitalWrite(13, LOW);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);

   digitalWrite(YP, HIGH);   //because TFT control pins
   digitalWrite(XM, HIGH);

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) 
  {
   p.x = map(p.x, TS_MAXX, TS_MINX, 0, 320);
   p.y = map(p.y, TS_MAXY, TS_MINY, 0, 240);
if(p.x>10 && p.x<290 && p.y>80 && p.y<140 && buttonSensordatenEinstellungen)
  {
    Fenster2();
  }
if(p.x>10 && p.x<290 && p.y>147 && p.y<203 && buttonSensordatenEinstellungen)
  {
    Fenster3();
  }
 }
delay(0);
}


void EinstellungenToutch()
{
  while(buttonFenster3 = true)

 {
  Timerfunktion();
buttonFenster1 = false;
 digitalWrite(13, HIGH);
TSPoint p = ts.getPoint();
digitalWrite(13, LOW);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);

   digitalWrite(YP, HIGH);   //because TFT control pins
   digitalWrite(XM, HIGH);

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
  {
   p.x = map(p.x, TS_MAXX, TS_MINX, 0, 320);
   p.y = map(p.y, TS_MAXY, TS_MINY, 0, 240);
 
if(p.x>10 && p.x<290 && p.y>80 && p.y<120 && buttonSensordatenEinstellungen)
  {
    Fenster4();
  }
if(p.x>10 && p.x<290 && p.y>130 && p.y<170 && buttonSensordatenEinstellungen)
  {
    Fenster5();
  }

delay(0);
  }
 back1();
 }
}

void UhrzeitToutch()
{
  Timerfunktion();
buttonFenster2 = false;
 digitalWrite(13, HIGH);
TSPoint p = ts.getPoint();
digitalWrite(13, LOW);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);

   digitalWrite(YP, HIGH);   //because TFT control pins
   digitalWrite(XM, HIGH);

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
  {
   p.x = map(p.x, TS_MAXX, TS_MINX, 0, 320);
   p.y = map(p.y, TS_MAXY, TS_MINY, 0, 240);
if(p.x>235 && p.x<278 && p.y>85 && p.y<127 && buttonSensordatenEinstellungen)
  {
    Fenster4_1();
  }
 
if(p.x>42 && p.x<82 && p.y>85 && p.y<127 && buttonSensordatenEinstellungen)
  {
    Fenster4_2();
  }
 }
delay(0);
}


void MspeedToutch()
{
 Timerfunktion();
 buttonFenster2 = false;
 digitalWrite(13, HIGH);
 TSPoint p = ts.getPoint();
 digitalWrite(13, LOW);
 pinMode(XM, OUTPUT);
 pinMode(YP, OUTPUT);

    digitalWrite(YP, HIGH);   //because TFT control pins
   digitalWrite(XM, HIGH);

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
  {
   p.x = map(p.x, TS_MAXX, TS_MINX, 0, 320);
   p.y = map(p.y, TS_MAXY, TS_MINY, 0, 240);
if(p.x>235 && p.x<278 && p.y>85 && p.y<127 && buttonSensordatenEinstellungen)
  {
    Fenster5_1();
  }
 
if(p.x>42 && p.x<82 && p.y>85 && p.y<127 && buttonSensordatenEinstellungen)
  {
    Fenster5_2();
  }
 }
delay(0);
}

david_prentice

#3
Jun 05, 2018, 05:19 pm Last Edit: Jun 05, 2018, 05:21 pm by david_prentice
If you are posting code,  please post a complete sketch.  i.e. so that it can be built.
There is no "Fenster".    I don't mind if there are non-English function names or non-English comments.   I do mind if the IDE can not build the sketch.

If it is a sketch with multiple tabs,  ZIP up the sketch directory and attach the Zip.

It is also helpful to know which "RTClib.h" you are using.   The Library Manager will tell you.
I am still not sure what hardware you have.   SPI ILI9341 board normally has an XPT2046 Touch controller or perhaps STMPE610.    Seeed have a shield with raw resistive panel (I think).

David.

david_prentice

#4
Jun 05, 2018, 06:42 pm Last Edit: Jun 05, 2018, 11:00 pm by david_prentice
Regarding DS3231 with ILI9341.   Here is a simple sketch.   Note the two versions of loop().

Formatting code with Arduino Print methods is horrible.   It is much easier to use C sprintf() and print the result.

The other "loop()" uses a helper function that pads a number with 0.

Code: [Select]


#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Adafruit_ILI9341.h>
// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include <Wire.h>         // this #include still required because the RTClib depends on it
#include "RTClib.h"

Adafruit_ILI9341 tft(10, 9, 8);

RTC_DS3231 rtc;

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

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {
    rtc.begin();
    // following line sets the RTC to the date & time this sketch was compiled
    if (rtc.lostPower()) {
        rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    }
    tft.begin();            //
    tft.setRotation(1);     // 3=landscape mode -w- row pins on right...
    tft.fillScreen(BLACK);  //Set's LCD Back Ground as Black

    tft.fillRect(60, 180, 201, 40, RED);
    tft.setTextColor(WHITE, BLACK);
    tft.setTextSize(3);
}

void loop()
{
    DateTime now = rtc.now();
    char buf[20];
    sprintf(buf, "%04d/%2d/%2d", now.year(), now.month(), now.day());
    tft.setCursor(30, 20);
    tft.print(buf);
    sprintf(buf, "(  %s  )", daysOfTheWeek[now.dayOfTheWeek()]);
    tft.setCursor(30, 70);
    tft.print(buf);
    sprintf(buf, "%02d:%02d:%02d", now.hour(), now.minute(), now.second());
    tft.setCursor(30, 120);
    tft.print(buf);
    delay(1000);
}

// An alternative is to write a helper function:

void print0(uint16_t val)
{
    if (val < 10) tft.print("0");
    tft.print(val);
}

void loop_old()
{
    DateTime now = rtc.now();
    tft.setCursor(30, 20);
    print0(now.year());
    tft.print("/");
    print0(now.month());
    tft.print("/");
    print0(now.day());
    tft.setCursor(30, 70);
    tft.print("(  ");
    tft.print(daysOfTheWeek[now.dayOfTheWeek()]);
    tft.setCursor(230, 70);
    tft.print(" )");

    tft.setCursor(30, 120);
    print0(now.hour());
    tft.print(':');
    print0(now.minute());
    tft.print(':');
    print0(now.second());
    delay(1000);
}

You will need to alter the constructor() for your TFT wiring.
Then comment out the rtc.adjust() statement.    If your DS3231 has got a battery,  it will keep time perfectly.

David.

Edit.  I changed the class to RTC_DS3231.   You (and I) had RTC_Millis
I also added code to only adjust on first build.

Pass6

Thank you for always answering my questions. I have tested your code and function, but it does not display the exact time. All the same I would like to stay on my start code and just improve it finally to get the results that I wish.The tools I use are: a TFT LCD Resistiv Touchplatin (2.8 inch) Adafruit, a PmodRTCC and Arduino Mega.
I decided to go step by step now. Here is the code I wrote yesterday. I would like a reaction when you press the Start button. But alas my Start button does not work. Can you tell me or I made a mistake?
How can you program the window change when you touch the screen?

Code: [Select]

// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_ILI9341.h>
//#include <TouchScreen.h>
#include <Adafruit_STMPE610.h>


#include <Arduino.h>
#include <Wire.h>         // this #include still required because the RTClib depends on it
#include "RTClib.h"

Adafruit_STMPE610 touch = Adafruit_STMPE610();

//Touchscreen X+ X- Y+ Y- pins
#define YP A3  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 5   // can be a digital pin
#define XP 4   // can be a digital pin

// This is calibration data for the raw touch data to the screen coordinates
#define TS_MINX 150
#define TS_MINY 130
#define TS_MAXX 3800
#define TS_MAXY 4000


#define TFT_CS 10
#define TFT_DC 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
   #define Serial SerialUSB
#endif

RTC_Millis rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

//TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
#define STMPE_CS 8
Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);

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

boolean RecordOn = false;

#define FRAME_X 60
#define FRAME_Y 180
#define FRAME_W 201
#define FRAME_H 40

#define REDBUTTON_X FRAME_X
#define REDBUTTON_Y FRAME_Y
#define REDBUTTON_W FRAME_W
#define REDBUTTON_H FRAME_H

void drawFrame()
{
  tft.drawRect(FRAME_X, FRAME_Y, FRAME_W, FRAME_H, ILI9341_BLACK);
}

boolean buttonStart = true;
boolean buttonFenster = true;
boolean buttonErweiterungen = true;
boolean buttonFenster1 = true;
boolean buttonSensordatenEinstellungen = true;
boolean buttonFenster2 = true;
boolean buttonFenster3 = true;
//boolean buttonFenster4 = true;

void StartBtn()
{
  tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_RED);
  tft.setCursor(REDBUTTON_X + 50 , REDBUTTON_Y + (REDBUTTON_H/3));
  tft.setTextColor(ILI9341_BLACK);
  tft.setTextSize(3);
  tft.println("Start");
 
}

void setup () {
  Serial.begin(9600);
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));


  if (!ts.begin()) {
    Serial.println("Couldn't start touchscreen controller");
  }
  else {
  Serial.println("Touchscreen started");
  }

  tft.begin();  // this returns the above results. below you can see how I replaced all this once i know which one I have...
  tft.fillScreen(ILI9341_WHITE);  //Set's LCD Back Ground as ILI9341_BLACK
  tft.setRotation(1); // 3=landscape mode -w- row pins on right...
  ts.begin();
  StartBtn();
}

void loop () {
 
  if (!ts.bufferEmpty())
  {
  TS_Point p = ts.getPoint();
      // Scale using the calibration #'s
      // and rotate coordinate system
      p.x = map(p.x, TS_MINY, TS_MAXY, 0, tft.width());
      p.y = map(p.y, TS_MINX, TS_MAXX, 0, tft.height());

      int y = tft.height() - p.x;
      int x = p.y;

if((x > REDBUTTON_X) && (x < (REDBUTTON_X + REDBUTTON_W))) {
        if ((y > REDBUTTON_Y) && (y <= (REDBUTTON_Y + REDBUTTON_H))) {
          Serial.println("Start btn hit");
          StartBtn();
        }
      }
    }
 
    DateTime now = rtc.now();
   
    tft.setTextSize(3);
    tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
    tft.setCursor(30, 20);
    tft.println(now.year(), DEC);
    Serial.print(now.year(), DEC);

    tft.setTextSize(3);
    tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
    tft.setCursor(110, 20);
    tft.println('/');
    Serial.print('/');

    tft.setTextSize(3);
    tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
    tft.setCursor(140, 20);
    tft.println(now.month(), DEC);
    Serial.print(now.month(), DEC);

    tft.setTextSize(3);
    tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
    tft.setCursor(170, 20);
    tft.println('/');
    Serial.print('/');

    tft.setTextSize(3);
    tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
    tft.setCursor(200, 20);
    tft.println(now.day(), DEC);
    Serial.print(now.day(), DEC);

    tft.setTextSize(3);
    tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
    tft.setCursor(30, 70);
    tft.println("(");
    Serial.print("(");

    tft.setTextSize(3);
    tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
    tft.setCursor(70, 70);
    tft.println(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
   
    tft.setTextSize(3);
    tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
    tft.setCursor(230, 70);
    tft.println(" )");
    Serial.print(") ");

    tft.setTextSize(3);
    tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
    tft.setCursor(30, 120);
    tft.println(now.hour(), DEC);
    Serial.print(now.hour(), DEC);

    tft.setTextSize(3);
    tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
    tft.setCursor(70, 120);
    tft.println(':');
    Serial.print(':');

    tft.setTextSize(3);
    tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
    tft.setCursor(90, 120);
    tft.println(now.minute(), DEC);
    Serial.print(now.minute(), DEC);

    tft.setTextSize(3);
    tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
    tft.setCursor(130, 120);
    tft.println(':');
    Serial.print(':');
   
    tft.setTextSize(3);
    tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
    tft.setCursor(150, 120);
    tft.println(now.second(), DEC);
    Serial.print(now.second(), DEC);
    Serial.println();
 
    delay(1000);

}

   



david_prentice

Please post a real link to the actual screen that you have on your desk.

I do not have STMPE610 controller.   I don't even know if you do!  i.e. Adafruit_STMPE610.h
Your earlier posts implied that you had a raw Resistive panel i.e. TouchScreen.h

I might have a MCP7940N RTC chip but it would be a pain to hook it up.

I gave you some code for a DS3231 RTC that I had tested in real life.   Your message #1 implied that you had a DS3231.
The most important tip was : simplify and re-use code e.g. with helper function.

It is not much good saying
Quote
it does not display the exact time.
If you don't have a DS3231,  you would have to use the RTC_Millis class.

If you want to learn how to use the STMPE610 you should run the library examples.
If you want to learn how to use the RTClib you should run the library examples.

Adapt small sections at a time.    e.g. RTC on Serial Terminal

Note that RTC_millis just uses the crap Uno ceramic resonator.   It will keep bad time.   And obviously reset when you press reset button, upload code or you power off/on.

David.

Pass6

HI,
Everything that I have in my first message and also a week or two ago are no longer up to date. Since last week I've got new hardware (2.8 inch TFT Resistive Touch Board from Adafruit and a PmodRTCC)
Here is the link for the display: https://learn.adafruit.com/adafruit-2-8-tft-touch-shield-v2/overview.
Because of this new hardware, I have to use other libraries now. The problem I have now is switching from one window to another when I press the Start button. When pressing the start button comes the other window but the clock remains without further counting.

Here is the link for my code: https://drive.google.com/open?id=1Qtr1q0FehKodGahRAdvecxUlBollaZzc

david_prentice

First off.   Your Google Drive is painful.    I can't read the code without downloading it.
Why not ZIP up your project and attach it to your message?

Seriously,   adapt the STMPE610 examples to learn how to use the STMPE610.

I note that you have not taken any notice of my "helper function" advice.

I don't have a STMPE610.    Of course I could implement your ideas with different hardware.
But if I spend time and effort,   you will simply ignore any suggestions.

From a RTC project point of view.   My example initialises the DS3231 to the Compile Time when first run.
And it has been displaying the correct time ever since.    You can do exactly the same with a MCP79410 chip.    I suspect there is even an MCP79410 library example out there.

The MCP79410 works in a similar way to DS1307, DS3231, ...
It uses a different Slave address but the registers are much the same.

David.

Pass6

Hi,

Is there a specific library to set the time, date and year?

Passy

david_prentice

Examples just steal the compile time macros e.g. _TIME_ and _DATE_
Parse the values and initialise the RTC registers accordingly.

The examples also provide a test to check whether the RTC is already running.
A subsequent Reset or Power-up will not set RTC to the compile time.
This is only possible with a battery-backed RTC chip.   If you use millis() it starts at 0 again.

Study the library code if you want to see how they do it.

David.

Pass6

Hello here is the code that I wrote to be able to set the time on my screen. But this code does not work completely. my Program works as follows: I first press the "Set" button to have the position where I have to make the setting. After I press either "Up" or "Down" to set the time or Date.The setting to finish I press the "OK" button to save the setting.
The problem is that when I press "Down" or "Up" this one does the adjustment once (ie, if the current time is 10h and I want to set at 12h, the "Up" button changes and displays just 11h). In addition the new time is displayed on the old (they are superimposed). Can you please help me solve the problem?

A big thank you in advance.

Passy

Code: [Select]

void Setting(){
  Timerfunktion();
  DateTime now = rtc.now();
 
 /*TS_Point p = ts.getPoint();
 
  p.x = map(p.x, TS_MINY, TS_MAXY, 0, tft.height());
    p.y = map(p.y, TS_MINX, TS_MAXX, 0, tft.width());

      int y = tft.height() - p.x;
      int x = p.y;*/


 if(touch.touched())
  {
        TS_Point p = ts.getPoint();
 
    p.x = map(p.x, TS_MINY, TS_MAXY, 0, tft.height());
    p.y = map(p.y, TS_MINX, TS_MAXX, 0, tft.width());

      int y = tft.height() - p.x;
      int x = p.y;

   if ((y>=211)&&(y<=242))
    {
       if((x>=100)&&(x<=150))    //Set button
       {
        tft.drawRect(100,211,50,31, ILI9341_YELLOW);
        if(count==8)count=0;
            count++;
            Serial.print(count);
       }

       if((x>=250)&&(x<=300))     //OK button
       {
            count=7;
       }
    }
 

       if((x>=100)&&(x<=160))    //UP button
       {
        if((y>=130)&&(y<=180))
        {
          switch(count)
          {
            case 1:
            {
              hrs=now.hour();
              hrs++;
              if(hrs>=24)hrs=0;
              Serial.print(hrs);
              tft.setCursor(30, 100);
              //tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
              tft.println(hrs);
            }
            break;
            case 2:
            {
              minu=now.minute();
              minu++;
              if(minu>=60)minu=0;
              Serial.print(minu);
              tft.setCursor(80, 100);
              //tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
              tft.print(minu);
             
            }
            break;
            case 3:
            {
              dy2=now.day();
              dy2++;
              if(dy>=7)dy=0;
              Serial.print(dy2);
              tft.setCursor(180, 50);
              //tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
              tft.print(dy2);
             
            }
            break;
            case 4:
            {
              yrs=now.year();
              yrs++;
              if(yrs>=9)yrs+0;
              Serial.print(yrs);
              tft.setCursor(30, 50);
              //tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
              tft.print(yrs);
             
            }
            break;
            case 5:
            {
              mnth=now.month();
              mnth++;
              if(mnth>=12)mnth=1;
              Serial.print(mnth);
              tft.setCursor(130, 50);
              //tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
              tft.print(mnth);
            }
            break;
         }
       }
    }

    if((x>=230)&&(x<=290))    //DOWN button 230, 130, 60, 50
       {
        if((y>=130)&&(y<=190))
        {
          switch(count)
          {
            case 1:
            {
              hrs=now.hour();
              hrs--;
              if(hrs>=24)hrs=0;
              Serial.print(hrs);
              tft.setCursor(30, 100);
              //tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
              tft.print(hrs);
             
            }
            break;
            case 2:
            {
              minu=now.minute();
              minu--;
              if(minu>=60)minu=0;
              Serial.print(minu);
              tft.setCursor(80, 100);
              //tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
              tft.print(minu);
             
            }
            break;
            case 3:
            {
              dy2=now.day();
              dy2--;
              if(dy2>=31)dy=0;
              Serial.print(dy2);
              tft.setCursor(180, 50);
              //tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
              tft.print(dy2);
             
            }
            break;
            case 4:
            {
              yrs=now.year();
              yrs--;
              if(yrs>=9)yrs+0;
              Serial.print(yrs);
              tft.setCursor(30, 50);
              //tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
              tft.print(yrs);
             
            }
            break;
            case 5:
            {
              mnth=now.month();
              mnth--;
              if(mnth>=12)mnth=1;
              Serial.print(mnth);
              tft.setCursor(130, 50);
              //tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
              tft.print(mnth);
             
            }
            break;
         }
       }
     }
  }

}
 

Pass6

Hello.
I would like to display on my TFT screen some data that I recorded on an SD Card. Do you have any idea how I could do it?
All the examples I saw just show how to display on a TFT screen an image record on an SD card.

Thanks

Passy

david_prentice

Go on.   Explain what data and what you want to do with it.

Reading data from an SD Card is exactly the same as any file on a PC.
You can read text or raw binary data.   Process them just like you would on a PC.

Then write text to a Serial Terminal or the TFT screen.   With exactly the same functions or methods.
Or write binary data to the TFT screen e.g. render an image

David.

Pass6

In fact I created with the help of Arduino a txt datei and inside it I wrote a word and a number. I would like to post this on my TFT Screen. Is there a command that achieves this?

Go Up