Professional Documents
Culture Documents
OLED 242 Notes
OLED 242 Notes
OLED 242 Notes
Table of Contents
1. Introduction
2. Quick Spec
3. Pin Functions
4. Connecting Display to Arduino Uno
5. Download U8GLIB library
6. Display Chipset and Initialization
7. Hello World Example
8. How to use the U8GLIB library
9. Best practices when using U8GLIB library
10. General Restrictions of the U8GLIB library
11. Animations
12. List of all the U8GLIB functions
13. Code Examples
14. Printing a variable
15. OLED display Gauge Meter
16. Mechanical Dimensions
17. Manufacturer Notes
OLED 2.42” Display SSD1309 Chipset
compiled by Micro Robotics www.robotics.org.za
1. Introduction
The 2.42" OLED is a 12864 pixel display that is based on COG
OLED technology. The display use the new SSD1309 display
driver and commucate via SPI (default) or I2C. The display is
also 3.3V an 5V ready.
128 x 64
2. Quick Spec
Type : OLED
Size : 128 x 64 Dots
Chipset : SSD1309
Interface : SPI (default) also I2C
Supply : 3.3 to 5V
3. Pin Functions
ARDUINO UNO
(SS) 10 7-CS
(DC) 9 6-DC
*
(RES) 8 5-RES
(MOSI) 11 4-SDA
(SCK) 13 3-SCL
+ 5V 2-VSS
GND 1-GND
https://github.com/olikraus/u8glib
Click the on Download Arduino Version from Github
u8glib_arduino_v1.18.1.zip
6 . Display Chipset and Initialization
void draw(void) {
u8g.setFont(u8g_font_unifont);
u8g.drawStr( 0,10, "Hello World!");
}
void setup(void) {
}
void loop(void) {
// picture loop
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
63
8 . How to use the U8GLIB library
Once the display is physically connected to an
Arduino Board three steps are required to bring some
graphics on the display:
https://github.com/olikraus/u8glib/wiki/thelloworld
void draw(void) {
// graphic commands to redraw the complete
// screen should be placed here
u8g.setFont(u8g_font_unifont);
u8g.drawStr( 0, 20, "Hello World!");
}
10 . General Restrictions of the U8GLIB library
void draw(void) {
// graphic commands should be placed here
u8g.setFont(u8g_font_unifont);
u8g.drawStr( 0, y_pos, "Hello World!");
y_pos++; // Wrong: Global variable modified
} // inside picture loop / draw()
11 . Animations
If you would like to program an animation which increases
the y-position for each picture, then increase y_pos
outside the picture loop:
void draw(void) {
// graphic commands to redraw screen must be placed here
u8g.setFont(u8g_font_unifont);
u8g.drawStr( 0, 12, "Hello World!");
}
void loop(void) {
// picture loop
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
x
0 127
0,0
0 Hello World
12 = Font Height
y
63
12 . List if U8GLIB Functions
begin setCursorColor
disableCursor setCursorFont
drawBitmap setCursorPos
drawBitmapP setCursorStyle
drawBox, drawCircle setDefaultBackgroundColor
drawDisc, drawEllipse setDefaultForegroundColor
drawFilledEllipse getFontLineSpacing
drawFrame, drawHLine getHeight
drawLine, drawPixel getMode
drawRBox, drawRFrame getWidth
drawStr getStrWidth
drawStr90, drawStr180 InitSPI, InitHWSPI
drawStr270, drawStrP Init8Bit InitComFn
drawStr90P, drawStr180P setDefaultMidColor
drawStr270P, drawTriangle setFont
drawVLine setFontLineSpacingFactor
drawXBM, drawXBMP setFontPosBaseline
define u8g_logo_width 38 setFontPosBottom
define u8g_logo_height 24 setFontPosCenter
enableCursor setFontPosTop
firstPage setFontRefHeightAll
getColorIndex setFontRefHeightExtendedText
getFontAscent setFontRefHeightText
getFontDescent setPrintPos
nextPage setRGB
print setRot90, setRot180,
setColorIndex setRot270, setScale2x2
setContrast sleepOn, sleepOff
undoRotation
undoScale
U8GLIB
13 . U8GLIB Examples
u8g.drawPixel(0,0); u8g.drawPixel(127,0);
u8g.drawPixel(0,63); u8g.drawPixel(127,63);
80
12
80,12 30
20
u8g.drawFrame(80,12,30,20);
80
12
80,12
30
20
14 . Printing a variable
u8g.drawBox(80,12,20,30);
u8g.setPrintPos(54,60);
u8g.print(x);
https://github.com/olikraus/u8glib/wiki/u8glib
User Reference
https://github.com/olikraus/u8glib/wiki/userreference
Available Fonts
https://github.com/olikraus/u8glib/wiki/fontgroup
Font Size
https://github.com/olikraus/u8glib/wiki/fontsize
15. OLED display Gauge Meter
https://steemit.com/utopian-io/@pakganern/
oled-display-gauge-meter-using-potentiometer-arduino
16. Mechanical Dimensions
16. Manufacturer Notes