It’s time for the first official episode of Tech Talk with Gus. In this episode we’ll be talking about and demonstrating an OLED 0.96" display. These cool little displays can be used in a number of projects, and are very cheap.
SSD1306 Datasheet
Adafruit_SSD1306 Drivers
Sorry Maurico, when we migrated to this forum, the code was removed from the comment area. I’ve added it back here below:
// code is from adafruit originally GitHub - adafruit/Adafruit_SSD1306: Arduino library for SSD1306 monochrome 128x64 and 128x32 OLEDs
// Many improvements are needed. This is just a “get me started” code
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
namespace SSD1306_OLED
{
public class Program
{
static int SSD1306_LCDHEIGHT = 64;
static int SSD1306_LCDWIDTH = 128;
static ushort SSD1306_I2C_ADDRESS = (0x3C);
static I2CDevice.Configuration con =
new I2CDevice.Configuration(SSD1306_I2C_ADDRESS, 400);
static I2CDevice I2C = new I2CDevice(con);
static void ssd1306_command(int cmd)
{
I2CDevice.I2CTransaction[] xActions =
new I2CDevice.I2CTransaction[1];
// create write buffer (we need one byte)
byte[] buff = new byte[2];
buff[1] = (byte) cmd;
xActions[0] = I2CDevice.CreateWriteTransaction(buff);
if (I2C.Execute(xActions, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
}
static void InitDisplay()
{
// Init sequence
ssd1306_command(0xae);// SSD1306_DISPLAYOFF); // 0xAE
ssd1306_command(0xd5);// SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
ssd1306_command(0x80); // the suggested ratio 0x80
ssd1306_command(0xa8);// SSD1306_SETMULTIPLEX); // 0xA8
ssd1306_command(SSD1306_LCDHEIGHT - 1);
ssd1306_command(0xd3);// SSD1306_SETDISPLAYOFFSET); // 0xD3
ssd1306_command(0x0); // no offset
ssd1306_command(0x40);// SSD1306_SETSTARTLINE | 0x0); // line #0
ssd1306_command(0x8d);// SSD1306_CHARGEPUMP); // 0x8D
if (false)//vccstate == SSD1306_EXTERNALVCC)
{ ssd1306_command(0x10); }
else
{ ssd1306_command(0x14); }
ssd1306_command(0x20);// SSD1306_MEMORYMODE); // 0x20
ssd1306_command(0x00); // 0x0 act like ks0108
ssd1306_command(0xa1);// SSD1306_SEGREMAP | 0x1);
ssd1306_command(0xc8);// SSD1306_COMSCANDEC);
ssd1306_command(0xda);// SSD1306_SETCOMPINS); // 0xDA
ssd1306_command(0x12);
ssd1306_command(0x81);// SSD1306_SETCONTRAST); // 0x81
if (false)//vccstate == SSD1306_EXTERNALVCC)
{ ssd1306_command(0x9F); }
else
{ ssd1306_command(0xCF); }
ssd1306_command(0xd9);// SSD1306_SETPRECHARGE); // 0xd9
if (false)//vccstate == SSD1306_EXTERNALVCC)
{ ssd1306_command(0x22); }
else
{ ssd1306_command(0xF1); }
ssd1306_command(0xd8);// SSD1306_SETVCOMDETECT); // 0xDB
ssd1306_command(0x40);
ssd1306_command(0xa4);//SSD1306_DISPLAYALLON_RESUME); // 0xA4
ssd1306_command(0xa6);// SSD1306_NORMALDISPLAY); // 0xA6
ssd1306_command(0x2e);// SSD1306_DEACTIVATE_SCROLL);
ssd1306_command(0xaf);// SSD1306_DISPLAYON);//--turn on oled panel
///////////////////
///////////////////
}
static void Render(byte[] data)
{
ssd1306_command(0x21);// SSD1306_COLUMNADDR);
ssd1306_command(0); // Column start address (0 = reset)
ssd1306_command(SSD1306_LCDWIDTH - 1); // Column end address (127 = reset)
ssd1306_command(0x22);// SSD1306_PAGEADDR);
ssd1306_command(0); // Page start address (0 = reset)
ssd1306_command(7); // Page end address
byte[] img = new byte[(128 * 64 / 8)+1];
img[0] = 0x40;
Array.Copy(data, 0, img, 1, 128 * 64 / 8);
//img[50]=0xAA;
xActions[0] = I2CDevice.CreateWriteTransaction(img);
if (I2C.Execute(xActions, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
}
public static void Main()
{
InitDisplay();
Bitmap LCD = new Bitmap(128, 64);
Font fnt = Resources.GetFont(Resources.FontResources.NinaB);
int counter = 0;
int x = 50;
int dx = 5;
while (true)
{
LCD.DrawText("Count: " + counter++, fnt, Microsoft.SPOT.Presentation.Media.Color.White, 10, 10);
LCD.DrawEllipse(Microsoft.SPOT.Presentation.Media.Color.White, x, 40, 5, 5);
LCD.DrawEllipse(Microsoft.SPOT.Presentation.Media.Color.White, 128-x, 50, 5, 5);
byte[] img = GHI.Utilities.Bitmaps.Convert(LCD, GHI.Utilities.Bitmaps.Format.Bpp1x128);
Render(img);
LCD.Clear();
x += dx;
if (x < 0 || x > 128)
dx *= -1;
System.Threading.Thread.Sleep(30);
}
}
}
}
1 Like
Mike
September 22, 2017, 6:37pm
#4
Did I see a 2016 copyright notice at the end of the video?
That’s when it was actually produced. 10/14/16, almost 1 year ago.
Mike
September 22, 2017, 7:40pm
#6
Ah! Today being Friday, I thought it was a new video.
Hanos
September 23, 2017, 11:27am
#7
Beutiful thing i need to get known of it