intro screen in m2tk lib with glcd

Hello, i build a menu with m2tk lib in a glcd monitor.

I want intro screen when i turn on arduino, this intro screen is in a seperate procedure.

After this intro screen enter in the main menu.

The problem is that i have 2 conflicts between the two libraries.

//libraries
#include <glcd.h>
#include "fonts/allFonts.h" // for access to all distributed fonts
#include "bitmaps/Image1.h" //image in thw introscreen
#include "M2tk.h"	
#include "utility/m2ghglcd.h"

uint8_t uiKeySelectPin = 2;
uint8_t uiKeyDownPin = 3;
uint8_t uiKeyUpPin = 4;
uint8_t uiKeyExitPin = 5;


#define MAIN_MENOU 1

extern M2tk m2;


uint8_t state; 	


void main_menu(){
	state = MAIN_MENOU;
	m2.clear();
}

M2_LABEL(hello_world_label, "f1", "Hello World");

M2tk m2(&hello_world_label, NULL, NULL, m2_gh_glcd_bf);


void setup()
{
  
  m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
  m2.setPin(M2_KEY_NEXT, uiKeyDownPin);
  m2.setPin(M2_KEY_PREV, uiKeyUpPin);
  m2.setPin(M2_KEY_EXIT, uiKeyExitPin);  
  
  
  introScreen();
  
  state = MAIN_MENOU;
    
}


void set_next_state(void) {
  switch(state) {
    case MAIN_MENOU:  break;
    
  }
}

void loop()
{
	m2.checkKey();
	if ( m2.handleKey() ) {
		 m2.draw();
		 }
set_next_state();
}

void introScreen(){      

  GLCD.Init(NON_INVERTED);          // initialize the library
  GLCD.ClearScreen();               
  //GLCD.DrawBitmap(Image1, 40, 0);   //Image1
  GLCD.DrawRoundRect(0, 0, 127, 63, 10, BLACK);  
  //GLCD.SelectFont(Arial_bold_14);       // select fixed width system font
  GLCD.CursorToXY(6,26);                
  GLCD.print("AAAAAAAAAAA 1.0");        // print a message
  delay(5000);                          
  GLCD.ClearScreen();
}

The message of conflict
Image1.h : Image1 causes a section type conflict
Arial_bold_14.h : Arial_bold_14 causes a section type conflict
Error compiling

Hi

There is a tutorial which gives some introduction on how to combine graphics and M2tklib: Google Code Archive - Long-term storage for Google Code Project Hosting.

The actual error in your code is more difficult. At the moment i can not do more than give you some ideas and keywords.

  • As far as I know fonts are defined (not declared) in the .h files, which might lead to some problems, when included twice
  • Font definition make use of the PROGMEM attribute.
  • GNU C++ is has at least one bug with the PROGMEM sections.
  • GNU C++ has changed its behaviour with respect to PROGMEM area. The error might depend on the IDE version and the question whether you have installed a parallel gnu compiler suite.

Ideas for a solution:

  • Using C-Code instead of C++ code sometimes helps
  • Maybe an additional C++ file for the intro screen might also help
  • You might consider to use U8glib instead of GLCD (if this is a KS0108 display with 128x64 pixel size). Fonts in U8glib are declared in a different way so that the above mentioned problem "usually" will not appear.

Some more discussion happend here:
http://forum.arduino.cc/index.php/topic,77405.0.html
But i think there was also no result...

Oliver

Part of the issue here is the simplistic (poor) font methodology used in GLCD.
(It was inherited from its parent library ks0108). Because the fonts don't have
a separate external declaration, it creates issues when the font header is included more than once.
(like in separate modules) because the data ends up being declared & defined more than once - At some point I will fix this.
(It not as easy as it sounds since there are several font tools out there that create font files that I don't have control over)
But I think part of the issue in this case is also the way u8glib is working around some of the C++ progmem issues.

As Oliver said there are issues with PROGMEM and C++
PROGMEM often issues warnings in C++ when it shouldn't, so there have been attempts at creating
work arounds to suppress the warnings.
Some of these "work arounds" eliminate the warnings but create other issues.

Also, I'm starting to see different libraries attempt different work arounds and that can create problems as well
when used together as the work arounds are potentially incompatible with each other.
For example,
This popular "work around":

#ifdef PROGMEM
#undef PROGMEM
#define PROGMEM __attribute__((section(".text"))) // works on both AVR and ARM
#endif

Will break M2tklib because the two m2_rom pointers that use M2_PROGMEM in utility/m2.h create an
error if this work around done before m2.h is included.
A safer M2_PROGMEM definition would be:

#define PROGMEM  __ATTR_PROGMEM__

to avoid any of those PROGMEM work arounds.

Overall, the avr-gcc PROGMEM stuff is a kludge that is quite fragile.
I've wrestled with progmem C++ issues on Arduino for quite some time.
Its a mess because of the different versions of avr-gcc and now all the work arounds
that are being used.


Oliver, we need to sync up off line.
I'm in the process of a major update of the GLCD library.
There are also some issues with the way Paul has defined his PROGMEM compatibility macro
for his teensy3 product that will more than likely affect your stuff as well.

Lets talk offline and I'll fill you in.

--- bill

Hi hydrogen99

I try to reproduce the problem on my PC, but Image1.h is missing. Can you attach this file also.
What is your exact version of the Arduino IDE?

@Bill: E-Mail sent.

Oliver

olikraus:
Hi hydrogen99

I try to reproduce the problem on my PC, but Image1.h is missing. Can you attach this file also.
It isn't needed. He aleady comment out the code that used it.
Just comment out the include.
and then uncomment the SelectFont()

What is your exact version of the Arduino IDE?
I found it failed with 1.0 and 1.0.5

ok, thanks, i can reproduce the problem.

Oliver

Here is at least one workaround, which at least compiles (not checked on the target):

Update "Arial_bold_14.h"

Instead of

static uint8_t Arial_bold_14[] PROGMEM = {

use

static uint8_t Arial_bold_14[] __attribute__ ((section (".progmem.arial_bold_14"))) = {

Oliver

Thanks for the answers.

For know i'm trying to do my sketch with u8glib.

I 'll post the result =

Unfortunately i can't managed to do it.
The lib u8glib was perfect with my ks0108 monitor but i confused with the structure.
I want an intro screen like in photo, and after 5 sec to start my main menou.
In the area image i want to have an image wicth i have in .h format.

Here is my code so far:

//1
#include "U8glib.h"
#include "M2tk.h"
#include "utility/m2ghu8g.h"

//2. constructor
U8GLIB_KS0108_128 u8g(22, 23, 24, 25, 26, 27, 28, 29, 37, 33, 34, 36, 35);

//3.
uint8_t uiKeySelectPin = 2;
uint8_t uiKeyDownPin = 3;
uint8_t uiKeyUpPin = 4;
uint8_t uiKeyExitPin = 5;

//4. 
#define MAIN_MENOU 1

//5.
extern M2tk m2;

//6.
uint8_t state; 	

//7.


void main_menu(){
	state = MAIN_MENOU;
	m2.clear();
}

M2_LABEL(hello_world_label, "f1", "Hello World");

//8.
M2tk m2(&hello_world_label, NULL, NULL, m2_gh_u8g_bfs);

//9. 
void setup()
{
  
	// Connect u8glib with m2tklib
  m2_SetU8g(u8g.getU8g(), m2_u8g_box_icon);

  // Assign u8g font to index 0
  m2.setFont(0, u8g_font_6x12r);

  
  m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
  m2.setPin(M2_KEY_NEXT, uiKeyDownPin);
  m2.setPin(M2_KEY_PREV, uiKeyUpPin);
  m2.setPin(M2_KEY_EXIT, uiKeyExitPin);  
  
   
    
  state = MAIN_MENOU;
    
   introScreen();
}

//10.
void set_next_state(void) {
  switch(state) {
    case MAIN_MENOU:  break;
    }
}

//11. 
void draw(void) {
    m2.draw();
}

//12. ???????? ??? main loop
void loop()
{
// menu management
  m2.checkKey();    
  if ( m2.handleKey() != 0 ) { 
    u8g.firstPage();  
    do {
      draw();
    } while( u8g.nextPage() );
  }
set_next_state();
}



void introScreen() {    

uint8_t u8g_Begin(u8g_t *u8g); //reset monitor

//u8g.drawBitmapP( 0, 0, 1, 8, rook_bitmap); //show image
u8g.drawRFrame(5, 10, 40, 30, 10);
u8g.setFont(u8g_font_unifont);
u8g.drawStr( 0, 20, "AAAAAAAAA");
delay(5000);                          
uint8_t u8g_Begin(u8g_t *u8g); //reset monitor
}

intro screen.jpg

Always place graphics commands within the firstPage/nextPage loop.
u8g_Begin is not required.

void introScreen() {    
    u8g.firstPage();  
    do {
        //u8g.drawBitmapP( 0, 0, 1, 8, rook_bitmap); //show image
        u8g.drawRFrame(5, 10, 40, 30, 10);
        u8g.setFont(u8g_font_unifont);
        u8g.drawStr( 0, 20, "AAAAAAAAA");
    } while( u8g.nextPage() )
   delay(5000);                          
}

Oliver

Oliver,
It took me quite a while to grasp the u8glib screen update methodology as well.
While it isn't that complicated once you "get it", it wasn't immediately obvious to me
because it was so different and foreign to me.

I wonder if it would make it easier for folks, if you provided a wrapper function or macro
to hide the first/next drawing loop?

Users could pass the macro/function the name of the u8g object and the users drawing function.
The macro/function could take care of the rest.

--- bill

Thank you oliver, my project go one step further.
The following code does exactly what i want.

But one last abeyance, is posibly to show in introsceen() a bitmap.h which i create with the tool provided with glcd library?

//1.Libraries
#include "U8glib.h"
#include "M2tk.h"
#include "utility/m2ghu8g.h"

//2. constructor KS0108
U8GLIB_KS0108_128 u8g(22, 23, 24, 25, 26, 27, 28, 29, 37, 33, 34, 36, 35);

//3.digital pins
uint8_t uiKeySelectPin = 2;
uint8_t uiKeyDownPin = 3;
uint8_t uiKeyUpPin = 4;
uint8_t uiKeyExitPin = 5;

//4. program states

#define MAIN_MENOU 1

//5.
extern M2tk m2;

//6.variables
uint8_t state; 	

//7.procedures states


void main_menu(){
	state = MAIN_MENOU;
	m2.clear();
}

M2_LABEL(hello_world_label, NULL, "Hello World");

//8. constructor m2tklib
M2tk m2(&hello_world_label, NULL, NULL, m2_gh_u8g_bfs);

//9. setup
void setup()
{
	introScreen();
  	// Connect u8glib with m2tklib
  m2_SetU8g(u8g.getU8g(), m2_u8g_box_icon);

  // Assign u8g font to index 0
  m2.setFont(0, u8g_font_6x12r);

  //pins
  m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
  m2.setPin(M2_KEY_NEXT, uiKeyDownPin);
  m2.setPin(M2_KEY_PREV, uiKeyUpPin);
  m2.setPin(M2_KEY_EXIT, uiKeyExitPin);  
  
   
  //first state  
  state = MAIN_MENOU;
    
  }

//10.procedure find the next state
void set_next_state(void) {
  switch(state) {
    case MAIN_MENOU:  break;
    }
}

//11. draw
void draw(void) {
    m2.draw();
}

//12. main loop
void loop()
{
// menu management
  m2.checkKey();    /
  if ( m2.handleKey() != 0 ) { 
    u8g.firstPage();  
    do {
      draw();
    } while( u8g.nextPage() );
  }
set_next_state();
}

//Intro screen
void introScreen() {    
    u8g.firstPage();  
    do {
        u8g.drawRFrame(0, 0, 128, 64, 10);
        u8g.setFont(u8g_font_unifont);
        u8g.drawStr( 0, 20, "MY PROGECT v1.0");
    } while( u8g.nextPage() );
   delay(5000);                          
}

@Bill:
Indeed i have thought about option, but i took over the concept from the dogm128 lib (which had been the predecessor for u8glib). I know the concept is difficult to understand...

@hydrogen99
You can use gimp and export your bitmap as XBM (monochrome) bitmap. XBM is actually plain c code which can be copyied into your source code (.c or .h). Then use the drawXBMP command.

Oliver

olikraus:
@hydrogen99
You can use gimp and export your bitmap as XBM (monochrome) bitmap. XBM is actually plain c code which can be copyied into your source code (.c or .h). Then use the drawXBMP command.

Oliver

Don't you have to insert some kind of progmem attribute?

bperrybap:

olikraus:
@hydrogen99
You can use gimp and export your bitmap as XBM (monochrome) bitmap. XBM is actually plain c code which can be copyied into your source code (.c or .h). Then use the drawXBMP command.

Oliver

Don't you have to insert some kind of progmem attribute?

Fully correct. Currently i am away from my normal computer equipment with only limited access to e-mail and internet. Please excause my short answers.
Details regarding the PROGMEM attribute are given here: Google Code Archive - Long-term storage for Google Code Project Hosting.

Oliver

olikraus:

bperrybap:

olikraus:
@hydrogen99
You can use gimp and export your bitmap as XBM (monochrome) bitmap. XBM is actually plain c code which can be copyied into your source code (.c or .h). Then use the drawXBMP command.

Oliver

Don't you have to insert some kind of progmem attribute?

Fully correct. Currently i am away from my normal computer equipment with only limited access to e-mail and internet. Please excause my short answers.
Details regarding the PROGMEM attribute are given here: Google Code Archive - Long-term storage for Google Code Project Hosting.

Oliver

Thank you oliver. Now my intro screen is perfect