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