Lcd4bit problem

Hi, im new to the world of microcontrollers and arduino.

been trying to set up an lcd for a while. ive been using this guide Arduino Tutorial - connecting a parallel LCD

Ive had some success, it runs fine normally but when you uncomment the code to utilise the second line on the the LCD, it does not work properly it just displays the info thats supposed to be displayed after the info displayed on the first line.

I read somewhere that the LCD4BIT library doesnt automatically configure it for a 2 line LCD, how do i go about doing this?

Thanks

Dan

If you read the documentation on the Arduino Playground, you will see that there is a command to do this.

LCD4Bit lcd = LCD4Bit(1);

this example would set it to a 1 line display. So to make it a two we would...

LCD4Bit lcd = LCD4Bit(2);

Haven't tested it myself but, I'm sure it works fine!

Ben

ok , well i tried the simple code on the lcd4bit page and modified it to work as a 2 line interface but it gives the following error when compiling. any ideas?

error: expected constructor, destructor, or type conversion before '.' token

#include <LCD4Bit.h>
LCD4Bit lcd = LCD4Bit(2); //create a 2-line display.
lcd.clear();
delay(1000);
lcd.printIn("arduino");

I copied your code and it compile fine (in v.0015).

I think you have put #include <LCD4Bit.h> inside the void loop(){} section, which will not work. So it needs to be moved outside of any functions. Could you copy your code exactly as it is in the IDE please?

Ben

ok well i intially thought that i could just use the code above as is, but have now changed it to

#include <LCD4Bit.h>

void setup()
{
LCD4Bit lcd = LCD4Bit(2);
}

void loop()
{
lcd.clear();
delay(1000);
lcd.printIn("arduino");
}

the error i get now is;

In function 'void loop()':
error: 'lcd' was not declared in this scope

thanks for you help, ive been struggling with this for a couple of weeks now.

Arg... silly mistake

Figured it out using the the example that came with the lcd4bit library.

thanks for your time.

That's OK. Just for the record, shouldn't:

LCD4Bit lcd = LCD4Bit(2);

go in void loop()?

Or if not, how did you do it?

The declaration of the LCD object should be at global scope, i.e. outside the functions 'setup()' and 'loop()'.

#include <LCD4Bit.h>

LCD4Bit lcd = LCD4Bit(2);

void setup()
{
   lcd.clear();
}

void loop()
{
   delay(1000);
   lcd.println("arduino");
}

Incidentally, it's 'println', not 'printIn', an 'L' not an 'I'.

Incidentally, it's 'println', not 'printIn', an 'L' not an 'I'.

i cant get that to work ? when i use

lcd.println("temp ");

instead of

lcd.prinIn("temp ");

i get this error:

error: 'class LCD4Bit' has no member named 'println'

I have had some success with the following code, what i am trying to do is diplay the word RPM on the top line of the LCD and Temp on the bottom line. The only problem is that it the word temp flashes in unison with the LED? why is it doing this?

How do i display a varible on the LCD also?

#include <LCD4Bit.h> 
LCD4Bit lcd = LCD4Bit(2); 

char rpm = 1500;
char temp = 52;


void setup() { 
  pinMode(13, OUTPUT);  //heart beat
  lcd.init();
             }

void loop() {  
  
  lcd.cursorTo(1,0);
  lcd.printIn("RPM ");
  //lcd.printIn(rpm);
  lcd.cursorTo(2, 0);  //line=2, x=0.
  lcd.printIn("temp ");
  digitalWrite(13, HIGH);  //light the debug LED
  delay(1000);
  digitalWrite(13, LOW);
  lcd.clear();
 
  //lcd.print(temp);
  
}

thanks

Dan

No, it is void printIn(char value[]); // I not l

it should be println but that's not the way that library was written :frowning:

Dan, why not use the LiquidCrystal library, it's much easier to print variables using that library.

I will check it out, thanks

it should be println but that's not the way that library was written

OK, sorry for the confusion! I've used the standard LiquidCrystal library in 4-bit mode, where of course it is 'println' with an 'L'.