Pages: 1 2 [3]   Go Down
Author Topic: Connecting a graphical LCD via a I2C using a 16-bit port expander  (Read 13276 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 278
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, thanks for the update.  I would be happy to design a PCB and send you a few if I had a schematic to work from?

Also wondering if your project can support different GLCD resolutions?  Thanks
Logged

Dallas, TX USA
Offline Offline
Faraday Member
**
Karma: 63
Posts: 2636
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nick,
I'm a bit confused as to how the code is really working on the read side.
The data lines should be read 320ns after E is raised but *before* E is lowered
because the data is only guaranteed to be valid on the data bus 10ns after E is lowered.

If I look at readData() it
raises and lowers E twice which will do the "dummy" read and then
the real "read",
but it isn't valid to read the data lines on the data bus *after* you lower E since
the glcd is supposed to tri-state the data bus when E is low.
So the validity of the data lines is rapidly collapsing between when the
loop ends and when the data lines are sampled lower in the routine
Since just a single AVR instruction is going to take more than 10ns I'm not sure
how the code can read the data from the glcd.

Were you getting valid data on your glcd reads? or just always getting 0 or FF?
i.e. does line() work properly by overstriking the existing pixels?
Am I missing something?

--- bill

Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It's working but perhaps by good luck rather than good management. Do you mean to change it to be like this?

Code:
// read the byte corresponding to the selected x,y position
byte I2C_graphical_LCD_display::I2C_graphical_LCD_display::readData ()
{
 
#ifdef WRITETHROUGH_CACHE
  return _cache [_cacheOffset];
#endif
 
  // data port (on the MCP23017) is now input
  expanderWrite (IODIRB, 0xFF);
 
  // lol, see the KS0108 spec sheet - you need to read twice to get the data
  startSend ();
    doSend (GPIOA);                  // control port
    doSend (LCD_RESET | LCD_READ | LCD_DATA | LCD_ENABLE | _chipSelect);  // set enable high
  endSend ();

  startSend ();
    doSend (GPIOA);                  // control port
    doSend (LCD_RESET | LCD_READ | LCD_DATA | _chipSelect);  // pull enable low to toggle data
  endSend ();

  startSend ();
  doSend (GPIOA);                  // control port
  doSend (LCD_RESET | LCD_READ | LCD_DATA | LCD_ENABLE | _chipSelect);  // set enable high
  endSend ();

  byte data;

  if (_ssPin)
    {
    digitalWrite (_ssPin, LOW);
    SPI.transfer ((_port << 1) | 1);  // read operation has low-bit set
    SPI.transfer (GPIOB);             // which register to read from
    data = SPI.transfer (0);          // get byte back
    digitalWrite (_ssPin, HIGH);
    }
  else
    {
    // initiate blocking read into internal buffer
    Wire.requestFrom (_port, (byte) 1);
   
    // don't bother checking if available, Wire.receive does that anyway
    //  also it returns 0x00 if nothing there, so we don't need to bother doing that
    data = i2c_read ();
    } 

  // drop enable AFTER we have read it
  startSend ();
  doSend (GPIOA);                  // control port
  doSend (LCD_RESET | LCD_READ | LCD_DATA | _chipSelect);  // pull enable low to toggle data
  endSend ();

  // data port (on the MCP23017) is now output again
  expanderWrite (IODIRB, 0);
 
  return data;
 
}  // end of I2C_graphical_LCD_display::readData

That also appears to work. smiley
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Were you getting valid data on your glcd reads? or just always getting 0 or FF?
i.e. does line() work properly by overstriking the existing pixels?

Yes I was.
Yes it does.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, thanks for the update.  I would be happy to design a PCB and send you a few if I had a schematic to work from?

The schematic is here:

http://www.gammon.com.au/forum/?id=10940

I already did an Eagle file for it (attached). It may or may not be 100% correct, I haven't tested it.


Also wondering if your project can support different GLCD resolutions?  Thanks

Not sure, it's been a while since I worked on it.

* Graphicl LCD Backpack.brd (18.31 KB - downloaded 32 times.)
* Graphicl LCD Backpack.sch (69.87 KB - downloaded 30 times.)
Logged

Dallas, TX USA
Offline Offline
Faraday Member
**
Karma: 63
Posts: 2636
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Were you getting valid data on your glcd reads? or just always getting 0 or FF?
i.e. does line() work properly by overstriking the existing pixels?

Yes I was.
Yes it does.

Interesting... I'm kind of surprised.

hmm. I wonder if it is glcd specific and some glcd modules disable the bus in s/w vs hardware
(which might make the validity stretch beyond the E dropping a while longer)
or maybe they use R/W to determine when to drive the bus and not actually gate it with E.
The samsung ks0107/8 spec and all of the glcd specs I have show
the read data only being valid while E is high.
They may not have really implemented it that way but
its probably best/safest to read the data when E is high - That's what I do in the glcd library.

--- bill




Logged

UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 278
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Nick, much appreciated - if you PM me I will send you a few when they arrive :-)

Might take a month or two.....
Logged

Sevilla. Spain
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

He made ​​his project and it works perfectly.
I have a question with arduino rookie.
I see in the library instruction to display on the LCD voltage value is refreshed every 5 seconds. It is a decimal variable (eg 230.33 volts)
I've tried with:
lcd.letter (voltage);
But I get an X.

Thank you and congratulations on your development.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello.
This is the only post on internet that talk abour glcd with st7920 controller connect in i2c to arduino.
I have this display http://mikroshop.ch/pdf/QC12864B.pdf.
there isn't CS1 and CS2 !
there is a chance a use this display with i2c expander mcp23017.

Sorry i beginner in english and arduino too.

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is anybody have a luck to use this library and MCP23017 with 19264 displays? I mean 3 chips select?
chip / pin   CS0   CS1   CS2
chip 0   LOW   HIGH   HIGH
chip 1   HIGH   LOW   HIGH
chip 2   HIGH   HIGH   LOW
Logged

Pages: 1 2 [3]   Go Up
Jump to: