[SOLVED] Use Blynk with tft lcd

I’m having trouble setting up the Arduino mega 2560 with a 2.4 display mcufriend .
everything working . but when I set the code blynk, and the turn white TFT .

can someone give me a hand ?
sorry my english is very bad.
king regards
rafael avila

Maybe smth is with your code? Could you share it?

thanks for your contact.
I 'm not a programmer, this code is a unification of several other tutorials over the internet .
I’m a enthusiast of arduino, im just need bulding up something interesting and useful to my house .

HARDWARE
Arduino Mega 2560
Ethershield w5100
LCD TFT MCUFRIEND 2.4

WIRING
ETHERSHIELD - MEGA
from ICSP to ICSP header with common pin arrangement, and 10 to pin 10

LCD - MEGA


below the code

//#include <Adafruit_GFX.h>    // Libreria de graficos
#include <Adafruit_TFTLCD.h> // Libreria de LCD 
#include <TouchScreen.h>     // Libreria del panel tactil
#include "Wire.h"
#include <DHT.h> //Carrega a biblioteca DHT
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h> // This part is for Ethernet stuff

char auth[] = "580fecd5cdba49778da2c48b72884909"; // Put your Auth Token here. (see Step 3 above)

int X; // Variáveis que armazenam as coordenadas
int Y; // X, Y, onde nós pressionamos e variável Z
int Z; // armazenará a pressão realizada

#define YP A1 // Y+ is on Analog1
#define XM A2 // X- is on Analog2
#define YM 7 // Y- is on Digital7
#define XP 6 // X+ is on Digital6

#define DHTPIN A5 //Define a ligação ao pino de dados do sensor
#define DHTTYPE DHT11 //Define o tipo de sensor DHT utilizado
DHT dht(DHTPIN, DHTTYPE);
 int thisChar = 'a';

#define Botao1 47
#define Botao2 49
#define Botao3 45
#define Botao4 53
 
#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940
 
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 330);
 
//Definicao de cores
#define BLACK           0x0000
#define BLUE            0x001F
#define RED             0xF800
#define GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0
#define WHITE           0xFFFF

#define LCD_CS A3   // Definição dos Pinos do LCD
#define LCD_CD A2   // para poder visualizar elementos graficos
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); // Instancia LCD 

 
// Armazena o estado dos botões
bool valor_botao1 = 0;
bool valor_botao2 = 0;
bool valor_botao3 = 0;
bool valor_botao4 = 0;
 
#define MINPRESSURE 1
#define MAXPRESSURE 1000
 
void setup(void) 
{
  Serial.begin(9600);
  Blynk.begin(auth);  // Here your Arduino connects to the Blynk Cloud.
  Wire.begin();
  dht.begin();
  int X, Y, W = tft.width(), h = tft.height();
  Serial.println("TFT Test");
  delay(100);
 
  tft.begin(0x7575); // Iniciamos o LCD especificando 0 controlador ILI7575.
  Serial.print("Driver encontrado: ");
  tft.fillScreen(BLACK);
  tft.setRotation(3);

 // (valor 1, valor 2, valor 3, valor 4, valor5)
    // valor 1 movimenta o desenho nos sentidos direita esquerda / esquerda direita
    // valor 2 linha em que o objeto esta sendo desenhado
    // valor 3 tamanho do objeto desenhado na horizontal
 
    //desenha o retangulo maior de texto
      tft.drawRoundRect(119, 15, 198, 50, 5, WHITE);
    //desenha o retangulo pequeno on/off
      tft.drawRoundRect(255, 15, 62, 50, 5, WHITE);
    
    // define a cor do texto e tamanho
       tft.setTextColor(GREEN);
       tft.setTextSize(3);
  
  // valor 1, valor 2
  // valor 1 define a coluna inicial do texto
     tft.setCursor(125, 30);
     tft.println("Sala");
 
  tft.drawRoundRect(119, 70, 198, 50, 5, WHITE);
  tft.drawRoundRect(255, 70, 62, 50, 5, WHITE);
  tft.setTextColor(MAGENTA);
  tft.setTextSize(3);
  tft.setCursor(125, 85);
  tft.println("Varanda");
 
  tft.drawRoundRect(119, 125, 198, 50, 5, WHITE);
  tft.drawRoundRect(255, 125, 62, 50, 5, WHITE);
  tft.setTextColor(MAGENTA);
  tft.setTextSize(3);
  tft.setCursor(125, 140);
  tft.println("Garagem");
 
  tft.drawRoundRect(119, 180, 198, 50, 5, WHITE);
  tft.drawRoundRect(255, 180, 62, 50, 5, WHITE);
  tft.setTextColor(RED);
  tft.setTextSize(3);
  tft.setCursor(125, 195);
  tft.println("Tomada");
 
 pinMode(13, OUTPUT);
 pinMode(Botao1, OUTPUT);
 pinMode(Botao2, OUTPUT);
 pinMode(Botao3, OUTPUT);
 pinMode(Botao4, OUTPUT); // ANODO DO LED

 digitalWrite(Botao1, HIGH); 
 digitalWrite(Botao2, HIGH); 
 digitalWrite(Botao3, HIGH); 
 digitalWrite(Botao4, HIGH); 
 
  //Preenchimento OFF
  tft.setTextColor(WHITE);
  tft.setCursor(260, 30);
  tft.println("OFF");
  tft.setCursor(260, 85);
  tft.println("OFF");
  tft.setCursor(260, 140);
  tft.println("OFF");
  tft.setCursor(260, 195);
  tft.println("OFF");
 
}

void loop()
{
  Blynk.run(); // All the Blynk Magic happens here...
  TSPoint p = ts.getPoint();
  pinMode(XM, OUTPUT);
  digitalWrite(XM, LOW);
  pinMode(YP, OUTPUT);
  digitalWrite(YP, HIGH);
  pinMode(YM, OUTPUT);
  digitalWrite(YM, LOW);
  pinMode(XP, OUTPUT);
  digitalWrite(XP, HIGH);
 
  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));
    if (p.y > 200)
    {
      Serial.print("py: ");
      Serial.print(p.y);
      Serial.print(" px: ");
      Serial.print(p.x);
 
      
      //Testa botao amarelo
      if (p.x > 235 & p.x < 295)
      {
        if (valor_botao1 == 0)
        {
          tft.fillRoundRect(256, 16, 60, 48, 5, GREEN);
          tft.setTextSize(3);
          mostra_on(269, 30);
          valor_botao1 = !valor_botao1;
          digitalWrite(Botao1, LOW);
        }
        else
        {
          tft.fillRoundRect(256, 16, 60, 48, 5, RED);
          tft.setTextSize(3);
          mostra_off(260, 30);
          valor_botao1 = !valor_botao1;
          digitalWrite(Botao1, HIGH);
        }
      }
 
      //Testa botao verde
      if (p.x > 160 & p.x < 198)
      {
        if (valor_botao2 == 0)
        {
          tft.fillRoundRect(256, 71, 60, 48, 5, GREEN);
          tft.setTextSize(3);
          mostra_on(269, 85);
          valor_botao2 = !valor_botao2;
          digitalWrite(Botao2, LOW);
        }
        else
        {
          tft.fillRoundRect(256, 71, 60, 48, 5,  RED);
          tft.setTextSize(3);
          mostra_off(260, 85);
          valor_botao2 = !valor_botao2;
          digitalWrite(Botao2, HIGH);
 
        }
      }
 
      //Testa botao azul
      if (p.x > 65 & p.x < 126)
      {
        if (valor_botao3 == 0)
        {
          tft.fillRoundRect(256, 126, 60, 48, 5, GREEN);
          tft.setTextSize(3);
          mostra_on(269, 140);
          valor_botao3 = !valor_botao3;
          digitalWrite(Botao3, LOW);
        }
        else
        {
          tft.fillRoundRect(256, 126, 60, 48, 5,  RED);
          tft.setTextSize(3);
          mostra_off(260, 140);
          valor_botao3 = !valor_botao3;
          digitalWrite(Botao3, HIGH);
        }
      }
 
      //Testa botao vermelho
      if (p.x > 0 & p.x < 58)
      {
        if (valor_botao4 == 0)
        {
          tft.fillRoundRect(256, 181, 60, 48, 5, GREEN);
          tft.setTextSize(3);
          mostra_on(269,195);
          valor_botao4 = !valor_botao4;
          digitalWrite(Botao4, LOW);
        }
        else
        {
          tft.fillRoundRect(256, 181, 60, 48, 5,  RED);
          tft.setTextSize(3);
          mostra_off(260,195);
          valor_botao4 = !valor_botao4;
          digitalWrite(Botao4, HIGH);
        }
       

      }
    }
  }
}

 
void mostra_on(int x, int y)
{
  tft.setTextColor(BLACK);
  tft.setCursor(x, y);
  tft.println("ON");
  delay(100);
}
 
void mostra_off(int x, int y)
{
  tft.setTextColor(WHITE);
  tft.setCursor(x, y);
  tft.println("OFF");
  delay(90);

delay(100);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
float hi = dht.computeHeatIndex(f, h);

tft.setTextColor(WHITE);
    tft.setTextSize(2);
    tft.setCursor(4,2); 
      tft.print("Humidade"); 
      tft.setCursor(4,32);
      tft.print(h);
      delay(100);
      tft.println("%");
      tft.setCursor(4,90); 
      tft.print("Temp"); 
      tft.setCursor(4,120); 
      tft.print(t);
      delay(100);
      tft.println("C ");
      tft.setCursor(4,190); 
      tft.println("Termica");
      tft.setCursor(4,220);  
      hi=(hi-32)*0.56;
      tft.print(hi);
      delay(100);
      tft.println("C"); 
}

I see you have most of your things setup in the void loop(). This is not recommended. It’s better to use timers and leave the loop alone as much as possible.

But what I think your main problem is that LCD and Ethernet both use SPI bus and there is a pin conflict somewhere. I vaguely seem to remember I encountered something similar with a 2.4" SPI LCD screen too.

1 Like

Tanks Lichsignaal.

but the problem only occurs when I change the commented line

//Blynk.run(); // All the Blynk Magic happens here…

if i comment this line every things works fine.

i need to learn more about the language C and timmers because im not a programmer.

Tanks for your reply.
Best Regards
Rafael Avila

I think it’s because Blynk addresses the network interface and that probably sets the CS pin to HIGH but the problem, I think, is in that the Ethernet and TFT use the same CS pin, which will not work. Is it maybe possible to put the CS ping from the two devices on two separate pins?

Maybe change the code on blinkethernet work or the code on Adafruit_TFTLCD.
But this is much for me.

following the Arduino configuration SPI - Arduino Reference
the pinout used at the interfaces of my settings are not on the same pin . on Arduino Mega the icsp pinout is:

Mega2560
51 or ICSP-4
50 or ICSP-1
52 or ICSP-3
53

How exactly have you wired things up? I’m having a hard time picturing the image, can you make a photo of your total setup? I think the ICSP pins are the same as the “regular” I/O pins. The most important thing is to have al the CS pins on different pins. Is that the case?

I use a similar display and found that it uses A4 - Adafruit uses that to init the display - so in my case I could not use i2c. I moved it to D10 and abandoned the SD card.

Tonight, I send photos of my system. thank you

Sunspot simple change the pin A4 to A10 ? i dont use the sdcard reader. all pins off. change only the line :
#define LCD_RESET A4 to#define LCD_RESET A10`
?

Thanks
Rafael Avila

Yes I did -

#define LCD_RESET A4

to

#define LCD_RESET A10
and clipped off the A4 A5 pins on the LCD and ran a wire from the LCD_RESET pin on the LCD (A4) to the A10 pin on the other edge (it goes to the SD socket)

Certainly Ada fruit SW does use the A4 pin. But I did this for i2c that needs A4 and A5 - I am not sure that you need A4 in your system?

(edit - why the big font . . .sorry?)

This is the wiring pinout, i change on the code the pin A4 to A10 and dont work.
All functions working.
after uncomment the line //Blynk.run(); the TFT turn White.

pinout LCD TFT MCUFRIEND
LCD_D2 --> MEGA D2
LCD_D3 --> MEGA D3
LCD_D4 --> MEGA D4
LCD_D5 --> MEGA D5
LCD_D6 --> MEGA D6
LCD_D7 --> MEGA D7
LCD_D8 --> MEGA D8
LCD_D9 --> MEGA D9
LCD_RST --> MEGA A4
LCD_CS --> MEGA A3
LCD_RS --> MEGA A2
LCD_WR --> MEGA A1
LCD_RD --> MEGA A0
GND --> MEGA GND
5V --> MEGA 5V
3V --> MEGA 3V

Pinout W5100
ICSP 1 --> MEGA D50/MISO
ICSP 2 --> MEGA Vcc
ICSP 3 --> MEGA D52/SCK
ICSP 4 --> MEGA D51/MOSI
ICSP 5 --> MEGA D53
ICSP 6 --> MEGA Gnd
pin 10 --> MEGA D10

Some Pictures:




thanks for the help, good weekend to all

No Problem sunspot, tanks :smile:
not working change the pin A4 to A10 .

Yes Lichtsignaal, all CSs is in different Pins.
I Post pictures and a full wiring setup.
Tanks for the help.

guys already works! only changed the pin A4 to RESET and now working !
first step its ok!
Now 2 round! DTH11 and Clock.

thanks to all !