Hello Everyone,
I am a bit rusty but trying to get this code working for my project. It was originally coded for a different display using the same Arduino board I currently have. I am fairly sure the code at lines 46 & 48 are giving me the issues. Code compiles fine, only issue is getting anything to display.
I have gotten test example using different libraries to work so I know hardware/soldering is good.
- seesaw_shield18_test.ino - adafruit libs examples
Problem code:
UTFT myGLCD(ITDB32S,38,39,40,41);
ITDB02_Touch myTouch(6,5,4,3,2); ////////////////////////////////////////////////////////////////////
I know the model below is correct from the UTFT documentation but feel the numbering for the pins is incorrect and all combinations I have found do not work
UTFT myGLCD(ITDB18SP, , , ,);
Thank you ahead of time whoever may reach out to help.
Hardware:
Arduino Mega 2560
Adafruit 1.8" TFT shield, 3 button + joystick
Below is full code, warning there is some French and what not but should be irrelevent, code is otherwise working fine for anther screen.
//#include <UTFT_SdRaw.h> /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ATTENTION, Le Touch screen ne fonctionne pas avec la librairie UTOUCH et URTOUCH, il faut ITDB02_Touch
// V1.05
//Inversion de la logic capteur pour D-M9BV
// V1.04
//Passage en Long pour les cycles
// V0.03
//Ajout du capteur fin de course
//Ajout de la mérmoire EEPROM pour sauvegarder les derniers paramètres de cycles
#define VERSION "v1.05"
#include <UTFT.h>
//#include <URTouch.h> /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <EEPROM.h>
#include <ITDB02_Touch.h> /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define PINDISTRIBUTEUR 13
#define PINCAPTEUR 12
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
unsigned long LastTimer = millis();
boolean CycleEnCours=0;
boolean Distributeur=0; // 0 OFF – 1 ON
boolean Capteur =1; // 1 On continue, 0 Arret
unsigned long CycleFait =0 ;
unsigned long Cycles; // récupuré dans la mémoire
unsigned int TempsHaut; // récupuré dans la mémoire
unsigned int TempsBas; // récupuré dans la mémoire
UTFT myGLCD(ITDB32S,38,39,40,41);
//ITDB02_Touch URTouch(6,5,4,3,2); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ITDB02_Touch myTouch(6,5,4,3,2); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int x, y;
byte pageidP;
byte pageid = 10; // Remettre 10
// 5 réservé page démarrage
// 10 menu
// 20 page paramètrage
// 30 Page DCY
// 40 Page de tarage
// 120 Ouverture clavier numérique
char stCurrentNum[10]="";
byte stCurrentNumLen=0;
byte donneeClavierNum; // stock la position de la donnée en cours de modification
boolean maj = 0;
///////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////SETUP//////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
void setup()
{
SetUpEEPROM(); // a commenter apres le versement.
Cycles = EEPROMReadLong(0) ;
TempsHaut = EEPROMReadInt(4) ;
TempsBas = EEPROMReadInt(6);
pinMode(11, OUTPUT);
digitalWrite(11, HIGH);
pinMode(PINDISTRIBUTEUR, OUTPUT);
digitalWrite(PINDISTRIBUTEUR, LOW);
pinMode(PINCAPTEUR, INPUT_PULLUP); // Le capteur est à relier à la masse,The sensor must be grounded
myGLCD.InitLCD(LANDSCAPE);
myGLCD.clrScr();
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_LOW);
Serial.begin(9600);
myGLCD.setFont(BigFont);
glcdAffichage();
}
///////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////LOOP//////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
void loop()
{
if ( pageid == 30 || pageid == 40) testCapteurFinDeCourse();
if ( CycleEnCours==1 && ( (Distributeur ==0 && (long)(millis()-LastTimer) > TempsBas) || (Distributeur ==1 && (long)(millis()-LastTimer) > TempsHaut)))
{
LastTimer = millis();
fonctionDistributeur();
}
if (myTouch.dataAvailable())
{
Serial.println("ActionTouchPad();");
actionTouchPad();
delay(200);
}
}
///////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////FONCTIONS////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
void testCapteurFinDeCourse()
{
Capteur = digitalRead (PINCAPTEUR);
Capteur = !Capteur;
myGLCD.printNumI(Capteur,CENTER,90+25);
if ( CycleEnCours == 0) return; // Si tout va bien, on ne fait rien, if all goes well, we do nothing
if ( Capteur == 1) return; // Si tout va bien, on ne fait rien, Si tout va bien, on ne fait rien
CycleEnCours = 0;
Distributeur = 0;
digitalWrite(PINDISTRIBUTEUR, Distributeur) ;
boutonString(5, 5, 310,29, "ESSAI INTERROMPU" , 45,6, 255, 255, 255,1); // En rouge
boutonString(10, 200, 153,29, "PRECEDENT" , 6,6, 255, 255, 255,1); // Bouton PRECEDENT
myGLCD.printNumI(Distributeur,CENTER,40+25);
}
void fonctionDistributeur()
{
Distributeur = ! Distributeur;
digitalWrite(PINDISTRIBUTEUR, Distributeur) ;
if (Distributeur == 1)
{
CycleFait++;
myGLCD.printNumI(CycleFait,90,150);
if (CycleFait==Cycles)
{
CycleEnCours = 0;
Distributeur = 0;
digitalWrite(PINDISTRIBUTEUR, Distributeur) ;
boutonString(5, 5, 310,29, "ESSAI TERMINE" , 45,6, 255, 0, 0,1); // En rouge
boutonString(10, 200, 153,29, "PRECEDENT" , 6,6, 255, 255, 255,1); // Bouton PRECEDENT
}
}
myGLCD.printNumI(Distributeur,CENTER,40+25);
}
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////EEPROM//////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
void SetUpEEPROM()
{
EEPROMWriteLong(0, 123456789); //Cycle
EEPROMWriteInt(4, 500); //TempsHaut
EEPROMWriteInt(6, 500); //TempsBas
}
//This function will write a 2 byte integer to the eeprom at the specified address and address + 1
void EEPROMWriteInt(int p_address, int p_value)
{
byte lowByte = ((p_value >> 0) & 0xFF);
byte highByte = ((p_value >> 8) & 0xFF);
EEPROM.write(p_address, lowByte);
EEPROM.write(p_address + 1, highByte);
}
//This function will read a 2 byte integer from the eeprom at the specified address and address + 1
unsigned int EEPROMReadInt(int p_address)
{
byte lowByte = EEPROM.read(p_address);
byte highByte = EEPROM.read(p_address + 1);
return ((lowByte << 0) & 0xFF) + ((highByte << 8) & 0xFF00);
}
//This function will read a 4 byte integer from the eeprom at the specified address and address + 3
void EEPROMWriteLong(int address, long value)
{
byte four = (value & 0xFF);
byte three = ((value >> 8) & 0xFF);
byte two = ((value >> 16) & 0xFF);
byte one = ((value >> 24) & 0xFF);
EEPROM.write(address, four);
EEPROM.write(address + 1, three);
EEPROM.write(address + 2, two);
EEPROM.write(address + 3, one);
}
//Read the 4 bytes from the eeprom memory.
long EEPROMReadLong(long address)
{
long four = EEPROM.read(address);
long three = EEPROM.read(address + 1);
long two = EEPROM.read(address + 2);
long one = EEPROM.read(address + 3);
return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF);
}
///////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////AFFICHAGE////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
void glcdAffichage() //redessine la page complète, efface les données
{
//Page 10. Page Menu
if(pageid==10)
{
myGLCD.fillScr(100, 200, 230); // bleuté
myGLCD.setColor(0,0, 0); // noir
myGLCD.setBackColor(100, 200, 230); // sur bleuté
myGLCD.print("Menu",CENTER,12);
boutonString(50, 50, 200,29, "Tarage Verin" , 6,6, 255, 255, 255,1); // Bouton Tarage Vérin
boutonString(50, 100, 200,29, "Test Cycles" , 6,6, 255, 255, 255,1); // Bouton Tarage Vérin
myGLCD.print(VERSION, 225, 215);
}
//Page 20. Paramétrage du cycle
if(pageid==20)
{
myGLCD.fillScr(100, 200, 230); // bleuté
myGLCD.setColor(0,0, 0); // noir
myGLCD.setBackColor(100, 200, 230); // sur bleuté
myGLCD.print("Parametrage Cycle",CENTER,12);
myGLCD.printNumI(Cycles,170,50);
myGLCD.printNumI(TempsHaut,200,75);
myGLCD.printNumI(TempsBas,200,100);
myGLCD.print("ms",270,75);
myGLCD.print("ms",270,100);
myGLCD.print("ms",270,135);
myGLCD.print("Duree cycle:",5,135);
myGLCD.print("Duree essai:",5,160);
myGLCD.printNumI(TempsBas+TempsHaut,200,135);
boutonString(8, 48, 150,20, "Nb Cycles" , 10,4, 255, 255, 255,0); // Bouton CYCLES
boutonString(8, 73, 150,20, "Duree Haute" , 10,4, 255, 255, 255,0); // Bouton TEMPS HAUT
boutonString(8, 98, 150,20, "Duree Basse" , 10,4, 255, 255, 255,0); // Bouton TEMPS BAS
boutonString(180, 200, 122,29, "SUIVANT" , 6,6, 255, 255, 255,1); // Bouton SUIVANT
boutonString(10, 200, 153,29, "PRECEDENT" , 6,6, 255, 255, 255,1); // Bouton PRECEDENT
unsigned long reste = Cycles*((TempsBas+TempsHaut)/1000.0);
if ( reste < 3600 )
{
int Minutes = reste/60;
if (Minutes >=60) Minutes =59;
myGLCD.printNumI(Minutes,200,160);
myGLCD.print("M",240,160);
}
else if ( reste >=3600 && reste < 86400)
{
int Heure = reste/3600;
myGLCD.printNumI(Heure,200,160);
myGLCD.print("H",235,160);
}
else
{
int Jour = reste/86400;
myGLCD.printNumI(Jour,200,160);
myGLCD.print("J",290,160);
}
delay(500); // pour eviter de rentre trop vite dans la saisie
}
//Page 30. DCY
else if(pageid==30) // Page test
{
myGLCD.fillScr(100, 200, 230); // bleuté
myGLCD.setColor(0,0, 0); // noir
myGLCD.setBackColor(100, 200, 230); // sur bleuté
boutonString(5, 5, 310,29, "Depart/Reprise" , 30,6, 255, 255, 255,1); // Bouton Depart
myGLCD.printNumI(0,90,150);
myGLCD.print("/",90,150+25);
myGLCD.printNumI(Cycles,110,150+25);
myGLCD.print("Etat distributeur",CENTER,40);
myGLCD.printNumI(Distributeur,CENTER,40+25);
myGLCD.print("Etat Capteur",CENTER,90);
myGLCD.printNumI(Capteur,CENTER,90+25);
boutonString(10, 200, 153,29, "PRECEDENT" , 6,6, 255, 255, 255,1); // Bouton PRECEDENT
}
//Page 40. Page Tarage
else if(pageid==40)
{
myGLCD.fillScr(100, 200, 230); // bleuté
myGLCD.setColor(0,0, 0); // noir
myGLCD.setBackColor(100, 200, 230); // sur bleuté
boutonString(5, 5, 310,29, "OFF" , 140,6, 255, 255, 255,1); // Bouton OFF
myGLCD.print("Etat distributeur",CENTER,40);
myGLCD.printNumI(Distributeur,CENTER,40+25);
myGLCD.print("Etat Capteur",CENTER,90);
myGLCD.printNumI(Capteur,CENTER,90+25);
boutonString(10, 200, 153,29, "PRECEDENT" , 6,6, 255, 255, 255,1); // Bouton PRECEDENT
}
//120. Clavier numérique
else if(pageid==120)
{
boutonString(35, 25, 250,200, "" , 20,20, 255, 255, 255,0);
boutonString(40, 30, 240,40, "" , 5,5, 100, 200, 230,0);
myGLCD.setFont(SmallFont);
exempleNum();
myGLCD.setFont(BigFont);
for ( byte i = 0; i<5 ; i++)
for ( byte y = 0; y <2 ; y++) boutonString(40+i*50, 80+50*y,40,40, String(i+5*y),11,11, 100, 200, 230,1);
boutonString(40, 180, 90,40, "" , 11,11, 100, 200, 230,1);
boutonString(140, 180, 40,40, "C" , 11,11, 255, 127, 39,1);
boutonString(190, 180, 40,40, "A", 11,11, 255, 0, 0,1);
boutonString(240, 180, 40,40, "V", 11,11, 0, 255, 0,1);
}
}
///////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////TOUCH PAD////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
void actionTouchPad() //Actions liées au TouchPad
{
//while (myTouch.dataAvailable())
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
Serial.print("x : ");
Serial.print(x);
Serial.print(" y : ");
Serial.println(y);
//Page 10. Menu
if ( pageid == 10 && x>=50 && y>=50 && x<=250 && y<=79) // Bouton Tarage Vérin
{
AttenteSurCadre(50, 50, 250, 79);
pageid=40;
glcdAffichage();
}
if ( pageid == 10 && x>=50 && y>=100 && x<=250 && y<=129) // Bouton Test Cycles
{
AttenteSurCadre(50, 50, 250, 79);
pageid=20;
glcdAffichage();
}
//Page 20. Paramétrage du cycle
if ( pageid == 20 && x>=180 && y>=200 && x<=302 && y<=229) // Bouton SUIVANT
{
AttenteSurCadre(180, 200, 302, 229);
pageid=30;
glcdAffichage();
}
else if ( pageid == 20 && x>=10 && y>=200 && x<=163 && y<=229)//Bouton PRECEDENT
{
AttenteSurCadre(10, 200, 163, 229);
pageid=10;
glcdAffichage();
}
else if ( pageid == 20 && x>=8 && y>=48 && x<=158 && y<=68) // Bouton CYCLES
{
AttenteSurCadre(8, 48, 158, 68);
donneeClavierNum=0;
pageidP=pageid;
pageid=120;
glcdAffichage();
}
else if ( pageid == 20 && x>=8 && y>=73 && x<=158 && y<=93) // TEMPS HAUT
{
AttenteSurCadre(8, 73, 158, 93);
donneeClavierNum=1;
pageidP=pageid;
pageid=120;
glcdAffichage();
}
else if ( pageid == 20 && x>=8 && y>=98 && x<=158 && y<=118) // TEMPS BAS
{
AttenteSurCadre(8, 98, 158, 118);
donneeClavierNum=2;
pageidP=pageid;
pageid=120;
glcdAffichage();
}
//Page 30. DCY
else if ( pageid == 30 && CycleEnCours==0 && x>=10 && y>=200 && x<=163 && y<=229)//Bouton PRECEDENT
{
AttenteSurCadre(10, 200, 163, 229);
pageid=20;
CycleFait=0;
Distributeur=0;
digitalWrite(PINDISTRIBUTEUR, Distributeur) ;
glcdAffichage();
}
else if ( pageid == 30 && CycleEnCours==0 && Cycles!=CycleFait && x>=5 && y>=5 && x<=315 && y<=34)// Bouton START
{
AttenteSurCadre(5, 5, 315, 34);
boutonString(5, 5, 310,29, "Cycle en cours..." , 30,6, 255, 255, 255,1);
boutonString(10, 200, 153,29, "PRECEDENT" , 6,6, 255, 0, 0,1);
if (Cycles != CycleFait) CycleEnCours =1;
delay(800);
}
else if ( pageid == 30 && CycleEnCours==1 && x>=5 && y>=5 && x<=315 && y<=34)// Bouton STOP
{
AttenteSurCadre(5, 5, 315, 34);
boutonString(5, 5, 310,29, "Depart/Reprise" , 30,6, 255, 255, 255,1);
boutonString(10, 200, 153,29, "PRECEDENT" , 6,6, 255, 255, 255,1);
CycleEnCours =0;
}
//Page 40. Tarage Vérin
else if ( pageid == 40 && x>=10 && y>=200 && x<=163 && y<=229)//Bouton PRECEDENT
{
AttenteSurCadre(10, 200, 163, 229);
pageid=10;
Distributeur=0;
digitalWrite(PINDISTRIBUTEUR, Distributeur) ;
glcdAffichage();
}
else if ( pageid == 40 && x>=5 && y>=5 && x<=315 && y<=34)//Bouton ON/OFF
{
AttenteSurCadre(5, 5, 315, 34);
Distributeur=!Distributeur;
digitalWrite(PINDISTRIBUTEUR, Distributeur) ;
myGLCD.printNumI(Distributeur,CENTER,40+25);
if (Distributeur==0) boutonString(5, 5, 310,29, "OFF" , 140,6, 255, 255, 255,1); // Bouton OFF
else boutonString(5, 5, 310,29, "ON" , 140,6, 255, 255, 255,1); // Bouton ON
}
//120. Clavier numérique
else if ( pageid==120 && x>=240 && y>=180 && x<=280 && y<=220) // sortie avec sauvegarde
{
AttenteSurCadre(240, 180, 280, 220);
recupNombre();
pageid=pageidP;
glcdAffichage();
}
else if ( pageid==120 && x>=190 && y>=180 && x<=230 && y<=220) // sortie sans sauvegarde
{
AttenteSurCadre(190, 180, 230, 220);
initCurrentNum();
pageid=pageidP;
glcdAffichage();
}
else if ( pageid==120 && x>=140 && y>=180 && x<=180 && y<=220) // bouton correction
{
AttenteSurCadre(140, 180, 180, 220);
initCurrentNum();
myGLCD.setFont(SmallFont);
myGLCD.print(" ", 48, 195);
myGLCD.setFont(BigFont);
}
else if ( pageid==120 && x>=40 && y>=80 && x<=80 && y<=120) // bouton 0
{
AttenteSurCadre(40, 80, 80, 120);
updateStrNum('0');
}
else if ( pageid==120 && x>=90 && y>=80 && x<=130 && y<=120) // bouton 1
{
AttenteSurCadre(90, 80, 130, 120);
updateStrNum('1');
}
else if ( pageid==120 && x>=140 && y>=80 && x<=180 && y<=120) // bouton 2
{
AttenteSurCadre(140, 80, 180, 120);
updateStrNum('2');
}
else if ( pageid==120 && x>=190 && y>=80 && x<=230 && y<=120) // bouton 3
{
AttenteSurCadre(190, 80, 230, 120);
updateStrNum('3');
}
else if ( pageid==120 && x>=240 && y>=80 && x<=280 && y<=120) // bouton 4
{
AttenteSurCadre(240, 80, 280, 120);
updateStrNum('4');
}
else if ( pageid==120 && x>=40 && y>=130 && x<=80 && y<=170) // bouton 5
{
AttenteSurCadre(40, 130, 80, 170);
updateStrNum('5');
}
else if ( pageid==120 && x>=90 && y>=130 && x<=130 && y<=170) // bouton 6
{
AttenteSurCadre(90, 130, 130, 170);
updateStrNum('6');
}
else if ( pageid==120 && x>=140 && y>=130 && x<=180 && y<=170) // bouton 7
{
AttenteSurCadre(140, 130, 180, 170);
updateStrNum('7');
}
else if ( pageid==120 && x>=190 && y>=130 && x<=230 && y<=170) // bouton 8
{
AttenteSurCadre(190, 130, 230, 170);
updateStrNum('8');
}
else if ( pageid==120 && x>=240 && y>=130 && x<=280 && y<=170) // bouton 9
{
AttenteSurCadre(240, 130, 280, 170);
updateStrNum('9');
}
// else
// {
while (myTouch.dataAvailable())
myTouch.read();
delay(50);
// }
}
///////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////GRAPHISME////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
// Dessine un cadre rouge tant qu'une touche n'est pas relachée, permet de vider le buffer du pad
//Draws a red frame as long as a key is not released, allows to empty the pad buffer999
void AttenteSurCadre(int x1, int y1, int x2, int y2)
{
myGLCD.setColor(255, 0, 0); //rouge
myGLCD.drawRoundRect (x1, y1, x2, y2);
while (myTouch.dataAvailable())
myTouch.read();
delay(10);
myGLCD.setColor(0, 0, 0); //noir
myGLCD.drawRoundRect (x1, y1, x2, y2);
}
void boutonString(int x, int y, int Lo, int la, String c, int xx, int yy, byte R, byte G, byte B, boolean Gras)
{
myGLCD.setColor(R, G, B);
myGLCD.setBackColor(R, G, B);
myGLCD.fillRoundRect (x,y, x+Lo , y+la);
myGLCD.setColor(0, 0, 0); //noir
if(Gras==0) myGLCD.setFont(SmallFont);
myGLCD.print(c,x+xx,y+yy);
myGLCD.setFont(BigFont);
myGLCD.drawRoundRect (x,y, x+Lo , y+la);
myGLCD.setBackColor(100, 200, 230); //bleuté
}
//AFFICHE ET STOCKE LA VALEUR EN COURS DE FRAPPE
void updateStrNum(int val)
{
if (stCurrentNumLen<9)
{
stCurrentNum[stCurrentNumLen]=val;
stCurrentNumLen++;
stCurrentNum[stCurrentNumLen]='\0';
myGLCD.setFont(SmallFont);
myGLCD.print(" ", 48, 195);
myGLCD.print(stCurrentNum, 48, 195);
myGLCD.setFont(BigFont);
}
}
void initCurrentNum()
{
stCurrentNum[0]='\0';
stCurrentNumLen=0;
}
//RECUPERE LA VALEUR DANS LE CLAVIER NUMERIQUE
void recupNombre()
{
if (stCurrentNumLen==0) return; // Le buffer est vide
unsigned long n = atol(stCurrentNum);
initCurrentNum();
switch (donneeClavierNum)
{
case 0: // NOMBRE DE CYCLE
if ( n==0) n=1;
if ( n>=1000000000) n=999999999; // <1 milliard
Cycles = n;
EEPROMWriteLong(0, Cycles);
Serial.println(Cycles);
break;
case 1: // DUREE HAUTE
if ( n==0) n=1;
if ( n>=10000) n = 9999;
TempsHaut= (int)n ;
EEPROMWriteInt(4, TempsHaut);
Serial.println(TempsHaut);
break;
case 2: // DUREE BASSE
if ( n==0) n=1;
if ( n>=10000) n = 9999;
TempsBas = (int)n;
EEPROMWriteInt(6, TempsBas);
Serial.println(TempsBas);
break;
}
}
void exempleNum()
{
switch (donneeClavierNum)
{
case 0:
myGLCD.print("Nombre de cycles < milliard",CENTER,36);
break;
case 1:
myGLCD.print("Duree Haute en ms(1-9999)",CENTER,36);
myGLCD.print("Ex : pour 2,5s, taper 2500",CENTER,51);
break;
case 2:
myGLCD.print("Duree Basse en ms(1-9999)",CENTER,36);
myGLCD.print("Ex : pour 2,5s, taper 2500",CENTER,51);
break;
}
}```