Go Down

Topic: Questions on ssd1306 i2c screens. (Read 1 time) previous topic - next topic

CatDadJynx

#15
May 22, 2018, 07:53 pm Last Edit: May 22, 2018, 07:55 pm by CatDadJynx
This is true for AVR architectures only:
u8g2.drawXBM() --> The bitmap must be in SRAM area, the declaration does not require the U8X8_PROGMEM attribute.
u8g2.drawXBMP() --> The bitmap must be in Flash ROM area, the declaration requires the U8X8_PROGMEM attribute.

Oliver

Ahh, okay, the reference manual said

Quote
Note: The XBMP version requires, that the bitmap array is defined in this way:
Code: [Select]
static const unsigned char u8g_logo_bits[] U8X8_PROGMEM = { ...


And then, comparably, the tutorial just said to change

Code: [Select]
static unsigned char bitmap_bits[]


to

Code: [Select]
static const unsigned char bitmap_bits[] PROGMEM


But Id just forgotten to ask for more information on that as well, so thank you for clarifying! Now I see what you mean. Ive also made a few additional changes i saw later on in the tutorial, which answered my question about setup and loop as well. My updated code looks like this (but I have not yet replaced the delay with mills, or put the bitmap in a separate tab as im still not sure which parts to use to do so (or is it just the things before setup?) Anyway, my updated code is here:

Code: [Select]
#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
const long screenInterval = 1000;           // interval at which to buffer (milliseconds)
unsigned long sensorInterval;
unsigned long previousMillis;

// Copy the contents of your .xbm file below
#define eyesstraight_width 65
#define eyesstraight_height 64
static unsigned char eyesstraight_bits[] PROGMEM = {
   0x6f, 0xff, 0x00, 0x00, 0x00, 0x00, 0xb6, 0x7f, 0x01, 0x5f, 0xff, 0x00,
   0x00, 0x00, 0x00, 0xae, 0x7f, 0x01, 0xb7, 0x7f, 0x00, 0x00, 0x00, 0x00,
   0xb6, 0xff, 0x00, 0xaf, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x6e, 0xbf, 0x01,
   0xb7, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xaa, 0x7f, 0x01, 0xfe, 0xed, 0x00,
   0x00, 0x00, 0x00, 0xfe, 0xed, 0x01, 0xfd, 0xdb, 0x00, 0x00, 0x00, 0x00,
   0xfe, 0xdb, 0x01, 0xfb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0xea, 0x01,
   0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd6, 0x01, 0xfd, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0xfa, 0x01, 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0xea, 0x01, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x01,
   0xaf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x01, 0xaf, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x7e, 0x01, 0xdf, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x7e, 0x01, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xae, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x6f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0xde, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x57, 0xbf, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0xff, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0xd7, 0x7f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0xfc, 0xdb, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xea, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xdb, 0x01, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0xfe, 0xed, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0xfc, 0xdb, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb, 0xd5, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x57, 0xff, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0xdf, 0x7f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x57, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xde, 0x7f, 0x01,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5f, 0xff, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x4b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x01, 0xdf, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x7e, 0x01, 0xb7, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0xfe, 0x00, 0xaf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbe, 0x01,
   0xb7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x01, 0xfe, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0xea, 0x01, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0xd6, 0x01, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfa, 0x01,
   0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0xd6, 0x01, 0xfd, 0xff, 0x00,
   0x00, 0x00, 0x00, 0xfe, 0xf5, 0x01, 0xfb, 0xeb, 0x00, 0x00, 0x00, 0x00,
   0xfe, 0xeb, 0x01, 0x6f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x76, 0x7f, 0x01,
   0xdf, 0x7e, 0x00, 0x00, 0x00, 0x00, 0xae, 0xbf, 0x01, 0xaf, 0xff, 0x00,
   0x00, 0x00, 0x00, 0xaa, 0x7f, 0x01, 0xb7, 0x7e, 0x00, 0x00, 0x00, 0x00,
   0xde, 0x7f, 0x01, 0xaf, 0xff, 0x00, 0x00, 0x00, 0x00, 0x56, 0x7f, 0x01 };


void draw(void) {
// graphic commands to redraw the complete screen should be placed here
u8g2.drawXBM( 0, 0, eyesstraight_width, eyesstraight_height, eyesstraight_bits);
}

void setup(void) {
 u8g2.begin();
}

void loop(void) {
 // picture loop
 u8g2.firstPage();
 do {
     draw();
    } while( u8g2.nextPage() );

 // rebuild the picture after some delay
 delay(1000);
}

olikraus


CatDadJynx

sooo... does it work?
Oliver
Sorry, I wasnt sure if I was on the right track or not so didnt test it. But I just did, and unfortunately it doesnt work yet. It compiles and uploads just fine, but the display is simply blank (no pixels are lit at all).

olikraus

At least the code looks correct...

Oliver

CatDadJynx

Hmm... I'm thinking because the bitmap is different than the screen size maybe I'm drawing it in the wrong location and it isn't displaying? Might just mess with it and see if I can't get it working somehow then, I suppose

david_prentice

You must have started with a JPG or PNG of your eyeball.
It is simply your use of a PC program to create the bitmap as a C array.

There are several  formats for the array e.g. XBM or regular BMP.
Then you use the appropriate method to display it.

Post a link to the original artwork or just insert the image to your message.

From memory,   the tutorial shows you how to create the C  array.

David.

CatDadJynx

You must have started with a JPG or PNG of your eyeball.
It is simply your use of a PC program to create the bitmap as a C array.

There are several  formats for the array e.g. XBM or regular BMP.
Then you use the appropriate method to display it.

Post a link to the original artwork or just insert the image to your message.

From memory,   the tutorial shows you how to create the C  array.

David.
Hmm... I did what you'd described above (started with a JPEG/PNG and used GIMP to convert the file to an XBM), then I inserted the C data array as described in the tutorial reference manual. Where I think I may have messed up is actually the syntax in my use of PROGMEM, as I opened up another project Im working on (a diy arduboy) and the answer was looking me right in the face, provided the syntax used in that library is typical of others. I dont mean to overly complicate things, but seems I had that line of code wrong, so im gonna try to change that around before uploading the original images and trying again. Will update here shortly.

CatDadJynx

#22
May 26, 2018, 01:47 am Last Edit: May 26, 2018, 02:00 am by CatDadJynx
Okay, on the plus side it seems that was part of the problem, and now it *does* display some pixels, but on the downside the pixels are just noise. Here is the line I changed:

Code: [Select]
static const unsigned char eyesstraight_bits[] PROGMEM = {


to

Code: [Select]
PROGMEM static const unsigned char eyesstraight_bits[] = {


But now, I would wager youre right on the C data array being incorrect (as would explain the noise), so here is the first file Im trying.

Edit: it seems I was mistaken... I saw in the reference manual it said "static const unsigned char u8g_logo_bits[] U8X8_PROGMEM = { ..."

And when I tried to modify the code accordingly, I noticed it took up more memory (leading me to believe it was putting it in flash) so I removed that line, leaving progmem in the same place, and it seems now it'll still display pixels regardless where that is. So I'm unsure, here is the source image.

david_prentice

@CatDadJynx,

Your display is doing exactly what you asked it to.   i.e. show a very low resolution mono image.

The GIMP software makes an attempt to re-create the grey as black and white dots.    It also had to do some rescaling.
The net result is pretty horrible.   Just look at it before creating the C array.

The u8g2 library can display XBM from Flash or SRAM but it can only do ordinary bitmaps from SRAM.
Adafruit_GFX style libraries can display ordinary bitmaps from SRAM or Flash.

You can choose whatever format you like e.g. XBM or regular
But it is only practical to store in Flash because SRAM is limited on a Uno.

Create your mono image in 128x64 resolution or whatever.    View it on your PC before sending it to your Arduino sketch.

David.

CatDadJynx

@CatDadJynx,

Your display is doing exactly what you asked it to.   i.e. show a very low resolution mono image.

The GIMP software makes an attempt to re-create the grey as black and white dots.    It also had to do some rescaling.
The net result is pretty horrible.   Just look at it before creating the C array.

The u8g2 library can display XBM from Flash or SRAM but it can only do ordinary bitmaps from SRAM.
Adafruit_GFX style libraries can display ordinary bitmaps from SRAM or Flash.

You can choose whatever format you like e.g. XBM or regular
But it is only practical to store in Flash because SRAM is limited on a Uno.

Create your mono image in 128x64 resolution or whatever.    View it on your PC before sending it to your Arduino sketch.

David.
Oh alright, now I see what you mean, seems I'd had my wires crossed, thanks! And yeah, that makes sense, I was just confused as the tutorial specified to lock the resolution in gimp (what Im also using) which wouldn't let me do it at the screens actual resolution (128x64) just the aspect ratio (which I used 64). Will go ahead and fix this and update, thanks!

CatDadJynx

#25
May 28, 2018, 02:20 am Last Edit: May 28, 2018, 02:22 am by CatDadJynx
Hmm, I've tried again from the beginning and opened the original PNG in gimp, changed the color index, trimmed out all the background, scaled the image to keep the aspect of the bitmap (64x64) but using the resolution of the screen (128x64), then exported as an xbm file, taken the bit array it gave me, put that back into my code, changed the bitmap to progmem, compiled and uploaded but still just noise. The size and location of the overall bits is correct, just not sure where it's going wrong or what else I'm missing here.

CatDadJynx


olikraus

as usual... difficult to say without your latest version of the code.

Oliver

CatDadJynx

Of course, sorry. Thanks!

Code: [Select]
#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
const long screenInterval = 1000;           // interval at which to buffer (milliseconds)
unsigned long sensorInterval;
unsigned long previousMillis;

// Copy the contents of your .xbm file below
#define eyesstraight_width 65
#define eyesstraight_height 64
PROGMEM const static unsigned char eyesstraight_bits[] = {
   0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0xff,
   0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
   0x01, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00,
   0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0xff,
   0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
   0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
   0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
   0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01,
   0xff, 0xff, 0xff, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff,
   0x00, 0x00, 0xfe, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0x00, 0x00, 0xfe,
   0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x01,
   0xff, 0xff, 0xff, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff,
   0x00, 0x00, 0xfe, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0x00, 0x00, 0xfe,
   0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x01,
   0xff, 0xff, 0xff, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff,
   0x00, 0x00, 0xfe, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0x00, 0x00, 0xfe,
   0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x01,
   0xff, 0xff, 0xff, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff,
   0x00, 0x00, 0xfe, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0x00, 0x00, 0xfe,
   0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x01,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01,
   0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
   0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
   0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0xff,
   0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
   0x01, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00,
   0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0xff,
   0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
   0x01, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00 };


void draw(void) {
// graphic commands to redraw the complete screen should be placed here
u8g2.drawXBM( 30 , 0, eyesstraight_width, eyesstraight_height, eyesstraight_bits);
}

void setup(void) {
 u8g2.begin();
}

void loop(void) {
 // picture loop
 u8g2.firstPage();
 do {
     draw();
    } while( u8g2.nextPage() );

 // rebuild the picture after some delay
 delay(1000);
}

david_prentice

#29
Jun 03, 2018, 12:43 am Last Edit: Jun 03, 2018, 12:44 am by david_prentice
Your XBM is stored in PROGMEM  So you should use:
Code: [Select]


void draw(void) {
// graphic commands to redraw the complete screen should be placed here
u8g2.drawXBMP( 30 , 0, eyesstraight_width, eyesstraight_height, eyesstraight_bits);
}


Well,  I suppose that your graphic is a bit easier to see.   But it is still very blocky.

Why don't you create round eyes?    Even TV eyes would have curved edges.

David.

Go Up