sparkfun / SparkFun_SSD1320_OLED_Arduino_Library

Display graphics and text on a flexible grayscale display
10 stars 5 forks source link

Flipping the display vertically doesn't work as expected #2

Closed anselmpaul closed 5 years ago

anselmpaul commented 6 years ago

Hey everyone, first of all thanks for this cool library.

I'm trying to rotate my display by 180°, so flip it horizontally and vertically. I've found that your library provides both a flipHorizontal and a flipVertical function, but I either don't understand their intended behaviour or they don't quite work. Instead of flipping / mirroring the content, the display just clears with flipVertical. Here's an example sketch (run from an Arduino Uno) and a gif of the output (my display already took some beating...).


// Includes 
// ------------------------------------------------
// ------------------------------------------------
#include <SSD1320_OLED.h>
#include "graphics.h"       // stores all bitmap graphics

// pgmspace
#if (defined(__AVR__))
  #include <avr/pgmspace.h>
#else
  #include <pgmspace.h>
#endif

// Pins
// ------------------------------------------------
// ------------------------------------------------
#define OLED_CS 10          // Chip Select, OLED
#define OLED_RES 9          // Reset, OLED

// OLED Display Instance
SSD1320 flexibleOLED(OLED_CS, OLED_RES);

// Setup
// ------------------------------------------------
// ------------------------------------------------
void setup() {
    // Begin Serial for Debug
    Serial.begin(115200);

    pinMode(OLED_CS,OUTPUT);

    // Init OLED Display (Display is 160 wide, 32 high)
    flexibleOLED.begin(160, 32);
    flexibleOLED.clearDisplay();
    // Load Graphic
    //loadImage(macaque,sizeof(macaque));
    flexibleOLED.setFontType(0);
    flexibleOLED.setCursor(5, 5);
    flexibleOLED.print("Hello World");
    flexibleOLED.display();
}

// Main Loop 
// ------------------------------------------------  
// ------------------------------------------------
void loop() {
    delay(2000);
    flexibleOLED.flipVertical(true);
    loadImage(macaque,sizeof(macaque));
    delay(2000);
    flexibleOLED.flipVertical(false);
    loadImage(macaque,sizeof(macaque));
}

void loadImage(const unsigned char *image, int imageSize){
    flexibleOLED.setRowAddress(0);
    flexibleOLED.setColumnAddress(0);
    //Send the bytes from program memory to OLED display
    for (int i = 0 ; i < imageSize ; i++)
    {
      byte theByte = pgm_read_byte(image + i);

      flexibleOLED.data(theByte); //Write byte directly to display
    }
}

flipvertical (I didn't attach the graphics.h, as it just contains the macaque image as byte array, storing it in PROGMEM)

nseidle commented 6 years ago

If I remember correctly those commands were stubs included from our other OLED libraries but the SSD1320 does not have built in support for display flipping. Sorry for the confusion. Be sure to checkout the datasheets for the SSD1320 here. There are some ways to configure the segment order and wrapping (section 6.7 GDDRAM), but that would require some additional changes to the library.