M2TKLIB Hello World with LiquidCrystal_I2C

I worked with fm to ensure that the library is transparently compatible with the original LiquidCrystal library.

Ah, this explains why it had been that easy to port the existing procedures to New LiquidCrystal lib.

I was requested by several users to support I2C for m2tklib character displays, but i do not plan to support any further libs. In fact, you both confirmed me that this lib is flexible enough to support several other types of hardware also.

Oliver

now the M2TKLIB Hello World example works, modified as below.

Thanks for the feedback. Let me know if there are any questions regarding M2tklib.

Oliver

digimate:
Yes, was just writing this when you posted - now the M2TKLIB Hello World example works, modified as below. Changes are to include <Wire.h>, to include <LiquidCrystal_I2C.h> instead of <LiquidCrystal.h>, and to set it up using "LiquidCrystal_I2C lcd ( 0x3F,2,1,0, 4,5,6,7,3,POSITIVE);"

#include <Wire.h> 

#include <LiquidCrystal_I2C.h>
#include "M2tk.h"
#include "utility/m2ghnlc.h"

LiquidCrystal_I2C lcd ( 0x3F,2,1,0, 4,5,6,7,3,POSITIVE);

M2_LABEL(hello_world_label, NULL, "Hello World!");
M2tk m2(&hello_world_label, NULL, NULL, m2_gh_nlc);

void setup() {
 m2_SetNewLiquidCrystal(&lcd, 16, 2);
}

void loop() {
 m2.draw();
 delay(500);
}




Thanks for ALL the help !

When I try to compile this code I get an error as follows.

Arduino: 1.5.6-r2 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

Build options changed, rebuilding all

Using library Wire in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire (legacy)

Using library LiquidCrystal_I2C in folder: C:\Users\KB0NRK\Documents\Arduino\libraries\LiquidCrystal_I2C (legacy)

Using library M2tk in folder: C:\Users\KB0NRK\Documents\Arduino\libraries\M2tk (legacy)

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=156 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\mega -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire -IC:\Users\KB0NRK\Documents\Arduino\libraries\LiquidCrystal_I2C -IC:\Users\KB0NRK\Documents\Arduino\libraries\M2tk C:\Users\KB0NRK\AppData\Local\Temp\build1579395692306476180.tmp\MenuX2L.cpp -o C:\Users\KB0NRK\AppData\Local\Temp\build1579395692306476180.tmp\MenuX2L.cpp.o

In file included from MenuX2L.ino:4:
C:\Users\KB0NRK\Documents\Arduino\libraries\M2tk/utility/m2ghnlc.h:32: error: variable or field 'm2_SetNewLiquidCrystal' declared void
C:\Users\KB0NRK\Documents\Arduino\libraries\M2tk/utility/m2ghnlc.h:32: error: 'LCD' was not declared in this scope
C:\Users\KB0NRK\Documents\Arduino\libraries\M2tk/utility/m2ghnlc.h:32: error: 'lc_ptr' was not declared in this scope
C:\Users\KB0NRK\Documents\Arduino\libraries\M2tk/utility/m2ghnlc.h:32: error: expected primary-expression before 'cols'
C:\Users\KB0NRK\Documents\Arduino\libraries\M2tk/utility/m2ghnlc.h:32: error: expected primary-expression before 'rows'
MenuX2L.ino:6: error: 'POSITIVE' was not declared in this scope
MenuX2L.ino: In function 'void setup()':
MenuX2L.ino:12: error: 'm2_SetNewLiquidCrystal' was not declared in this scope

can you help me?

You either have the wrong library or don't have it properly installed.
For that LiquidCrystal_I2C constructor, you need this library:
https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home

bperrybap:
You either have the wrong library or don't have it properly installed.
For that LiquidCrystal_I2C constructor, you need this library:
https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home

I have LiquidCrystal_V1.2.1 installed and use it in other sketches.

If I change the above example with "LiquidCrystal_I2C lcd(0x27, 20, 4);", which works for me it highlights the following line.

m2_SetNewLiquidCrystal(&lcd, 16, 2);

And gives the error -
Arduino: 1.5.6-r2 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

Build options changed, rebuilding all

Using library Wire in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire (legacy)

Using library LiquidCrystal_I2C in folder: C:\Users\KB0NRK\Documents\Arduino\libraries\LiquidCrystal_I2C (legacy)

Using library M2tk in folder: C:\Users\KB0NRK\Documents\Arduino\libraries\M2tk (legacy)

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=156 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\mega -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire -IC:\Users\KB0NRK\Documents\Arduino\libraries\LiquidCrystal_I2C -IC:\Users\KB0NRK\Documents\Arduino\libraries\M2tk C:\Users\KB0NRK\AppData\Local\Temp\build1579395692306476180.tmp\MenuX2L.cpp -o C:\Users\KB0NRK\AppData\Local\Temp\build1579395692306476180.tmp\MenuX2L.cpp.o

In file included from MenuX2L.ino:4:
C:\Users\KB0NRK\Documents\Arduino\libraries\M2tk/utility/m2ghnlc.h:32: error: variable or field 'm2_SetNewLiquidCrystal' declared void
C:\Users\KB0NRK\Documents\Arduino\libraries\M2tk/utility/m2ghnlc.h:32: error: 'LCD' was not declared in this scope
C:\Users\KB0NRK\Documents\Arduino\libraries\M2tk/utility/m2ghnlc.h:32: error: 'lc_ptr' was not declared in this scope
C:\Users\KB0NRK\Documents\Arduino\libraries\M2tk/utility/m2ghnlc.h:32: error: expected primary-expression before 'cols'
C:\Users\KB0NRK\Documents\Arduino\libraries\M2tk/utility/m2ghnlc.h:32: error: expected primary-expression before 'rows'
MenuX2L.ino: In function 'void setup()':
MenuX2L.ino:13: error: 'm2_SetNewLiquidCrystal' was not declared in this scope

As you can see I am new to this and need working codeto learn from.
Thanks Earl

earlboatman:

bperrybap:
You either have the wrong library or don't have it properly installed.
For that LiquidCrystal_I2C constructor, you need this library:
https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home

I have LiquidCrystal_V1.2.1 installed and use it in other sketches.

If I change the above example with "LiquidCrystal_I2C lcd(0x27, 20, 4);", which works for me it highlights the following line.

m2_SetNewLiquidCrystal(&lcd, 16, 2);

Due to the way the IDE has chosen to do builds,
you can't have two libraries installed that use a header file with the same file name.
If you do, it will cause problems.

LiquidCrystal_I2C.h is a library header file in both
fm's library and the LiquidCrystal_I2c library you are using
so you can only have one them installed at time.
Also, keep in mind that those two libraries don't have the same functionality and are initialized differently.

My recommendation is to use fm's library since that one works on all the PCF8574 based backpacks.
The catch is you must properly fill in the constructor to tell it how the pins on the pcf8574 chip are
wired to the hd44780 interface on the lcd.

--- bill

bperrybap:
You either have the wrong library or don't have it properly installed.
For that LiquidCrystal_I2C constructor, you need this library:
https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home

How do you use the LiquidCrystal_I2C constructor? Do I need to change the name of the library to LiquidCrystal_I2C so it can find the header file?

The IDE will find the header no matter what the directory name of the library is.
It looks in all of the to find the header file. And that is why you can't have two
libraries with the same library header file name since the IDE may find the library
header in a different library than the one you want.

In terms of using the constructor, it is used to initialize the library object
the parameters are specific to each library.
To see what they are and how to use them you must consult the documentation
for each library.
Below are constructor examples from two different libraries.
Each of these creates a library object called "lcd" for the library.

LiquidCrystal_I2C lcd(0x27, 20, 4);
LiquidCrystal_I2C lcd ( 0x3F,2,1,0, 4,5,6,7,3,POSITIVE);

Beyond the constructor, there are also initialization functions that must be called.
And those are also specific to the given library.
Here are typical examples of those functions:

lcd.init();
lcd.begin();

You must first pick which library you want to use and for these two libraries only
one can be installed at a time.
Then use the proper constructor and initialization functions for that library.

With PCF8574 based backpacks, there is no "it just works" solution for all backpacks,
since there is no standardized way to wire up the PCF8574 chip i/o pins to a HD44780 LCD.

The two libraries that you have mentioned are different.

The LiquidCrystal_I2C library will only work on some backpacks since the pin wiring is hard coded.
fm's library since will work on any PCF8574 based backpack but you have to fill in the constructor
with the proper pin mapping for your board.

I prefer fm's library since it will work on any board. But you do have get the constructor
correct to get it to work.

My suggestion at this point, is to drop back to a simpler environment to
get the LCD working before you try toss m2tklib on top of it.
i.e. do some sort of "hello world" to ensure that the LCD is configured properly.

My recommendation is to use fm's library as it is fully compatible with the standard
LiquidCrystal library.
What that means is that to change from using the 4 bit interface, all you have to do
is change the header file(s) you include, change the constructor, and it will "just work".
No changes to the actual sketch code will be needed.

If you go with the LiquidCrystal_I2C library and are luckily enough that it even works
with your backpack, you will have modify your sketch code to change the begin() call as well,
sinc the LiquidCrystal_I2C library requires using an init() function.

--- bill

cleaning out the libraries did i t and also using " lcd.begin(20,4);".

now I can use your menus with some of of my displays.

I also have some Akafugu TWILCD 40x2/40x4/RGB Display Controller Backpacks from Akafugu Corporation and want to use RGB with my project and so will half to incorporate the TWILiquidCrystal library.

thanks for your help.