Unable to print to the LCD from Void Loop - Help please

Hi
I’m trying to build Reef controller for my Aquarium
I have some problem with my LCD , i can’t print from void loop :-/
Hope someone here will help me to solve it
Thank you :slight_smile:

#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
#include <LiquidCrystal.h>
#include <OneWire.h>

OneWire ds(10); // on pin 10
int Pump1 = 30;
int Pump2 = 32;
int Pump3 = 34;
int Pump4 = 36;
int Pump5 = 38;
int Pump6 = 40;
int Pump7 = 42;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

const int ledPin = 8;
//const int floatSwitch = 9;
const int pump8 = 10;
//int floatStatecounter = 0;
//int buttonState = 0;
//long lastButtonState = 0;
//long failSafe = 5000;

int Emergency_switch = 11; //Will close the pump in case of over load
int TopSwitch = 10;//The max water level
int Button_Switch = 9;//The min water level

void setup() {

Wire.begin(); //initialize the I2C bus
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0,0);
//Print a message to the LCD.
lcd.print(“Reef Controller”);
delay(3000);
lcd.setCursor(0,1);
lcd.print(“test”);
delay(5000);

pinMode(ledPin, OUTPUT);
pinMode(Emergency_switch, INPUT);
pinMode(TopSwitch, INPUT);
pinMode(Button_Switch, INPUT);
pinMode(pump8, OUTPUT);

pinMode(Pump1, OUTPUT);
pinMode(Pump2, OUTPUT);
pinMode(Pump3, OUTPUT);
pinMode(Pump4, OUTPUT);
pinMode(Pump5, OUTPUT);
pinMode(Pump6, OUTPUT);
pinMode(Pump7, OUTPUT);

Serial.begin(9600);
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus()!= timeSet)
Serial.println(“Unable to sync with the RTC”);
else
Serial.println(“RTC has set the system time”);
}

void loop()
{
Pumps();
Temp();
ATO();
}
//DOISING SYSTEM**********
void Pumps(){

if(weekday()==1&&hour()==19&&minute()==19&&second()<3){
digitalWrite(Pump1,HIGH);//Day1 8:00
lcd.clear();
lcd.setCursor(0,1);
lcd.print(“Puamp1 is working”);
Serial.print(“Puamp1 is working”);
delay(3000);
digitalWrite(Pump1, LOW);
delay(500);
}
else if(weekday()==2&&hour()==19&&minute()==19&&second()<3){
digitalWrite(Pump2,HIGH);//Day2 8:00
lcd.clear();
lcd.setCursor(0,1);
lcd.println(“Puamp2 is working”);
Serial.print(“Puamp2 is working”);
delay(3000);
digitalWrite(Pump2, LOW);
delay(500);

}
else if(weekday()==1&&hour()==19&&minute()==19&&second()<3){
digitalWrite(Pump3,HIGH);//Day3 8:00
lcd.clear();
lcd.setCursor(0,1);
lcd.print(“Puamp3 is working”);
Serial.print(“Puamp3 is working”);
delay(3000);
digitalWrite(Pump3, LOW);
delay(500);
}
else if(weekday()==4&&hour()==19&&minute()==19&&second()<3){
digitalWrite(Pump4,HIGH);//Day4 8:00
lcd.clear();
lcd.setCursor(0,1);
lcd.print(“Puamp4 is working”);
Serial.print(“Puamp4 is working”);
delay(3000);
digitalWrite(Pump4, LOW);
delay(500);

}
else if(weekday()==5&&hour()==19&&minute()==19&&second()<3){
digitalWrite(Pump5,HIGH);//Day5 8:00
lcd.clear();
lcd.setCursor(0,1);
lcd.print(“Puamp5 is working”);
Serial.print(“Puamp5 is working”);
delay(3000);
digitalWrite(Pump5, LOW);
delay(500);
}
else if(weekday()==6&&hour()==19&&minute()==19&&second()<3){
digitalWrite(Pump6,HIGH);//Day6 8:00
lcd.clear();
lcd.setCursor(0,1);
lcd.print(“Puamp6 is working”);
Serial.print(“Puamp6 is working”);
delay(3000);
digitalWrite(Pump6, LOW);
delay(500);

}
else if(weekday()==7&&hour()==20&&minute()==00&&second()<3){
digitalWrite(Pump7,HIGH);//Day7 8:00
lcd.clear();
lcd.setCursor(0,1);
lcd.print(“Puamp7 is working”);
Serial.print(“Puamp7 is working”);
delay(3000);
digitalWrite(Pump7, LOW);
delay(500);

}
}
//READ TEMPRATURE*******
void Temp(){
byte i;
byte present = 0;
byte data[12];
byte addr[8];
int Temp;
if ( !ds.search(addr)) {
//Serial.print(“No more addresses.\n”);
ds.reset_search();
return;
}

Serial.print(“R=”); //R=28 Not sure what this is
for( i = 0; i < 8; i++) {
Serial.print(addr*, HEX);*

  • Serial.print(" ");*

  • }*

  • if ( OneWire::crc8( addr, 7) != addr[7]) {*

  • Serial.print(“CRC is not valid!\n”);*

  • return;*

  • }*

  • if ( addr[0] != 0x28) {*

  • Serial.print(“Device is not a DS18S20 family device.\n”);*

  • return;*

  • }*

  • ds.reset();*

  • ds.select(addr);*

  • ds.write(0x44,1); // start conversion, with parasite power on at the end*

  • delay(1000); // maybe 750ms is enough, maybe not*

  • // we might do a ds.depower() here, but the reset will take care of it.*

  • present = ds.reset();*

  • ds.select(addr); *

  • ds.write(0xBE); // Read Scratchpad*

  • Serial.print(“P=”); *

  • Serial.print(present,HEX);*

  • Serial.print(" ");*

  • for ( i = 0; i < 9; i++) { // we need 9 bytes*
    _ data = ds.read();_
    _ Serial.print(data*, HEX);
    Serial.print(" ");
    }
    Temp=(data[1]<<8)+data[0];//take the two bytes from the response relating to temperature*
    * Temp=Temp>>4;//divide by 16 to get pure celcius readout*
    * //next line is Fahrenheit conversion*
    // Temp=Temp*1.8+32; // comment this line out to get celcius_

* Serial.print(“T=”);//output the temperature to serial port*
* Serial.print(Temp);*
* Serial.print(" ");*
* Serial.print(" CRC=");*
* Serial.print( OneWire::crc8( data, 8), HEX);*
* Serial.println();*
}
//AUTO TOP OFF**********
void ATO()
{
* if(Button_Switch==LOW && TopSwitch==LOW && pump8==LOW||Button_Switch==HIGH && TopSwitch==LOW && pump8==LOW)
_ {
digitalWrite(pump8, HIGH);
lcd.print(“ATO is on”);
}_
else if (TopSwitch==HIGH||Emergency_switch==HIGH)
_ {
digitalWrite(pump8, LOW);
lcd.print(“ATO is off”);*_

* }*
}
time_t compileTime(void)
{
#define FUDGE 15 //fudge factor to allow for compile time (seconds, YMMV)
char compDate = DATE, compTime = TIME, months = “JanFebMarAprMayJunJulAugSepOctNovDec”;
_ char chMon[3], m;
int d, y;
_

tmElements_t tm;

* time_t t;
_ strncpy(chMon, compDate, 3);
chMon[3] = ‘\0’;
m = strstr(months, chMon);
tm.Month = ((m - months) / 3 + 1);
tm.Day = atoi(compDate + 4);
tm.Year = atoi(compDate + 7) - 1970;
tm.Hour = atoi(compTime);
tm.Minute = atoi(compTime + 3);
tm.Second = atoi(compTime + 6);
t = makeTime™;
return t + FUDGE; //add fudge factor to allow for compile time*
}
void printTime(time_t t)
{
printI00(hour(t), ‘:’);
printI00(minute(t), ‘:’);
printI00(second(t), ’ ');
Serial.print(dayShortStr(weekday(t)));
* Serial.print(’ ');
printI00(day(t), ’ ‘);
Serial.print(monthShortStr(month(t)));
Serial.print(’ ');
Serial.println(year(t));
}
//Print an integer in “00” format (with leading zero),
//followed by a delimiter.
//Input value assumed to be between 0 and 99.
void printI00(int val, char delim)
{
if (val < 10) Serial.print(‘0’);
Serial.print(val);
Serial.print(delim);
return;
}*_

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

You assign some pins to LCD .

Then you assign some of those pins to inputs and outputs !

const int ledPin = 8;
//const int floatSwitch = 9;
const int pump8 = 10;
//int floatStatecounter = 0;
//int buttonState = 0;
//long lastButtonState = 0;
//long failSafe = 5000;

int Emergency_switch = 11; //Will close the pump in case of over load 
int TopSwitch = 10;//The max water level
int Button_Switch = 9;//The min water level

For inputs and outputs use different pins than you declared for LCD !

Allso - you have pin 10 as 1Wire input and then you declare it as output !! This will newer work.
PS - when posting your code , use code tags ( The # sign jus above smileys ) !!!

Before we get trapped in software, does your LCD work? In another sketch?

First i'm sorry for the mistake with the code before
I did change the pins now but there is no change at all

Yes the basic code works great with my lcd

Any idea ? =(

So post youl full and actual code. Use code tags !

#include <Time.h>  
#include <Wire.h>  
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t
#include <LiquidCrystal.h>
#include <OneWire.h>


OneWire  ds(53);  // on pin 10
int Pump1 = 30;
int Pump2 = 32;
int Pump3 = 34;
int Pump4 = 36;
int Pump5 = 38;
int Pump6 = 40;
int Pump7 = 42;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

const int ledPin = 20;
//const int floatSwitch = 9;
const int pump8 = 21;
//int floatStatecounter = 0;
//int buttonState = 0;
//long lastButtonState = 0;
//long failSafe = 5000;

int Emergency_switch = 11; //Will close the pump in case of over load 
int TopSwitch = 22;//The max water level
int Button_Switch = 9;//The min water level 

void setup()  {
 
  Wire.begin(); //initialize the I2C bus
   // set up the LCD's number of columns and rows:
 lcd.begin(16, 2);
 lcd.clear();
 lcd.setCursor(0,0);
  //Print a message to the LCD.
 lcd.print("Reef Controller");
 delay(3000);
 lcd.setCursor(0,1);
 lcd.print("test");
 delay(5000);

  
  pinMode(ledPin, OUTPUT);
  pinMode(Emergency_switch, INPUT);
  pinMode(TopSwitch, INPUT);
  pinMode(Button_Switch, INPUT);
  pinMode(pump8, OUTPUT);
  
  pinMode(Pump1, OUTPUT);
  pinMode(Pump2, OUTPUT);
  pinMode(Pump3, OUTPUT);
  pinMode(Pump4, OUTPUT);
  pinMode(Pump5, OUTPUT);
  pinMode(Pump6, OUTPUT);
  pinMode(Pump7, OUTPUT);
 
  Serial.begin(9600);
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  if(timeStatus()!= timeSet)
     Serial.println("Unable to sync with the RTC");
   else
     Serial.println("RTC has set the system time");
}

   
void loop()
{
 Pumps();
 Temp();
 ATO();
}
//*********************************DOISING SYSTEM*******************************************
void Pumps(){
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("Void Loop Test");
  if(weekday()==1&&hour()==19&&minute()==19&&second()<3){
        digitalWrite(Pump1,HIGH);//Day1 8:00
        lcd.clear();
        lcd.setCursor(0,1);
        lcd.print("Puamp1 is working");
        Serial.print("Puamp1 is working");
        delay(3000);
        digitalWrite(Pump1, LOW);
        delay(500);
}
  else if(weekday()==2&&hour()==19&&minute()==19&&second()<3){
        digitalWrite(Pump2,HIGH);//Day2 8:00
        lcd.clear();
        lcd.setCursor(0,1);
        lcd.println("Puamp2 is working");
        Serial.print("Puamp2 is working");
        delay(3000);
        digitalWrite(Pump2, LOW);
        delay(500);

}
  else if(weekday()==1&&hour()==19&&minute()==19&&second()<3){
        digitalWrite(Pump3,HIGH);//Day3 8:00
        lcd.clear();
        lcd.setCursor(0,1);
        lcd.print("Puamp3 is working");
        Serial.print("Puamp3 is working");
        delay(3000);
        digitalWrite(Pump3, LOW);
        delay(500);
}
  else if(weekday()==4&&hour()==19&&minute()==19&&second()<3){
        digitalWrite(Pump4,HIGH);//Day4 8:00
        lcd.clear();
        lcd.setCursor(0,1);
        lcd.print("Puamp4 is working");
        Serial.print("Puamp4 is working");
        delay(3000);
        digitalWrite(Pump4, LOW);
        delay(500);

}
  else if(weekday()==5&&hour()==19&&minute()==19&&second()<3){
        digitalWrite(Pump5,HIGH);//Day5 8:00
        lcd.clear();
        lcd.setCursor(0,1);
        lcd.print("Puamp5 is working");
        Serial.print("Puamp5 is working");
        delay(3000);
        digitalWrite(Pump5, LOW);
        delay(500);
}
  else if(weekday()==6&&hour()==19&&minute()==19&&second()<3){
        digitalWrite(Pump6,HIGH);//Day6 8:00
        lcd.clear();
        lcd.setCursor(0,1);
        lcd.print("Puamp6 is working");
        Serial.print("Puamp6 is working");
        delay(3000);
        digitalWrite(Pump6, LOW);
        delay(500);

}
  else if(weekday()==7&&hour()==20&&minute()==00&&second()<3){
        digitalWrite(Pump7,HIGH);//Day7 8:00
        lcd.clear();
        lcd.setCursor(0,1);
        lcd.print("Puamp7 is working");
        Serial.print("Puamp7 is working");
        delay(3000);
        digitalWrite(Pump7, LOW);
        delay(500);

}
}
//**********************************READ TEMPRATURE*****************************************
void Temp(){
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];
  int Temp;
  if ( !ds.search(addr)) {
      //Serial.print("No more addresses.\n");
      ds.reset_search();
      return;
  }
  
  Serial.print("R=");  //R=28 Not sure what this is
  for( i = 0; i < 8; i++) {
    Serial.print(addr[i], HEX);
    Serial.print(" ");
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.print("CRC is not valid!\n");
      return;
  }
  
  if ( addr[0] != 0x28) {
      Serial.print("Device is not a DS18S20 family device.\n");
      return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1);         // start conversion, with parasite power on at the end
  
  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
  
  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad

  Serial.print("P=");  
  Serial.print(present,HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print("  ");
  }
  Temp=(data[1]<<8)+data[0];//take the two bytes from the response relating to temperature

  Temp=Temp>>4;//divide by 16 to get pure celcius readout

  //next line is Fahrenheit conversion
 // Temp=Temp*1.8+32; // comment this line out to get celcius
  
  Serial.print("T=");//output the temperature to serial port
  Serial.print(Temp);
    Serial.print("  ");


  Serial.print(" CRC=");
  Serial.print( OneWire::crc8( data, 8), HEX);
  Serial.println();
}
//**********************************AUTO TOP OFF********************************************
void ATO()
{
  if(Button_Switch==LOW && TopSwitch==LOW && pump8==LOW||Button_Switch==HIGH && TopSwitch==LOW && pump8==LOW)
  {
    digitalWrite(pump8, HIGH);
    lcd.print("ATO is on");
  }
  else if (TopSwitch==HIGH||Emergency_switch==HIGH)
  {
        digitalWrite(pump8, LOW);
        lcd.print("ATO is off");
  
  }
}

time_t compileTime(void)
{
#define FUDGE 15        //fudge factor to allow for compile time (seconds, YMMV)

    char *compDate = __DATE__, *compTime = __TIME__, *months = "JanFebMarAprMayJunJulAugSepOctNovDec";
    char chMon[3], *m;
    int d, y;
    tmElements_t tm;
    time_t t;

    strncpy(chMon, compDate, 3);
    chMon[3] = '\0';
    m = strstr(months, chMon);
    tm.Month = ((m - months) / 3 + 1);

    tm.Day = atoi(compDate + 4);
    tm.Year = atoi(compDate + 7) - 1970;
    tm.Hour = atoi(compTime);
    tm.Minute = atoi(compTime + 3);
    tm.Second = atoi(compTime + 6);
    t = makeTime(tm);
    return t + FUDGE;        //add fudge factor to allow for compile time
}

void printTime(time_t t)
{
 printI00(hour(t), ':');
 printI00(minute(t), ':');
 printI00(second(t), ' ');
 Serial.print(dayShortStr(weekday(t)));
  Serial.print(' ');
  printI00(day(t), ' ');
  Serial.print(monthShortStr(month(t)));
  Serial.print(' ');
  Serial.println(year(t));
}

//Print an integer in "00" format (with leading zero),
//followed by a delimiter.
//Input value assumed to be between 0 and 99.
void printI00(int val, char delim)
{
    if (val < 10) Serial.print('0');
    Serial.print(val);
    Serial.print(delim);
    return;
}

This is my full code
Thanks for your help

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int Button_Switch = 9

Does this work at the arduino start ?

//Print a message to the LCD.
 lcd.print("Reef Controller");
 delay(3000);
 lcd.setCursor(0,1);
 lcd.print("test");
 delay(5000);

yes this part works good , the only problem is from the void loop

Did you change pin 9 ?

I did it now and the problem was solved THANK YOU MAN :slight_smile:

You're welcome :slight_smile: Sometimes tiny little things that are hard to catch are giving a headache :slight_smile:

waski:
tiny little things that are hard to catch are giving a headache :slight_smile:

For what it’s worth, my diagnostic approach would have been something like this. Seeing as you knew the LCD actually worked (or if you didn’t, you had tested it in a sketch of its own), I would have stripped the faulty code down by commenting out most of the code to be left with something like this:

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void setup()  {

 lcd.begin(16, 2);
 lcd.clear();
 lcd.setCursor(0,0);
  //Print a message to the LCD.
 lcd.print("Reef Controller");

}

void loop() {}

Then, assuming that worked, replace the commented out parts gradually until the problem comes back.

JimboZA:

waski:
tiny little things that are hard to catch are giving a headache :slight_smile:

I would have stripped the faulty code down by commenting out most of the code to be left with something like this:

Rather than comment out code using comments,
it is much better to conditionally disable it.
It is often easier and you don't have to worry about the nested comments
inside the code block being disabled.

i.e.

#if 0
(any code in here will be ignored.)
#endif