Go Down

Topic: Blinking 16x2 LCD (Read 156 times) previous topic - next topic

mrbilky

Well not quite blinking in the real sense more like a pulse I have been building up my code and it's working and all has been good - learning quite a bit but I'm stuck on this one, the LCD (16x2 I2C 4 wire) is pulsing and I'm not quite sure it's the code I've looked but the led's on the uno are not pulsing but the LCD is albeit faint but annoying any ideas? I have 3 led's to the 3 data pins for both looks and debugging they do not pulse I've tried power from the board as well as from my bench top power supply

Code: [Select]

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



// initialize the library with the numbers of the interface pins
LiquidCrystal_I2C lcd(0x27, 16, 2);

int senpin = A0;


void setup()
{
  lcd.init(); //initialize the lcd
  lcd.backlight(); //open the backlight

  lcd.begin(16, 2); // set up the LCD's number of columns and rows:
  lcd.clear();


  pinMode(A0, INPUT); //set up analog pin A1 to be input
  pinMode(2, OUTPUT); // red led
  pinMode(3, OUTPUT); // yellow led
  pinMode(4, OUTPUT); // green led
}

void loop()

{
  lcd.setCursor(0, 0); // Sets the cursor to col 0 and row 0
  lcd.print(analogRead(A0)); // Prints value on senpin A0 to LCD

  int senpin = analogRead(A0); //take a sample


  if (senpin < 370 && senpin >= 0) {
    lcd.clear();
    lcd.setCursor(4, 0);
    lcd.print("Low water");
    lcd.setCursor(3, 1);
    lcd.print("Near death!");
    digitalWrite(2, HIGH);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);

  }
  if (senpin < 600 && senpin >= 370) {
    lcd.clear();
    lcd.setCursor(5, 0);
    lcd.print("I need");
    lcd.setCursor(1, 1);
    lcd.print("A little more!");
    digitalWrite(2, LOW);
    digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
  }
  if (senpin < 1000 && senpin >= 600) {
    lcd.clear();
    lcd.setCursor(1, 0);
    lcd.print("That's enough");
    lcd.setCursor(1, 1);
    lcd.print("I'm drowning!");
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, HIGH);
  }
  {
    delay (1000);
  }
}





mrbilky

Ok so I found the issue if it is one it's the delay cycle is there a way to prevent it or is it just something to live with the moisture sensor should have a relatively short delay as when you water a plant it will need immediate response to prevent over watering is this logic on track? I'm willing to listen to options/adjustments to the code/hardware if there is one would just like a general idea not the fix would like to conquer that myself it greatly helps with the learning curve!

Nick_Pyner

Get rid of that cowardly
    lcd.clear();
and learn to properly format the output to the display.

You already have some cursor control so you may be OK without actually doing anything else.

mrbilky

Get rid of that cowardly
    lcd.clear();
and learn to properly format the output to the display.

You already have some cursor control so you may be OK without actually doing anything else.
HaHa that's my first attempt at integrating the LCD I did hack some of the code from other sketches it was originally setup with a red, yellow and green LED for moisture levels, I don't have a pot to control the contrast maybe because the backlight is on full it's more noticeable?

Nick_Pyner

backlight is on full it's more noticeable?
No, I think what is noticeable is the bad code you picked up, and no amount of fiddlearsing with the backlight will solve the problem..

I submit the name of the game is to only change that which needs to be changed. Indeed you can be in a position where it makes sense to print to LCD in setup.

Go Up