How to change line on LCD using LcdBarGraph.h

Hi guys,

new on the forum.

I am trying to use the LcdBarGraph.h library to do a bar graph which will increase/decrese according to voltage mesured on analog pin0. Here is my code bellow. My problem is that lcd.setCursor(0,1); and lcd.setCursor(0,0); do not work at all. I want to put Voltage on line 0 of LCD and Bar graph on line 1 of LCD.

Any help?

Thanks
Filipe

New_lcd_bar_graph.ino (991 Bytes)

My problem is that lcd.setCursor(0,1); and lcd.setCursor(0,0); do not work at all.

I don’t see where you used lcd.setCursor(0,0);.

Have you tried a simpler sketch first? You want to do your troubleshooting with a more or less static display, in other words with the display code in setup() rather than in loop().

Try this code and see if your cursor positioning works:

#include <LiquidCrystal.h>

//LiquidCrystal lcd(RS, E, D4, D5, D6, D7);
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);      // put your pin numbers here

void setup()
  {
  lcd.begin(16, 2);                          // put your LCD parameters here
  lcd.print("hello, world!");
  lcd.setCursor(0,1);
  lcd.print("it works!");

  delay(2000);                               // wait for 2 seconds

  lcd.setCursor(0,0);
  lcd.print("back to top row");
  }

void loop()
  {
                                             // do nothing in 'loop'
  }

Don

Hello Don,

thanks for your reply. Unfortunately it does not work.

My code works but I just cannot set the Cursor where I want, I will try as you said with a simple sketch first.

BTW I used the lcd.setCursor on lines 23 and 33 of my code file:

void loop()
{

  lcd.setCursor(0,0); //<------------------------------------------------------HERE
  int analogPin0=analogRead(0);
  float voltage = analogPin0 * (5.0/1024.0);
  lcd.print(voltage);
  lcd.print(" V");
  lcd.print(" - ");
  lcd.print(analogPin0);
  
  // -- draw bar graph from the analog value readed
  
  lcd.setCursor(0,1); //<------------------------------------------------------HERE
  lbg.drawValue( analogPin0, 1024);
  

  

  
  // -- do some delay: frequent draw may cause broken visualization
  delay(100);
}

Regards,
Filipe

thanks for your reply. Unfortunately it does not work.

Telling us what it does do would be helpful.

BTW I used the lcd.setCursor on lines 23 and 33 of my code file:

Here’s the code you posted earlier which is the code I was referring to:

#include <LcdBarGraph.h>
#include <LiquidCrystal.h>


byte lcdNumCols = 16; // -- number of columns in the LCD

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // -- creating LCD instance
LcdBarGraph lbg(&lcd, lcdNumCols);  // -- creating bargraph instance, format is (&lcd, lcdNumCols, start X, start Y). So (&lcd, 16, 0, 1) would set the bargraph length to 16 columns and start the bargraph at column 0 on row 1.

void setup(){
  // -- initializing the LCD
  lcd.begin(lcdNumCols, 2);
  lcd.clear();
  // -- do some delay some time I've got broken visualization
  
  delay(100);
  
}

void loop()
{

  lcd.setCursor(0,1);
  int analogPin0=analogRead(0);
  float voltage = analogPin0 * (5.0/1024.0);
  lcd.print(voltage);
  lcd.print(" V");
  lcd.print(" - ");
  lcd.print(analogPin0);
  
  // -- draw bar graph from the analog value readed
  
  lcd.setCursor(0,1);
  lbg.drawValue( analogPin0, 1024);
  

  

  
  // -- do some delay: frequent draw may cause broken visualization
  delay(100);
}

Don

Hi again,

I just figgered it out. I did not read correctly the comments:

LcdBarGraph lbg(&lcd, lcdNumCols, 0, 1);  // -- creating bargraph instance, format is (&lcd, lcdNumCols, start X, start Y). So (&lcd, 16, 0, 1) would set the bargraph length to 16 columns and start the bargraph at column 0 on row 1.

I did not put the 0, 1 so it was always on the 0 positions row of the lcd.

Thanks