Sunday, July 20, 2014

MicroLCD issues

I have just started investigating why both of my new OLED displays require a 2 pixel offset to the right in order to prevent truncating the display.  Starting out easy, we go with the simplest bit of code to turn on the LCD.

#include <Wire.h>
#include <MicroLCD.h>

LCD_SSD1306 lcd;

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

void loop()
{
  // put your main code here, to run repeatedly:

}

This code results in the following display.  Notice the white bar on the right side.  The display clear code is already suspect.  Unplugging the display and re-running the code moves the white bar to the left side of the display running the entire way from top to bottom.



This is the code in the LCD initialization function that clears the display.

    ssd1306_command(SSD1306_SETLOWCOLUMN | 0x0);  // low col = 0
    ssd1306_command(SSD1306_SETHIGHCOLUMN | 0x0); // hi col = 0
    ssd1306_command(SSD1306_SETSTARTLINE | 0x0);  // line #0

    for (byte i = 0; i < SSD1306_LCDHEIGHT / 8; i++) {
      // send a bunch of data in one xmission
        ssd1306_command(0xB0 + i);//set page address
        ssd1306_command(0);//set lower column address
        ssd1306_command(0x10);//set higher column address

        for(byte j = 0; j < 8; j++){
            Wire.beginTransmission(_i2caddr);
            Wire.write(0x40);
            for (byte k = 0; k < SSD1306_LCDWIDTH / 8; k++) {
                Wire.write(0);
            }
            Wire.endTransmission();
        }

    }

If I change k < SSD1306_LCDWIDTH to k <= SSD1306_LCDWIDTH then I can get the entire display to clear.  However, this is suspect because as written, it should work logically speaking.

When the device is initialized, if no cursor setting operations are performed, the first text will be displayed in the lower left corner without any truncation.  Once any cursor setting is done, The truncation is present from that point forward.

I will dig into the driver further, but for now I have fixed this by moving the inter-character spacing to the front of a character rather than the end and additionally provide two additional inter-character spaces at the beginning of a line of text.

#include <Wire.h>
#include <MicroLCD.h>


LCD_SSD1306 lcd;
uint8_t invert = 0;

void setup()
{
  lcd.begin();
  lcd.clear();
  for (int i = 0; i < 8; i++)
  {
    lcd.print("A");
    lcd.print(i);
    lcd.print("-----------------");
    lcd.print(i);
    lcd.println("B");
  }

}

loop()
{
}

The code above now displays correctly with no truncation.  This provides for 21 colums by 8 rows of text using the 5x8 font.  When I have time to dig into this further, I will post further updates on this topic.




No comments:

Post a Comment

Post a Comment