Go Down

Topic: Rotary Encoder, Button, and LCD User interface with Menu (Read 7684 times) previous topic - next topic

Delta_G

I've been using this same code for a few projects now to create a user interface using a single rotary encoder and a button to drive a menu on an LCD as well as the various user input functions.  I got tired of moving the code from one project to another the hard way so I decided to condense it into a library.  And in response to a few recent posts I thought I would share what I'm doing.  It's called REBL_UI.

It currently uses a different LiquidCrystal library that uses a shift register to save pins on the Arduino and drives the LCD through a shift register on the SPI bus, but could easily be adapted to work with any of the existing flavors of LiquidCrystal with only a few lines of code needing to change.  If you need help with modifications, ask here or on my github page.

The code can be found on my github page along with my LCD library.  There is one simple example code included but for a bigger example see my Disco_Doser code on the same page. 

I don't know if you'll find it useful or not, but it doesn't cost me anything to share it so here it is. 

Link to REBL_UI repo.

Link to LiquidCrystal_SPI_8Bit
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

OldSteve

I have a feeling that a lot of people will find it useful ;)
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

larryd

No technical PMs.
The last thing you did is where you should start looking.

vangalvin

Do you by any chance have an example that uses the LiquidCrystal.h library and an LCD without a shift register?

Kuba_eM

Kuba_eM

vangalvin

I join to the above request
in REBLDisplay.cpp

change to this...
void initLCD(uint8_t aRsPin, uint8_t aEnablePin, uint8_t aD1, uint8_t aD2, uint8_t aD3, uint8_t aD4) {

#ifdef USING_SERIAL
   Serial.begin(19200);
#else
   LCD = new LiquidCrystal(aRsPin, aEnablePin, aD1, aD2, aD3, aD4);
   LCD->begin(NUM_LCD_COLS, NUM_LCD_ROWS);
   LCD->noCursor();
   LCD->clear();
   //setColor(BLUE);

#endif
}

in REBLDisplay.h
Change to this
void initLCD(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t);

In your sketch add these
#define LCD_D1 4
#define LCD_D2 5
#define LCD_D3 6
#define LCD_D4 7

and change to this.
initLCD(LCD_RS_PIN, LCD_ENABLE_PIN, LCD_D1, LCD_D2, LCD_D3, LCD_D4);


Pretty sure that was all i used to make it work :)

Oh and I changed the include to use
#include <LiquidCrystal.h>
instead of the SPI one.


snewpers

Not sure if there will be any response but I'll give it a shot anyway.

I would like to use it with and I2C LCD Library and would like to know what it is I should modify?

I've seen several different libraries but planning to use this one: Library

Thanks!

snewpers

in REBLDisplay.cpp

change to this...
void initLCD(uint8_t aRsPin, uint8_t aEnablePin, uint8_t aD1, uint8_t aD2, uint8_t aD3, uint8_t aD4) {

#ifdef USING_SERIAL
   Serial.begin(19200);
#else
   LCD = new LiquidCrystal(aRsPin, aEnablePin, aD1, aD2, aD3, aD4);
   LCD->begin(NUM_LCD_COLS, NUM_LCD_ROWS);
   LCD->noCursor();
   LCD->clear();
   //setColor(BLUE);

#endif
}

in REBLDisplay.h
Change to this
void initLCD(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t);

In your sketch add these
#define LCD_D1 4
#define LCD_D2 5
#define LCD_D3 6
#define LCD_D4 7

and change to this.
initLCD(LCD_RS_PIN, LCD_ENABLE_PIN, LCD_D1, LCD_D2, LCD_D3, LCD_D4);


Pretty sure that was all i used to make it work :)

Oh and I changed the include to use
#include <LiquidCrystal.h>
instead of the SPI one.


Tried all this but still loads of errors.

jasonmrc


tried your example but am getting this


exit status 1
'fun1' was not declared in this scope


I've been using this same code for a few projects now to create a user interface using a single rotary encoder and a button to drive a menu on an LCD as well as the various user input functions.  I got tired of moving the code from one project to another the hard way so I decided to condense it into a library.  And in response to a few recent posts I thought I would share what I'm doing.  It's called REBL_UI.

It currently uses a different LiquidCrystal library that uses a shift register to save pins on the Arduino and drives the LCD through a shift register on the SPI bus, but could easily be adapted to work with any of the existing flavors of LiquidCrystal with only a few lines of code needing to change.  If you need help with modifications, ask here or on my github page.

The code can be found on my github page along with my LCD library.  There is one simple example code included but for a bigger example see my Disco_Doser code on the same page. 

I don't know if you'll find it useful or not, but it doesn't cost me anything to share it so here it is. 

Link to REBL_UI repo.

Link to LiquidCrystal_SPI_8Bit

Delta_G

Which example?  Post exactly what you have on YOUR code.  Because the code in the example definitely has those functions defined. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Also trying to get the REBL_UI_Example to work:

Code: [Select]
Arduino: 1.8.5 (Windows 7), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

REBL_UI_Example:17: error: 'fun1' was not declared in this scope

    "display", fun1   }

               ^

REBL_UI_Example:20: error: 'pressToExit' was not declared in this scope

    "press", pressToExit   }

             ^

REBL_UI_Example:23: error: 'pickNumber' was not declared in this scope

    "enter number", pickNumber   }

                    ^

REBL_UI_Example:26: error: 'fourLetterWord' was not declared in this scope

    "enter string", fourLetterWord   }

                    ^

REBL_UI_Example:29: error: 'enterTime' was not declared in this scope

    "set time", enterTime   }

                ^

REBL_UI_Example:32: error: 'showTime' was not declared in this scope

    "show time", showTime   }

                 ^

C:\Users\uraynara\Documents\Arduino\REBL_UI_Example\REBL_UI_Example.ino: In function 'boolean enterTime()':

REBL_UI_Example:161: error: 'now' was not declared in this scope

      timeSetTime = now();

                        ^

REBL_UI_Example:169: error: 'setTime' was not declared in this scope

        setTime(timeSetTime);

                           ^

REBL_UI_Example:175: error: 'now' was not declared in this scope

      displayTime(now());

                      ^

C:\Users\uraynara\Documents\Arduino\REBL_UI_Example\REBL_UI_Example.ino: In function 'boolean showTime()':

REBL_UI_Example:192: error: 'now' was not declared in this scope

  displayTime(now());  // display the running time

                  ^

exit status 1
'fun1' was not declared in this scope


Post exactly what you have on YOUR code.  Because the code in the example definitely has those functions defined.  
This is your example, your code. I see the functions defined...so I'm confused. Maybe, where is the Time.h library?


Delta_G

where is the Time.h library?


It's the normal Time library that everyone uses.  You can pick it up off this site or from the library manager.
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Ok, so by Michael Margolis. Was there any resolution on how to fix the error?

I just don't understand how you got this to work, and it doesn't work for other people.

Delta_G

Thank-you to contributor per1234 on github for submitting the fix.  Code should be good now.
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Delta_G

The function not declared in this scope errors are fixed.  I just compiled on 1.8.5 and it works as it is now on the github.  Sorry for the errors. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Go Up