This tutorial uses Arduino
**The library I've posted here is out of date for newer versions of Arduino and i don't have the time to fix it right now. Parts of the tutorial are still valid, but the library won't work!!
4D Systems makes some really nice serial OLEDS. They aren't hard to use, but the documentation for them is very scattered. This tutorial pulls together the various pieces i've found so that you can get up and running very quickly.
Start by skimming through the user manual for your particular 4D OLED.
µOLED-128-GMD
µOLED-96-G1
µOLED-160-GMD1
The OLED I worked with was the µOLED-128-GMD. The other OLEDs listed have the same pinouts and as far as i know should work similarly.
Start by loading images on the SD card for an OLED slide show. This will serve as a test run to see if the images are on the card properly before you do any coding.
1. Get the images on the Micro SD card.
Download Graphics Composer from the 4d website. http://www.4dsystems.com.au/downloads.php The only version they have is for PCs. You need a microSD to USB adapter so that you can write to the card. The directions to load images with the software come with the zipped sofware file. You can do some minor image editing with the software, but the program is clunky. I suggest cropping and sizing the image in photoshop beforehand. A text file will be created when you upload your pictures. You will need this later for part II so don't get rid of it.
2. Plug stuff in
Put the SD card in the OLED card slot. Make sure the jumper is connecting both pins on the back. Plug in power (Voltage supply from 3.3V to 6.0V) and Gnd.
3. Show off
Wow everyone with your tiny slide show.
1.Download the library
Oscar Gonzalez, the 4d distributor in Spain, wrote up a library with functions that can help you get started.
It's got these useful functions:
// Get 16bits value from RGB (0 to 63, 565 format)
int GetRGB(int red, int green, int blue)
// Clears the screen
void OLED_Clear()
//drawing functions
void OLED_PutPixel(char x, char y, int color)
void OLED_DrawLine(char x1, char y1, char x2, char y2, int color)
void OLED_DrawRectangle(char x, char y, char width, char height, char filled, int color)
void OLED_DrawCircle(char x, char y, char radius, char filled, int color)
// Change font format - FontType can be: OLED_FONT5X7, OLED_FONT8X8, OLED_FONT8X12
void OLED_SetFontSize(char FontType)
void OLED_DrawText(char column, char row, char font_size, char *mytext, int color)
void OLED_DrawSingleChar(char column, char row, char font_size, char MyChar, int color)
Once you've downloaded the library, put it in the following path arduino-0010 -> hardware -> libraries. When you start writing your program in arduino, import the OLED library. The library is specifically written for the MicroOLED-160-GMD1module, but works fine with the other modules, except the x parameter on all functions can't be more than the number of pixels that your 4D_OLED has.
2. Set up the circuit
* Wire the OLED's TX pin to arduino's RX pin.
*
A 1k resistor should be wired between OLED's RX pin and arduino's TX pin.
*
Oscar's library has been setup to use arduino pin 8 as the reset button for the OLED, so wire the 'R' pin on the OLED to pin 8 on Arduino.
* Wire power and GND from the breadboard to Arduino.
* Put the OLED jumper on only one pin (so that the two pins are NOT conntected)
4. Examine the text file that was created when you were working with graphics composer.
You will need the sector addresses of each image to be able to call them up using the OLED's "Display image/Icon from memory card. This will be the last three number in the list that's give after the height and width.
You will see a string of numbers like "64, 73, 0, 0, 128, 128, 16, 0, 16, 0." You want are the "0, 16, 0."
5. Arduino Code
To send out commands serially from Arduino, you'll use the 'printByte()' method as opposed to the Serial.print() method. You'll be using the OLED's "Display Image/Icon from Memory Card" command. 4D labels this as an extended command, so a '40' hex must be sent before the Display Image command. The following code will load images and then draw on them, resulting in drawing a nose on Tom, a hat on John and earrings on Giana.
#include <oled160drv.h>
void setup() {
Serial.begin(9600);
pinMode(8, OUTPUT); // sets the digital pin as output
//function from Oscar's library, using pin8 to control reset of the OLED
OLED_Init();
//cler screen
OLED_Clear();
}
void loop() {
//Display first image
printByte(0x40); //extcmd in hex
printByte(0x49); //cmd in hex
printByte(0); //x
printByte(0); //y
printByte(128); //width 128
printByte(128); //height 128
printByte(16); //colour mode 16
//sector address of photo
printByte(0); //0
printByte(16); //16
printByte(0); //0
delay(2000);
//draw a nose: function from library
//void OLED_DrawCircle(char x, char y, char radius, char filled, int color)
OLED_DrawCircle(78, 68, 10, 1, 63488);
delay(2000);
//Display 2nd image
printByte(0x40); //extcmd
printByte(0x49); //cmd
printByte(0); //x
printByte(0); //y
printByte(128); //width 128
printByte(128); //height 128
printByte(16); //colour mode
//sector address of photo
printByte(0); //0
printByte(16); // 16
printByte(64); //64
delay(2000);
//draw a hat using two rectanagles: function from library
//void OLED_DrawRectangle(char x, char y, char width, char height, char filled, int color)
OLED_DrawRectangle(30, 0, 80, 30, 1, 99999);
OLED_DrawRectangle(10, 30, 120, 10, 1, 99999);
delay(2000);
//Display third image
printByte(0x40); //extcmd
printByte(0x49); //cmd
printByte(0); //x
printByte(0); //y
printByte(128); //width 128
printByte(128); //height 128
printByte(16); //colour mode
//sector address of photo
printByte(0); //0
printByte(16); // 16
printByte(128); //128
delay(2000);
//function from library
//void OLED_DrawLine(char x1, char y1, char x2, char y2, int color)
OLED_DrawLine(5, 5, 100, 5, 63488);
OLED_DrawLine(10, 10, 100, 10, 63488);
OLED_DrawLine(32, 82, 32, 100, 63488);
OLED_DrawLine(101, 70, 101, 100, 63488);
delay(5000);
}// end loop
6. Have fun Take pictures and let me know if you do anthing cool. Also please send any errors that you find on this page to JennyLC at Gmail dot com.
CSS by Mr. Awesome - Vaibhav Bhawsar