OLED 128x32 SSD1305 Xmega Library

Last post
20 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys,

after a few days, reading and re-reading the datasheet I could build a library for this OLED display, integrated with a controller SSD1305.
I can write text, draw a pixel etc., but when I try to read I find myself just bad data, someone can help me, thanks.
Put my code and attach a photo.

p.s. Using a Xmega128A1, default set to 2MHz, and AVR Studio 5.0

#include 
#include 
#include 
#include "SSD1305.h"

#define SSD1305_DATA_PORT		PORTH_OUT
#define SSD1305_DATA_DIR		PORTH_DIR
#define SSD1305_DATA_PIN		PORTH_IN

#define SSD1305_CONTROL_PORT	PORTJ_OUT
#define SSD1305_CONTROL_DIR		PORTJ_DIR

#define SSD1305_RD				(1 << PIN0)	//Read
#define SSD1305_WR				(1 << PIN1)	//Write
#define SSD1305_DC				(1 << PIN2)	//Data Or Command
#define SSD1305_RES				(1 << PIN3)	//Reset
#define SSD1305_CS				(1 << PIN4)	//Chip select

void GLCD_WriteData(unsigned char dataToWrite)
{
SSD1305_CONTROL_PORT |= (SSD1305_RD | SSD1305_DC);
SSD1305_CONTROL_PORT &= ~(SSD1305_CS |SSD1305_WR);
SSD1305_DATA_PORT = dataToWrite;
asm("nop");
SSD1305_CONTROL_PORT |= (SSD1305_WR);
}

void GLCD_WriteCommand(unsigned char commandToWrite)
{
SSD1305_CONTROL_PORT |= (SSD1305_RD);
SSD1305_CONTROL_PORT &= ~(SSD1305_CS |SSD1305_WR | SSD1305_DC);
SSD1305_DATA_PORT = commandToWrite;
asm("nop");
SSD1305_CONTROL_PORT |= (SSD1305_WR);
}

void GLCD_InitializePorts(void)
{	
SSD1305_CONTROL_DIR |= (SSD1305_DC | SSD1305_WR | SSD1305_RD | SSD1305_CS | SSD1305_RES);  //setta direzione 1 output
SSD1305_DATA_DIR = 0xFF;	//setta direzione 1 output
SSD1305_CONTROL_PORT &= ~ (SSD1305_DC | SSD1305_WR | SSD1305_RD | SSD1305_CS | SSD1305_RES); //setta i pin a 0
SSD1305_CONTROL_PORT |= (SSD1305_RES);  //Reset  High
_delay_ms(1);
SSD1305_CONTROL_PORT &= ~ (SSD1305_RES);  //Reset  Low
_delay_ms(10);
SSD1305_CONTROL_PORT |= (SSD1305_RES);  //Reset  High runtime mode
_delay_ms(1);
}

unsigned char GLCD_ReadData(void)
{
unsigned char tmp;
SSD1305_CONTROL_PORT |= (SSD1305_DC | SSD1305_WR);
SSD1305_CONTROL_PORT &= ~(SSD1305_CS | SSD1305_RD);
asm("nop");
SSD1305_DATA_DIR = 0x00;
asm("nop");
tmp =  SSD1305_DATA_PIN;
SSD1305_CONTROL_PORT |= (SSD1305_RD);
return tmp;
}

unsigned char GLCD_ReadByteFromROMMemory(unsigned char * ptr)
{
return pgm_read_byte(ptr);
}

void GLCD_Initialize(void)
{
GLCD_InitializePorts();
GLCD_WriteCommand(SSD1305_DISPLAYOFF);  // 0xAE
GLCD_WriteCommand(SSD1305_SETDISPLAYCLOCKDIV);  // 0xD5
GLCD_WriteCommand(0x80);  // the suggested ratio 0x80
GLCD_WriteCommand(SSD1305_SETMULTIPLEX); // 0xA8
GLCD_WriteCommand(0x3F);  // 0x3F 1/64 duty
GLCD_WriteCommand(SSD1305_SETDISPLAYOFFSET); // 0xD3
GLCD_WriteCommand(0x0); // no offset
GLCD_WriteCommand(SSD1305_SETSTARTLINE); // line #0
//GLCD_WriteCommand(SSD1305_SEGREMAP1); //0xA1
GLCD_WriteCommand(SSD1305_COMSCANDEC); //0xC8
GLCD_WriteCommand(SSD1305_SETCOMPINS); // 0xDA
GLCD_WriteCommand(0x12); // disable COM left/right remap
GLCD_WriteCommand(SSD1305_SETCONTRAST);
GLCD_WriteCommand(0xFF);
GLCD_WriteCommand(SSD1305_SETPRECHARGE); // 0xd9
GLCD_WriteCommand(0xF1);
GLCD_WriteCommand(SSD1305_SETVCOMDETECT); // 0xDB
GLCD_WriteCommand(0x40); // 0x20 is default?
GLCD_WriteCommand(SSD1305_DISPLAYALLON_RESUME); // 0xA4
GLCD_WriteCommand(SSD1305_NORMALDISPLAY); // 0xA6
GLCD_WriteCommand(SSD1305_MEMORYMODE); // 0x20
GLCD_WriteCommand(0x00); // 0x0 act like ks0108
GLCD_WriteCommand(SSD1305_SETLOWCOLUMN | 0x0);  // low col = 0
GLCD_WriteCommand(SSD1305_SETHIGHCOLUMN | 0x0);  // hi col = 0
//GLCD_WriteCommand(SSD1305_SEGREMAP | 0x1);
GLCD_WriteCommand(SSD1305_DISPLAYON);//--turn on oled panel
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You don't seem to return the dataport back to outputs after reading the response.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ops, right. Tomorrow I correct it and try.
Hope...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have found a solution, but it's a little mistake:

unsigned char GLCD_ReadData(void)
{
unsigned char tmp;
SSD1305_DATA_DIR = 0x00;
SSD1305_CONTROL_PORT &= ~(SSD1305_CS);
SSD1305_CONTROL_PORT |= (SSD1305_DC | SSD1305_WR);
SSD1305_CONTROL_PORT &= ~(SSD1305_RD);
SSD1305_CONTROL_PORT |= (SSD1305_RD);
SSD1305_CONTROL_PORT &= ~(SSD1305_RD);
SSD1305_CONTROL_PORT |= (SSD1305_RD);
SSD1305_CONTROL_PORT |= (SSD1305_CS);
tmp =  SSD1305_DATA_PIN;
SSD1305_DATA_DIR = 0xFF;
return tmp;
}

If you see the code, i must repeat RD (low, hight) 2 time, because the first time i read bad data?
Why????
Do you have a answer?
Tnku very much.
When I finish the library i post it here.

p.s. excuse me for my bad english, Im Italian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Read the datasheet more carefully... the first byte returned is a dummy and should be discarded.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

:( Iam a noob, datasheet is in english, some word escape for me :)
Tnku jayjay1974

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does it work now?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes perfectly. Very fast write and read. I finish library and then share it.
On the web there isnt ssd1305 library.
I draw pixel, line, rec, circle, text and bitmap, now Im tring to show animation.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I finish library and then share it.
Per me puoi farlo in Italiano o in Inglese. :wink:

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Andrea_IT wrote:
On the web there isnt ssd1305 library.
Here is an alternate but it does not appear to be as complete and as re-usable as yours.
http://www.newhavendisplay.com/app_notes/OLED_2_23_12832.txt
Newhaven Display, Graphic OLEDs

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


This use 6800 Parallel Mode, my 8080, but some function are interesting, tnku

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I attach my first release.

p.s. E' bello trovare altri italiani, ogni volta mi sembra di essere solo.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for sharing your code Andrea. I'm currently playing with a few GLCD for a couple of clients and I think that driver chip number has come up in one of them.

I have forgotten which one though, I have looked at so many in the past few days that my head is spinning...maybe I'm just possesed... :)

edit as a matter of interst does anyone know of a cross reference chart for different GLCD controllers? There seem to be some with different numbers that are pin and code compatible with each other.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Surely there are plenty of GLCD controller compatible with each other. Often, many of them are pre-configured, actually, my GLCD BL12832A1 SSD1305 controller which features a factory was set to only use mode 8080. But this can not find it on the datasheet, (IMPORTANT), I had to check with a tester pins BS1 and BS2, and understand how it operated.
I believe that the SSD,SED models, etc will eventually be compatible with each other, the only thing that changes is the address of the command, just replace them and it should go.
Now I want to try a larger GLCD and color soon.
p.s. JS you should write in Italian)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Andrea, I'm working working on a project with a display using the SSD1305 chip and have found this post very helpful, thank you. One thing, my display isn't turning on and I've rechecked my wiring countless times, so I suspect its code, do you have any tips on debugging the code, given that I can't see the response from the SSD chip? I suspect it might be the frequency but I can't find any definitive notes in the data sheets that indicate the codes for the multipliers and what the base frequency is.

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Andrea, thanks for the library, I consider it very useful. May I ask you about the text management? Does the library provide support for the fonts? Thanks, Gianluca

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Andrea, thank you for your code. It really helped me. But could you possible tell me how did you convert the Bitmap to text to display the Bluetooth logo?
Thanks, Gary

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Andrea, any updates on the library? Planning to use this controller in a project, and looking for different sized fonts, more graphics etc. Are you planning release newer versions of the library?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Andrea - if you're still out there perhaps you can answer a question.

While trying to use

Code: [Select]

Show_Font57_12832(1, 17, 0, 4);
Show_Font57_12832(1, 18, 0, 12);
Show_Font57_12832(1, 19, 0, 20);
Show_Font57_12832(1, 20, 0, 28);
Show_Font57_12832(1, 34, 0, 36);
Show_Font57_12832(1, 35, 0, 44);
Show_Font57_12832(1, 36, 0, 52);

(0 1 2 3 A B C)

I am unable to get the letters to be any closer than this without distortion of the distance on only some of the letters. (that is one full empty space between letters).

Can anyone suggest why this would be or does anyone have a better function that works correctly? I've tried quite a few different things without getting anywhere. The SSD1305 manual is definitely not clear on this subject.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Welcome to the Forum.

I've not looked at the 1305 data sheet, (wrong device currently to try to do so...).

Anyway, some devices have a character mode, were they act very much like a character LCD. If you send it a character, it automatically increments to the next "character" location. If your software also automatically increments the display pointers to the next location, then you will have a blank "character" space between characters.

JC