Go Down

Topic: LCD sometimes displaying rubbish (Read 1 time) previous topic - next topic

wattsie

Hi all...

I dived head first into the Arduino world after deciding I wanted an aquarium controller for my new reef tank.... I am happy to say that I found the whole thing challenging but I sussed out my programming to do what I want.... apart from my display!

Here is the problem.. Ill add code details soon, but just on the off chance that this is a simple noob mistake Ill detail the problem first!

I have a Uno running a program to:

Check the level of the water in my tank and fill it from a reservoir when it gets low.
Tell me when the reservoir is running low.
Check if a feed button is pressed to switch of pump for a short period.
Check to see if the filter cup is full.

Each of these functions work and displays on a sainsmart I2C LCD (4x20) to say if the levels are low or the filter is full etc. But every now and again I find that the display is showing random characters... like the matrix! When it does this it seems to freeze the program and nothing else works!

Is this a common problem ??

I have reached my limit of knowledge as I'm pretty new to this, so any help will be greatly appreciated! Ill add code once I am on the other computer with the arduino software!

Wattsie

floresta

#1
Nov 01, 2012, 07:50 pm Last Edit: Nov 01, 2012, 07:54 pm by floresta Reason: 1
Quote
Is this a common problem ??

Yes.  Didn't your search of previous posts in this forum turn up anything?

Quote
But every now and again I find that the display is showing random characters...

It's probably not that random.  Try disconnecting the pump and see what happens.

Don

dc42

It's quote common for folks to find that switching motors or solenoids messes up the LCD. However, if the whole device is freezing, it's probably because of a programming error.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

robtillaart

Quote
... like the matrix!

time to take the red pill?

Have you checked you hardware? loose connections can disrupt displays quite fast.

please post your code, so we can check that part!

ALso a good analysis strategy is to strip your program to the smallest program showing the "bug"
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

wattsie

Hi all... thanks for the reply's!

I had a search through, but the beauty of searches is if you start in the wrong direction your knackered! haha.... I was looking for LCD issues but after a bit of digging on relays and power surges I found topic that detailed a capacitor over the LCD power pins... worth a try....

So I switched off all the pumps etc to stop over-flowing my tank and wreaking havoc on the water salinity levels etc and tried to simulate the fault so I could test the fix.

I have not worked out why code-wise, but when the top up float switched the relay on to add fresh water it worked then froze the program... nothing else worked until the 'feed' button is pressed which didnt make the relay work to switch the wave pumps off, but turned the display into the meatrix ..... time for the red pill indeed...

So I knew the problem and the cure seems to be the capacitor... I have the display at the end of a length of Cat 5e cable above the tank, and a capacitor over the +ve and gnd has fixed the problems!

Now after each action the system returns to its normal state and the display is good!

Just in case anyone wants to add any direction to my wandering code.... here it is...




Its a bit messy and over commented, but thats just so i can follow it!

Any comments / quidance greatly apprecaited!!

Wattsie


wattsie

Code: [Select]

------------------------------------------------------------------------------------------------------------------
// AQUARIUM CONTROLLER v5.4 01/11/12

// update 2.0 - ok pin added (5/10/12)
// update 3.0 - feed powerhead off added (7/10/12)
// update 4.0 - skimmer full added - not working 100% though
// update 5.0 - LCD added, ro pump on for 5 seconds only to avoid overflows
// update 5.1 - skimmer full code relay clicks back and forth??
// update 5.2 - start of temp code added - to main screen to start with
// update 5.3 - skimmer full relay clicking fixed hopefully
// update 5.4 - skimmer full relay still clicking - nearly fixed

// NOTE relay needs to be driven low to operate!
// NOTE LCD starts at 0,0 not 1,1
// I2C pins A4 is SDA and A5 is SCL

// planned updates

// timer display for feed
// temperature control
// light controls

// set additional libraries to load into flash memory

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

// define I2C LCD data

#define I2C_ADDR    0x3f                   // Define I2C Address where the PCF8574A is
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

// set pin names for each pin number

const int sumplevelPin = 2;                //pin 2 connects to sump level probe
const int ropumpPin = 3;                   //pin 3 connects to ropump relay
const int alarmPin = 4;                    //pin 4 connects to LED
const int reslevelPin = 5;                 //pin 5 connects to reseviour level probe
const int okPin = 6;                       //pin 6 connects to 'all ok' LED
const int feedPin = 7;                     //pin 7 connects to wavemaker relay
const int feedledPin = 8;                  //pin 8 connects to feed LED
const int feedbuttonPin = 9;               //pin 9 connects to feed button
const int skimfullPin = 10;                //pin 10 connects to skim level probe
const int skimrelayPin = 11;               //pin 11 connects to skim relay

// set variables which will change whilst program is running

int sumplow = 0;
int reslow = 0;
int feed = 0;
int skimfull = 0;
int n = 1;

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

// Setup Procedure runs once.........

void setup()  //setup procedure to initialise pins as input/outputs

{
// initialise pins
 
 digitalWrite(13, LOW);                    //turns inbuilt led off
 
 
 pinMode(sumplevelPin, INPUT);
 pinMode(ropumpPin, OUTPUT);
 pinMode(reslevelPin, INPUT);
 pinMode(alarmPin, OUTPUT);
 pinMode(okPin, OUTPUT);
 pinMode(feedPin, OUTPUT);
 pinMode(feedledPin, OUTPUT);
 pinMode(feedbuttonPin, INPUT);
 pinMode(skimfullPin, INPUT);
 pinMode(skimrelayPin, OUTPUT);

 
 
 //initialise serial communications with te laptop at 9600 bps
 Serial.begin(9600);
 
 // initialise LCD 20X4 characeters
 
 lcd.begin (20,4);
 
}

//MAIN PROGRAM..................

void loop() //main part of the program that loops until reset

{
 digitalWrite(ropumpPin, HIGH);            //set ro pump relay pin to high
 digitalWrite(alarmPin, LOW);               //set alarm pin low - no alarm
 digitalWrite(okPin, HIGH);                  //light up ok led
 digitalWrite(feedledPin, LOW);            //feed LED off
 digitalWrite(feedPin, HIGH);                //set feed relay pin to low so its on
 
 reslow = digitalRead(reslevelPin);          //read resevoir level probe and call result reslow
 sumplow = digitalRead(sumplevelPin);     //read sump level probe and call result sumplow
 feed = digitalRead(feedbuttonPin);        //read feed button and call it feed
 skimfull = digitalRead(skimfullPin);        //read skim full level probe and call result skimfull
 
 // switch on backlight
 
 lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
 lcd.setBacklight(HIGH);
 lcd.home ();                   // go home
 
 // Display Data on LCD
 
 lcd.print("Aquarium Monitor");
 lcd.setCursor ( 0, 1 );         // go to the 1st char on 2d line
 lcd.print("Tank");
 lcd.setCursor ( 11, 1 );         // go to the 11th char on 2d line
 lcd.print("LEDs");
 lcd.setCursor ( 17, 0 );         // go to the 17th char on 1st line
 lcd.print("5.4");
 lcd.setCursor ( 0, 2 );          // go to the 1st char on 3rd line
 lcd.print("Sump");
 lcd.setCursor ( 11, 2 );         // go to the 11th char on 3rd line
 lcd.print("Resv");
 lcd.setCursor ( 0, 3 );          // go to the 1st char on 4th line
 lcd.print("Skim");
 lcd.setCursor ( 11, 3 );         // go to the 11th char on 4th line
 lcd.print("Feed");
 
 
 
 //____________________________________________________________________________________
 // Check if resevoir is running low......
 
 if (reslow == HIGH) //if the resevoir level is on, ie too low
     {
         digitalWrite(okPin, LOW);         //turn ok led  off
         digitalWrite(alarmPin, HIGH);     //then turn alarm on
         lcd.setCursor ( 16, 2 );          //go to the 16th char on 3rd line
         lcd.print("LOW");
         delay(10000);                     //give alarm LED time to flash
         Serial.print("ALARM !! RO RESEVOUR NEARLY EMPTY");
     }
     else
     {
         digitalWrite(alarmPin, LOW);      //if not leave alarm off
         lcd.setCursor ( 16, 2 );          // go to the 1st char on 3rd line
         lcd.print("OK ");
     }
 //____________________________________________________________________________________
 // Check if sump needs topping up......
 
 if (sumplow == HIGH)                      //if the sump level is on, ie too low
     {
         digitalWrite(okPin, LOW);         //turn ok led off
         digitalWrite(ropumpPin, LOW);     //then turn ro pump on
         lcd.setCursor ( 5, 2 );          //go to the 6th char on 3rd line
         lcd.print("LOW");
         delay(5000);
         digitalWrite(ropumpPin, HIGH);    //turn RO pump off
         lcd.setCursor ( 5, 2 );           //go to the 6th char on 3rd line
         lcd.print("OK ");
     }
     else
     {
         digitalWrite(ropumpPin, HIGH);    //if not leave ro pump off
         lcd.setCursor ( 5, 2 );            //go to the 6th char on 3rd line
         lcd.print("OK");
     }                                     //contine prog
 //____________________________________________________________________________________
 // Check to see if the feed button is being pressed
 
 if (feed == HIGH)                         //if the feed button is pressed
     {
         digitalWrite(feedledPin, HIGH);   //turn on feed LED
         digitalWrite(feedPin, LOW);       //turn off relay for powerheads
         lcd.setCursor ( 16, 3 );          //go to the 16th char on 4rd line
         lcd.print("YES");
         delay(100000);                    //wait ms
         delay(100000);                    //make pause longer
         digitalWrite(feedPin, HIGH);      //turn on relay for powerheads
         digitalWrite(feedledPin, LOW);    //turn off feed LED
         lcd.setCursor ( 16, 3 );          //go to the 16th char on 4rd line
         lcd.print("NO   ");
                                           
     }

  else      //do nothing and continue prog
 
     {
         lcd.setCursor ( 16, 3 );          //go to the 16th char on 4rd line
         lcd.print("NO   ");
     }
 //____________________________________________________________________________________
 // Check to see if the skimmer cup is full
 
 if (skimfull == HIGH)                     //if the skimmer cup probe is not floating breaking circuit
     {
       digitalWrite(skimrelayPin, HIGH);    
         lcd.setCursor ( 5, 3 );            //go to the 5th char on 4rd line
         lcd.print("OK  ");
       
         
       
     }        
 
 else
     {
       digitalWrite(alarmPin, HIGH);       //turn alarm LED on
         digitalWrite(okPin, LOW);
         digitalWrite(skimrelayPin, LOW);    //turn off skimmer
         lcd.setCursor ( 5, 3 );            //go to the 5th char on 4rd line
         lcd.print("FULL");    
     }
   
       
 //------------------------------------------------------------------------------------
 // Check Temps - to be continued
     //Tank Temp
     //check tank temp
     lcd.setCursor ( 5, 1 );            //go to the 5th char on 2d line
     lcd.print("xx'C");
     //LED Temp
     //check LED temp
     lcd.setCursor ( 16, 1 );            //go to the 16th char on 2d line
     lcd.print("xx'C");
 
 
}

floresta

After you get your noise and/or inductive spikes suppressed you should look into the possibility of enabling the 'watchdog timer'.  This timer is used to reset the processor when it gets lost. 

Don

wattsie


After you get your noise and/or inductive spikes suppressed you should look into the possibility of enabling the 'watchdog timer'.  This timer is used to reset the processor when it gets lost.


Seems like a good idea... I'd never even heard of a watchdog!

Ill be keeping a close eye on it all over the next few days and see how it goes!

Thanks for the idea!

wattsie

WinstonP

Yes, definitely check the line noise to the pumps and solenoids. Add capacitors to help suppress those. and double check the LCD connections. I had a problem with my serial LCD and it was caused by loose wiring on one end of the connector.

Go Up