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 ):
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.
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)
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.
@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. :~
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".
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)
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… :~
CS connected to ground or left unconnected at boot time => the display stays blank. Would be expected to be like that.
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)
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".
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?