i2c controller with 1602 LCD giving 'NEGATIVE' was not declared in this scope

I've created this thread to stop cluttering the other thread I accidentally hijacked at [SOLVED] MJKDZ brand I2C Controller working with 1602 LCD - #30 by system - Displays - Arduino Forum

If anyone can help then please continue in this thread instead. Thank you.

The include paths from the compile line look ok.
Given that the defines POSITIVE and NEGATIVE are not being defined that means that
the proper headers are not being included.

Your exact sketch compiles for me.
(Although your HelloWorld_i2c is different from the one included in the examples of fm's library)
Where did you get your library from?
Are you running the latest version from fm's bitbucket site?
version 1.2.1
https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
There are some similar and modified libraries out there being hosted by other sites.
Don't use them!
For example, if you used the LiquidCrystal_I2C library that had a link on the wordpress
site you linked to in the other thread, you will see the exact problem you are seeing.
That site is awful for showing examples that need fm's library and then
providing a link to a LiquidCrystal_I2C library that will not work with either of their examples.
My recommendation is to get a known real copy of fm's library from fm's site.
That is the library you want/need.

I'm guessing that will resolve your issue.

--- bill

I definitely got the library from the official site, but I am unsure which version it is. In any case it was sometime in the last month.

The official example doesn't include anything other than the i2c address in the constructor, but as soon as I get home I will load it up and check the version of the library that I have. I do know that I encountered the same problem when I added either POSITIVE or NEGATIVE when using a full constructor.

mihalski:
I definitely got the library from the official site, but I am unsure which version it is. In any case it was sometime in the last month.

The official example doesn't include anything other than the i2c address in the constructor, but as soon as I get home I will load it up and check the version of the library that I have. I do know that I encountered the same problem when I added either POSITIVE or NEGATIVE when using a full constructor.

Unfortunately, there is no revision information in the actual library files so it isn't obvious what revision for a library is.
But the latest released library hasn't changed in over a year.
If you got 1.2.1 from fm's bitbucket site in the last month you got the latest.

Something odd is happening. It appears that the sketch is somehow including LiquidCrystal_I2C.h from a different library.

As a test, go in and put a #error in the LiquidCrystal_I2C.h file that should be included.
maybe after these lines in the header file:

#include "I2CIO.h"
#include "LCD.h"
#error "blah blah blah" // just to check to see if this is really being included.

Can you post all the warnings and errors from the compile?
I'm guessing that there are other errors & warnings.

Also, the IDE does some really stupid things when it inserts other includes.
It can really mess up your code by puting the additional includes in the middle of your code
rather than at the top.
Try adding something like:

static char dummyvar; // dummy declaration for STUPID IDE!!!!

to the very top line of your sketch.
This will force the IDE to put its headers at the top instead of dropping them willy nilly
in the middle of your file which can screw up the other includes.

--- bill

Very odd indeed. Have you tried to instal the library from the new option on the IDE?
I don't think it will do much as you can already see the examples.

I'm on the road the next few days so I took the Arduino, i2c adapter and 1602 LCD with me as well as my Macbook.

I did a clean installation of Arduino and the NewLiquidCrystal library and then loaded the HelloWorld_i2c, changed the constructor to LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); and BAM!! Worked first time!

Now in a few days when I get home I'll have to figure out what evil is causing the problem on my main PC.

Thank you all for your help, and I'll return when I (hopefully) solve the problem with the help of your suggestions.

Regards,
Michal

One of things that is bad about the build methodology used by
the Arduino IDE is all the multiple/goofy include paths and the way the IDE constructs
the include paths.
The problem with the IDE methodology is that the IDE has to scan
your sketch and look for includes. Then it must scan the all the library directories to
look for the headers and then add the directory where each header is
found to the include path.
The problem with that methodology is that it doesn't work when there
are header name collisions.
i.e. two different directories could happen to have the same header file name.
The user will never know since it isn't obvious and odd things can happen.
Perhaps you have this going on in your system.
You may have a LiquidCrystal.h or LCD.h header file in some other library directory.

I've also seen cases where the C++ compiler won't put out an error
when a header file is not located or doesn't exist.
To me a missing header file is a hard error.


IMO, a better build methodology would have been to simply have two paths

  • one for the users "libraries" directory
  • one for the system "libraries" directory.
    And then not do any scanning.

Then sketches would specify the exact header they wanted.
i.e.
#include <Wire/Wire.h>
etc..

and not have to ever worry about any issues
related to header name collisions.

--- bill

Great it works for me too.
In my case, the matter was also :
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
(note the different address you should find thanks to the I2C scanner Arduino Playground - I2cScanner)