Jump to content

OLED text mirrored


lesthegrngo

Recommended Posts

Guys, I got the 0.96" OLED working for the altimeter readout fine, but when I tried to use the same sketch fon a 0.87" 128 x 32 OLED module adjusted for resolution, it displays the numerals mirrored, so that to see them correctly you have look at a reflection.

 

Any ideas why this woul happen? Apart from the resolution the sketch is the same, and both modules are i2c bought from buydisplay

 

Cheers

 

Led

Link to comment
Share on other sites

Here you go Vinc

 

#define DCSBIOS_IRQ_SERIAL

#include <DcsBios.h>

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>


#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif


char* displayString = "----";

// onDcsBiosWrite does not exist anymore, use Int16Buffers instead
DcsBios::Int16Buffer altPressure0Buffer(0x1086);
DcsBios::Int16Buffer altPressure1Buffer(0x1088);
DcsBios::Int16Buffer altPressure2Buffer(0x108a);
DcsBios::Int16Buffer altPressure3Buffer(0x108c);

void setup() {
 
 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  
 display.clearDisplay();

 
 DcsBios::setup();
}


void loop() {
 DcsBios::loop();
 
 if (altPressure0Buffer.hasUpdatedData()) { displayString[3] = mapeo(altPressure0Buffer.getData()); }
 if (altPressure1Buffer.hasUpdatedData()) { displayString[2] = mapeo(altPressure1Buffer.getData()); }
 if (altPressure2Buffer.hasUpdatedData()) { displayString[1] = mapeo(altPressure2Buffer.getData()); }
 if (altPressure3Buffer.hasUpdatedData()) { displayString[0] = mapeo(altPressure3Buffer.getData()); }
 
 display.clearDisplay();
 display.setTextSize(2);
  display.setTextColor(WHITE);
 display.setCursor(0,5);
 display.print(displayString);
 display.display();

 delay (75);

}

char mapeo(unsigned int valor){


 if (valor < 6553) { return '0'; }
 if (valor < 13107) { return '1'; }
 if (valor < 19660) { return '2'; }
 if (valor < 26214) { return '3'; }
 if (valor < 32767) { return '4'; }
 if (valor < 39321) { return '5'; }
 if (valor < 45874) { return '6'; }
 if (valor < 52428) { return '7'; }
 if (valor < 58981) { return '8'; }
 return '9' ;
 

}

 

 

And for completeness this is the code for the working Altimeter OLED (although poor definition numbers and without that cool scrolling that Middlefart managed to incorporate). As you can see apart from the text size and references the OLED screen resolution it is essentially the same

 

#define DCSBIOS_IRQ_SERIAL

#include <DcsBios.h>

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

char* displayString = "---";

// onDcsBiosWrite does not exist anymore, use Int16Buffers instead
DcsBios::Int16Buffer alt10000ftCounter(0x1080);
DcsBios::Int16Buffer alt1000ftCounter(0x1082);
DcsBios::Int16Buffer alt100ftCounter(0x1084);

void setup() {
 
 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  
 display.clearDisplay();
 
 DcsBios::setup();
}


void loop() {
 DcsBios::loop();
 
 if (alt10000ftCounter.hasUpdatedData()) { displayString[0] = mapeo(alt10000ftCounter.getData()); }
 if (alt1000ftCounter.hasUpdatedData()) { displayString[1] = mapeo(alt1000ftCounter.getData()); }
 if (alt100ftCounter.hasUpdatedData()) { displayString[2] = mapeo(alt100ftCounter.getData()); }
 
 display.clearDisplay();
 display.setTextSize(6);
 display.setTextColor(WHITE);
 display.setCursor(10,10);
 display.print(displayString);
 display.display();

 delay (75);

}

char mapeo(unsigned int valor){


 if (valor < 6553) { return '0'; }
 if (valor < 13107) { return '1'; }
 if (valor < 19660) { return '2'; }
 if (valor < 26214) { return '3'; }
 if (valor < 32767) { return '4'; }
 if (valor < 39321) { return '5'; }
 if (valor < 45874) { return '6'; }
 if (valor < 52428) { return '7'; }
 if (valor < 58981) { return '8'; }
 return '9' ;
 

}

 

Cheers

 

Les

Link to comment
Share on other sites

Hi Les,

 

put in the following line after the initialisation (display.begin(...)) :

 

display.ssd1306_command(0xA0);

or

display.ssd1306_command(0xA1);

to disable and enable horizontal mirroring.

 

like this

void setup()   {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.ssd1306_command(0xA0);
display.clearDisplay();

DcsBios::setup();
}

.

 

 

Edit: try this :-)


#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

void setup() {
 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
 display.clearDisplay();
}

void loop() {
 display.ssd1306_command(0xA1); // normal
 display.clearDisplay();
 display.setTextSize(2);
 display.setTextColor(WHITE);
 display.setCursor(11,15);
 display.print("DCS A-10C");
 display.display();
 delay(1000);
 
 display.ssd1306_command(0xA0); // mirrorred
 display.clearDisplay();
 display.setTextSize(2);
 display.setTextColor(WHITE);
 display.setCursor(11,15);
 display.print("DCS A-10C");
 display.display();
 delay(1000);
}


Edited by Vinc_Vega

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

Fine!

 

 

This forum helped me already a lot!

So I want to give back a little bit.

 

It's interesting to know which argument worked for you to demirror the display, is it 0xA0 or 0xA1 ?

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

Well, because 0xA0 should be the command to enable mirroring, your display seems to have hardware issues.

 

 

But if that corrects the error, it's a cheap and simple solution. :thumbup:

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...