Groove lcd module clash with my code

problem: i coded a programme to get data from sql, so when its connected it will keep on fetching the data from sql like the screen shot below.
Screenshot 2021-08-02 at 2.38.17 AM

but when i added the headers for the lcd light


#include <math.h>
#include <Ethernet.h>
#include <PubSubClient.h>
#include <Wire.h>
#include "rgb_lcd.h"

and this is what i get..

Screenshot 2021-08-02 at 2.40.07 AM

it only fetch it correctly once after that the whole thing either random letters.

my full code..

#include <math.h>
#include <Ethernet.h>
#include <PubSubClient.h>
#include <Wire.h>
#include "rgb_lcd.h"
//server
byte mac[]    = {  0xA8, 0x61, 0x0A, 0xAE, 0x2E, 0x03 };   //pls change to your arduino MAC, refer to the sticker on the side
IPAddress server(192, 168, 10, 122);   //change to the php server ip      
EthernetClient client;
//preset if statement 
int reading = LOW;
int state = HIGH;
int previous = LOW;
int buttonPin = 2;
int stateTime = 0;
int debounce = 100;
int buzz=4;
int light=3;
String status1;
String temperature;
void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(buzz, OUTPUT);
  pinMode(light, OUTPUT);
  Serial.begin(9600);
  Serial.println("Read data from database");
  Ethernet.begin(mac); 
  delay(1500); //wait for connection
      
  //print connection detail 
  Serial.print("Arduino IP Address        : ");   //ip
  Serial.println(Ethernet.localIP());   
  Serial.print("Subnet Mask       : ");
  Serial.println(Ethernet.subnetMask());
}
void loop() {
  // read the pushbutton input pin
  reading = digitalRead(buttonPin);

  // determine if the button is pressed with debounce
  if (reading == HIGH && previous == LOW && (millis() - stateTime) > debounce)
  {
    Serial.println("Button PUSHED");
    if (state == HIGH)
    {
      state = LOW;
      Serial.println("Status changed to LOW");
      
      delay(2000);
    }
    else {
      state = HIGH;
      Serial.println("Status changed to HIGH");
      delay(1000);
      digitalWrite(light, LOW);
      digitalWrite(buzz, LOW);
    }
    stateTime = millis();
  }
  if (state == LOW & client.connect(server, 80))
  {
     read_arduinodata();
   if (status1=="1")
   {
    digitalWrite(buzz, HIGH);
   }
   else
   {
    digitalWrite(buzz, LOW);
   }
   if (temperature=="1")
   {
    digitalWrite(light, HIGH);
   }
   else
   {
    digitalWrite(light, LOW);
   }
  }
  // update previous button state reading
  previous = reading;
}
void read_arduinodata(){  
  if (client.connect(server, 80))
  {
    Serial.println("-> Connected");
    Serial.println("Reading");
    client.print("GET http://localhost/test.php");   //change based on the server ip
    client.println( " HTTP/1.1");
    client.print( "Host: " );
    client.println( "Connection: close" );
    client.println();
    String receive = client.readString();   
    //Serial.println(receive); //activate this line to see the actual text you receive
    //Serial.println(receive.length()); //activate this line to see the length of text you receive
    status1=receive.substring(receive.length()-93,receive.length()-94);
    temperature=receive.substring(receive.length()-36,receive.length()-37);
    Serial.print("coolant:");
    Serial.println(status1);
    Serial.print("temperature:");
    Serial.print(temperature);
    client.println();
  }
}

hoping someone can tell me whats wrong with it, it my school project due on 2 more days
everything works except the lcd modules, if any mistake pls do tell me so i can learn from the mistake i made.

THANK YOU FOR SPENDING TIME TO READ THIS POST !

Im a newbie still learning

Can you uncomment the serial prints in read_arduinodata and post print out again?

So your very first request has a complete return, ending with extra new line after the html. Your second request that has wrong coolant and temperature return values are incomplete and you should see it's too short to have those values. The way you're receiving data is wrong. You should have some way to ensure that all data have been received. HTTP is a pipe like serial port. You either keep reading until the connection is closed by server, or you read, extract the Content-length header value, then count the returned content, without header, until you get every byte. You also did client.connect() twice, once in main function and another time in read_arduinodata(). I don't think that is right. Also you didn't close any of the connections. I'm not familiar with arduino wifi client (not anymore) so please read some basic examples provided by arduino.cc, try to understand the workflow of using arduino wifi client and update your code.

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.