Pages: [1]   Go Down
Author Topic: Problem addressing two displays in U8GLIB  (Read 829 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

first of all: thanks a lot for the great U8GLIB to all contributors. It is a pleasure using it.

I habe successfully used it for a while with an ST7920 based display, conected to an Arduino UNO. Now I would like to add a Nokia 5110 display as a second display, but this interferes with my first display. I did not connect the seconds display yet, just started with the additional code.

These are the defintions (I am using constants for the pins, but have resolved this here, so no complaints about this code, please ;-) ):

Code:
U8GLIB_ST7920_128X64_1X u8g    (4, 2, 3);        
U8GLIB_PCD8544          u8g_nok(4, 2, 12, 13, 5 ) ;

So I am sharing sck and mosi. Thought, this would be ok.

I have added a second (still empty) picture loop:

Code:
 // draw primary lcd
  u8g.firstPage();
  do {
    drawAll();
  } while( u8g.nextPage() );

  // draw secondary lcd
  u8g_nok.firstPage();
  do {
  } while( u8g_nok.nextPage() );

But as soon as the second loop is active (in addition to the unchanged loop for the first display) it draws a horizontal line with some (random?) dots on my ST7920 display.

What can I do to change this behaviour?
« Last Edit: August 05, 2013, 09:57:09 am by thomashb » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13478
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

(no experience with 2 graph displays, but here some thoughts)
In general you should disable them alternately so that only one is enabled at any time.

so check the constructors what is the (CS) Chip Select pin

Code: (not tested)
U8GLIB_ST7920_128X64_1X u8g (4, 2, 3);    // pin 3 is CS
U8GLIB_PCD8544          u8g_nok(4, 2, 12, 13, 5 ) ;  // pin 12 is CS

...

  // draw primary lcd
  digitalWrite(12, LOW);  // hard coded disable display 2
  digitalWrite(3, HIGH);
  u8g.firstPage();
  do {
    drawAll();
  } while( u8g.nextPage() );

  // draw secondary lcd
  digitalWrite(3, LOW);  // hard coded disable display 1
  digitalWrite(12, HIGH);
  u8g_nok.firstPage();
  do {
  } while( u8g_nok.nextPage() );


A nice way to alternate both displays is to use one pin as CS and use an invertor for one of the displays.
Then they are switched automatically. (but you cannot switch them on both).

Instead of this hard coded way, the library could be extended with an disable() and enable() and isEnabled() function.
For SPI it is not that difficult see above, for other interfaces it might be more work.
(but yes it would slow its performance down as every operation should check the state)

hope this helps
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

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

Hi

The initial code looks ok. Are you able to see the correct result on both displays by disabling the other picture loop completly?
First, ensure that both displays are working correctly under your hardware configuration.

Still there might be some risk, that u8glib has some bugs there. Adding to displays has not been tested so much.

Another option would be to use a virtual display. But i have not created a C++/Arduino example for this. Here is the plain c example for it: http://code.google.com/p/u8glib/wiki/virtualscreen.

Oliver

Logged

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

Rob, Oliver,

Thanks for your replies.

@Rob: I have tried your changes, but they do not have any effect. I assume the CS lines are handled correctly by U8GLIB so there is no need to explicitly set them. And I have measured some "pulses" on the CS line of the ST7920 display. So this looks ok, as far as I can see.

@Oliver: I have connected both displays now and they both look fine, showing their independent results. Only problem remains the one disturbed horizontal line on the ST7920 display, slighly above the middle (approxinately line 30). Once the picture loop for the PCD8544 (aka Nokia 5110) is removed the problem vanishes as well and the ST7920 looks perfectly right.

The best work around I have found by now is to reverse the order of the two picture loops, drawing the PCD8544 first and the ST920 afterwards ( I am refreshing the displays once a second). That way the problem is only visible for a short moment - but this is not the final solution, I hope. smiley-confuse

A virtual display does not seem to be the right solution here, since the two displays should remain independent from each other and one should not expand the other. Or did I get that wrong?

It somewhat looks to me as if the ST7920 hardware is ignoring the CS signal. Could that be the case? Did anyone experience a behavour like this before? The display type is "SainSmart LCD 12864".

Any more thoughts on this?
Logged

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

Virtual display: Correct, would not help here, but would be interessting to see if this works.

ST7920: This controller has some strange characteristics. I would not wonder if this is not working correctly. But maybe there is also a bug in U8glib. Maybe you can connect the CS line of the ST7920 with GND (CS of the ST7920 is high active), to check if the display still works (it should not work, because CS is LOW)

Oliver
Logged

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

Regarding the virtual displays: I would like to help in testing this functionality. But I did not succees in transferring the code to the Arduino. Did anyone do this already and can provide an example? Then I am happy to adopt it to my setup and test it.

Regarding CS:

I have tried some variantions now. Summary: the CS line shows strange behaviour on the ST7920…  smiley-confuse

1) CS connected to ground or left unconnected at boot time => the display stays blank. Would be expected to be like that.

2) CS connected to the CS output (3 in my case) all the time => the display updates and the destorted lines are displayed, only if the second display loop is active (as described in my earlier posts)

3) CS connected to the CS output (3 in my case) during booting and changed to ground after booting => the display updates with CS at ground (although it should not) and the destorted lines are displayed, no matter if the second display loop is active or not! Very strange…

I can not understand #3 completely, but it looks as if CS does not work as expected at least. I have checked the wiring several times and CS is correctly routed all the way from output 3 of the Uno to pin 4 of the LCD board, labelled "R/S(CS) - Data selection signal when parallel or chip selection when serial".

Any more debugging ideas on this?

Logged

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

To solve your initial problem: Will everything work if you use different pins for the CLK signal?
Or did you solve your initial problem in a different way?

Oliver
Logged

Pages: [1]   Go Up
Jump to: