Show Posts
Pages: [1] 2 3 ... 101
1  Using Arduino / Displays / Re: LCD menus with rotary encoder troubles. Using m2tklib on: September 15, 2014, 04:58:45 pm

Quote
Actually, is there a way to have an idle screen with the clock?

Sure, this is possible. First you need to figure out the inactivity. This is, if you never enter the if block in your main loop (m2.draw() is not executed for some seconds). For example, you can store the last active time in the if block. I created some code for this, but i did not test this. Same background information is also given here: https://code.google.com/p/m2tklib/wiki/t06glcd

Code:
int32_t last_action_time = 0;
uint8_t is_menu_active = 1;

void loop() {
  m2.checkKey();
  m2.checkKey();
  if ( is_menu_active != 0 ) {
    if ( m2.handleKey() ) {
      last_action_time = millis();  // user input append, store event time
      m2.draw();
    }
    if ( last_action_time > millis() + 20000 ) {  // nothing has happend for 20 sec.
     is_menu_active = 0;  // deactivate menu
      m2.setRoot(&m2_null_element);  // assign a predefined empty menu
   }
  else {
    // here you can use lcd.print() to output time on the lcd.
    // ...

    // menu is deactivated, but key detection still works
   // check for any user input
    if ( m2.getKey() != M2_KEY_NONE ) {
      // input has happend, store event time, activate menu
      last_action_time = millis();
      is_menu_active = 0;
      m2.setRoot(&top_el_expandable_menu);  // restore the toplevel dialog box
   }
  }
 }
}

Glad to see, that you managed to climb up the learning curve.

Oliver
2  Using Arduino / Displays / Re: U8glib: Graphics Lib for LCDs and OLEDs on: September 15, 2014, 03:42:50 pm
Hi

Thanks.

The question regarding color displays  came up very often. I finally decided to split off color displays and created Ucglib: https://code.google.com/p/ucglib/.

It has some small differences: I removed the "picture loop" (because it does not make sense for color TFTs/OLEDs), added true color support to all graphics primitives and updated the fonts a little bit (actually i replaced one of the fonts with another font).

Ucglib has its own thread here: http://forum.arduino.cc/index.php?topic=214966.0

Ucglib is quite young and it does not have the popularity as UTFT or the Adafruit Lib, But Ucglib is infact U8glib for color displays, especially for those users, who do not want to miss a large collection of fonts and an online documentation.

Oliver



3  Using Arduino / Displays / Re: LCD menus with rotary encoder troubles. Using m2tklib on: September 15, 2014, 03:32:31 pm
Hi

I am sorry, that some of my suggestions lead to a syntax error. I actually did not test anything. But i am glad you figured out a configuration, that works for you.

A typical top menu looks like this:
Code:
M2_ROOT(el_root_set_time, "", "set time", &top_el_set_time);
M2_ROOT(el_root_set_alarm, "", "set alarm", &top_el_set_alarm);

M2_LIST(list_main_menu) = {
    &el_root_set_time,
    &el_root_set_alarm
};

M2_VLIST(el_main_menu_vlist, NULL, list_main_menu);
M2_ALIGN(top_el_main_menu, "-1|1W64H64", &el_main_menu_vlist);

Instead of VLIST you can also use XYLIST, but VLIST automatically calculates the correct possition and ALIGN will center everything on the screen (so you do not need to deal with the xy position).

Of course for the constructor, you need to provide "top_el_main_menu" as a startingpoint for your menu structure.
Basically something like this will appear on the screen:


........................................
...........[set time]...................
...........[set alarm]..................
........................................


In fact it is usually a good idea to draw the desired layout before coding the menu.

Now it is time to code the "set time" dialog box. Let me just create a very simple input box. Sure it can be extended and enriched with some buttons:

[00]:[00]:[00]................................
[ok] [cancel]...........................
........................................
........................................


Now i think it is time to copy the data from my initial answer.

First, some tmporary variables are required for m2tklib:
Code:
uint8_t td_hour;
uint8_t td_min;
uint8_t td_sec;
You need to communicate through these variables. Values are taken from this global variables and user input is written to this variables.

Here is the code:
Code:
void td_ok_fn(m2_el_fnarg_p fnarg)
{
 // store the input data somewhere
}

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", &el_top);
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(top_el_set_time, NULL, list_td);
Please note, that the toplevel element has the name "top_el_set_time", which is refered by M2_ROOT from your top level menu. In fact M2_ROOT is like a goto statement. I acts like a button. Once pressed, it will give control to another dialog box.
Again, you could replace the nested VLIST and HLIST elements with a single XYLIST, but i prefer the automatic calculation of positions. So i hope you can read most of the code and maybe the only new element is M2_BUTTON.
M2_BUTTON is very similar to M2_ROOT: It adds a button. But once pressed, it just calls a function. In this case the function is "td_ok_fn". You can use any name of course. In fd_ok_fn, you will know, that the user has pressed the ok button and you need to do something with the values in the three global values.

A similar structure needs to be added for the date input.

Hope i have you enough information for proceeding here. If not, please continue to ask.

Oliver
4  Using Arduino / Displays / Re: LCD menus with rotary encoder troubles. Using m2tklib on: September 14, 2014, 02:18:46 pm
One more suggestion. I think with the rotary encoder it is better to use the 6-button handler:
Code:
M2tk m2(&top_el_hlist, m2_es_arduino_rotary_encoder, m2_eh_6bd, m2_gh_lc);

Additionally, you my want to change the events, which are sent by the rotary encoder:
Locate m2esarduino.c and
change line 233 to
Code:
      return M2_KEY_EVENT(M2_KEY_DATA_UP); /* disable debounce by M2tk algoritm */      
change line 245 to
Code:
      return M2_KEY_EVENT(M2_KEY_DATA_DOWN); /* disable debounce by M2tk algoritm */      

I think this will make more sense for you.

Oliver
5  Using Arduino / Displays / Re: LCD menus with rotary encoder troubles. Using m2tklib on: September 14, 2014, 01:06:34 pm
Hi

Of course my code example is not complete. It was just intended as an example, how to construct the menu.

As a second step, let us create a simple numeric entry with the encoder. You have already selected, a nice example, but "M2_U32NUM" is not what you want. Instead, Please use M2_U8NUM, which will (hopefully) behave as intended by you.
So let me replace U32NUM by U8NUM and let me discuss the example more closely

Code:
#include <LiquidCrystal.h>
#include "M2tk.h"
#include "utility/m2ghlc.h"

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

uint8_t uiKeySelectPin = A3;
uint8_t uiKeyNextPin = A2;
int t =0;

// instead of the uint32_t data type, we just need a uint8_t
//uint32_t number = 0;
uint8_t number = 0;

// i just keep this function, println will take care on the changed datatype
void fn_ok(m2_el_fnarg_p fnarg) {
  /* do something with the number */
  //t = number;
  Serial.println(number); 
}

// M2_LABEL just places a constant string on the screen, i guess you already noticed this
M2_LABEL(el_label, NULL, "Hour: ");
// now, i just replace the U32NUM with U8NUM
//M2_U32NUM(el_num, "a1c2", &number);
// however the options and arguments are different and also the behavior is different
// please learn to look at the reference manual. I did my very best to describe these option and arguments.
// They ARE important.
// https://code.google.com/p/m2tklib/wiki/elref#U8NUM
// first arg: name of the element
// second arg: format string, c2 defines two digits (columns) for the input, this means numbers from 00 to 99
// third arg: minimum value, here 0
// forth arg: maximum value, here 23
// fifth arg: pointer to the variable
M2_U8NUM(el_num, "a1c2", 0, 23, &number);

// just a button
M2_BUTTON(el_ok, "", "ok", fn_ok);

// list is used to nest elements and construct/group more complex dialog boxes (which can also be reused)
M2_LIST(list) = { &el_label, &el_num, &el_ok };
M2_HLIST(top_el_hlist, NULL, list);
M2tk m2(&top_el_hlist, m2_es_arduino_rotary_encoder, m2_eh_4bd, m2_gh_lc);

void setup()
{
  Serial.begin(57600);
    m2_SetLiquidCrystal(&lcd, 20, 4);
  m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
  m2.setPin(M2_KEY_ROT_ENC_A, A0);
  m2.setPin(M2_KEY_ROT_ENC_B, A1);
  m2.setPin( M2_KEY_EXIT, uiKeyNextPin);
}

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

Actually i do not remember whether the a option has an influence here. Please check by yourself, whether this
Code:
M2_U8NUM(el_num, "a1c2", 0, 23, &number);
or this
Code:
M2_U8NUM(el_num, "a0c2", 0, 23, &number);
makes a difference for you with respect to the user input. M2tklib can be adjusted in a lot of different ways regarding the user input. But i guess, this needs to be specified first by you.

Oliver
6  Using Arduino / Displays / Re: LCD menus with rotary encoder troubles. Using m2tklib on: September 14, 2014, 06:17:47 am
Hi

Let me start with the buttons: M2tklib assumes that the pushed button connects the ground, because there is an internal pull-up resistor, which is also activated. This means, your external resistor is not required (if the button connects to GND). Additionally, m2tklib includes a debounce algorithm. So also the cap is not required.

The encoder seems to be connected correctly. Also the software setup seems to be fine (but i can not verify this).

I think the first step should be to setup your input devices correctly and make the examples work.

Additionally here is some code from my projects with a time input dialog box:

Code:
/* 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(&el_top);
}

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", &el_top);
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);

Oliver

Edit: Pull-up Resistor
7  Using Arduino / Displays / Re: U8glib: Graphics Lib for LCDs and OLEDs on: September 13, 2014, 02:21:40 pm
Hi

Somehow the error messages sounds like, that the sketch is still to big. But again, i am not an expert for the Attiny45. It seems to be more often discussed in " Arduino Forum :: Using Arduino :: Microcontrollers".

Oliver
8  Using Arduino / Displays / Re: U8glib: Graphics Lib for LCDs and OLEDs on: September 13, 2014, 12:15:59 pm
In the HelloWorld example, line 130, replace
Code:
u8g.setFont(u8g_font_unifont);
with
Code:
u8g.setFont(u8g_font_unifontr);
Try to upload this example. If you get the same errors, then u8glib might be to big for the Attiny85.

Oliver
9  Using Arduino / Displays / Re: U8glib: Graphics Lib for LCDs and OLEDs on: September 13, 2014, 02:26:37 am
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
10  Using Arduino / Displays / Re: ILI9341 (new) SPI library for Arduino Due supporting DMA transfer on: September 12, 2014, 10:47:48 am
Yes, indeed. For the "gradient" feature, the colors are calculated on the fly and the data is sent pixel by pixel to the SPI subsystem. This does not benefit much from the SdSpi.h at the moment. Writing to an intermediate buffer would probably improve speed.

My biggest fear has been, that ucglib is very slow compared to your library, but i think this is not the case. For some graphics primitives (like box and polygon), there is a good improvent with SdSpi, but for text rendering, results are comparable. But it also shows, that the Arduino SPI library could be optimized for the Due.

Oliver

11  Using Arduino / Displays / Re: ILI9341 (new) SPI library for Arduino Due supporting DMA transfer on: September 12, 2014, 09:50:07 am
Hi

I spend some time to analyse SdSpi.h. I finally ended up to add SdSpi to ucglib (my own graphics lib).
Regarding speed, my results are a litle bit different.
With the standard SPI.h library, results are this:
  ILI9341, Arduino Due, HW SPI   Text: 12.4      Box: 22.4      Gradient: 16.5   

With SdSpi.h and some optimization, i get this:
  ILI9341, Arduino Due, HW SdSpi   Text: 13.9      Box: 38.0      Gradient: 19.7      with multibyte transfer   

My text and gradient speed test do not show much improvement over SPI.h. This means, that the original SPI.h library is already quite good. Main improvement is there in those cases, when multiple bytes need to be transmitted. Here speed is almost doubled.

Oliver
12  Using Arduino / Displays / Re: U8glib: Graphics Lib for LCDs and OLEDs on: September 12, 2014, 01:06:31 am
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
13  Using Arduino / Displays / Re: ILI9341 (new) SPI library for Arduino Due supporting DMA transfer on: September 11, 2014, 04:39:46 pm
ok, got the first include fixed, by adding the full path. But "Streaming.h" is still unknown. In fact i did not find such include file on my harddisk.

Oliver
14  Using Arduino / Displays / Re: ILI9341 (new) SPI library for Arduino Due supporting DMA transfer on: September 11, 2014, 03:07:10 pm
Hi MarekB

Nice work. I got your library working almost working. Well almost, because "graphicstestWithStats" reports an error:
Arduino: 1.5.5 (Linux), Board: "Arduino Due (Programming Port)"

graphicstestWithStats.ino:22: fatal error: ILI9341_due\fonts\Arial_bold_14.h: No such file or directory
compilation terminated.

I also get this error:
Arduino: 1.5.5 (Linux), Board: "Arduino Due (Programming Port)"

graphicstestWithStats.ino:24: fatal error: Streaming.h: No such file or directory
compilation terminated.

Any ideas? I am using Arduino 1.5.5 on Ubuntu. Again: "graphicstest" works perfect.

Thanks, Oliver
15  Using Arduino / Displays / Re: OLED display with 4-wire SPI mode, but without CS on: September 09, 2014, 10:35:17 am
Not supported by U8glib. Arduino Due of course can talk to I2C devices.

Oliver
Pages: [1] 2 3 ... 101