i2c LCD shield; how to display numers (integers or long)

Started by fettlab, April 01, 2015, 05:25:20 PM

Previous topic - Next topic


I just got the LCD shield, the supplied examples, included in the library folder, work great on Arduino.
It is a nice shield, and I like the solution of a PIC handling the i2c (more charming than with a i2c expander like an Adafruit shield eg)

There is no example for displaying numbers in the library, only for characters.
I find out the library doesn't support numbers at all (like other LCD libraries do, but they won't work on this shield) , so you should do a number (integer and  unsigned long in my sketch) to character conversion in the Arduino sketch. I tried several ways to do this conversion, with commands like itoa, ltoa, sprint, String. But without success, I keep getting errors.
No need to explain I want to display numbers (from calculation, measurement, clock eg) and not only text.

Can someone supply me with a simple example sketch for displaying numbers (integers or long) on the LCD Shield

Another question:
If I don't want to use it as a shield, but just connect it through 4 (V, GND, SDA, SCL) wires with for instance a AtTiny85 (my favorite) , should I supply 3.3 V power , 5 V power or both?
Same Question for the GPIO, do the outputs generate 3.3 V or 5 V and are the inputs 5 V proof?

Thanks for replying


In C, if you can display a C-style string (zero-terminated array of characters), the C's sprintf() or snprintf() should work (prefer the second one, the first one is unsafe), with code like snprintf(output_buffer,OUTPUT_BUFFER_SIZE,"%d",number); (use "%ld" for longs). And if all this fails, you can allways convert the numbers "by hand" using repeated divisions and converting the remainders to ASCII numbers by adding 0x30.


Thanks, snprintf() works great.
I found out I made a mistake in the buffer declaration, I wrote buffer(12) instead of buffer[12]. That's why ltoa and sprint() didn't work, it took me a long time to find, the error codes where misleading.