Reversing characters
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 84
- Joined: Tue Nov 02, 2010 7:29 am
Re: Reversing characters
Sorry for the delay; I'm waiting for a new arduino nano.
-
- Posts: 84
- Joined: Tue Nov 02, 2010 7:29 am
Re: Reversing characters
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".
I'm not sure what's wrong - do all the functions use drawPixel?
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);
}
}
}
}
-
- Posts: 84
- Joined: Tue Nov 02, 2010 7:29 am
Re: Reversing characters
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?
-
- Posts: 2
- Joined: Tue Aug 28, 2012 1:06 am
Re: Reversing characters
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:
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:
about 40 lines, you'll see:
Change that to:
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
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()) {
...
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) {
Code: Select all
#if defined SSD1331_COLORORDER_RGB
writeCommand(0x72); // RGB Color
#else
writeCommand(0x76); // BGR Color
#endif
Code: Select all
#if defined SSD1331_COLORORDER_RGB
writeCommand(0x70); // RGB Color
#else
writeCommand(0x74); // BGR Color
#endif
Don't forget to undo your other code changes, or you'll be half flipped again .
-Rob
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Reversing characters
Thanks Rob, That is handy to know!
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Reversing characters
Thanks! I've only got the monochrome SSD1306 - I'd have never figured that out for the 1331!
-
- Posts: 84
- Joined: Tue Nov 02, 2010 7:29 am
Re: Reversing characters
Wow! Thanks so much.
- plumleyhd
- Posts: 5
- Joined: Sat Aug 29, 2015 7:11 pm
Re: Reversing characters
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.
- plumleyhd
- Posts: 5
- Joined: Sat Aug 29, 2015 7:11 pm
Re: Reversing characters
I wonder if it matters that I'm using only text... Hmmm...
- plumleyhd
- Posts: 5
- Joined: Sat Aug 29, 2015 7:11 pm
Re: Reversing characters
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
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
- Monroe07
- Posts: 2
- Joined: Fri Sep 11, 2015 3:21 pm
Re: Reversing characters
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.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
- plumleyhd
- Posts: 5
- Joined: Sat Aug 29, 2015 7:11 pm
Re: Reversing characters
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.
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.
- Monroe07
- Posts: 2
- Joined: Fri Sep 11, 2015 3:21 pm
Re: Reversing characters
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 ?
- plumleyhd
- Posts: 5
- Joined: Sat Aug 29, 2015 7:11 pm
Re: Reversing characters
Yes. Well articulated, thank you.
Please be positive and constructive with your questions and comments.