olikraus / u8glib

Arduino Monochrom Graphics Library for LCDs and OLEDs
https://github.com/olikraus/u8glib/wiki
Other
1.24k stars 313 forks source link

Wrong render #527

Open ghost opened 1 year ago

ghost commented 1 year ago

When i connect my KS0108 to my Arduino Due it renders some letters wrong. 0 and 1 are rendered just fine but 2 and 3 are not, and instead of "rotary" it prints "rötäry" (Using unifont)

olikraus commented 1 year ago

Strange. Any code / pictures?

ghost commented 1 year ago

image Here is one

olikraus commented 1 year ago

Thanks. Can you also post the code which causes this?

ghost commented 1 year ago
#include <U8glib.h>
#include <ArduinoCompatibleFFT.h>

#define SAMPLES 128
#define AUDIO A0

U8GLIB_KS0108_128 u8g(22,23,24,25,26,27,28,29,34,30,31,33,32);  // I2C / TWI

int8_t im[SAMPLES];
int8_t re[SAMPLES];
int8_t fft[SAMPLES];
uint32_t lastChange;

void barchart()
{
  static int i, j;
  int val;

  for(i = 0; i < SAMPLES; i++){
    re[i] = analogRead(AUDIO);
    im[i] = 0;
    re[i] = re[i]-128;
  }

  fix_fft(re, im, 7, 0);

  for(i = 0; i < SAMPLES; i++)
  {
    fft[i] = (int)sqrt(re[i]*re[i]+im[i]*im[i]);
  } 
  u8g.firstPage();
  do{
    if(millis() - lastChange > 2000){
      for(int i = 0; i < SAMPLES/2; i++)
        u8g.drawLine(i*2, 64, i*2, 64-fft[i]);
    } else{
      u8g.setFont(u8g_font_unifont);
      u8g.setPrintPos(0, 20); 
      u8g.print("Rotary:");
      u8g.setPrintPos(0, 40); 
      u8g.print("Count");
    }

  }while(u8g.nextPage());
}

void setup(){u8g.begin();}

void loop(){barchart();}

The FFT is not really needed here so you can remove it

olikraus commented 1 year ago

You must not change the content of the picture loop itself. This means, the millis() check should be outside the loop. More like this (not tested):

  } 
  if(millis() - lastChange > 2000){
    u8g.firstPage();
    do{
        for(int i = 0; i < SAMPLES/2; i++)
          u8g.drawLine(i*2, 64, i*2, 64-fft[i]);
    }while(u8g.nextPage());
  } else{
    u8g.firstPage();
      u8g.setFont(u8g_font_unifont);
      u8g.setPrintPos(0, 20); 
      u8g.print("Rotary:");
      u8g.setPrintPos(0, 40); 
      u8g.print("Count");
     }while(u8g.nextPage());
  }
ghost commented 1 year ago

Well it dosen't display the text but the FFT yes