Monochrome 128*64 OLED screen - SSD1306 driver questions

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
fabienroyer
 
Posts: 15
Joined: Wed Jan 12, 2011 1:48 pm

Monochrome 128*64 OLED screen - SSD1306 driver questions

Post by fabienroyer »

Hi,

I ported the SSD1306 OLED display driver on github (https://github.com/adafruit/SSD1306) to C#, targeting the netduino micro-controller and I have a couple questions about the driver code. Please keep in mind that I have not yet been able to test my code with the actual display since it was shipped on Monday :)

So, here it goes...

Question #1:

Based on the functions in SSD1306.cpp and after reading the SSD1306's datasheet, you're using the 4-wire SPI interface of the controller (as opposed to the 3-wire SPI interface) and I was wondering if there was a specific reason why you chose to use Arduino's ShiftOut() function instead of using the hardware SPI support provided by the SPI Arduino library, combined with two other digital I/O lines controlling D/C and RST?

Question #2:

In ssd1306_command() and ssd1306_data() (SSD1306.cpp lines 369-383), the code pulses the CS line before spiwrite():

void SSD1306::ssd1306_command(uint8_t c) {
digitalWrite(cs, HIGH);
digitalWrite(dc, LOW);
digitalWrite(cs, LOW);
spiwrite(c);
digitalWrite(cs, HIGH);
}

Why is this necessary?

In the datasheet, "Figure 8-5 : Write procedure in 4-wire Serial interface mode" seems to show that CS is just kept low during the transmission and only brought back to high when it's complete.

Thanks,
-Fabien.

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Monochrome 128*64 OLED screen - SSD1306 driver questions

Post by adafruit »

1) so you could use any pins, not just the hardware SPI pins.

2) thats a typo :) but hey, it still works ;)

User avatar
fabienroyer
 
Posts: 15
Joined: Wed Jan 12, 2011 1:48 pm

Re: Monochrome 128*64 OLED screen - SSD1306 driver questions

Post by fabienroyer »

Thanks for the quick response :)
1) so you could use any pins, not just the hardware SPI pins.
Right, which is what the ShiftOut() function does in the driver today, bit-banging on the pins (http://www.arduino.cc/en/Reference/ShiftOut).

My question was: is there a reason why the SSD1306 driver isn't using hardware SPI (http://arduino.cc/en/Reference/SPI) instead in order to maximize throughput?

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Monochrome 128*64 OLED screen - SSD1306 driver questions

Post by adafruit »

yes, so that the user can use any pins they want

User avatar
fabienroyer
 
Posts: 15
Joined: Wed Jan 12, 2011 1:48 pm

Re: Monochrome 128*64 OLED screen - SSD1306 driver questions

Post by fabienroyer »

Got it! Thanks :)

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Monochrome 128*64 OLED screen - SSD1306 driver questions

Post by adafruit »

(also, to make it easier to port!)

please post up a photo when you get it working, we like to promote netduino hacking!

User avatar
fabienroyer
 
Posts: 15
Joined: Wed Jan 12, 2011 1:48 pm

Re: Monochrome 128*64 OLED screen - SSD1306 driver questions

Post by fabienroyer »

Will do!

User avatar
fabienroyer
 
Posts: 15
Joined: Wed Jan 12, 2011 1:48 pm

Re: Monochrome 128*64 OLED screen - SSD1306 driver questions

Post by fabienroyer »

No dice just yet with the C# driver on the netduino... but while testing the OLED display, I removed the need for the level shifter ;-)

http://fabienroyer.BANNED.com/2011/0 ... l-shifter/

I'll post an update when I have figured out the issue on the netduino.

Cheers,
-Fabien.

User avatar
scout119
 
Posts: 10
Joined: Mon Jan 04, 2010 11:02 pm

Re: Monochrome 128*64 OLED screen - SSD1306 driver questions

Post by scout119 »

I have ported the driver for FEZ Panda (SPI, .net microframework)

http://www.breakcontinue.com/archive/20 ... splay.aspx
http://www.tinyclr.com/forum/8/2211/

One issue I had with the device is that 2 pins were bridged on the back side of the board. Spend a lot of time trying to figure out why it didn't work. Almost got to the point of sending it back :D.
Since yours works with Arduino code it should be something else, anyways I am using SPI and it works on Panda. I have Netduino but haven't tried it on it. I will try it later and let you know if it works on Netduino.
Last edited by scout119 on Sun Jan 16, 2011 11:58 am, edited 2 times in total.

User avatar
fabienroyer
 
Posts: 15
Joined: Wed Jan 12, 2011 1:48 pm

Re: Monochrome 128*64 OLED screen - SSD1306 driver questions

Post by fabienroyer »

Hi Scout,

The only real difference that I see between your code and mine is in the SPI config:

Code: Select all

      
public AdaFruitSSD1306(SPI.SPI_module spiModule, Cpu.Pin DC, Cpu.Pin RST, Cpu.Pin CS) {
            dc = new OutputPort(DC, false);
            rst = new OutputPort(RST, false);

            var spiConfig = new SPI.Configuration(
                ChipSelect_Port: CS,
                ChipSelect_ActiveState: false, // CS active low
                ChipSelect_SetupTime: 0,
                ChipSelect_HoldTime: 0,
                Clock_IdleState: false, // <------------------------------- I have it set to false by default.
                Clock_Edge: true, // data clocked in on high edge
                Clock_RateKHz: 10000,
                SPI_mod: spiModule);
            
            Spi = new SPI(spiConfig);
        }
In your config, Clock_IdleState is set to true:

Code: Select all

        
public SSD1306(Cpu.Pin csPin, Cpu.Pin resetPin, Cpu.Pin dcPin, SPI.SPI_module spiModule)
        {
            SPI.Configuration spiConfig = new SPI.Configuration(csPin, false, 0, 0, true, true, 10000, spiModule);
            _spi = new SPI(spiConfig);
 
            _resetPin = new OutputPort(resetPin, false);
            _dcPin = new OutputPort(dcPin, false);
 
            Init();
        }
I'll try your driver later this weekend to see what happens on the netduino.

Just to confirm, the FEZ Panda sends SPI data with MSB first, right?

Cheers,
-Fabien.

User avatar
scout119
 
Posts: 10
Joined: Mon Jan 04, 2010 11:02 pm

Re: Monochrome 128*64 OLED screen - SSD1306 driver questions

Post by scout119 »

Yes.

If MSB is an issue on Netduino you can try bitbang method.
You'll have to comment SPI initialization and pass 2 more pins for clock and data.

Code: Select all

public void Write(byte data)
{
    byte i = 8;
    int mask;

    while (i > 0)
    {
        mask = (1 << i - 1);
        clkPin.Write(false);
        if (((int)data & mask) == 0)
            dataPin.Write(false);
        else
            dataPin.Write(true);
        clkPin.Write(true);
        --i;
    }
}

User avatar
fabienroyer
 
Posts: 15
Joined: Wed Jan 12, 2011 1:48 pm

Re: Monochrome 128*64 OLED screen - SSD1306 driver questions

Post by fabienroyer »

It turns out that sending data to the display using hardware SPI on the netduino does not work.
However, I was able to get the display working with the bit-banging method. This is very odd... :?

User avatar
scout119
 
Posts: 10
Joined: Mon Jan 04, 2010 11:02 pm

Re: Monochrome 128*64 OLED screen - SSD1306 driver questions

Post by scout119 »

Great!

I am glad it worked for you.

User avatar
fabienroyer
 
Posts: 15
Joined: Wed Jan 12, 2011 1:48 pm

Re: Monochrome 128*64 OLED screen - SSD1306 driver questions

Post by fabienroyer »

Thanks Scout.

I'll keep plugging at this issue with SPI as it would improve performance quite a bit, but at least, my netduino driver works now :)

Here's a link to the driver and sample code: http://fabienroyer.BANNED.com/2011/0 ... -netduino/

Cheers,
-Fabien.

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Monochrome 128*64 OLED screen - SSD1306 driver questions

Post by adafruit »

there is a max speed for the SPI. one thing that would make it faster is to update the library so it only refreshes the rectangle that has changed.
http://jeelabs.net/projects/cafe/reposi ... ow/GLCDlib has examples for this.

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

Return to “Other Products from Adafruit”