OLED Display Driver Config for Daisy Submodule

I have a 2.42" OLED screen with an SSD1309 driver (used in SPI mode) that I’m struggling to get working with the Daisy Patch Submodule. There’s another thread on the topic here but I’ve been unable to make much progess with it.

This is my wiring diagram:




(where SDA is MOSI and SCL is SPI SCK). And I’ve adapted the Daisy Seed OLED example so that it should work with the submodule. This is the code that I’ve used to setup the OLED display config:

hw.Init();

DaisyPatchSM::PinBank bankD;
bankD = DaisyPatchSM::PinBank::D;

MyOledDisplay::Config disp_cfg;

disp_cfg.driver_config.transport_config.spi_config.periph = SpiHandle::Config::Peripheral::SPI_2;

disp_cfg.driver_config.transport_config.spi_config.pin_config.nss = hw.GetPin(bankD,1);
disp_cfg.driver_config.transport_config.spi_config.pin_config.miso = hw.GetPin(bankD,8);  
disp_cfg.driver_config.transport_config.spi_config.pin_config.mosi = hw.GetPin(bankD,9);
disp_cfg.driver_config.transport_config.spi_config.pin_config.sclk = hw.GetPin(bankD,10);

disp_cfg.driver_config.transport_config.pin_config.dc = hw.GetPin(bankD,2);
disp_cfg.driver_config.transport_config.pin_config.reset = hw.GetPin(bankD,3);

display.Init(disp_cfg);

When using the original Peripheral::SPI_1 the MISO pin appears to be assigned to be a dummy pin so maybe I should be doing something similar when using SPI_2?

In case of those SSD1309/6 displays, no data is received over SPI. So assigning a dummy pin for MISO is fine and you can do the same here too.

Thank you. Could you tell me how to set a pin to be a dummy pin?

At the moment the screen stays blank and I don’t know what the issue is. It could be something to do with the MISO pin but there might be another problem?

This is explained in SPI docs

Thanks, I had a look at that page and it was very useful.

The display still isn’t happy and refuses to work. I’m starting to think that the board might be faulty. I’ll get a new one and see what happens

I was beginning to think that the submodule wasn’t working properly so I uploaded the “blinky” example to test it. It worked fine and the next time I uploaded the OLED display code it worked straight away. Very odd. I’ve included my full code below for reference.

/* Adapted from the Daisy Seed OLED example */

#include <stdio.h>
#include <string.h>
#include "dev/oled_ssd130x.h"
#include "daisy_patch_sm.h"

using namespace daisy;
using namespace patch_sm;

using MyOledDisplay = OledDisplay<SSD130x4WireSpi128x64Driver>;

DaisyPatchSM hw;
MyOledDisplay display;


int main(void)
{
    uint8_t message_idx;
    hw.Init();

    DaisyPatchSM::PinBank bankD;
    bankD = DaisyPatchSM::PinBank::D;

    MyOledDisplay::Config disp_cfg;

    disp_cfg.driver_config.transport_config.spi_config.periph = SpiHandle::Config::Peripheral::SPI_2;   

    disp_cfg.driver_config.transport_config.spi_config.pin_config.nss = hw.GetPin(bankD,1);
    disp_cfg.driver_config.transport_config.spi_config.pin_config.miso = Pin();
    disp_cfg.driver_config.transport_config.spi_config.pin_config.mosi = hw.GetPin(bankD,9);
    disp_cfg.driver_config.transport_config.spi_config.pin_config.sclk = hw.GetPin(bankD,10);

    disp_cfg.driver_config.transport_config.pin_config.dc = hw.GetPin(bankD,2);    
    disp_cfg.driver_config.transport_config.pin_config.reset = hw.GetPin(bankD,3);


    display.Init(disp_cfg);

    message_idx = 0;
    char strbuff[128];
    while(1)
    {
        System::Delay(500);
        switch(message_idx)
        {
            case 0: sprintf(strbuff, "Testing. . ."); break;
            case 1: sprintf(strbuff, "Daisy. . ."); break;
            case 2: sprintf(strbuff, "1. . ."); break;
            case 3: sprintf(strbuff, "2. . ."); break;
            case 4: sprintf(strbuff, "3. . ."); break;
            default: break;
        }
        message_idx = (message_idx + 1) % 5;
        display.Fill(true);
        display.SetCursor(0, 0);
        display.WriteString(strbuff, Font_11x18, false);
        display.Update();
    }
}

Pure wild speculation, as I don’t have a Seed and OLED…
Maybe disp_cfg needs to be defined as a global (outside of a function)? Variables defined outside of a function get initialized to 0 on startup, but variables inside a function (‘auto’ variables, on the stack) don’t get cleared, they contain whatever was left on the stack.

tennessee1729: This code was very helpful. thanks. I was struggling to get the OLED working but ended up with a working patch sm oscilloscope by the end of the day.

1 Like