M2TKLIB - A User-Interface-Toolkit for the Arduino Hardware

Hi Oliver and others,

Based on the 2L example I went on with my code. And made some modifications in oa the used font to create a space on the top of the display for a status line.
At frst I had troubles with the display suddenly blanking but the arduino kept on running.
That was fixed with a buffer that was too long in the drawStatus routine and moving the fontsetting to setup.
After that everything ran fine for a long while.

But now, when just waiting in the main menu, the display blanks again after 8 hours or so.
Is there a way to reset the display system (software part), without resetting the arduino?

Besides the drawstatus routine I included most of the rest for completeness sake.

here is the drawStatus routine

    void drawStatus(void)
{

  static long bmpTime=0;
  static char StatBuf[26];
  static float temprature;
  static float pressure;
  static int hi, lo;

     hi=int(RATemp.getAverage());
    lo=(RATemp.getAverage()-float(hi))*100;

  String line =  String(rtc.getTimeStr());// + bmp.readPressure() + " " + bmp.readTemperature()+" C");
  line += " ";
  line +=  (int(RADruk.getAverage())); //
  if(statMsgStat==1 && m2.getRoot() == &m2_null_element)
  {
    switch (Step)
    {
    case 1:
      line += " 12u  ";
      break;
    case 2:
      line += " 1d   ";
      break; 
    case 3:
      line += " 1.5d ";
      break; 
    case 4:
      line += " 2d   ";
      break; 
    case 5:
      line += " 2.5d ";
      break; 
    case 6:
      line += " 3d   ";
      break; 
    case 7:
      line += " 3.5d ";
      break;
    case 8:
      line += " 4d   ";
      break;
    default:
      line += "      ";
      break;      
    }
  }
  else
    line += "      ";
  line.concat(hi);
  line += '.';
  line.concat(lo);
  if(lo<10)
    line +='0';
  line += "C";
  line.toCharArray(StatBuf,26);
  u8g.drawStr(0,7, StatBuf);

}

The menu side. The stuff from the example has been cut out because the post exeded the maximum length.

U8GLIB_KS0108_128 u8g(27, 28, 29, 30, 31, 32, 33, 34, 26, 35, 36, 24, 25,37); 		// 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs1=14, cs2=15,di=17,rw=16

//=================================================
// Forward declaration of the toplevel element
M2_EXTERN_ALIGN(top_el_expandable_menu);


/*Create empty screen for graph barrograaf*/
M2_ROOT(el_barrograaf_goto_top, NULL, "t ",&top_el_expandable_menu);

//here very much code has been deleted to fit forum post
//these were modifications of the demo routines to do my menu things

menus call the toplevel element again
m2_menu_entry m2_2lmenu_data[] = 
{
//  { "Menu",  NULL },
  { "Show Graph", &m2_null_element },  //disable menu system
//  { "Show Graph", &list_element },  //disable menu system
  { "Navtex", &top_el_expandable_menu },
  { ". Allerts", &top_el_expandable_menu },
  { ". All msgs", &top_el_expandable_menu },
  { "Navtex Setup", &top_el_expandable_menu },
  { ". Set Area", &top_el_muse },
  { ". Set MSG", &top_el_muse1 },
  { "WIFI Setup", &top_el_expandable_menu },
  { ". Radio", &el_rb_grid },
  { ". Combo", &el_top_combo },  
  { "Serial setup", &el_setspeed_top_combo},
  { "Serial Monitor", NULL },
  { ". COM1", NULL },
  { ". COM2", NULL },
  { ". COM3", NULL },
  { ". COM4", NULL },
  { "Set Date", &el_top_date_menu },
  { "Set Time", &el_top_time_menu },
  { "Numbers ", &el_top_num_menu },
  { NULL, NULL },
};

// The first visible line and the total number of visible lines.
// Both values are written by M2_2LMENU and read by M2_VSB
uint8_t m2_2lmenu_first;
uint8_t m2_2lmenu_cnt;


M2_2LMENU(el_2lmenu,"l5F1e0W43",&m2_2lmenu_first,&m2_2lmenu_cnt, m2_2lmenu_data,65,102,'\0');
M2_SPACE(el_space, "W1h1");
M2_VSB(el_vsb, "l5W2r1", &m2_2lmenu_first, &m2_2lmenu_cnt);
M2_LIST(list_2lmenu) = { &el_2lmenu, &el_space, &el_vsb };
M2_HLIST(el_hlist, NULL, list_2lmenu);
M2_ALIGN(top_el_expandable_menu, "-1|0W64H64", &el_hlist);

// m2 object and constructor
M2tk m2(&top_el_expandable_menu, m2_es_arduino, m2_eh_4bs, m2_gh_u8g_ffs);

//key matrix

byte key_rows[] = {
  40,38,42,43,44,45,46,47};
byte key_cols[] = {
  10,11,12,41,39};


SPISRAM myRAM(7); // CS pin
char buffer[128];



long Pressure;


void setup() {

   //enable 5V dc/dc converter  
  pinMode(DC5V, OUTPUT);
  digitalWrite(DC5V,LOW);
  pinMode(CSRAM, OUTPUT);
  pinMode(Backlight, OUTPUT);
  analogWrite(Backlight,128);

  //setup keypad
  for(int i=0;i<8;i++)
  {
    //    Serial.println(key_rows[i]);
    pinMode(key_rows[i],OUTPUT);
    digitalWrite(i,HIGH);
  }
  for(int i=0;i<5;i++)
  {
    //    Serial.println(key_cols[i]);
    pinMode(key_cols[i],INPUT);
    digitalWrite(key_cols[i],HIGH);
  }
  
    if ( u8g.getMode() == U8G_MODE_R3G3B2 ) 
    u8g.setColorIndex(255);     // white
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
    u8g.setColorIndex(3);         // max intensity
  else if ( u8g.getMode() == U8G_MODE_BW )
    u8g.setColorIndex(1);         // pixel on


  // Connect u8glib with m2tklib
  m2_SetU8g(u8g.getU8g(), m2_u8g_box_icon);

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

  // Assign icon font to index 3
  m2.setFont(3, u8g_font_m2icon_7);
    
  u8g.setFont(u8g_font_5x7r);

  Wire.begin();
  Serial.begin(115200);


  if (!bmp.begin()) 
  {
    Serial.println("Could not find a valid BMP085 sensor, check wiring!");
    while (1) {
    }
  }
 //Setup SPI for SRAM
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  SPI.setDataMode(SPI_MODE0);
 
 //some test on the RTC for rome unresolved error
 Serial.println(rtc.getTimeStr());  //deze tijd is onjuist. Meestal 00:00:00
 Serial.println(rtc.getDateStr());
 delay(1000);
 Serial.println(rtc.getTimeStr()); //deze tijd is juist
 Serial.println(rtc.getDateStr());
 


 //init Flagspace
  getFlagSpace();

  if(flagSpace.regs.dataPointer<START_DATA||flagSpace.regs.dataPointer>END_DATA)
    flagSpace.regs.dataPointer=START_DATA;
//fat starts on 0x0000 so no check needed for msgPointer



//  Timeadjust(DateTime(__DATE__, __TIME__));

}

// Draw procedure, Arduino Setup & Loop


void draw(void) {
  drawStatus();
  drawGraphics();
  m2.draw();
}


void loop(){
  long r,timer=0;
 // float temp;
  while(1)
  {
    scheduler();

    KeyMatrix();

    m2.checkKey();

    if ( m2.handleKey() != 0 || millis()>timer ) 
    {
      timer=millis()+1000;
      u8g.firstPage();  
      do 
      {
        KeyMatrix();
        m2.checkKey();
          draw();
   
      } 
      while( u8g.nextPage() );
    }
  }
 }

And for completeness here is the head of my code.

#include <Wire.h>
#include <SPI.h>
#include "U8glib.h"
#include <Adafruit_BMP085.h>
#include <SPISRAM.h>
#include <stdlib.h>		// for itoa
#include "M2tk.h"
#include "utility/m2ghu8g.h"
#include <DS1302.h>
#include <DateTime.h>
#include "RunningAverage.h"

#define END_FAT         0x00BBF
#define START_DATA      0x00BC0
#define END_DATA        0x02BBF
#define MSG_BUF_START   0x02BC0
#define MSG_BUF_END     0x03CAF
#define MSG_START       0x03CB0
#define MSG_LAST        0x1EFFF
#define MSG_STOP        0x1EFFF
#define FLAGSPACE       0xFFF0

#define DC5V 22
#define CSRAM 7
#define Backlight 8

#define M2_KEY_0 20
#define M2_KEY_1 21
#define M2_KEY_2 22
#define M2_KEY_3 23
#define M2_KEY_4 24
#define M2_KEY_5 25
#define M2_KEY_6 26
#define M2_KEY_7 27
#define M2_KEY_8 28
#define M2_KEY_9 29

#define BARROGRAAF 1
#define THERMOGRAAF 2
#define PT_GRAPH 3
long currMsg=MSG_START;
long nu;
int sampleTime=5;
byte drawFunction=0;
byte Step=8; //Geeft de stap grootte aan voor het tekenen van het grafiek max END_DATA-START_DATA/128=65
char tMaxBuf[8];
char tMinBuf[8];
char dMaxBuf[8];
char dMinBuf[8];
char statMsgStat=1;

  float maxTempDraw;
  float minTempDraw;
  float maxDrukDraw;
  float minDrukDraw;

  long minMaxTimeout=0;

#define FLAGSPACE_UNION_SIZE 16

union bla{
  struct blie{
  unsigned int dataPointer; //2bytes
  unsigned int msgFATPointer;  //2bytes
  byte maxTemp;  //
  byte minTemp;
  byte test3;
  byte test4;
  int maxDruk; 
  int minDruk;
  byte test5;
  byte test6;
 
    } 
  regs;
  byte flagMap[FLAGSPACE_UNION_SIZE-1];
} 
flagSpace;  //regU

#define REG_UNION_SIZE 8

union regUnion {
  struct regStruct{
    float temp;
    float druk;
    
  } 
  regs;
  byte registerMap[REG_UNION_SIZE-1];
} 
dataUnion;  //regU

#define EEPROM_UNION_SIZE 8

union{
  struct{
   unsigned int com1Baud; 
   unsigned int com2Baud; 
   unsigned int com3Baud; 
   unsigned int com4Baud; 
  }
  regs;
  byte PROM[EEPROM_UNION_SIZE-1];
}
EE;