Example Code for Arduino-Display Text and Graphics
This article guides users through the process of displaying text and graphics on a 0.5 Inch OLED Display using Arduino, including hardware and software setup, wiring instructions, and sample code.
Hardware Preparation
- arduino UNO x1
- 0.5 Inch Oled pcb x1
- 0.5 Inch Oled Display x1
- some Dupont Cable
Software Preparation
- Arduino IDE V1.6.5 Click to Download Arduino IDE
Wiring Diagram
This step, it will requires you to solder the Pins on the PCB holes, please be careful with when you solder the pins.
Connect the module to DFRduino according to the following connection diagram.
Do not mix 3.3V and GND.
Finally, Connect your USB cable to your PC. OK, all the hardware step we need has been done.
Other Preparation Work
First we need Assembly the OLED PCB and display, Be careful in this process, the display connector is thin and fine.
- 0pen the Oled PCB connector
- Make the display cable into the connector, take care not to invert !!
Please be sure to use the tweezers or pen inserted into the the small hole on the top of the liquid crystal! Don't use hand! Don't use hand\! Don't use hand\! Important things need to be repeated for 3 times\! the test by hand in hand, We've broken three pieces direct use hand push when we started test it. This is the lesson of blood.
Please Gently! Gently! Gently! Push the LCD screen when start, the two iron with floor can just keep a screen cable inserted in the gap. Insert it from this gap, when encounter resistance, Don't force! Don't force! Don't force!At this time use tweezers or other sharp objects into the small hole,use a little force and keep this force until you feel that you have push it on the top, when you feel like it is not moving. Don't force! Don't force! Don't force! Then the last thing you need to do is to pull out the tweezer or other objects.
- Buckle the OLED PCB Board connector.
OK, The two things had connected together. Congratulations! You have completed the first step.
Sample Code
Since your hardware connection has been finished, the next step will be the code uploading.
First you need to download the library, and move these files to ARDUINO libraries folder, which is in the Arduino installation directory.
Click here to download U8glib library
Do you know how to install an Arduino library? You can refer to this tutorial:
How to install an Arduino library
And then we need to open the ARDUINO IDE, copy the following code and put it in the IDE windows. Select the right serial port and board type (Arduino UNO) in the menu, click "download" button.
#include "U8glib.h"
U8GLIB_LD7032_60x32 u8g(9, 8, 11, 10, 12);
void setup(void) {
}
const uint8_t rook_bitmap[] PROGMEM = {
0x00, // 00000000
0x55, // 01010101
0x7f, // 01111111
0x3e, // 00111110
0x3e, // 00111110
0x3e, // 00111110
0x3e, // 00111110
0x7f // 01111111
};
void loop(void) {
// picture loop
u8g.firstPage();
do {
u8g.setFont(u8g_font_unifont);
// u8g.setFont(u8g_font_osb21);
u8g.drawStr( 5, 20, "DFROBOT");
} while ( u8g.nextPage() );
delay(1000);
u8g.firstPage();
do {
u8g.drawCircle(30, 20, 18);
u8g.drawEllipse(26, 12, 7, 5,U8G_DRAW_UPPER_LEFT );
u8g.drawEllipse(34, 12, 7, 5, U8G_DRAW_UPPER_RIGHT);
u8g.drawTriangle(30,14, 27, 18, 33, 18);
u8g.drawFilledEllipse( 30, 25, 10,5, U8G_DRAW_LOWER_LEFT);
u8g.drawFilledEllipse( 30, 25, 10,5, U8G_DRAW_LOWER_RIGHT);
u8g.drawLine(30, 13, 30, 16);
u8g.drawFrame(0, 0,60 ,32);
} while ( u8g.nextPage() );
delay(5000);
u8g.firstPage();
do {
u8g.drawBitmapP(30, 16,1, 8, rook_bitmap);
} while ( u8g.nextPage() );
delay(1000);
u8g.firstPage();
do {
} while ( u8g.nextPage() );
delay(2000);
}
Result
Display DFROBOT on the screen.
Was this article helpful?
