Pages: 1 [2]   Go Down
Author Topic: M2TKLIB Hello World with LiquidCrystal_I2C  (Read 2699 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I found this data on the connections of my display

Quote
③PIN  CONNECTIONS       
Pin     Symbol   Function
1   VSS   Ground for Logic(0V)
2   VDD   Power supply for Logic(+5V)
3   V0   Power supply for LCD Driver
4   RS   H: Data;L: Instruction Code
5   R/W   H: Read;  L: Write
6   E   Enable signal
7~14   DB0~DB7   Data Bus Line
15   A   Backlight Power(+5V)
16   K   Backlight Power(0V)

and tried to write a 'constructor' as follows (based on the library code I have copied at the bottom of this post

Code:
LiquidCrystal_I2C lcd ( 0x3F, 6, 5,4 ,
                        7, 8, 9, 10,
                         15,POSITIVE);

All I am getting at the moment is the backlight turns off and nothing is displayed (although there seems to be 2 lines of faint characters (this is a 4 line display)

One thing I thought was odd is that it only has 4 data pins in the constructor, but the table above talks about 8.  I did try pins 11 to 14 instead of 7 to 10, but it doesn't seem to make any difference.

Code:
   /*!
    @method     
    @abstract   Class constructor.
    @discussion Initializes class variables and defines the I2C address of the
    LCD. The constructor does not initialize the LCD.
   
    @param      lcd_Addr[in] I2C address of the IO expansion module. For I2CLCDextraIO,
    the address can be configured using the on board jumpers.
    @param      En[in] LCD En (Enable) pin connected to the IO extender module
    @param      Rw[in] LCD Rw (Read/write) pin connected to the IO extender module
    @param      Rs[in] LCD Rs (Reset) pin connected to the IO extender module
    @param      d4[in] LCD data 0 pin map on IO extender module
    @param      d5[in] LCD data 1 pin map on IO extender module
    @param      d6[in] LCD data 2 pin map on IO extender module
    @param      d7[in] LCD data 3 pin map on IO extender module
    */
   LiquidCrystal_I2C(uint8_t lcd_Addr, uint8_t En, uint8_t Rw, uint8_t Rs,
                     uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7 );
   // Constructor with backlight control
   LiquidCrystal_I2C(uint8_t lcd_Addr, uint8_t En, uint8_t Rw, uint8_t Rs,
                     uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7,
                     uint8_t backlighPin, t_backlighPol pol);
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Another step forward  !      Figured out the constructor numbers are bit numbers, so I had to follow traces on the backpack board to see where the pfc8574 pins were wired to on the LCD display proper.  Then translate those to bit numbers.

For anyone else with a sainsmart LCD display with their "lcd2004" I2C adapter, the following seems to work.

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

Logged

Germany
Online Online
Edison Member
*
Karma: 100
Posts: 1232
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good to see that you made some progress here. Do the m2tklib examples work?

I have selected fm's New LiquidCrystal mainly because of the large number of supported display types. It has also a nice software architecture with a common base class (class LCD). All other variants are derived from this base clase. So I was able to use the base class inside m2tk and do the testing with the 8bit parallel variant. Indeed all my testing with the New LiquidCrystal lib had been very successful, so i was hoping that also the I2C variant will work without bigger problems.

@Bill: M2tk calls the "begin()" member function of the LCD base class to init the display. I can't remember if there exists something like a "init()" member function. It turned out, that the LCD base class had the same interface as the original Arduino LiquidCrystal class. And also my tests with the 8 bit hardware setup had not revealed any issue concerning init.

Oliver


Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);"

Code:
#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 !  
Logged

Dallas, TX USA
Offline Offline
Edison Member
*
Karma: 47
Posts: 2334
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Bill: M2tk calls the "begin()" member function of the LCD base class to init the display. I can't remember if there exists something like a "init()" member function. It turned out, that the LCD base class had the same interface as the original Arduino LiquidCrystal class. And also my tests with the 8 bit hardware setup had not revealed any issue concerning init.

I worked with fm to ensure that the library is transparently compatible with the original LiquidCrystal library.
The reason I brought up the begin()/init() issue is that there are some other i2c libraries out there (which I wouldn't recommend)
but are never the less popular and in use.
Those other i2c libraries have different constructors and specify the geometry in the constructor
and then use a call to init() to initialize them vs begin().
To me this is not smart since it makes them incompatible with the LiquidCrystal initialization.
But since it appears that your code calls the lcd initialization, it will matter to your code
if you decide to support these other i2c to hd44780 libraries.

My personal opinion, don't support those libraries and be done with it.
Just steer people to fm's library which works the same on many different interfaces.

--- bill
Logged

Germany
Online Online
Edison Member
*
Karma: 100
Posts: 1232
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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
Logged

Germany
Online Online
Edison Member
*
Karma: 100
Posts: 1232
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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
Logged

Pages: 1 [2]   Go Up
Jump to: