The DigiX > DigiX Projects

DigiX and Digol's 1.8" 160x128 OLED Display through SPI

(1/1)

DROBNJAK:
Since my Serial Monitor still doesn't work with DigiX, I had to plug in this, reasonably big, Digol's Display. I had few problems, to begin with, but tech support from Digol helped me sort it out.

I am using the display over SPI interface. To use SPI (or I2C) you need to first close the jumper on the back, so you connect SPI pad to middle pad and job done. That was explained in the manual.

What wasn't explained in the manual was how to adopt the demo code so it works! First you need to install the Digol Disp libraries, as usual. You can get libs from here: http://www.digole.com/index.php?productID=883

This post is mostly to help people like myself, who are not proficient in C, but are OK with Arduino IDE level programming. For anybody who encounters DigiX and Digol problem in future:

  - Don't do commenting out. Commenting out is misleading, it will just cause compiling errors.
  - yes, if you want to use SPI, than replace:
        #define _Digole_Serial_UART_
    with:
        #define _Digole_Serial_SPI_
  - DigiX's SPI pinout is very different from Arduino UNO's. I used SPI 2x3 header next to CPU. SPI header is 5V, so you'll get nice and bright OLED. You need to change few lines, like this:

      replace this original code:
         DigoleSerialDisp mydisp(8,9,10);  //SPI:Pin 8: data, 9:clock, 10: SS, you can assign 255 to SS, and hard ground SS pin on module
      with:
         DigoleSerialDisp mydisp(74,76,10);  //SPI:Pin 74:DATA, 76:CLK, 10:SS, you can assign 255 to SS, and hard ground SS pin on module

And to help you with wiring here are some prety, but useful, pictures:



N.B. Reset pin on the header is not SPI RESET/CS/SS pin. Most likely it is a board reset. For SPI RESET/CS/SS you need to go to pin 10 (white wire).

This is my wiring that worked:

   - Pin 74(MISO) to DATA, Green wire,
   - Pin 76(SCK) to CLK, Yellow wire,
   - Pin 75(MOSI) not used here,
   - Pin 10(RESET/SS/CS) to SS, White wire, needs to be connected to headers on the side.

Anyhow, here is the corrected code, for SPI, which works out of the box. Just copy and paste:


--- Code: ---/*
 *This demo code will show you all functions for
 *Digole Graphic LCD adapter
 */
#define _Digole_Serial_SPI_  //To tell compiler compile the special communication only,
//all available are:_Digole_Serial_UART_, _Digole_Serial_I2C_ and _Digole_Serial_SPI_
#include <DigoleSerial.h>
//--------UART setup, if you don't use UART, use // to comment following line
#if defined(_Digole_Serial_UART_)
DigoleSerialDisp mydisp(&Serial, 38400); //UART:Arduino UNO: Pin 1(TX)on arduino to RX on module
#endif
//--------I2C setup, if you don't use I2C, use // to comment following 2 lines
#if defined(_Digole_Serial_I2C_)
#include <Wire.h>
DigoleSerialDisp mydisp(&Wire,'\x27');  //I2C:Arduino UNO: SDA (data line) is on analog input pin 4, and SCL (clock line) is on analog input pin 5 on UNO and Duemilanove
#endif
//--------SPI setup, if you don't use SPI, use // to comment following line
#if defined(_Digole_Serial_SPI_)
DigoleSerialDisp mydisp(74,76,10);  //SPI:Pin 74:DATA, 76:CLK, 10:SS, you can assign 255 to SS, and hard ground SS pin on module
#endif

#define LCDCol 16
#define LCDRow 2
#define SC_W 160  //screen width in pixels
#define SC_H 128  //screen Hight in pixels
#include "DigoleImage.h"

prog_uchar welcomeimage[] PROGMEM = {
  0, 0, 0, 0, 0, 127
    , 0, 8, 1, 2, 0, 127
    , 0, 8, 0, 148, 0, 127
    , 0, 16, 0, 89, 112, 127
    , 3, 144, 0, 16, 144, 127
    , 28, 145, 192, 16, 144, 127
    , 1, 30, 128, 80, 144, 127
    , 9, 49, 3, 208, 144, 127
    , 5, 72, 0, 80, 144, 127
    , 2, 72, 0, 150, 144, 127
    , 3, 8, 0, 152, 208, 127
    , 5, 24, 0, 64, 160, 127
    , 4, 148, 0, 64, 128, 127
    , 8, 36, 0, 128, 128, 127
    , 16, 34, 3, 240, 128, 127
    , 32, 65, 0, 14, 0, 127
    , 0, 129, 128, 1, 252, 127
    , 3, 0, 64, 0, 0, 127
    , 0, 0, 0, 0, 0, 127
    , 0, 0, 0, 0, 0, 127
    , 0, 0, 0, 0, 0, 127
};
int ptr;
const char a[] = "disp char array";
const char b = 'Q';
int c = 3456;
String d = "I'm a string";
float pi = 3.1415926535;
double lg10;
const unsigned char fonts[] = {
  6, 10, 18, 51, 120, 123};
const char *fontdir[] = {
  "0\xb0", "90\xb0", "180\xb0", "270\xb0"};
 
void resetpos1(void) //for demo use, reset display position and clean the demo line
{
  mydisp.setPrintPos(0, 0, _TEXT_);
  delay(1500); //delay 2 seconds
  mydisp.println("                "); //display space, use to clear the demo line
  mydisp.setPrintPos(0, 0, _TEXT_);
}
void resetpos(void) //for demo use, reset display position and clean the demo line
{
  mydisp.setPrintPos(0, 1, _TEXT_);
  delay(1500); //delay 2 seconds
  mydisp.println("                "); //display space, use to clear the demo line
  mydisp.setPrintPos(0, 1, _TEXT_);
}

void setup() {
//  delay(10);  //waiting for display model ready
  mydisp.begin();
  mydisp.clearScreen(); //CLear screen
  /*----------Special function for color OLED ------------*/
  mydisp.print("Due to the limitation of memory on Arduino, we only can draw small size of color image here, you can read image from SD card, then display it on the screen then");
  delay(2000);
  resetpos1();
  mydisp.clearScreen();
  mydisp.setMode('C'); //set graphic Drawing Mode to COPY
  mydisp.print("Draw 256 color image");
  mydisp.drawBitmap256(19,40,120,30,digole256);  //use our image convert tool to convert, www.digole.com/tools
  delay(2000);
  resetpos1();
  mydisp.clearScreen();
  mydisp.setMode('C'); //set graphic Drawing Mode to COPY
  mydisp.print("Draw 262K color image");
  mydisp.drawBitmap262K(39,30,70,43,eyes);
  delay(2000);
  /*----------for text LCD adapter and graphic LCD adapter ------------*/
  resetpos1();
  mydisp.clearScreen();
  mydisp.setMode('C'); //set graphic Drawing Mode to COPY
//  for(unsigned int i=0;i<65535;i++)
//  {
//    mydisp.Print::print(random(255));
//  }
  //mydisp.displayConfig(1);    //set config display ON, 0=off
  //mydisp.setI2CAddress(0x29);  //this function only working when you connect using I2C, from 1 to 127
  //delay(1000);
  //mydisp.setLCDColRow(16,2);  //set LCD Col and Row, only time set up is OK
mydisp.displayConfig(0);
mydisp.disableCursor(); //disable cursor, enable cursore use: enableCursor();
  mydisp.drawStr(2, 0, "Demo TEXT now"); //display string at: x=4, y=0
  //Test print function
  mydisp.setColor(random(254)+1);
  mydisp.setPrintPos(0, 1, _TEXT_);
  mydisp.print(a); // display a char array
  resetpos();
  mydisp.setColor(random(254)+1);
  mydisp.print("display a char:");
  mydisp.setColor(random(254)+1);
  mydisp.print(b); //display a char
  resetpos();
  mydisp.setColor(random(254)+1);
  mydisp.print("int as DEC:");
  mydisp.setColor(random(254)+1);
  mydisp.print(c); //display 3456 in Dec
  resetpos();
  mydisp.setColor(random(254)+1);
  mydisp.print("as HEX:");
  mydisp.setColor(random(254)+1);
  mydisp.print(c, HEX); //display 3456 in Hex
  resetpos();
  mydisp.setColor(random(254)+1);
  mydisp.print("as OCT:");
  mydisp.setColor(random(254)+1);
  mydisp.print(c, OCT); //display 3456 in Oct
  resetpos();
  mydisp.setColor(random(254)+1);
  mydisp.print("BIN:");
  mydisp.setColor(random(254)+1);
  mydisp.print(c, BIN); //display 3456 in Bin
  resetpos();
  mydisp.setColor(random(254)+1);
  mydisp.print("float pi=");
  mydisp.setColor(random(254)+1);
  mydisp.print(pi); //display float of PI
  resetpos();
  mydisp.setColor(random(254)+1);
  mydisp.print("Pi6=");
  mydisp.setColor(random(254)+1);
  mydisp.print(pi, 6); //display PI in 6 Accuracy
  resetpos();
  mydisp.setColor(random(254)+1);
  mydisp.print("Pi*3=");
  mydisp.setColor(random(254)+1);
  mydisp.print(pi * 3, 6); //display PI time 3 in 6 Accuracy
  resetpos();
  mydisp.setColor(random(254)+1);
  mydisp.print("lg5=");
  mydisp.setColor(random(254)+1);
  mydisp.print(log(5), 8); //display log(5) in 8 Accuracy
  resetpos();
  mydisp.setColor(random(254)+1);
  mydisp.print(d); //display String object
  resetpos();
  for (uint8_t j = 0; j < 2; j++) //making "Hello" string moving
  {
    for (uint8_t i = 0; i < 10; i++) //move string to right
    {
      mydisp.setPrintPos(i, 1, _TEXT_);
      mydisp.setColor(random(254)+1);
      mydisp.print(" Hello ");
      delay(100); //delay 100ms
    }
    for (uint8_t i = 0; i < 10; i++) //move string to left
    {
      mydisp.setPrintPos(9 - i, 1, _TEXT_);
      mydisp.setColor(random(254)+1);
      mydisp.print(" Hello ");
      delay(100);
    }
  }
  mydisp.setColor(random(254)+1);
  mydisp.print("Enjoy it!");
  mydisp.enableCursor(); //enable cursor
  /*---------for Graphic LCD adapter only-------*/
  mydisp.disableCursor(); //enable cursor
  resetpos();
  mydisp.setColor(random(254)+1);
  mydisp.drawStr(0, 1, "Negative/flash");
  mydisp.setMode('~');
  for (uint8_t i = 0; i < 10; i++) {
    mydisp.drawBox(0, 13, 110, 13);
    delay(500);
  }
  resetpos();
  mydisp.clearScreen();
  mydisp.setColor(random(254)+1);
  mydisp.drawStr(0, 0, "Draw image in 4 dir");
  //display image in 4 different directions, use setRot90();setRot180();setRot270();undoRotation();setRotation(dir);
  for (uint8_t i = 0; i < 4; i++) {
    mydisp.setRotation(i);
    mydisp.setColor(random(254)+1);
    mydisp.drawBitmap(12, 12, 41, 21, welcomeimage);
  }
  mydisp.undoRotation();
  resetpos1();
  mydisp.clearScreen();
  mydisp.setColor(random(254)+1);
  mydisp.drawStr(0, 0, "draw a box");
  mydisp.setColor(random(254)+1);
  mydisp.drawBox(20, 15, 30, 40);
  //test drawing a circle
  resetpos1();
  mydisp.clearScreen();
  mydisp.setColor(random(254)+1);
  mydisp.drawStr(0, 0, "draw a circle and a pie");
  mydisp.setColor(random(254)+1);
  mydisp.drawCircle(31, 31, 30);
  mydisp.setColor(random(254)+1);
  mydisp.drawCircle(31, 31, 14, 1);
  //test drawing a Frame
  resetpos1();
  mydisp.clearScreen();
  mydisp.setColor(random(254)+1);
  mydisp.drawStr(0, 0, "draw a Frame");
  mydisp.setColor(random(254)+1);
  mydisp.drawFrame(20, 15, 30, 40);
  //Clear an area use set color =0
  resetpos1();
  mydisp.clearScreen();
  mydisp.drawStr(0, 0, "Clear an area by using set color=0");
  mydisp.setColor(random(254)+1);
  mydisp.drawCircle(35, 70, 35, 1);
  mydisp.setColor(random(254)+1);
  mydisp.drawBox(80, 40, 80, 60);
  mydisp.setMode('C'); //set graphic Drawing Mode to COPY
  mydisp.setColor(0);
  mydisp.drawCircle(110, 70, 25, 1);
  mydisp.drawBox(20, 50, 40, 30);
  //test drawing Pixels
  resetpos1();
  mydisp.clearScreen();
  mydisp.setColor(random(254)+1);
  mydisp.drawStr(0, 0, "draw Pixels");
  for (uint8_t i = 0; i < 20; i++) {
    mydisp.setColor(random(254)+1);
    mydisp.drawPixel(random(SC_W-1), 12 + random(SC_H-13));
  }
  //test drawing Lines
  resetpos1();
  mydisp.clearScreen();
  mydisp.setColor(random(254)+1);
  mydisp.drawStr(0, 0, "draw Lines");
  for (uint8_t i = 0; i < 10; i++) {
    mydisp.setColor(random(254)+1);
    mydisp.drawLine(random(SC_W-1), 12 + random(SC_H-13), random(SC_W-1), 12 + random(SC_H-13));
  }
  //test drawing Lines to
  resetpos1();
  mydisp.clearScreen();
  mydisp.setColor(random(254)+1);
  mydisp.drawStr(0, 0, "draw Lines to");
  mydisp.setColor(random(254)+1);
  mydisp.drawLine(random(SC_W-1), 12 + random(SC_H-13), random(SC_W-1), 12 + random(SC_H-13));
  for (uint8_t i = 0; i < 10; i++) {
    mydisp.setColor(random(254)+1);
    mydisp.drawLineTo(random(SC_W-1), 12 + random(SC_H-13));
  }
  //test differnt font
  resetpos1();
  mydisp.clearScreen();
  mydisp.setColor(random(254)+1);
  mydisp.drawStr(0, 0, "default font");
  mydisp.setFont(fonts[0]);
  mydisp.nextTextLine();
  mydisp.setColor(random(254)+1);
  mydisp.print("Font 6");
  mydisp.setFont(fonts[1]);
  mydisp.nextTextLine();
  mydisp.setColor(random(254)+1);
  mydisp.print("Font 10");
  mydisp.setFont(fonts[2]);
  mydisp.nextTextLine();
  mydisp.setColor(random(254)+1);
  mydisp.print("Font 18");
  mydisp.setFont(fonts[3]);
  mydisp.nextTextLine();
  mydisp.setColor(random(254)+1);
  mydisp.print("Font 51");
  resetpos1();
  mydisp.clearScreen();
  mydisp.setFont(fonts[4]);
  mydisp.setPrintPos(0, 0, _TEXT_);
  mydisp.setColor(random(254)+1);
  mydisp.print("Font 120");
  mydisp.setFont(fonts[5]); //font 123 only have chars of space and 1 to 9
  mydisp.setColor(random(254)+1);
  mydisp.nextTextLine();
  mydisp.print("123");
  resetpos1();
  mydisp.clearScreen();
  //User font using number: 200,201,202,203,only available after upload to adapter
  mydisp.setFont(10);
  mydisp.setColor(random(254)+1);
  mydisp.drawStr(0, 0, "User font using:200,201,202,203,available after upload to adapter,16Kb space.");
  //move area on screen
  resetpos1();
  mydisp.clearScreen();
  mydisp.setColor(random(254)+1);
  mydisp.print("move area on screen");
  mydisp.setColor(random(254)+1);
  mydisp.drawCircle(31, 31, 14, 1);
  delay(2000);
  mydisp.moveArea(31, 31, 15, 15, 5, 8);
  //set display mode, affect all graphic functions, the available mode: "|"-or,"&"-and,"^"-xor,"!"-not,"C"-copy
  resetpos1();
  mydisp.clearScreen();
  mydisp.setColor(random(254)+1);
  mydisp.print("use xor or not mode to show a Circle Animation");
  mydisp.setMode('^');
  for (uint8_t i = 1; i < 31; i++) {
    mydisp.setColor(random(254)+1);
    mydisp.drawCircle(31, 31, i); //draw a circle
    delay(50);
    mydisp.drawCircle(31, 31, i); //disappear the previos draw
  }
  //this section show how to use enhanced TEXT position functions:
  //setTextPosBack(),setTextPosOffset() and setTextPosAbs() to make some thing fun
  resetpos1();
  mydisp.clearScreen();
  mydisp.setMode('|');
  mydisp.setColor(random(254)+1);
  mydisp.print("Bold D");
  mydisp.setFont(120);
  mydisp.nextTextLine();
  mydisp.setColor(random(254)+1);
  mydisp.print('D');
  mydisp.setTextPosBack(); //set text position back
  delay(2000);
  mydisp.setTextPosOffset(2, 0); //move text position to x+2
  mydisp.setColor(random(254)+1);
  mydisp.print('D'); //display D again, under or mode, it will bold 'D'
  //use setTextPosAbs() to make a Animation letter
  resetpos1();
  mydisp.clearScreen();
  mydisp.setColor(random(254)+1);
  mydisp.print("make > animation");
  mydisp.setFont(51);
  mydisp.setMode('C');
  for (uint8_t i = 0; i < SC_W-20; i++) {
    mydisp.setTextPosAbs(i, 45);
    mydisp.setColor(random(254)+1);
    mydisp.print('>');
    delay(5);
  }
  //show font in different direction
  resetpos1();
  mydisp.clearScreen();
  mydisp.setFont(fonts[1]);
  mydisp.setColor(random(254)+1);
  mydisp.print("show font in different direction");
  resetpos1();
  mydisp.clearScreen();
  for (uint8_t i = 0; i < 4; i++) {
    mydisp.setRotation(i);
    mydisp.setFont(fonts[2]);
    mydisp.setPrintPos(0, 0);
    for (uint8_t j = 0; j < 3; j++) {
      mydisp.setFont(fonts[2 - j]);
      if (j != 0)
        mydisp.nextTextLine();
      mydisp.setColor(random(254)+1);
      mydisp.print(fontdir[i]);
    }
  }
  resetpos1();
  mydisp.clearScreen();
  mydisp.setMode('C'); //set graphic Drawing Mode to COPY
  mydisp.setColor(random(254)+1);
  mydisp.drawHLine(0, SC_H/2-1, SC_W-1); //draw horizontal LiNe
  mydisp.setColor(random(254)+1);
  mydisp.setPrintPos(0, SC_H/2-1, 1); //Set Graphic position
  for (uint8_t i = 1; i <= SC_W-1; i = i + 6) //this loop will draw sin graph
  {
    mydisp.setColor(random(254)+1);
    mydisp.drawLineTo(i, (uint8_t) (SC_H/2 - (float) (sin(i * 3.14 / (SC_W/2-1))*(SC_H/2))));
  }
}

void loop() {
}


--- End code ---

And on a closing note, Digol's OLED is guite bright and crisp and, yes, I can read letters from about 170 degrees inclination. I would say its better than TFT. Just don't leave it on more than neccessary, because it will burn in (I guess, all OLEDs do that).

Digol's libraries are bit banging directly to pins, so I would say it would be great if Digol sits down and writes a proper libraries with a complete abstraction.

rholt:
Thanks for this post. Very good "detour signs" to look out for when I get my Digole delivered. Posts like this save so much "reinvent the wheel" time. They are much appreciated. I'll check back in after I've run my oled through it's first sketch.

thanks again,
Russ from Coral Springs, Fl

Navigation

[0] Message Index

Go to full version