LCD Bitmap - Updated v1.6

bperrybap:

teckel:
Compatible with Arduino 0023.

The examples will not work "as is" with releases prior to 1.0 because of the .ino extension.
If you renamed them to .pde then the examples could work "out of the box" with both
the the post and pre 1.0 releases.

--- bill

Thanks! That's why the sketches weren't listed in 0023. I just did a cut and paste to test because for "whatever" reason it wouldn't load. Now the mystery has been answered. I'll make the changes for the next release.

Tim

Hi,

I have installed arduino 1.0.1 and I just downloaded LCDBitmap library . I loaded the LCDBitmap_standard_4bit example and try to compile it.

This is the outcome:

/home/ydirgan/SCRIPTS/Arduino/arduino-1.0.1/libraries/LCDBitmap/LCDBitmap.h:89:17: error: LCD.h: not found
In file included from LCDBitmap_Standard_4bit.cpp:2:
/home/ydirgan/SCRIPTS/Arduino/arduino-1.0.1/libraries/LCDBitmap/LCDBitmap.h:110: error: expected `)' before ‘’ token
/home/ydirgan/SCRIPTS/Arduino/arduino-1.0.1/libraries/LCDBitmap/LCDBitmap.h:133: error: ISO C++ forbids declaration of ‘LCD’ with no type
/home/ydirgan/SCRIPTS/Arduino/arduino-1.0.1/libraries/LCDBitmap/LCDBitmap.h:133: error: expected ‘;’ before ‘
’ token
LCDBitmap_Standard_4bit:4: error: no matching function for call to ‘LCDBitmap::LCDBitmap(LiquidCrystal*, int, int)’
/home/ydirgan/SCRIPTS/Arduino/arduino-1.0.1/libraries/LCDBitmap/LCDBitmap.h:108: note: candidates are: LCDBitmap::LCDBitmap()
/home/ydirgan/SCRIPTS/Arduino/arduino-1.0.1/libraries/LCDBitmap/LCDBitmap.h:108: note: LCDBitmap::LCDBitmap(const LCDBitmap&)

The first line shows a LCD.h not found statement... where LCD.h header is?. Am I missing something?.

any advice will be appreciated.

Regards

YADL

You will need to download the "New LiquidCrystal" library, aka, the LCD library:
https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home

Tim,
maybe to help newbies, you could add a compile time check/error to tell them how to resolve the issue.
For example, LCDBitmap.h includes <LiquidCrystal.h>
fm's LiquidCrystal.h includes "LCD.h" so the include of "LCD.h" is not needed in LCDBitmap.h
(This will eliminate the preprocessor error).

Then instead of the include for LCD.h
do a compile time check for a define that is only in fm's library.
Something like maybe:

#ifndef BACKLIGHT_ON
#error You need to install this version of the LiquidCrystal library: https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
#endif

(hint... hint...) maybe it would be useful to have a more unique define that could be checked
to compile time detect the existence/use of the replacement LiquidCrystal replacement library...

--- bill

yadirgan:
Hi,

I have installed arduino 1.0.1 and I just downloaded LCDBitmap library . I loaded the LCDBitmap_standard_4bit example and try to compile it.

This is the outcome:

/home/ydirgan/SCRIPTS/Arduino/arduino-1.0.1/libraries/LCDBitmap/LCDBitmap.h:89:17: error: LCD.h: not found
In file included from LCDBitmap_Standard_4bit.cpp:2:
/home/ydirgan/SCRIPTS/Arduino/arduino-1.0.1/libraries/LCDBitmap/LCDBitmap.h:110: error: expected `)' before ‘’ token
/home/ydirgan/SCRIPTS/Arduino/arduino-1.0.1/libraries/LCDBitmap/LCDBitmap.h:133: error: ISO C++ forbids declaration of ‘LCD’ with no type
/home/ydirgan/SCRIPTS/Arduino/arduino-1.0.1/libraries/LCDBitmap/LCDBitmap.h:133: error: expected ‘;’ before ‘
’ token
LCDBitmap_Standard_4bit:4: error: no matching function for call to ‘LCDBitmap::LCDBitmap(LiquidCrystal*, int, int)’
/home/ydirgan/SCRIPTS/Arduino/arduino-1.0.1/libraries/LCDBitmap/LCDBitmap.h:108: note: candidates are: LCDBitmap::LCDBitmap()
/home/ydirgan/SCRIPTS/Arduino/arduino-1.0.1/libraries/LCDBitmap/LCDBitmap.h:108: note: LCDBitmap::LCDBitmap(const LCDBitmap&)

The first line shows a LCD.h not found statement... where LCD.h header is?. Am I missing something?.

any advice will be appreciated.

Regards

YADL

I guess I missed this. I had believed LCDBitmap would work without the "New LiquidCrystal" library. But, that doesn't seem to be the case. Attached to this message are replacement library files. Save and replace these files with the existing files in your Arduino/libraries/LCDBitmap/ folder. I don't have a 4bit project in front of me to test, but the attached files do compile with a stock Arduino 1.0.1 with the LCDBitmap_Standard_4bit sketch.

Let me know if it works.

Tim

LCDBitmap.h (6.93 KB)

LCDBitmap.cpp (5.51 KB)

bperrybap:
Tim,
maybe to help newbies, you could add a compile time check/error to tell them how to resolve the issue.
For example, LCDBitmap.h includes <LiquidCrystal.h>
fm's LiquidCrystal.h includes "LCD.h" so the include of "LCD.h" is not needed in LCDBitmap.h
(This will eliminate the preprocessor error).

Actually, when using a 4bit connection the LCDBitmap library was supposed to work without the need for the New LiquidCrystal library. I've changed the code so it should work with or without the New LiquidCrystal library and attached the revision to my previous reply.

Adding an error if trying to use other connection types without the New LiquidCrystal library is a good idea too, and I'll probably be implementing that as well.

Tim

Thanks, it worked!.

I had changed the LCD reference for LiquidCrystal and of course it worked, but nice to have the latest files with the conditionals.

Regards

YADL

yadirgan:
Thanks, it worked!.

I had changed the LCD reference for LiquidCrystal and of course it worked, but nice to have the latest files with the conditionals.

Regards

YADL

Thanks for testing. I'll incorporate that in the next release.

Tim

Hi, thanks for this great library. I got it working successfully using an Arduino Leonardo, running IDE v1.0.1, with your modified version of the library attached on an above post. However, I've been playing around with the bars function and can't figure out: How could I use your library to display the value (graphical) of some analog inputs? Suppose I have 3 analog inputs. I read them, re-map or convert them, and display those values with a bar, with the highest possible value creating a full bar, and the lowest possible value giving an empty bar. Any help or suggestions would be great.

Hydromea:
Hi, thanks for this great library. I got it working successfully using an Arduino Leonardo, running IDE v1.0.1, with your modified version of the library attached on an above post. However, I've been playing around with the bars function and can't figure out: How could I use your library to display the value (graphical) of some analog inputs? Suppose I have 3 analog inputs. I read them, re-map or convert them, and display those values with a bar, with the highest possible value creating a full bar, and the lowest possible value giving an empty bar. Any help or suggestions would be great.

The barGraph method is fairly straight-forward, the syntax is as follows:

bitmap.barGraph(bars, *graph, color, update);

is the number of bar graphs you want to display.
is an array of height values (these values are in pixels, with the range from 0 to 16).
is either ON or OFF.
is etiher UPDATE or NO_UPDATE (in the next release, v1.5, all functions default to NO_UPDATE if not specified).

So, if you want 3 bar graphs for your 3 analog sensors, you would do something like this:

#include <LiquidCrystal.h>
#include <LCDBitmap.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LCDBitmap bitmap(&lcd, 0, 0);  // Set the bitmap to the &lcd display at character position 0,0.
byte graph[3]; // Bar graph with 3 columns.

int analogPin1 = A1;
int analogPin2 = A2;
int analogPin3 = A3;

void setup() {
  lcd.begin(16,2); // Initalize the LCD display, do this before you initalize LCDBitmap.
  bitmap.begin();  // Then initalize the LCD bitmap.
}

void loop() {
  // analogRead returns values from 0 to 1023, the barGraph displays values from 0 to 16 (1023+13)/61=16.98.
  // This does the conversion without using floating point math keeping your compiled code small.
  graph[0] = (analogRead(analogPin1) + 13) / 61;
  graph[1] = (analogRead(analogPin2) + 13) / 61;
  graph[2] = (analogRead(analogPin3) + 13) / 61;
  bitmap.barGraph(3, graph, ON, UPDATE);  // Display the bar graph.
  delay(50);
}

Note: code compiles, but is untested.

Tim

Version 1.5 released:

4bit method now works without the New LiquidCrystal library (was always supposed to work this way, oversight on my part). Update switch now optional on all functions, defaults to NO_UPDATE.

Download LCDBitmap Library v1.5

Tim

You are awesome! I was thinking of this a couple of weeks ago!
It's like you read my mind :wink:

I am going to try this out!
I had made this myself:
http://freeduality.tk/?page_id=16
a lcd controled by a IO expander.
and had written a library for it,
you say your code works with the standard lcd library :)?

I'll give it a try with my code tomorrow and will let you know :slight_smile:

just can\t say it enough, this is so awesome! :slight_smile:

greetings,
Duality

duality:
You are awesome! I was thinking of this a couple of weeks ago!
It's like you read my mind :wink:

I am going to try this out!
I had made this myself:
http://freeduality.tk/?page_id=16
a lcd controled by a IO expander.
and had written a library for it,
you say your code works with the standard lcd library :)?

I'll give it a try with my code tomorrow and will let you know :slight_smile:

just can\t say it enough, this is so awesome! :slight_smile:

greetings,
Duality

LCDBitmap works with the standard LiquidCrystal library if your LCD connection is standard 4-bit parallel (6 wires). If your LCD's connection is I2C or uses a shift register, you'll also need the New LiquidCrystal library in addition to the LCDBitmap library.

Tim

LCDBitmap updated to version 1.6. This is a small update that fixes a range checking bug. As the library is very stable at this point, I'll probably start working on a different method of bitmap storage to save SRAM space. Download the new version from the link below:

LCDBitmap Library v1.6 Download

Tim

Tim,
The preprocessor check you are using in LCDBitmap.h for trying to detect
the missing new liquidCrystal library is not using valid preprocessor syntax.
#ifdef does not support logical operations, so it isn't working the way you
intended it to work.
You will see the warning when using the 1.x IDE.

The sub device defines being checked seem to be for the purpose of including "LCD.h" but
the liquidCrystal.h in the new LiquidCrystal library already includes "LCD.h".
Since there is no need to include "LCD.h" again,
I would suggest avoiding the use of the sub device defines as it ties the bitmap library
to modifications and updates to the fm's library. i.e. if a new sub device is added
or the sub device define changes, this library breaks.

There are a couple of ways to handle it.

  1. Do nothing instead
  2. error off if neither the stock or fm's library is being used.

It depends on if you want to give an error if the user is using some other LCD library
other than stock LiquidCrystal or fm's library.

I would lean towards option 2 as it offers a meaningful error vs just breaking with
nothing but strange errors if they are using some other 3rd party LCD library.

It turns out that even including <LiquidCrystal.h> is problematic because when using another
3rd party LCD library (LiquidCrystalFast for example) the include path will not point to a directory that contains this header file
as the alternate library does not have it/use it.
Luckily the compiler doesn't treat a missing include file as a fatal error and
will generate a few more errors beyond this condition.
So while very ugly and will generate a few strange errors/warnings before the useful error message,
it is still possible to give the user the error to indicate that the bitmap library only works
with the new LiquidCrystal library.

Here is an alternative that works:

#ifndef LiquidCrystal_h // Using some library other than stock LiquidCrystal?
#ifndef _LCD_H_ // using some other library than fm's new LiquidCrystal?
    #error You must install New LiquidCrystal library to work with non-4bit projects: http:/bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
#endif
#endif

This will work with the stock LiquidCrystal library or fm's library and if some other 3rd party
library is used, reports the error.


Just a minor nit, the declaration of "sample" in the examples creates a warning.
It needs to be declared as an unsigned int to eliminate that.

--- bill

bperrybap:
Tim,
The preprocessor check you are using in LCDBitmap.h for trying to detect
the missing new liquidCrystal library is not using valid preprocessor syntax.
#ifdef does not support logical operations, so it isn't working the way you
intended it to work.
You will see the warning when using the 1.x IDE.

However, you can do:

#if defined(FOO) && defined(BAR) && (!defined(BLETCH) || (BLETCH > 4))
#error "bogus"
#endif

MichaelMeissner:

bperrybap:
Tim,
The preprocessor check you are using in LCDBitmap.h for trying to detect
the missing new liquidCrystal library is not using valid preprocessor syntax.
#ifdef does not support logical operations, so it isn't working the way you
intended it to work.
You will see the warning when using the 1.x IDE.

However, you can do:

#if defined(FOO) && defined(BAR) && (!defined(BLETCH) || (BLETCH > 4))

#error "bogus"
#endif

#if is the "smarter" proper preprocessor directive choice as it supports logicals, bitwise, math, and even text comparisons,
but the point I was trying to make was that using the sub device defines and
the include of "LCD.h" is not really needed and has the potential to break should the new LiquidCrystal
library be expanded to other sub devices in the future.

--- bill

bperrybap:
Tim,
The preprocessor check you are using in LCDBitmap.h for trying to detect
the missing new liquidCrystal library is not using valid preprocessor syntax.
#ifdef does not support logical operations, so it isn't working the way you
intended it to work.
You will see the warning when using the 1.x IDE.

The sub device defines being checked seem to be for the purpose of including "LCD.h" but
the liquidCrystal.h in the new LiquidCrystal library already includes "LCD.h".
Since there is no need to include "LCD.h" again,
I would suggest avoiding the use of the sub device defines as it ties the bitmap library
to modifications and updates to the fm's library. i.e. if a new sub device is added
or the sub device define changes, this library breaks.


Just a minor nit, the declaration of "sample" in the examples creates a warning.
It needs to be declared as an unsigned int to eliminate that.

I get no warnings with Arduino 0023 nor 1.0.1. Not sure what warnings I should be seeing.

The LCD.h include was added as suggested by fm. However, it does appear that it's not needed. Never questioned the requirement as I assumed it was needed.

I do see the error in my ifdef logic, I'll change that in a new release.

Making "sample" an unsigned int adds about 500 bytes to the compiled code size (because it loads the floating point library). Not sure where you see a warning with this one either as I see no warning. I could change it to "#define sample 4000", but that appears to work exactly the same as the "const". More interested in why I'm not getting any warnings and why I should be using an unsigned int instead of a const or define as it's not really a variable, it's static.

Tim

teckel:
I get no warnings with Arduino 0023 nor 1.0.1. Not sure what warnings I should be seeing.

Turn on "Show verbose output during" [] compilation
under [File]->[Preferences]
Then you will see the warning.

Making "sample" an unsigned int adds about 500 bytes to the compiled code size (because it loads the floating point library).
Not sure where you see a warning with this one either as I see no warning. I could change it to "#define sample 4000", but that appears to work exactly the same as the "const". More interested in why I'm not getting any warnings and why I should be using an unsigned int instead of a const or define as it's not really a variable, it's static.

Tim

When you say "static" I assume you mean "not changing" vs a static declaration
as "static" to the compiler merely means that it is not visible to other modules.
It is independent of type. (char, int, unsigned int, etc...)

I'm guessing that when you changed the variable type to "unsigned int" that you removed the "const"
declaration.
If so, then you are not getting the floating point library but rather
what you are seeing is the difference in optimization that is possible when
declaring the variable a "const" vs not const AND also not "static".

In this code, if it were declared "static" instead of "const" the compiler would have optimized it the same as if it were declared const.
To avoid the warning, the type needs be unsigned because both millis() and in particular currentMillis
are both unsigned.

The compiler complains about comparing a signed variable "sample" to an unsigned variable "currentMillis"
because the comparisons will probably not work as intended if sample is negative or overlows past 32767 and becomes
negative.

To keep things clean and avoid the warning, you should declare sample to be some unsigned type.
To get the best optimization, you will also need to declare it const or static.

const unsigned int sample = 4000;  // Sets how long to run each sample

--- bill

Yes, I meant static as in not changing, not as a static declaration, and I get what you're talking about.

However, it seems that this:

#define sample 4000

would be an easier/better way to do it rather than using the const:

const unsigned int sample = 4000;

Less chance of the compiler complaining if the comparison variable type changes. It seems either way are treated identically to the compiler.

Tim