Arduino | SQL | LCD (Display)

Hi,

I try to write on the display the contents of a variable. This variable receives information from the Data Base. The problem is that I can not write the contents of the variable (rcv) on the display.

can anyone help me?

tks

Arduino_SQL.ino (2.65 KB)

If you are not getting anything at all displayed on the LCD, then try first with a minimal sketch which tests only the LCD without any other logic. If that does not work, post a wiring diagram.

OP's code

#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal.h>
 
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

byte ip[] = { 192,168,1,216};

byte servidor[] = { 192,168,1,185};

EthernetClient cliente;

float sensor1 = 0;
float sensor2 = 0;
float sensor3 = 0;

int pinSensorPIRDireita = 8;
int led = 9;
int valorSensorPIRDireita = 0;

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

String rcv=""; 
 
void setup() 
{
    // set up the LCD's number of columns and rows:
 lcd.begin(16, 2);
  // Print a message to the LCD.

lcd.print("Hello World!");
  
   Serial.begin(9600);
   Ethernet.begin(mac, ip);  
    
//    servidor.begin(); 
     pinMode(pinSensorPIRDireita,INPUT);
     pinMode(led,OUTPUT); 

} 

void httpRequest()
{
  if (cliente.connect(servidor, 8095))
  {
    //Serial.println("Connection established 1");
    cliente.print(String("GET ") + "/arduino/lerdados.php/" +"\r\n\r\n"); //GET request for server response.
    unsigned long timeout = millis();
    while (cliente.available() == 0)
    {
      if (millis() - timeout > 25000) //If nothing is available on server for 25 seconds, close the connection.
      {
        return;
      }
    }
    while(cliente.available())
    {
      String line = cliente.readStringUntil('\r'); //Read the server response line by line..
      rcv+=line; //And store it in rcv.
      
    }
    cliente.stop(); // Close the connection.
  }
  else
  {
    Serial.println("Connection failed 1");
  }
  Serial.println("Received string: ");
  Serial.println(rcv); //Display the server response.
  
   // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);
  // Print a message to the LCD.
    lcd.clear();
    lcd.setCursor(0,1);
   lcd.print("Hello");
  rcv = "";

  
}



 void loop() 
{
      
    char comando = Serial.read();
    sensor1 = 5;
    sensor2 = 10;
    sensor3 = 15;
    httpRequest();
    delay(20000);
 
    if (comando == 'a')
    {
      if(cliente.connect(servidor, 8095))
      {
        Serial.println("ligado ao servidor");
        cliente.print("GET /arduino/guardardados.php?"); 
        cliente.print("sensor1="); 
        cliente.print(sensor1); 
        cliente.print("&sensor2="); 
        cliente.print(sensor2); 
        cliente.print("&sensor3="); 
        cliente.println(sensor3);

        Serial.println("Sensor1 = ");
        Serial.println(sensor1);
        Serial.println("Sensor2 = ");
        Serial.println(sensor2);
        Serial.println("Sensor3 = ");
        Serial.println(sensor3);

       
         
         cliente.stop(); 
      }
      else
      {
        Serial.println("erro ao ligar ao servidor");
      }
     
    }
}