Thursday, June 20, 2013

Universal 8 Bit Graphics Library bug

A while back I posted a video that showed a strange bug that was happening with my oscilloscope LCD program. It used U8GLib or the Universal 8 Bit Graphics Library.  The video is available at, http://youtu.be/1qPy6FVSllY

** UPDATE ** This problem is caused by updating the data while it is being displayed.  The update must not happen within the display loop.

Then I made a perfectly working oscilloscope using the Universal TFT Library and a better LCD. So then I thought I would go back and see what was the problem with U8GLib.

To rule out the LCD display I purchased a KS0108 compatible display because I could run it with its own support software or with the U8GLib.  With the KS0108 driver, I could not scale the amplitude of the input waveform, a new issue.  However the sine wave turned out perfectly using the KS0108 driver.  Then the same software really went crazy when I tried to use the U8GLib drivers.  Here is the video on YouTube, http://youtu.be/l-I4vf83OIc

Does anyone else have this problem or know of a solution??

Here is a picture of what the display should look like;


 But this is what happens when you move the position control to center the sine wave;

3 comments:

Gianni Gallo said...

good evening
I have the same problem y between y35 and y45
It does not display the string.
In my project I use an LCD 12864 st7920 Arduino Mega and a 4x4 keypad
sorry but I did not understand how you solved the problem.
can you show me the piece of code you used to solve the problem
TKS Gianni

Bob Davis said...

** UPDATE ** This problem is caused by updating the data while it is being displayed. The update must not happen within the display loop.

Bob Davis said...

#include "U8glib.h"
// 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
U8GLIB_ST7920_128X64_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16);

int Sample[128];
int Input=0;
int OldInput=0;
int rate=0;

void u8g_prepare(void) {
u8g.setFont(u8g_font_6x10);
u8g.setFontRefHeightExtendedText();
u8g.setDefaultForegroundColor();
u8g.setFontPosTop();
}
void DrawMarkers(void) {
u8g.drawFrame (0,0,128,64);
u8g.drawPixel (22,16);
u8g.drawPixel (43,16);
u8g.drawPixel (64,16);
u8g.drawPixel (85,16);
u8g.drawPixel (106,16);
u8g.drawPixel (22,32);
u8g.drawPixel (43,32);
u8g.drawPixel (64,32);
u8g.drawPixel (85,32);
u8g.drawPixel (106,32);
u8g.drawPixel (22,48);
u8g.drawPixel (43,48);
u8g.drawPixel (64,48);
u8g.drawPixel (85,48);
u8g.drawPixel (106,48);
}

void sample_data(void){
// wait for a trigger of a positive going input
// Input=analogRead(A0);
while (Input < OldInput){
OldInput=analogRead(A0);
Input=analogRead(A0);
}
// collect the analog data into an array
// do not do division by 10.24 here, it makes it slower!
for(int xpos=0; xpos<128; xpos++) {
Sample[xpos]=analogRead(A0);
}
}

void draw(void) {
u8g_prepare();
DrawMarkers();
// display the collected analog data from array
// Sample/10.24 because 1024 becomes 100 = 5 volts
for(int xpos=1; xpos<128; xpos++) {
u8g.drawLine (xpos, Sample[xpos]/10.24, xpos+1, Sample[xpos+1]/10.24);
}
}

void setup(void) {
// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 )
u8g.setColorIndex(255); // RGB=white
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
u8g.setColorIndex(3); // max intensity
else if ( u8g.getMode() == U8G_MODE_BW )
u8g.setColorIndex(1); // pixel on, black
}
void loop(void) {
// Set sample speed according to switch on A1
// picture loop
sample_data();
u8g.firstPage();
do { draw(); }
while( u8g.nextPage() );
// rebuild the picture after some delay
delay(100);
}