I'm using your 0.96 OLED display in an attempt to create a small heads up display. The simplest way to accomplish this is without using any mirrors at all: the screen is positioned facing down on my forehead and projects onto a piece of plastic at a 45˚ angle. As text is important to my project, I am wondering if there is a way to write backwards characters on the LCD (so they appear correctly to me) without having to draw lines and functions for each number.
Is there a solution I'm over looking, or could I do this with the createChar command or http://www.quinapalus.com/hd44780udg.html?
Reversing characters
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Reversing characters
I think the most straightforward way is to just modify the Adafruit_SSD1306::drawPixel() function to mirror the X coordinates.
-
- Posts: 84
- Joined: Tue Nov 02, 2010 7:29 am
Re: Reversing characters
What if I copied the function and reversed the coordinates - would that mess up a lot of the library/would it require a lot of changes?
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Reversing characters
All the drawing functions in the library end up calling drawpixel. You would have to change all those calls.
Probably easier to make a copy of the library with a different name for mirrored displays.
Probably easier to make a copy of the library with a different name for mirrored displays.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Reversing characters
adafruit_support is right. I think that all you have to do is add one line to Adafruit_SSD1306.cpp:
Code: Select all
// the most basic function, set a single pixel
void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) {
if ((x < 0) || (x >= width()) || (y < 0) || (y >= height()))
return;
x = (width - x) - 1; //mirror display left<->right
// check rotation, move pixel around if necessary
switch (getRotation()) {
… etc ...
-
- Posts: 84
- Joined: Tue Nov 02, 2010 7:29 am
Re: Reversing characters
That seems to work on part of the test sketch - some of the words are now correct, but others still seem wrong. I wrote this to see what was going on:
No matter how I edit this part of the code, it does not change:
Code: Select all
#define sclk 12
#define mosi 11
#define cs 10
#define rst 9
#define dc 8
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1331.h>
#include <SPI.h>
Adafruit_SSD1331 display = Adafruit_SSD1331(cs, dc, mosi, sclk, rst);
void setup(void) {
Serial.begin(9600);
display.begin();
Serial.println("init");
display.fillScreen(BLACK);
}
void loop() {
display.setCursor(5, 5);
display.fillScreen(WHITE);
display.setTextColor(BLACK);
display.setTextSize(4);
display.print(123);
delay(80);
display.fillScreen(BLACK);
}
void Adafruit_SSD1331::drawPixel(int16_t x, int16_t y, uint16_t color)
{
x = (WIDTH - x) - 1; //mirror display left<->right
//y = (HEIGHT - y) - 1;
if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) return;
// check rotation, move pixel around if necessary
switch (getRotation()) {
etc...
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Reversing characters
Hmmm. What exactly isn't right about it? I mean, why would some stuff be right and other stuff not? Can you post a picture?
So you're using the color OLED - I assumed you were using the monochrome, and used the SSD1306 library for my example. Shouldn't matter anyway. I've got one of the monochromes - I'll see if I can reproduce it here...
So you're using the color OLED - I assumed you were using the monochrome, and used the SSD1306 library for my example. Shouldn't matter anyway. I've got one of the monochromes - I'll see if I can reproduce it here...
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Reversing characters
Alright, I just tried it with my monochrome 128X96. Seems to work just fine. I attached a couple of pictures below. Here's the code:
Code: Select all
// the most basic function, set a single pixel
void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) {
if ((x < 0) || (x >= width()) || (y < 0) || (y >= height()))
return;
x = (WIDTH - x) - 1;
// check rotation, move pixel around if necessary
switch (getRotation()) {
case 1:
-
- Posts: 84
- Joined: Tue Nov 02, 2010 7:29 am
Re: Reversing characters
I am now having issues getting the display to work at all - here is my setup. I'm not sure what's wrong. I have tested the connections to the 74LVC245 with a multimeter and the wires to the arduino. Nothing seems to help.
I'm using the example test sketch.
I'm using the example test sketch.
-
- Posts: 84
- Joined: Tue Nov 02, 2010 7:29 am
Re: Reversing characters
Never mind! It was a faulty ground wire. These things never cease to frustrate me. Here is a picture of the reversing issue (using the default test sketch - the drawPixel is modified).
As you can see, the blue numbers are not reversed but the red text at the top ("Hello World!") is. The larger Hello World is also incorrect.
As you can see, the blue numbers are not reversed but the red text at the top ("Hello World!") is. The larger Hello World is also incorrect.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Reversing characters
Are you rotating the display at all? One "hello world" is rotated 180 from the other. What happens with the unmodified example sketch?
-
- Posts: 84
- Joined: Tue Nov 02, 2010 7:29 am
Re: Reversing characters
If I don't modify anything, the red Hello World! is directly above the yellow.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Reversing characters
But, is the mirrored orientation of everything correct with the unmodified sketch?bobulisk wrote:If I don't modify anything, the red Hello World! is directly above the yellow.
-
- Posts: 84
- Joined: Tue Nov 02, 2010 7:29 am
Re: Reversing characters
It's not. I can only get part of the sketch to mirror- it is very strange. I've been looking to see if anything in the test functions could affect this, but I don't see much.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Reversing characters
This is very strange. The fact that the red "Hello World" is reversed but the yellow "Hello Wo" is not makes no sense at all.
Is it possible that you accidentally changed some other part of Adafruit_SSD1331.cpp? If you comment out the line with the x reversal, does the display go back to normal, or does it still have issues?
Maybe you ought to grab a fresh copy of the library. drawPixel should be modified to look like this:
Is it possible that you accidentally changed some other part of Adafruit_SSD1331.cpp? If you comment out the line with the x reversal, does the display go back to normal, or does it still have issues?
Maybe you ought to grab a fresh copy of the library. drawPixel should be modified to look like this:
Code: Select all
void Adafruit_SSD1331::drawPixel(int16_t x, int16_t y, uint16_t color)
{
if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) return;
x = (WIDTH - x) - 1; //mirror image
// check rotation, move pixel around if necessary
switch (getRotation()) {
Please be positive and constructive with your questions and comments.