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

Re: Reversing characters

Post by bobulisk »

Sorry for the delay; I'm waiting for a new arduino nano.

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

Re: Reversing characters

Post by bobulisk »

I just got a new arduino and copy of the library. I'm having the same problem. With the example sketch, the smaller "hello world" is reversed while the larger is not. With my own test sketch, the numbers are not. That sketch is here.

All it does is have the display write "12.3".

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() {
  Serial.begin(9600); 
  uint16_t time = millis();
  display.begin();
  lcdTestPattern();
  display.fillScreen(BLACK);
  display.setTextColor(WHITE); 
  display.setTextSize(3); 
  display.println("init");
  delay(400); 
  display.fillScreen(BLACK);
  time = millis() - time;
  display.setCursor(15, 25); 
  display.fillScreen(WHITE); 
  display.setTextColor(BLACK);
  display.setTextSize(3); 
  display.print("12.3"); 
}

void loop() {
}

void lcdTestPattern() {
  uint32_t i,j;
  display.goTo(0, 0);

  for(i=0;i<64;i++) {
    for(j=0;j<96;j++) {
      if(i>55){
        display.writeData(WHITE>>8);
        display.writeData(WHITE);
      }
      else if(i>47){
        display.writeData(BLUE>>8);
        display.writeData(BLUE);
      }
      else if(i>39){
        display.writeData(GREEN>>8);
        display.writeData(GREEN);
      }
      else if(i>31){
        display.writeData(CYAN>>8);
        display.writeData(CYAN);
      }
      else if(i>23){
        display.writeData(RED>>8);
        display.writeData(RED);
      }
      else if(i>15){
        display.writeData(MAGENTA>>8);
        display.writeData(MAGENTA);
      }
      else if(i>7){
        display.writeData(YELLOW>>8);
        display.writeData(YELLOW);
      }
      else {
        display.writeData(BLACK>>8);
        display.writeData(BLACK);
      }
    }
  }
}





I'm not sure what's wrong - do all the functions use drawPixel?

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

Re: Reversing characters

Post by bobulisk »

I'm having the same problem with the default sketch. Some text is reversed, some is not. Would I have to call the drawPixel for something to change?

giseburt
 
Posts: 2
Joined: Tue Aug 28, 2012 1:06 am

Re: Reversing characters

Post by giseburt »

Edit: I found a way to flip it without rotation.

For the SSD1331, in the library the drawLine() routine uses hardware accelerated line drawing, and bypasses drawPixel(). This is a good thing, and actually speeds up much of the drawing in the test routine (and probably in the "real world" sketch as well).

You'll have to modify that routine as well. Something like this:

Code: Select all

void Adafruit_SSD1331::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
	x0 = (WIDTH - x0) - 1;        //mirror image
	x1 = (WIDTH - x1) - 1;        //mirror image

  // check rotation, move pixel around if necessary
  switch (getRotation()) {
...
Another gotcha is the pushColor() routine, which pushes a pixel at a time, taking advantage of the order that the display draws the pixels and that it'll automatically advance to the next one.

An interesting alternative to the software flip is to do it in hardware.

First, undo all of your flipping changes.

Then, below this line:

Code: Select all

void Adafruit_SSD1331::begin(void) {
about 40 lines, you'll see:

Code: Select all

#if defined SSD1331_COLORORDER_RGB
    writeCommand(0x72);				// RGB Color
#else
    writeCommand(0x76);				// BGR Color
#endif
Change that to:

Code: Select all

#if defined SSD1331_COLORORDER_RGB
    writeCommand(0x70);				// RGB Color
#else
    writeCommand(0x74);				// BGR Color
#endif
You can flip vertically and horizontally (rotating), by changing the 70/74 to 60/64. To flip just vertically, use 62/66.

Don't forget to undo your other code changes, or you'll be half flipped again :).

-Rob

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

Re: Reversing characters

Post by adafruit_support_bill »

Thanks Rob, That is handy to know!

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

Re: Reversing characters

Post by adafruit_support_rick »

Thanks! I've only got the monochrome SSD1306 - I'd have never figured that out for the 1331!

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

Re: Reversing characters

Post by bobulisk »

Wow! Thanks so much.

User avatar
plumleyhd
 
Posts: 5
Joined: Sat Aug 29, 2015 7:11 pm

Re: Reversing characters

Post by plumleyhd »

Has anyone come up with a solution that works for mirroring? I tried modifying Drawpixel() using: x = (WIDTH-x) - 1; but that has zero effect. If I short the serial in ICSP that mirrors the screen, but clearly a not starter... Sad.

User avatar
plumleyhd
 
Posts: 5
Joined: Sat Aug 29, 2015 7:11 pm

Re: Reversing characters

Post by plumleyhd »

I wonder if it matters that I'm using only text... Hmmm...

User avatar
plumleyhd
 
Posts: 5
Joined: Sat Aug 29, 2015 7:11 pm

Re: Reversing characters

Post by plumleyhd »

Solution:
Change comscan direction in init() in the SSD1306.cpp
ssd1306_command(SSD1306_COMSCANINC) becomes ssd1306_command(SSD1306_COMSCANINC);
//where SSD1306_COMSCANDEC is defined as 0xC8
//where SSD1306_COMSCANINC is defined as 0xC0

//add to void setup()
display.setRotation(2);

Keep separate copies of mirror and unmirrored configured SSD1306.cpp

User avatar
Monroe07
 
Posts: 2
Joined: Fri Sep 11, 2015 3:21 pm

Re: Reversing characters

Post by Monroe07 »

Adafruit_SSD1306.cpp
(26.89 KiB) Downloaded 32 times
forgive me Plumleyhd, I dont understand your response of
plumleyhd wrote:Solution:
Change comscan direction in init() in the SSD1306.cpp
ssd1306_command(SSD1306_COMSCANINC) becomes ssd1306_command(SSD1306_COMSCANINC);
//where SSD1306_COMSCANDEC is defined as 0xC8
//where SSD1306_COMSCANINC is defined as 0xC0

//add to void setup()
display.setRotation(2);

Keep separate copies of mirror and unmirrored configured SSD1306.cpp
It appears that the current version of the .cpp file doesnt have "ssd1306_command(SSD1306_COMSCANINC)" in it. It does however have COMSCANDEC in it. I will include the version i have and perhaps you can better explain what modifications I need to make to it to "mirror" the image so that it looks correct when held to a mirror.
Adafruit_SSD1306.cpp
(26.89 KiB) Downloaded 32 times

User avatar
plumleyhd
 
Posts: 5
Joined: Sat Aug 29, 2015 7:11 pm

Re: Reversing characters

Post by plumleyhd »

Change
ssd1306_command(SSD1306_COMSCANINC)
to:
ssd1306_command(SSD1306_COMSCANDEC)

"DEC"is defined in the .h file as address: 0xC8
Changing it to "INC" changes the address to: 0xC0
This reverses to output to the screen.
Because its reversed the image is now upside down also.
Fortunately, setRotation command is available to fix that.

User avatar
Monroe07
 
Posts: 2
Joined: Fri Sep 11, 2015 3:21 pm

Re: Reversing characters

Post by Monroe07 »

So your saying to change "ssd1306_command(SSD1306_COMSCANDEC);" to "ssd1306_command(SSD1306_COMSCANINC);" in the section for the respective screen you're using and that will change the value it uses when initializing the screen from 0xC8 to 0xC0 ?

User avatar
plumleyhd
 
Posts: 5
Joined: Sat Aug 29, 2015 7:11 pm

Re: Reversing characters

Post by plumleyhd »

Yes. Well articulated, thank you.

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

Return to “Arduino”