Remember that the LCD library print() functions accept single ascii characters or strings of characters. So first you have to convert your number into a string representation. The wiki section above shows how to do this using the itoa() function.
It might make sense for the LCD library to provide another function, say printNumber(int) which took an integer and printed its string representation in decimal.
First off, kudo's for the instructions in the 4bit playground page. If I had been paying attention to the datasheet I found for my display, I'd have got it working the first time (For some reason the pin numbering is ass-backwards on my LCD). Still, I have a small question. For now, the random fruit example works perfectly. Single line, scrolling, all the bits. But, if I enable the 2nd line and the commented out 'score' bit the display stays empty. No noise, no nothing. Backlight comes on, but no character appear. Am I missing something, or have my earlier attempts killed just the second line? The display is a pc1602f, which should be hd44780 compatible.
(excuse me for lifting this old thread from the depths of oblivion)
Ive adapted your code into my little program, but can't find out how to make it show the temperature as 26,1 as oposed to the 261 format it is in now ?!?! Im sure you have a solution, I just can't see it since i've only been into arduino programming for about 4 days now :-/
My code is at the bottom.
int heat = 451;
char heat_str[4] = " "; //reserve the string space first
itoa(heat, heat_str, 10);
lcd.printIn(heat_str);
//todo: make sure number can be notated within str length.
My code..
#include <LCD4Bit.h>
LCD4Bit lcd = LCD4Bit(2);
int temperaturePin = 2; // select the input pin for the temperature
for(i = 0; i < 20; ++i)
{
val += analogRead(temperaturePin); // read the value from the sensor
delay(50);
}
val /= 4.06; // conversion value to millivolts
if(val > 28 * 10) // temperature in deg C times 10, since we're measuring to tenths of a degree
digitalWrite(13,HIGH);
else
digitalWrite(13,LOW);
int heat = val;
char heat_str[5] = " "; //reserve the string space first
itoa(val, heat_str, 10);
neillzero,
Thanks so much for the trouble shooting help! I've been sitting here looking over the wiring over and over and over, wondering what could be wrong.
Turns out, once I delete LCD4bit.o and recompiled the code, it worked perfectly! I'm glad I found your post, maybe this should be in the wiki? Maybe it is and I missed it!
Thanks again!
I always use LCD4Bits library...but i build it with a new LCD WH1602, and do not work...
in the Lib note this:
// ########## pin assignment ##########
int RS = 12; // Register Select
int RW = 11; // Read/Write
int En = 2; // Enable
//DB should be an unseparated group of pins - because of lazy coding in push_nibble()
int DB[] = {7, 8, 9, 10}; // DB4 .. DB7
That on the default lib, my Lib:
// ########## pin assignment ##########
int RS = 3; // Register Select
int RW = 11; // Read/Write
int En = 2; // Enable
//DB should be an unseparated group of pins - because of lazy coding in push_nibble()
int DB[] = {8, 5, 7, 6}; // DB4 .. DB7 :o
So this is not working... could be the pin assignment?
Ive adapted your code into my little program, but can't find out how to make it show the temperature as 26,1 as oposed to the 261 format it is in now ?!?! Im sure you have a solution, I just can't see it since i've only been into arduino programming for about 4 days now :-/
Solow, read the attached post and you will get it.
I've got a question, I haven't seen anyone else getting these strange results.
I have a HD44780 LCD and finally got it to display characters with the example. Only problem is, I don't see fruits I see characters like ->, 0, etc. It's like the character map used isn't correct for my LCD. Can these vary by LCD or isn't the ascii universal?
Any ideas? I've been playing with pins and am going to start probing to make sure all my connections are being made. Anything else I should look for?
EDIT
Nevermind my dumb question. I was feeding corrupt data (data pins were backwards)
That is an improvement. But why not use the LCD code provided in release 0012. It has much richer print functionality with the added benefit that it uses the same syntax as the Serial print routines.
I now wrote a simple method to test this (no error handling, just a proof of concept ):
void myCursorTo(int aLine, int aCol)
{
int CmdToWrite = 128; //0x80
switch(aLine)
{
case 1:
CmdToWrite = CmdToWrite + aCol;
break;
case 2:
// this line is buggy, jumps only to first column of line 2
CmdToWrite = CmdToWrite + 40 + aCol;
break;
}
lcd.commandWrite(CmdToWrite);
}
By using this to position the cursor, moving to second line and writing the content now just needs 35msec. A really great speed improvement.
I've been looking at the LCD library, and connecting up a genuine Hitachi HD44780 LCD in 4-bit mode. With that chip, extra delays are required after certain operations/commands. But the code in "LiquidCrystal" uses explicit delays in microseconds, and does not use the "ready" bit output from the chip. Would a version of the library that did use the "Ready" bit be a useful thing to have? It would have the advantage of working faster with clone HD44780 chips (which need less delay), but would most likely make the code size bigger.
Hello I downloaded the LCD4Bit library,
I am using a 16x2 LCD (Amber on Black) from Sparkfun (GDM1602K)
The Pins and connections as fallows:
LCD -> Arduino
4 (RS) to Arduino Pin 12
5 (RW) to Arduino Pin GND
6 (E) to Arduino Pin 2
DB4 to Arduino Pin7
DB5 to Arduino Pin8
DB6 to Arduino Pin9
DB7 to Arduino Pin10
VSS GND to Arduino GND
VDD +5V to Arduino Pin 5V
I also connect the Pins on LCD 15(4.2V Led) and 16 (Power Supply for BKL 0v) to Arduino 5V and GND pins.
And I load up the example sketch from the library, upload it to Arduino and run it, the Test Led on 13 keeps blinking means data is going but there is no sign of any light/character on my LCD.
I just re checked the connections and the Backlight works fine now but now I have an another problem.
When I disconnect the Power lines for the lcd Display (not the ones for the Backlight) I see a pulse on the screen but nothings shows up,
it is like if I am going to write "Apple" on the screen, the boxes corresponding to those 5 letters light up for a very shortly like the letters going to appear but then nothing happens.
When I connect the power lines from Arduino to LCD that effect disappears and I just see the backlight.
I tried both 5V and 3V3 pins on arduino. But no luck.
Any ideas ?