Reversing characters

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
bobulisk
 
Posts: 84
Joined: Tue Nov 02, 2010 7:29 am

Reversing characters

Post by bobulisk »

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?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Reversing characters

Post by adafruit_support_bill »

I think the most straightforward way is to just modify the Adafruit_SSD1306::drawPixel() function to mirror the X coordinates.

bobulisk
 
Posts: 84
Joined: Tue Nov 02, 2010 7:29 am

Re: Reversing characters

Post by bobulisk »

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?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Reversing characters

Post by adafruit_support_bill »

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.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Reversing characters

Post by adafruit_support_rick »

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 ...

bobulisk
 
Posts: 84
Joined: Tue Nov 02, 2010 7:29 am

Re: Reversing characters

Post by bobulisk »

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:

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); 
}
No matter how I edit this part of the code, it does not change:
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...

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Reversing characters

Post by adafruit_support_rick »

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...

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Reversing characters

Post by adafruit_support_rick »

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:
IMG_0568.jpg
IMG_0568.jpg (235.65 KiB) Viewed 1953 times
IMG_0569.jpg
IMG_0569.jpg (232.5 KiB) Viewed 1953 times

bobulisk
 
Posts: 84
Joined: Tue Nov 02, 2010 7:29 am

Re: Reversing characters

Post by bobulisk »

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.
setup1.png
setup1.png (925.49 KiB) Viewed 1936 times
setup2.png
setup2.png (826.35 KiB) Viewed 1936 times
setup3.png
setup3.png (948.9 KiB) Viewed 1936 times
I'm using the example test sketch.

bobulisk
 
Posts: 84
Joined: Tue Nov 02, 2010 7:29 am

Re: Reversing characters

Post by bobulisk »

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.
setup4.png
setup4.png (326.87 KiB) Viewed 1936 times

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Reversing characters

Post by adafruit_support_rick »

Are you rotating the display at all? One "hello world" is rotated 180 from the other. What happens with the unmodified example sketch?

bobulisk
 
Posts: 84
Joined: Tue Nov 02, 2010 7:29 am

Re: Reversing characters

Post by bobulisk »

If I don't modify anything, the red Hello World! is directly above the yellow.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Reversing characters

Post by adafruit_support_rick »

bobulisk wrote:If I don't modify anything, the red Hello World! is directly above the yellow.
But, is the mirrored orientation of everything correct with the unmodified sketch?

bobulisk
 
Posts: 84
Joined: Tue Nov 02, 2010 7:29 am

Re: Reversing characters

Post by bobulisk »

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.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Reversing characters

Post by adafruit_support_rick »

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:

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()) {

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”