Turning 0.91" display on command

I made a voltmeter and thermometer using the Atmega 328P - AU but a problem appeared! I want to provide power to the display by using the PB5 pin. However, no image is displayed here is my code:

// 128x32_OLED_Hello_World_u8glib
// based on the Olikraus u8glib library supporting I2C graphic displays
// public domain

#include <U8glib.h>

U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0);

void setup(void)
{
pinMode(5, OUTPUT); //configure PD5 pin as output
//Set font.
u8g.setFont(u8g_font_unifont);
u8g.setColorIndex(1); // display draws with pixel on
}
void loop(void)
{
digitalWrite(5, HIGH); //turn the display on
u8g.firstPage();
do {
draw();
} while (u8g.nextPage());
delay(50);
}
void draw(void)
{
u8g.setFont(u8g_font_helvB14); // font change – helvB14
u8g.drawStr(20, 13, "Hello");
u8g.setFont(u8g_font_unifont); // font change – standard
u8g.drawStr(20, 28, "World");

u8g.drawCircle (110, 15, 15); // contour
u8g.drawCircle (105, 14, 4); // left eye
u8g.drawCircle (115, 14, 4); // right eye

u8g.drawPixel (103,22); // mouth
u8g.drawPixel (118,22); // mouth
u8g.drawPixel (104,23); // mouth
u8g.drawPixel (117,23); // mouth
u8g.drawPixel (105,24); // mouth
u8g.drawPixel (116,24); // mouth
u8g.drawLine (106, 25, 115,25); // mouth
}

Can someone spot my mistake because it compiles just perfectly but there is no display output :slight_smile:?

PB5 != 5 according to this

be sure your oled display is 5v tollerant
(most newer one's are, but some older ones use 3v3)

1 Like

I tried changing the pin number and reuploading the sketch but nothing changed :frowning:

put a LED with resistor on that pin and make sure it lights up

1 Like

Hi net_worker,

You appear to be missing a couple of items for the display -

1. The display "begin" command in the Setup

 u8g2.begin();

You will need to issue this "begin" command after applying power to the display.

2. The Wire library for the I2C

#include <Wire.h>  

HTH?

Thank you very much ! The problem is solved :grin:!

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.