Organic Light Emitting Diode (OLED) displays are nice displays for embedded systems because they do not require a backlight to operate and have a sharp crisp display. The SSD1306 OLED is a popular display used in embedded systems projects today because it uses the I2C protocol and unlike the industry standard HD77480 they do not require as much space or I/O lines. In this example we interface the PIC32Mx270F256D to a SSD1306 OLED.

SSD1306 OLED

The SSD1306 OLED comes in two versions, there is the SPI verion and the I2C version. This example assumes you are using the I2C version.

The OLED is widely supported on the internet and is useful for embedded projects. The PIC32MX270F256D has no problem driving this display.


Connections

The SSD1306 is connected to the I2C1 bus of the PIC32MX270F256D.


C Program

/*
 * File: Main.c
 * Author: Armstrong Subero
 * Processor: PIC32MX270F256D w/Ext OSC @ 4MHz, PLL to 48 MHz, 3.3v
 * Program: 24_SSD1306
 * Compiler: XC32 (v1.44, MPLAX X v4.00)
 * Program Version: 1.0
 *                             
 * Program Description: This Program Allows PIC32MX270F256D to use the SSD1306
 *                      OLED 
 * 
 * Hardware Description: An SSD1306 OLED is connected to the I2C1 bus.
 * 
 * Change History:
 *
 * Author             Rev     Date          Description
 * Armstrong Subero   1.0     17/09/2018    Initial Release.
 * 
 *                      
 * Created September 17th, 2018, 1:55 PM
 */

/*******************************************************************************
 Includes and defines
*******************************************************************************/
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#include "PIC32MX270_STD.h"
#include "Delay.h"
#include "i2c.h"
#include "logoart.c"
#include "SSD1306.h"
  

/*******************************************************************************
* Function Name: void initMain (void)
*
* Specification: initializes main
*
*******************************************************************************/
void initMain(void)
{  
    uc_init();              // initialize microcontroller
    
    i2c_master_setup();        // initialize master I2C
    I2C1CONbits.A10M = 1;
    I2C1CONbits.STRICT = 1;
    delay_ms(1000);
}


/*******************************************************************************
* Function Name: void main (void)
*
* Specification: main function
*
*******************************************************************************/
void main(void) {
    
    initMain();            // initializes main function
    OLED_init();           // initialize the OLED
    delay_ms(1000);
   
    while(1)
    {
      // print string at x = 0, y = 0
      OLED_gotoxy(0,0);   
      OLED_Write_String("Hello World");
    }


The program initializes the display and writes some text.


Link to project

You can download the entire project here!

SSD1306 Project

Leave a Reply

Your email address will not be published. Required fields are marked *