Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong render #527

Open
ghost opened this issue Feb 14, 2023 · 6 comments
Open

Wrong render #527

ghost opened this issue Feb 14, 2023 · 6 comments

Comments

@ghost
Copy link

ghost commented Feb 14, 2023

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
Copy link
Owner

Strange. Any code / pictures?

@ghost
Copy link
Author

ghost commented Feb 15, 2023

image
Here is one

@olikraus
Copy link
Owner

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

@ghost
Copy link
Author

ghost commented Feb 15, 2023

#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
Copy link
Owner

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
Copy link
Author

ghost commented Feb 21, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant