Go Down

Topic: Help with menu on GLCD (Read 2174 times) previous topic - next topic

Redhawk10

Im new at this. Im looking at using my arduino mega2560 to control my aquarium. What im looking for is a menu structure that i could set the time the lights switch on&off set pH and the RTC for adjusting time and for adjusting temp. I would like a main screen that displays time/temperature/pH/lights that are on or off. Then menus that I can adjust the settings of each.

Tom Carpenter

What display did you want to use? How do you want to control it?

These are important questions as it determines exactly how things would work.
~Tom~

Redhawk10

hi, its a 128x64 glcd and want to control it with push buttons

olikraus

Hi

Maybe you find m2tklib useful: http://code.google.com/p/m2tklib/

Date entry is discussed as example 2 for M2_LABEL element: http://code.google.com/p/m2tklib/wiki/elref#LABEL. Time entry would be similar.

A main menu might be constructed like in the "rapunzel" example or you might use the new M2_2LMENU element to construct a main menu with scroll bar http://code.google.com/p/m2tklib/wiki/elref#2LMENU:


M2tklib requires a low level graphics library. GLCDv3 and u8glib are supported.

Oliver


Redhawk10

Code: [Select]
#include <glcd.h> // inform Arduino IDE that we will use GLCD library
#include "M2tk.h"
#include "utility/m2ghglcd.h"

uint8_t uiKeySelectPin = 10;
uint8_t uiKeyDownPin = 9;
uint8_t uiKeyUpPin = 8;
uint8_t uiKeyExitPin = 11;

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

// Left entry: Menu name. Submenus must have a '.' at the beginning
// Right entry: Reference to the target dialog box (In this example all menus call the toplevel element again
m2_menu_entry m2_2lmenu_data[] =
{
   { "Main", &top_el_expandable_menu },
   { "Temerature", NULL },
   { ". Min/Max/Ave", &top_el_expandable_menu },
   { ". Current Sensors", &top_el_expandable_menu },
   { ". Settings", &top_el_expandable_menu },
   { "Lighting", NULL },
   { ". 10 Watt Blue", &top_el_expandable_menu},
   { ". 10 Watt White", &top_el_expandable_menu },
   { ". 50 Watt White", &top_el_expandable_menu },
   { "pH", NULL },
   { ". Current", &top_el_expandable_menu },
   { ". Settings", &top_el_expandable_menu },
   { "Time/Date", NULL },
   { ". Settings", &top_el_expandable_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 definition
// Option l4 = four visible lines
// Option e15 = first column has a width of 15 pixel
// Option W43 = second column has a width of 43/64 of the display width

M2_2LMENU(el_2lmenu,"l4e15W43",&m2_2lmenu_first,&m2_2lmenu_cnt, m2_2lmenu_data,'+','-','\0');
M2_SPACE(el_space, "W1h1");
M2_VSB(el_vsb, "l4W2r1", &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|1W64H64", &el_hlist);

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


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); 
}

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

}


Hi there, I have changed the menu the way i would like it. The next question is how to add a RTC to diplay the in the Main and Time/Date menu and be able to adjust it in the settings menu, and the same for the temperature using a dallas DS18B20.

Thanks

olikraus

Hi

Time and date entry is available is available in an example file, which i made once for the botmat project:
http://code.google.com/p/m2tklib/source/browse/arduino/botmat_u8g/Botmat/Botmat.pde

See lines 230ff

I have used the rtc lib from here: http://code.google.com/p/ds1307new/

Oliver

Redhawk10

I,m still lost. If i select a menu it goes to the main, how to i make it go to RTC so i can change the settings. Thanks

olikraus

I probably need to see your current code.
Oliver

Redhawk10

How do i add the RTC code from http://code.google.com/p/m2tklib/source/browse/arduino/botmat_u8g/Botmat/Botmat.pde  into the code that i posted earlier. Thats were im stuck.

olikraus

1) Copy lines 228 to 320 from the Botmat.pde to your code.
2) Add two buttons to your existing menus and call the two toplevel elements el_top_td and el_top_dt

Oliver

Redhawk10

Code: [Select]
/*

  2LMenu.pde

  GLCD Example

  m2tklib = Mini Interative Interface Toolkit Library
 
  Copyright (C) 2012  olikraus@gmail.com

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

#include <glcd.h> // inform Arduino IDE that we will use GLCD library
#include "M2tk.h"
#include "utility/m2ghglcd.h"
#include "Wire.h"
#include <DS1307new.h>
#include "U8glib.h"
#include "utility/m2ghu8g.h"
#include "utility/U8g.h"
#define DEFAULT_FONT u8g_font_6x13
#define ICON_FONT u8g_font_m2icon_9
#define BIG_FONT u8g_font_fub20r



uint8_t uiKeySelectPin = 10;
uint8_t uiKeyDownPin = 9;
uint8_t uiKeyUpPin = 8;
uint8_t uiKeyExitPin = 11;


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


// Left entry: Menu name. Submenus must have a '.' at the beginning
// Right entry: Reference to the target dialog box (In this example all menus call the toplevel element again
m2_menu_entry m2_2lmenu_data[] =
{
  { "Main", &el_top_td  },
  { "Temerature", NULL },
  { ". Min/Max/Ave", &top_el_expandable_menu },
  { ". Current Sensors", &top_el_expandable_menu },
  { ". Settings", &top_el_expandable_menu },
  { "Lighting", NULL },
  { ". 10 Watt Blue", NULL},   { ". 10 Watt White", &top_el_expandable_menu },
  { ". 50 Watt White", &top_el_expandable_menu },
  { "pH", &top_el_expandable_menu },
  { ". Current", &top_el_expandable_menu },
  { ". Settings", &top_el_expandable_menu },
  { "Time/Date", NULL },
  { ". Time Adjust", &el_top_td },
  { ". Date Adjust", &el_top_dt },
  { 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 definition
// Option l4 = four visible lines
// Option e15 = first column has a width of 15 pixel
// Option W43 = second column has a width of 43/64 of the display width

M2_2LMENU(el_2lmenu,"l5e15W43",&m2_2lmenu_first,&m2_2lmenu_cnt, m2_2lmenu_data,'+','-','\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|1W64H64", &el_hlist);
M2tk m2(&top_el_expandable_menu, m2_es_arduino, m2_eh_4bs, m2_gh_glcd_ffs);



/*=========================================================================*/
/* edit time dialog */

uint8_t td_hour;
uint8_t td_min;
uint8_t td_sec;

void td_get_from_RTC(void)
{
  RTC.getTime();
  td_hour = RTC.hour;
  td_min = RTC.minute;
  td_sec = RTC.second;


}

void td_put_to_RTC(void)
{
  RTC.getTime();
  RTC.fillByHMS(td_hour, td_min, td_sec);
  RTC.setTime();
  RTC.startClock(); 
}

void td_ok_fn(m2_el_fnarg_p fnarg)
{
  td_put_to_RTC();
  m2.setRoot(&top_el_expandable_menu);
}

M2_U8NUM(el_td_hour, "c2", 0,23,&td_hour);
M2_LABEL(el_td_sep1, NULL, ":");
M2_U8NUM(el_td_min, "c2", 0,59,&td_min);
M2_LABEL(el_td_sep2, NULL, ":");
M2_U8NUM(el_td_sec, "c2", 0,59,&td_sec);

M2_LIST(list_time) = { &el_td_hour, &el_td_sep1, &el_td_min, &el_td_sep2, &el_td_sec };
M2_HLIST(el_time, NULL, list_time);

M2_ROOT(el_td_cancel, NULL, "cancel", &top_el_expandable_menu);
M2_BUTTON(el_td_ok, NULL, "ok", td_ok_fn);
M2_LIST(list_td_buttons) = {&el_td_cancel, &el_td_ok };
M2_HLIST(el_td_buttons, NULL, list_td_buttons);

M2_LIST(list_td) = {&el_time, &el_td_buttons };
M2_VLIST(el_top_td, NULL, list_td);

/*=========================================================================*/
/* edit date dialog */

uint8_t dt_day;
uint8_t dt_month;
uint8_t dt_year;

void dt_get_from_RTC(void)
{
  RTC.getTime();
  dt_day = RTC.day;
  dt_month = RTC.month;
  dt_year = (RTC.year-2000);
}

void dt_put_to_RTC(void)
{
  RTC.getTime();
  RTC.fillByYMD(dt_year+2000, dt_month, dt_day);
  RTC.setTime();
  RTC.startClock(); 
}

void dt_ok_fn(m2_el_fnarg_p fnarg)
{
  dt_put_to_RTC();
  m2.setRoot(&top_el_expandable_menu);
}

M2_U8NUM(el_dt_day, "c2", 1,31,&dt_day);
M2_LABEL(el_dt_sep1, NULL, ".");
M2_U8NUM(el_dt_month, "c2", 1,12,&dt_month);
M2_LABEL(el_dt_sep2, NULL, ".");
M2_U8NUM(el_dt_year, "c2", 0,99,&dt_year);

M2_LIST(list_date) = { &el_dt_day, &el_dt_sep1, &el_dt_month, &el_dt_sep2, &el_dt_year };
M2_HLIST(el_date, NULL, list_date);

M2_ROOT(el_dt_cancel, NULL, "cancel", &top_el_expandable_menu);
M2_BUTTON(el_dt_ok, NULL, "ok", dt_ok_fn);
M2_LIST(list_dt_buttons) = {&el_dt_cancel, &el_dt_ok };
M2_HLIST(el_dt_buttons, NULL, list_dt_buttons);

M2_LIST(list_dt) = {&el_date, &el_dt_buttons };
M2_VLIST(el_top_dt, NULL, list_dt);



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); 
}

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


This is what ive done so far, dont know if its correct. When i run it i can set date and time but all are 00:00:00.

Thanks
Rob

olikraus

Hi

To me it seems, that your scetch has two issues.

1) Please do not mix U8glib and GLCD. You should remove the following includes:
#include "U8glib.h"
#include "utility/m2ghu8g.h"
#include "utility/U8g.h"

For the rest of this post, i assume, that you have a KS0108 based display connected.

2) Pin conflicts
Wire.h will use A4 and A5 by default (as far as i remember). However the default configuration of the GLCD lib will also use A4. As a result, nothing will work. By the way, a conflict also exists with your key assignment and the GLCD lib.
This must be resolved before using Wire.h: Reconfigure GLCD to use some other pin than A4.

Next steps:
a) Ensure that some M2tklib examples for GLCD are ok.
b) Reconfigure GLCD lib in a way that you can add your buttons and I2C (A4 and A5)
c) Include Wire.h into some existing GLCD examples and ensure, that the example still working
d) Add key assignments and ensure that your keys are working
f) If all is fine and running with an included Wire.h continue to write your menu.

Conclusion:
What i assume at the moment: It is not a problem with M2tklib, but there are conflicts between Wire.h, GLCD lib and key assignments.

Hope that helps to solve your problem,
Oliver

Redhawk10

hi Oliver,
I removed #include "U8glib.h"
#include "utility/m2ghu8g.h"
#include "utility/U8g.h"

My display is a TM12864L-2 on arduino Mega there nothing connected to A4 or A5, It displays the menu and scrolls up and down with the buttons.It does not display the time comming from the RTC it just 00:00:00 which i can change up and down. when i select ok it does set the time. checked it with rtc sketch.

Thanks
Rob

olikraus

The "...get_from_RTC" procedures are not called. So the variables are not setup and are still zero.
One solution could be to introduce a new button, which reads the value from the RTC.

Example: Add a new button to the time dialog, which reads the current time from the RTC:
Code: [Select]

void td_read_fn(m2_el_fnarg_p fnarg)
{
  td_get_from_RTC();
}

M2_BUTTON(el_td_read, NULL, "read", td_read_fn);
M2_ROOT(el_td_cancel, NULL, "cancel", &top_el_expandable_menu);
M2_BUTTON(el_td_ok, NULL, "ok", td_ok_fn);
M2_LIST(list_td_buttons) = {&el_td_read, &el_td_cancel, &el_td_ok };
M2_HLIST(el_td_buttons, NULL, list_td_buttons);


Similar for the date example.

Oliver

Go Up