SSD1306 OLED display not working on FEZ Duino

I found a few topics in this forum on the SSD1306 with code that works on the FEZ Feather, among others, so I decided I would give it a try on my FEZ Duino. I copied some code and adjusted it so it would technically work on my device, but it throws an error and I cannot figure out exactly why. Using the step-by-step debugger of Visual Studio it appears that the issue happens somewhere in the creation of a new SSD1306Controller object, but that does not help me (a beginner) much…
The error:

The thread '<No Name>' (2) has exited with code 0 (0x0).
    #### Exception System.Exception - CLR_E_TIMEOUT (1) ####
    #### Message: 
    #### GHIElectronics.TinyCLR.Devices.I2c.Provider.I2cControllerApiWrapper::WriteRead [IP: 0000] ####
    #### GHIElectronics.TinyCLR.Devices.I2c.I2cDevice::WriteRead [IP: 0027] ####
    #### GHIElectronics.TinyCLR.Devices.I2c.I2cDevice::Write [IP: 000c] ####
    #### GHIElectronics.TinyCLR.Drivers.SolomonSystech.SSD1306.SSD1306Controller::SendCommand [IP: 0012] ####
    #### GHIElectronics.TinyCLR.Drivers.SolomonSystech.SSD1306.SSD1306Controller::Initialize [IP: 0009] ####
    #### TinyCLROLED.Program::Main [IP: 0024] ####
Exception thrown: 'System.Exception' in GHIElectronics.TinyCLR.Devices.I2c.dll
An unhandled exception of type 'System.Exception' occurred in GHIElectronics.TinyCLR.Devices.I2c.dll

The code:

using GHIElectronics.TinyCLR.Devices.I2c;
using GHIElectronics.TinyCLR.Drivers.BasicGraphics;
using GHIElectronics.TinyCLR.Drivers.SolomonSystech.SSD1306;
using GHIElectronics.TinyCLR.Pins;

namespace OLED_Test
{
    internal class Program
    {
        static void Main()
        {
            uint white = 0x00ffffffU;

            I2cConnectionSettings ics = new I2cConnectionSettings(0x78, I2cAddressFormat.SevenBit, 400_000U);
            I2cController i2CController = I2cController.FromName(SC20100.I2cBus.I2c2);
            I2cDevice device = i2CController.GetDevice(ics);
            SSD1306Controller ctl = new SSD1306Controller(device);

            var basicGfx = new BasicGraphics(128, 64, ColorFormat.OneBpp);
            basicGfx.Clear();

            basicGfx.DrawString("Test", white, 0, 0, 2, 8);

            ctl.DrawBufferNative(basicGfx.Buffer);
        }
    }
}

The address is not 0x78, it should be 0x3C.

You have wrong address that why it does not work.

And, you don’t need to pass device address, code should be something like this, no need device address, the driver will handle it :

 var i2ccontroler = I2cController.FromName(SC20100.I2cBus.I2c1);
            var setting = SSD1306Controller.GetConnectionSettings();
            var i2cdev = i2ccontroler.GetDevice(setting);
            var display = new SSD1306Controller(i2cdev);
2 Likes

Thanks, this does work. Out of curiousity though, what does the address refer to? The resistor on the back of my display modules are set to 0x78.
Also would it be possible to update the FEZ Duino pinout guide to include which pins are SCL & SDA for both I2C1 and I2C2 so (new) users don’t get confused? They are explicitly named on, among others, the one for the FEZ Pico.

I2C1 for different board, it was an example, forget I2C1, use whatever your board does have. Glad to know it works.

0x3C is the 7-bit SLA address. The SSD1306 must receive this address and a read bit (1) or write R/W(0) in the form of a byte, i.e. 2*SLA+R/W during communication (0x78 with R/W=0). This calculation is automatically done by the library.

1 Like