Go Down

Topic: U8glib: Graphics Lib for LCDs and OLEDs (Read 224968 times) previous topic - next topic

olikraus

Hi

Without having this tested, i think the warning can be ignored.

Code: [Select]

const char szLabel[] PROGMEM = "Max:";  // defined in global space

u8g.getStrWidthP((unsigned char *)szLabel); // Inside a function


askjacob

Just thought I'd say thank you for this library. I have used it to get some ebay 1.6 inch 128x64 yellow/green oleds up and running with no hassle at all, what an amazing feat.

These displays are all over ebay at the moment, the top 16 rows are yellow, the rest are green and if you can use that in your application they look pretty great.

My config is:

Code: [Select]

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK);

void setup ()  {
 
//oled
uint8_t setmode = 1; //set to BW mode
u8g.setColorIndex(1); //Set colour to "white"


...for anyone "googling" out there how to get started with a 1.6" ebay yellow-green OLED display and arduino.

A quick question however:

Do you have any tips on how to slim down the program memory footprint? I am only using a single small font, and a few 'primitives' - basically print and scale2x2. As far as I know, the complier/linker SHOULD only use stuff that is called, but I have a suspicion more is tacked on, used or not when it comes to libraries... thoughts? Otherwise I am going to just make a copy of the library and just try the slash, burn and see method :)

Cheers and thanks again,

Jacob

bperrybap


I have a suspicion more is tacked on, used or not when it comes to libraries... thoughts? Otherwise I am going to just make a copy of the library and just try the slash, burn and see method :)

Before running off and spending time on a hunch, why not just take a look and
actually see where all the space is going?
Create a listing file from the linked image and you will see all the code generated
and linked in.
That will tell you exactly what is being linked in and how big things are.

--- bill

askjacob

I have, and there is a large chunk there. A lot of stuff in the code is, for example dedicated to constructors for devices that may or may not be invoked during run-time - not compile time, so I think I can save a fair bit of space if I trim it to the bone.

Or, end up with a non-functioning library as I sever a vital organ. Hence asking the author for his thoughts as I head in.

Cheers
Jacob

bperrybap


I have, and there is a large chunk there. A lot of stuff in the code is, for example dedicated to constructors for devices that may or may not be invoked during run-time - not compile time, so I think I can save a fair bit of space if I trim it to the bone.

Or, end up with a non-functioning library as I sever a vital organ. Hence asking the author for his thoughts as I head in.

Cheers
Jacob

So you created a listing file from the .elf file and actually saw dead code that isn't called and constructor code
for other devices in the linked image?

When I built the "HelloWorld" example for the i2c SD1306 128x64 module for a UNO board,
I only saw the routine for the one expected constructor and not any others.

I'm curious what you saw.

--- bill

olikraus

Yes, the listing file would be nice to see.
Depending on the fonts U8glib requires about 10K. If you do not need ASCII chars with code higher than 127, then fonts with a "r" postfix can be used to reduce flash memory.
Also other libraries and the use of floating point are common reasons for increased memory usage.

Oliver

askjacob

Hi Oliver.

First of all, this was not ever intended as any kind of critique on your library - but more on the lack of control and visibility on what the Arduino IDE gives on it's handling of libraries and compiling.

I have found inconsistent results with certain individual libraries with what is done - trimming out unused classes and functions can "greatly" reduce the final build, slightly reduce it, or not at all. Additionally moving code from a library into the main codebase can sometimes also reduce the overhead. Keep in mind here, I am talking about a handful of bytes here and there, not huge amounts all over the place. It all adds up though, when you are at the limit. Same with SRAM.

My thoughts here: this can hard to quantify and test easily, and often does not show up until your program is complex enough possibly edge case the compiler and optimizer, at whatever configuration the Arduino IDE uses.

Perhaps I am outgrowing the Arduino IDE. The hardware platform is nice, and the ability to ignore the 'arduino bits' when you want to is nice too.

Here is the thing though:

1 - Thanks Oliver for the great library. It has saved me much energy and head scratching, and allowed me to provide a neat UI to my project
2 - Thanks for the suffix "r" tip - that alone gave me 4K headroom to play with - much more breathing space and now development time rather than needing to start chopping around inside libraries :)

I'm glad I asked in here :)

PS does anyone have any good win32/win64 elf listers? I cannot find anything that has been developed beyind say 2009/2010 and they all crash post list generation, making anylsis/comparison between compiles very HARD!

Cheers
Jacob

bperrybap

Without looking at the actual final linked image to see everything and
what is linked in you are dancing in the dark.

Previously you said you did this,  but now it sounds like you haven't.

The gcc tool set comes with a set of binutils. There is a tool "objdump" to look at .elf files
The avr-gcc tool package that comes with the IDE comes with the gcc binutils.
In that package,  objdump is called "avr-objdump"
I recommend using that with the -S and -h options.

--- bill

askjacob

#218
Jul 30, 2014, 02:31 am Last Edit: Jul 30, 2014, 02:32 am by askjacob Reason: 1

Without looking at the actual final linked image to see everything and
what is linked in you are dancing in the dark.

Previously you said you did this,  but now it sounds like you haven't.

--- bill



I have been 'doing it' , but the best I could get using was T34 - however it would crash out post-parsing so I had to work with what was visible with the crash dialogue box open (it didn't cover the output) but I could not screengrab it to compare. The machine I am using is a corporate device where I have been given a sandbox area to play in, however it is still restricted somewhat and does seem to make a lot of apps misbehave, especially since we had some GPO's pushed to minimise the impact of the crytpobit type of viruses (limits execution locations etc).

I will grab the gcc toolchain and give it a shot.

Thanks for that!

Jacob

bperrybap


I will grab the gcc toolchain and give it a shot.
Jacob

If you are using the IDE, then you already have everything you need
as the IDE comes with the avr-gcc tools and the avr version of gnu binutils.
--- bill

Raphango


Yes, the listing file would be nice to see.
Depending on the fonts U8glib requires about 10K. If you do not need ASCII chars with code higher than 127, then fonts with a "r" postfix can be used to reduce flash memory.
Also other libraries and the use of floating point are common reasons for increased memory usage.

Oliver



Thanks for this awesome piece o' advice in reducing consumed memory. But how do I exactly implement it to my code? I'm intending to use my Attiny85 controlling a SSD1306 and I really don't know where to begin..... =(

Raphango


Hi Oliver,

I managed to add support for Arduino ATtiny85 hardware SPI. I tested it with an SSD1306 OLED controller (Adafruit 128x32) and it seems to be working OK. As predicted, it spares some CPU time and program memory.

The mod is attached. Feel free to include it into future releases, as is or modified.

Part of the credit goes to Nick Gammon, thanks to the code he posted there: http://forum.arduino.cc/index.php?topic=152432.0

Danke schön for your library.  :)


Please, would you tell me how did you manage to do it? I'm pretty noob at these advanced issues. I have downloaded your zip file but I don't know where to put the files. Could you please make a little "tutorial" on how to use u8glib with the ATtiny85? I'm using an Arduino Nano as ISP.

olikraus

Quote
I have downloaded your zip file but I don't know where to put the files.

In the Arduino IDE, there is a "Sketch" menu, which allows you to import and add a library. Just provide the zip from the u8glib download location. After this, you will find all the u8glib examples available in the Menu of the Arduino IDE.

Oliver

Raphango


Quote
I have downloaded your zip file but I don't know where to put the files.

In the Arduino IDE, there is a "Sketch" menu, which allows you to import and add a library. Just provide the zip from the u8glib download location. After this, you will find all the u8glib examples available in the Menu of the Arduino IDE.

Oliver
I have sucessfully imported the u8glib into my Arduino and I've already managed to upload some of the example codes. Using my Arduino Nano and the SSD1306, it works perfectly! The problem is: I want to use an ATtiny85 instead of the Arduino Nano you get it? The same codes that were uploaded to Ardu Nano won't work in the ATtiny85... I am using the Ardu Nano as ISP, with all the correct options selected, but it still give me these errors while compiling:
Code: [Select]
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe: OLED128x64_HelloWord.cpp.elf section .text will not fit in region text
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe: region text overflowed by 1436 bytes
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o: In function `__vector_14':
(.text+0x0): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_default' defined in .vectors section in c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o: In function `__vector_default':
(.vectors+0x0): relocation truncated to fit: R_AVR_13_PCREL against symbol `__init' defined in .init0 section in c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o: In function `__vector_default':
(.vectors+0x2): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_1' defined in .text section in c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o: In function `__vector_default':
(.vectors+0x4): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_2' defined in .text section in c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o: In function `__vector_default':
(.vectors+0x6): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_3' defined in .text section in c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o: In function `__vector_default':
(.vectors+0x8): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_4' defined in .text section in c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o: In function `__vector_default':
(.vectors+0xa): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_5' defined in .text.__vector_5 section in core.a(wiring.c.o)
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o: In function `__vector_default':
(.vectors+0xc): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_6' defined in .text section in c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o: In function `__vector_default':
(.vectors+0xe): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_7' defined in .text section in c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o: In function `__vector_default':
(.vectors+0x10): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_8' defined in .text section in c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o: In function `__vector_default':
(.vectors+0x12): additional relocation overflows omitted from the output

olikraus

I have never tested U8glib with Attiny85. The error message seem to indicate, that the size of the sketch is to big for the Attiny85.

Oliver

Go Up