Learning to use OLED displays

Examples, screenshots, graphics, fonts...
MaxZ
Posts: 330
Joined: 31 Jan 2019, 11:48
Location: Boskoop, Netherlands

Learning to use OLED displays

Post by MaxZ »

Hi all,

I want to learn about using OLED displays. But rather than cluttering another topic with my questions, I have started my own topic.
I am using the sketch that Phil wrote for his servo pwm meter viewtopic.php?f=41&t=776&start=10 as a starting point.

Referring to the sketch, I have some questions:

- I acquired a SSD1306 128x64 display, does it suffice to replace

Code: Select all

U8GLIB_SSD1306_128X32
with

Code: Select all

U8GLIB_SSD1306_128X64
?

- the sprintf() function is new to me, so I searched for some info on its use, which I eventually found here: https://arduinobasics.blogspot.com/2019 ... ction.html. It strikes me that the %d format is specified for a signed integer, yet in the sketch it is used for the unsigned long integer pwidth. There does not seem to be a format for that type?

Cheers,
Max.
User avatar
RON
Site Admin
Posts: 613
Joined: 12 Jun 2017, 15:09
Location: Stokesley North Yorkshire

Re: Learning to use OLED displays

Post by RON »

Hi Max

The 128 x 64 will replace the 128 x 32 but it won't fill all the screen, like this...
Screenshot 2019-09-02 at 17.35.44.jpg
Thats what I used when I first made Phil's mini tester. I did alter the code slightly so that it all fit in and even added a battery monitor, a bit like this...

The blue/yellow oleds are quite nice, easily available from the Bay
fullsizeoutput_5d4.jpeg


Ron
G0MBV Class A Radio Amateur, North Yorkshire
User avatar
Phil_G
Posts: 597
Joined: 15 Feb 2018, 23:32
Contact:

Re: Learning to use OLED displays

Post by Phil_G »

from memory I think I use use

#include "U8glib.h"

then either
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0); // for 0.96" 128x64 display

or

U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0); // for 1.3" 128x64 display


... so yes it looks like your assumption is correct Max Image

For example:

Code: Select all


#include "U8glib.h"

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0); // for 0.96" 128x64 display

void draw(void) {
  u8g.setFont(u8g_font_unifont);
  u8g.drawStr( 0, 22, "Hello World!");
}

void setup(void) {
}

void loop(void) {
  // picture loop
  u8g.firstPage();  
  do {
    draw();
  } while( u8g.nextPage() );
  
  // keep on redrawing the screen after a delay
  delay(50);
}

I've said it before, I find the most time-consuming part of these displays is choosing a suitable font....

Cheers
Phil
MaxZ
Posts: 330
Joined: 31 Jan 2019, 11:48
Location: Boskoop, Netherlands

Re: Learning to use OLED displays

Post by MaxZ »

Thanks Phil. Any comments on the sprintf() thing?

Btw, you included the "Graphene" program in another thread, to create images on the Oled. Unfortunately it is Windows-only software, which my Mac will not swallow. In the search for an alternative I found this http://javl.github.io/image2cpp/. It can be saved as a web archive for offline use, and it should work on both platforms. It will even scale the imported picture to the required size. I have not tried it in a sketch to see how it looks on screen (because I still have to set it up :roll: ), but I thought I'd share it here.

Here is an example of the classic Fokker logo, which took only a minute to create from a much larger size picture:

Code: Select all

// 'Logo_Fokker', 128x64px
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0x80, 0x1f, 0xff, 0xff, 0xff, 0xfe, 0x43, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xfc, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xfe, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xe0, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xfe, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xc0, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xfe, 0x73, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0x80, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x73, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0x00, 0x00, 0x00, 0x03, 0xfe, 0x0f, 0xfe, 0x73, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xfe, 0x07, 0xff, 0x80, 0x1f, 0xfe, 0x07, 0xfe, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xfc, 0x1f, 0xff, 0xff, 0xff, 0xfe, 0x07, 0xfe, 0x33, 0xff, 0xf3, 0x9f, 0xff, 0xff, 0xff, 0xff
0xfc, 0x7f, 0xff, 0xff, 0xff, 0xfc, 0x47, 0xfe, 0x33, 0xff, 0xe1, 0x8e, 0x7f, 0xff, 0xff, 0xff
0xf8, 0x7f, 0xff, 0xff, 0xff, 0xfc, 0x63, 0xfe, 0x13, 0xff, 0xc1, 0x80, 0x7f, 0xff, 0xff, 0xff
0xf8, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x63, 0xff, 0x13, 0x87, 0xd1, 0xc0, 0x7f, 0xef, 0xff, 0xff
0xf1, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x63, 0xff, 0x03, 0x87, 0x99, 0xe0, 0x7f, 0xcf, 0xff, 0xff
0xf1, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x73, 0xff, 0x03, 0x07, 0x99, 0xe4, 0x7f, 0x8f, 0xff, 0xff
0xf3, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x73, 0xff, 0x07, 0x47, 0x99, 0xe4, 0x3f, 0x1f, 0xff, 0xff
0xf3, 0xff, 0xff, 0x3f, 0xff, 0xfc, 0x33, 0xff, 0x86, 0xc7, 0x99, 0xe4, 0x1c, 0x3f, 0xff, 0xff
0xf3, 0xff, 0xff, 0x1f, 0xff, 0xfc, 0x33, 0xff, 0x86, 0xc7, 0x99, 0xe4, 0x00, 0x3f, 0xff, 0xff
0xf3, 0xff, 0xfe, 0x1f, 0xff, 0xfe, 0x13, 0xcf, 0x82, 0xcf, 0x8b, 0xcc, 0x00, 0x7f, 0xff, 0xff
0xf3, 0xff, 0xfe, 0x1f, 0xff, 0xfe, 0x13, 0x87, 0xc2, 0xcf, 0x83, 0xce, 0x00, 0xff, 0xff, 0xff
0xf3, 0xff, 0xfe, 0x1f, 0xff, 0xfe, 0x03, 0x87, 0xc0, 0xdf, 0x83, 0x8e, 0x03, 0xff, 0xff, 0xff
0xf3, 0xff, 0xfe, 0x1f, 0xff, 0xff, 0x07, 0x07, 0xc0, 0x9f, 0x83, 0x0f, 0x8f, 0xff, 0xff, 0xff
0xf1, 0xff, 0xfe, 0x0f, 0xff, 0xff, 0x06, 0x47, 0xe0, 0xbf, 0xc0, 0x0f, 0xff, 0xff, 0xff, 0xff
0xf1, 0xff, 0xfe, 0x0f, 0xff, 0xff, 0x06, 0xc7, 0xe0, 0x7f, 0xc0, 0x1f, 0xff, 0xfc, 0xff, 0xff
0xf9, 0xff, 0xfe, 0x0f, 0xff, 0xff, 0x86, 0xcf, 0xc0, 0x07, 0xc0, 0x1f, 0xff, 0xf0, 0x7f, 0xff
0xf8, 0xff, 0xfe, 0x0f, 0xff, 0xff, 0x86, 0xcf, 0xc0, 0x03, 0x80, 0x3f, 0xff, 0xe0, 0x7f, 0xff
0xf8, 0xff, 0xfe, 0x0f, 0xff, 0x9f, 0x84, 0x9f, 0xc0, 0x40, 0x18, 0xff, 0xff, 0x00, 0x7f, 0xff
0xfc, 0x7f, 0xfe, 0x07, 0xfd, 0x07, 0xc0, 0x9f, 0x90, 0xc0, 0x3f, 0xff, 0xf8, 0x00, 0x7f, 0xff
0xfe, 0x7f, 0xff, 0x07, 0xf9, 0x07, 0x80, 0xbf, 0x90, 0xe0, 0x3f, 0xff, 0xc0, 0x00, 0x7f, 0xff
0xfe, 0x3f, 0xff, 0x07, 0xe1, 0x03, 0x80, 0x3f, 0x98, 0xe0, 0x7f, 0xfe, 0x00, 0x00, 0xff, 0xff
0xff, 0x1f, 0xff, 0x07, 0xc1, 0x83, 0x20, 0x07, 0x38, 0xf1, 0xff, 0xf8, 0x00, 0x01, 0xff, 0xff
0xff, 0x8f, 0xff, 0x03, 0x09, 0x80, 0x60, 0x03, 0x38, 0xff, 0xff, 0x80, 0x00, 0x07, 0xff, 0xff
0xff, 0xc7, 0xff, 0x80, 0x19, 0xc0, 0xe0, 0x00, 0x38, 0xff, 0xfe, 0x00, 0x00, 0x1f, 0xff, 0xff
0xff, 0xe3, 0xff, 0x80, 0x79, 0xe0, 0xe0, 0xc0, 0x7d, 0xff, 0xf0, 0x00, 0x01, 0xff, 0xff, 0xff
0xff, 0xf1, 0xfe, 0x00, 0xf9, 0xfc, 0xf0, 0xc0, 0x7f, 0xff, 0xc0, 0x00, 0x0f, 0xff, 0xff, 0xff
0xff, 0xf8, 0x7c, 0x01, 0xf8, 0xfc, 0xf1, 0xe0, 0xff, 0xfe, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff
0xff, 0xfe, 0x3c, 0x01, 0xf8, 0xfc, 0xf1, 0xe1, 0xff, 0xf8, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0x0e, 0x01, 0xfc, 0xfc, 0xf1, 0xff, 0xff, 0xc0, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xc3, 0xc0, 0xfc, 0x7c, 0xf9, 0xff, 0xff, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xf0, 0xc0, 0xfc, 0x3c, 0xf9, 0xff, 0xfc, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xf8, 0x60, 0xfc, 0x18, 0xf9, 0xff, 0xf0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xfe, 0x00, 0xfe, 0x00, 0xf9, 0xff, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0x80, 0xfe, 0x00, 0xff, 0xff, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xe0, 0x7f, 0x00, 0xff, 0xfc, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xf0, 0x7f, 0x00, 0xff, 0xf0, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xf0, 0x7f, 0x81, 0xff, 0xc0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xf8, 0x3f, 0xe7, 0xff, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xf8, 0x1f, 0xff, 0xfc, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xf8, 0x0f, 0xff, 0xf0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xfc, 0x4f, 0xff, 0xe0, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xfc, 0x27, 0xff, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xfc, 0x27, 0xfe, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xfe, 0x37, 0xfc, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xfe, 0x33, 0xf0, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xff, 0x13, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xff, 0x93, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xff, 0xc3, 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xff, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
Cheers,
Max.
MaxZ
Posts: 330
Joined: 31 Jan 2019, 11:48
Location: Boskoop, Netherlands

Re: Learning to use OLED displays

Post by MaxZ »

It worked for me, but only after I discovered that all the commas at the end of each line were missing :o :)
DSC03914.JPG
Cheers,
Max.
MaxZ
Posts: 330
Joined: 31 Jan 2019, 11:48
Location: Boskoop, Netherlands

Re: Learning to use OLED displays

Post by MaxZ »

And I found out why, I forgot to pick one of the Arduino formats of the output. I am using U8glib.
MaxZ
Posts: 330
Joined: 31 Jan 2019, 11:48
Location: Boskoop, Netherlands

Re: Learning to use OLED displays

Post by MaxZ »

:D
This is the code I have used, mostly grabbed from Phil's fuse resetter. I only replaced the bitmap info with the one that was generated by this resource.

Code: Select all

#include <U8glib.h>
#define logo_width 16  // (in bytes)
#define logo_height 64 // in bits :-)
static unsigned char Fokker_logo[]  = 
{
// 'Logo_Fokker', 128x64px
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x87, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0x80, 0x0f, 0xff, 0xff, 0xff, 0xfe, 0x43, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xf8, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xfe, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xe0, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xfe, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xc0, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xfe, 0x73, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0x80, 0x00, 0x00, 0x00, 0x7f, 0x1f, 0xfe, 0x73, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0x00, 0x00, 0x00, 0x01, 0xfe, 0x0f, 0xfe, 0x73, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xfe, 0x07, 0xff, 0x80, 0x1f, 0xfe, 0x07, 0xfe, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xfc, 0x1f, 0xff, 0xff, 0xff, 0xfe, 0x07, 0xfe, 0x33, 0xff, 0xe3, 0x9f, 0xff, 0xff, 0xff, 0xff, 
  0xfc, 0x3f, 0xff, 0xff, 0xff, 0xfc, 0x47, 0xfe, 0x33, 0xff, 0xe1, 0x8e, 0x7f, 0xff, 0xff, 0xff, 
  0xf8, 0x7f, 0xff, 0xff, 0xff, 0xfc, 0x63, 0xfe, 0x13, 0xff, 0xc1, 0x80, 0x7f, 0xff, 0xff, 0xff, 
  0xf8, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x63, 0xfe, 0x13, 0x87, 0xd1, 0xc0, 0x7f, 0xef, 0xff, 0xff, 
  0xf1, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x63, 0xff, 0x03, 0x87, 0x99, 0xc0, 0x7f, 0xcf, 0xff, 0xff, 
  0xf1, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x73, 0xff, 0x03, 0x07, 0x99, 0xe4, 0x7f, 0x8f, 0xff, 0xff, 
  0xf1, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x73, 0xff, 0x03, 0x47, 0x99, 0xe4, 0x3f, 0x1f, 0xff, 0xff, 
  0xf3, 0xff, 0xff, 0x3f, 0xff, 0xfc, 0x33, 0xff, 0x86, 0xc7, 0x99, 0xe4, 0x1c, 0x3f, 0xff, 0xff, 
  0xf3, 0xff, 0xfe, 0x1f, 0xff, 0xfc, 0x33, 0xff, 0x86, 0xc7, 0x99, 0xe4, 0x00, 0x3f, 0xff, 0xff, 
  0xf3, 0xff, 0xfe, 0x1f, 0xff, 0xfe, 0x13, 0xcf, 0x82, 0xcf, 0x8b, 0xcc, 0x00, 0x7f, 0xff, 0xff, 
  0xf3, 0xff, 0xfe, 0x1f, 0xff, 0xfe, 0x13, 0x87, 0xc2, 0xcf, 0x83, 0xce, 0x00, 0xff, 0xff, 0xff, 
  0xf3, 0xff, 0xfe, 0x1f, 0xff, 0xfe, 0x03, 0x87, 0xc0, 0x9f, 0x83, 0x8e, 0x03, 0xff, 0xff, 0xff, 
  0xf3, 0xff, 0xfe, 0x1f, 0xff, 0xff, 0x03, 0x07, 0xc0, 0x9f, 0x83, 0x0f, 0x8f, 0xff, 0xff, 0xff, 
  0xf1, 0xff, 0xfe, 0x0f, 0xff, 0xff, 0x06, 0x47, 0xe0, 0xbf, 0xc0, 0x0f, 0xff, 0xff, 0xff, 0xff, 
  0xf1, 0xff, 0xfe, 0x0f, 0xff, 0xff, 0x06, 0xc7, 0xe0, 0x3f, 0xc0, 0x1f, 0xff, 0xfc, 0xff, 0xff, 
  0xf9, 0xff, 0xfe, 0x0f, 0xff, 0xff, 0x86, 0xcf, 0xc0, 0x07, 0xc0, 0x1f, 0xff, 0xf0, 0x7f, 0xff, 
  0xf8, 0xff, 0xfe, 0x0f, 0xff, 0xff, 0x86, 0xcf, 0xc0, 0x03, 0x80, 0x3f, 0xff, 0xc0, 0x7f, 0xff, 
  0xf8, 0xff, 0xfe, 0x0f, 0xff, 0x0f, 0x84, 0x9f, 0xc0, 0x00, 0x18, 0xff, 0xff, 0x00, 0x7f, 0xff, 
  0xfc, 0x7f, 0xfe, 0x07, 0xfd, 0x07, 0xc0, 0x9f, 0x90, 0xc0, 0x3f, 0xff, 0xf8, 0x00, 0x7f, 0xff, 
  0xfe, 0x7f, 0xff, 0x07, 0xf1, 0x07, 0x80, 0xbf, 0x90, 0xe0, 0x3f, 0xff, 0xc0, 0x00, 0x7f, 0xff, 
  0xfe, 0x3f, 0xff, 0x07, 0xe1, 0x03, 0x80, 0x3f, 0x98, 0xe0, 0x7f, 0xfe, 0x00, 0x00, 0xff, 0xff, 
  0xff, 0x1f, 0xff, 0x07, 0xc1, 0x03, 0x20, 0x07, 0x18, 0xf1, 0xff, 0xf0, 0x00, 0x01, 0xff, 0xff, 
  0xff, 0x8f, 0xff, 0x03, 0x09, 0x80, 0x60, 0x03, 0x38, 0xff, 0xff, 0x80, 0x00, 0x07, 0xff, 0xff, 
  0xff, 0xc7, 0xff, 0x80, 0x19, 0xc0, 0xe0, 0x00, 0x38, 0xff, 0xfe, 0x00, 0x00, 0x1f, 0xff, 0xff, 
  0xff, 0xe3, 0xff, 0x80, 0x39, 0xe0, 0xe0, 0xc0, 0x7d, 0xff, 0xf0, 0x00, 0x01, 0xff, 0xff, 0xff, 
  0xff, 0xf1, 0xfe, 0x00, 0xf9, 0xfc, 0xf0, 0xc0, 0x7f, 0xff, 0x80, 0x00, 0x0f, 0xff, 0xff, 0xff, 
  0xff, 0xf8, 0x7c, 0x01, 0xf8, 0xfc, 0xf1, 0xe0, 0xff, 0xfe, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 
  0xff, 0xfe, 0x3c, 0x01, 0xf8, 0xfc, 0xf1, 0xe1, 0xff, 0xf0, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0x0e, 0x01, 0xf8, 0xfc, 0xf1, 0xff, 0xff, 0xc0, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xc3, 0xc0, 0xfc, 0x7c, 0xf1, 0xff, 0xff, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xf0, 0xc0, 0xfc, 0x3c, 0x79, 0xff, 0xfc, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xf8, 0x20, 0xfc, 0x18, 0x79, 0xff, 0xf0, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xfe, 0x00, 0xfe, 0x00, 0xf9, 0xff, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0x80, 0xfe, 0x00, 0xff, 0xff, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xe0, 0x7f, 0x00, 0xff, 0xfc, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xf0, 0x7f, 0x00, 0xff, 0xf0, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xf0, 0x7f, 0x81, 0xff, 0xc0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xf8, 0x3f, 0xe3, 0xff, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xf8, 0x1f, 0xff, 0xfc, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xf8, 0x0f, 0xff, 0xf0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xfc, 0x0f, 0xff, 0xc0, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xfc, 0x27, 0xff, 0x80, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xfc, 0x27, 0xfe, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xfe, 0x37, 0xf8, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xfe, 0x33, 0xf0, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0x13, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0x93, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xc3, 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0);



void setup() {
  // Display something to prove that the OLED is working
  u8g.firstPage();
  do {
  u8g.setColorIndex(1);
  u8g.drawBitmap( 0, 0, logo_width, logo_height, Fokker_logo);  
  } while ( u8g.nextPage() );
}

void loop() {
  // put your main code here, to run repeatedly:

}
Thing were getting messed up when I copied the whole arduino code as generated, including

Code: Select all

const unsigned char Fokker_logo [] PROGMEM = {
User avatar
Phil_G
Posts: 597
Joined: 15 Feb 2018, 23:32
Contact:

Re: Learning to use OLED displays

Post by Phil_G »

This is a great tool, since its bi-directional you can also use it to inverse any existing graphics:

IMG_20190904_163953_519.JPG

Also since all of the code is scripted within the html page, you can 'save' the page as a local app.
This is the best find for a good while Max!

I tried your method with one of my graphics and its perfect Max.
These were my settings:

oled_conversion_settings.jpg

Re the sprintf() thing, I think what they mean is that the %d formatter will correctly handle a '-' so it suits signed or unsigned variables. Sprintf() is a very handy function for pre-formatting & modifying strings prior to display. You have to be sure that space is allocated to 'sprintf into' though, it will happily overwrite anything!
MaxZ
Posts: 330
Joined: 31 Jan 2019, 11:48
Location: Boskoop, Netherlands

Re: Learning to use OLED displays

Post by MaxZ »

Phil_G wrote: 04 Sep 2019, 16:44 Sprintf() is a very handy function for for pre-formatting & modifying strings prior to display. You have to be sure that space is allocated to 'sprintf into' though, it will happily overwrite anything!
Yeah I have been experimenting with that also for a bit. First thing I noticed that you should not size the character array too tight, it will compile without throwing any error messages but it will simply not show anything on the screen. The other thing I found out is that the U8glib does not recognize the String() variable, you have to use the char* type instead (which incidentally is not included in the arduino reference page).

Glad I shared my find.

Cheers,
Max.
MaxZ
Posts: 330
Joined: 31 Jan 2019, 11:48
Location: Boskoop, Netherlands

Re: Learning to use OLED displays

Post by MaxZ »

Right, time to turn the knowledge on oled programming into something useful. I copied Phil's servo pwm meter, and I am now adding to the code to include a voltage reading, similar to Ron's.

I am struggling to present a float value, the volts reading, onto the oled. Here are some snippets of my code:
Schermafbeelding 2019-09-15 om 11.37.56.png
Schermafbeelding 2019-09-15 om 11.37.56.png (16.41 KiB) Viewed 6665 times
Schermafbeelding 2019-09-15 om 11.36.48.png
Schermafbeelding 2019-09-15 om 11.36.48.png (18.28 KiB) Viewed 6665 times
Uploading is fine, no error messages. But all I am getting as a representation of the volts value is a question mark, same result in the serial monitor. The problem seems to be the float value formatting to characters, when I change the type to int and use %d all is well.

What am I doing wrong?

(I know I have to change "volts" to an integer once I actually read the analog input at Vin, but it still will be a float after multiplying with the calibration factor, right?)

Cheers,
Max.
Post Reply