0

Monochrome 128*64 OLED screen - SSD1306 driver questions
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Monochrome 128*64 OLED screen - SSD1306 driver questions

by fabienroyer on Wed Jan 12, 2011 2:04 pm

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.

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

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

by adafruit on Wed Jan 12, 2011 2:27 pm

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

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

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

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

by fabienroyer on Wed Jan 12, 2011 2:37 pm

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?

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

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

by adafruit on Wed Jan 12, 2011 2:52 pm

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

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

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

by fabienroyer on Wed Jan 12, 2011 2:59 pm

Got it! Thanks :)

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

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

by adafruit on Wed Jan 12, 2011 3:03 pm

(also, to make it easier to port!)

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

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

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

by fabienroyer on Wed Jan 12, 2011 5:49 pm

Will do!

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

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

by fabienroyer on Fri Jan 14, 2011 3:40 am

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.wordpress.com/2011/0 ... l-shifter/

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

Cheers,
-Fabien.

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

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

by scout119 on Sat Jan 15, 2011 2:14 pm

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.

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

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

by fabienroyer on Sat Jan 15, 2011 2:54 pm

Hi Scout,

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

Code: Select all | TOGGLE FULL SIZE
     
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 | TOGGLE FULL SIZE
       
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.

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

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

by scout119 on Sat Jan 15, 2011 3:25 pm

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 | TOGGLE FULL SIZE
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;
    }
}

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

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

by fabienroyer on Sun Jan 16, 2011 8:19 pm

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

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

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

by scout119 on Sun Jan 16, 2011 11:27 pm

Great!

I am glad it worked for you.

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

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

by fabienroyer on Mon Jan 17, 2011 2:58 am

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.wordpress.com/2011/01/16/driving-an-adafruit-ssd1306-oled-display-with-a-netduino/

Cheers,
-Fabien.

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

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

by adafruit on Mon Jan 17, 2011 4:34 pm

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.

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

Please be positive and constructive with your questions and comments.