Very basic menu.

@ jurs Sorry for my english , i am dutch. I like to adjust a DIY bench power supply with a rotary knob.

For now the menu structure i think:

mainmenu: Outputrelais on/off with the button (panic) Adjust Volt Adjust Current

submenu Volt -> 5 x preset -> adjust 0-35 volt submenu Current -> 5 x preset ->adjust current limiter

Therefor I have setup a nano3 + LCD 2x16 + rotary knob with button.

I found your sketch and a test with that give me a very nice and smooth control feeling. :) I like it.

I have loaded your sketch and edit the LCD and knob pinning. The start menu is OK. Then i press button , ive get the next menu started with "Set Date" and if a rotate i get the next items till "Exit". When i push the button at Ëxit" i return to main menu. All fine.

My problem: I can not change the "Set Date" item or other items in the submenu. :confused:

Can you help me.

Ben

BenI2C: I have loaded your sketch and edit the LCD and knob pinning. The start menu is OK.

Oh, miracle! At least one person has actually loaded AND tested the rotary encoder menu code I posted!

BenI2C: Then i press button , ive get the next menu started with "Set Date" and if a rotate i get the next items till "Exit". When i push the button at Ëxit" i return to main menu. All fine.

My problem: I can not change the "Set Date" item or other items in the submenu. :confused:

If you want to edit the date, press the knob while "Set Date" is visible, then the editor is activated and a cursor appears. You than can rotate the cursor left/right to the digit you want to change, then press the knob to change the value. You can finish editing mode by rotating the cursor to the right end of the line ("abort editing") or if you move the cursor on "OK" and press the button ("Finish and save value").

I'm wondering if you fully have understood, what's currently built into the code.

After the menu has been activated it is as easy as that: - no underline cursor visible: You can switch between different menu items - underline cursor visible: You are in edit mode and can edit the selected item

There is nothing like a two-level menu system, but it is a one-level menu and data entry system.

Editing (underline cursor visible) is simply done by pressing the knob: Rotate cursor left/right to the digit you want to enter, then press the knob and the digit will change with each keypress.

BenI2C: For now the menu structure i think:

mainmenu: Outputrelais on/off with the button (panic) Adjust Volt Adjust Current

submenu Volt -> 5 x preset -> adjust 0-35 volt submenu Current -> 5 x preset ->adjust current limiter

Currently no other editing than "date" and "time" is supported, but it would be possible to create different editors, i.e. for editing numbers and boolean values.

A possible menu for doing settings, adapted for your application would be perhaps (not implemented yet, but could be done):

menuitem_t menuitems[]={
  {10, '2', ' ', (char*)"Set Voltage-1"}, // 2-digit voltage (V?) editing
  {11, '3', ' ', (char*)"Set Current-1"}, // 3-digit current (mA?) editing
  {20, '2', ' ', (char*)"Set Voltage-2"},
  {21, '3', ' ', (char*)"Set Current-2"},
  {30, '2', ' ', (char*)"Set Voltage-3"},
  {31, '3', ' ', (char*)"Set Current-3"},
  {40, '2', ' ', (char*)"Set Voltage-4"},
  {41, '3', ' ', (char*)"Set Current-4"},
  {50, '2', ' ', (char*)"Set Voltage-5"},
  {51, '3', ' ', (char*)"Set Current-5"},
  {88, 'B', ' ', (char*)"Emergency OFF: false"}, // boolean option setting (true/false)
  {99, ' ', ' ', (char*)"Exit"},        // exit menu option
};

That would require to add some new editors to the menu: - a 2-digit editor for volts - a 3-digit editor for milliamperes - a boolean value editor

Edited values are to be saved to EEPROM, so that the current settings are to be loaded after a power failure from EEPROM, before the program starts executing again, correct?

Such like that? Or can you better explain the details about what you want?

Thanks jurs for your reply.

jurs: If you want to edit the date, press the knob while "Set Date" is visible, then the editor is activated and a cursor appears.

My problem is: -> NO editor is activated if i press the button! So no cursor.

BenI2C: Thanks jurs for your reply.

My problem is: -> NO editor is activated if i press the button! So no cursor.

My code uses these two functions for switching the cursor on and off:

  lcd.noCursor(); // switch underline cursor off
...
  lcd.cursor(); // switch underline cursor on

Did you do test with a short test sketch, that the LCD library you are using is providing these two functions and that they are working as they should? I've tested the code with the "Liquidcrystal" library that comes with the Arduino-IDE.

I have loaded the code from you before. -menuRotary.zip- Arduino -IDE 1.6.5 I think the cursor appears ONLYy if editor is activated. I cant activate the editor :confused: .

BenI2C: I think the cursor appears ONLYy if editor is activated.

That's correct: The cursor appear ONLY if the item editor is activated.

And in my demo the item editor can only be activated if the menu item is of type "D" (date editor) or "T" (time editor).

BenI2C: I cant activate the editor :confused: .

Did you do any changes to the demo code that I provided?

If so: Which changes?

The only i have changed:

LiquidCrystal lcd(12,11, 10, 9,8, 7); // initialization for LCD Keypad Shield
  #define LCDWIDTH 16
  #define ENCODERPIN_A 3
  #define ENCODERPIN_B 2
  #define BUTTONPIN 4

BenI2C: The only i have changed:

LiquidCrystal lcd(12,11, 10, 9,8, 7); // initialization for LCD Keypad Shield
  #define LCDWIDTH 16
  #define ENCODERPIN_A 3
  #define ENCODERPIN_B 2
  #define BUTTONPIN 4

So you are using the default LiquidCrystal library, too. So the results should also be the same, too.

I just looked up the Arduino release notes for v.1.6.5 and found that:

ARDUINO 1.6.5 - 2015.06.15 ... [libraries] * LiquidCrystal fixes. Thanks @newbie15

Possibly that were "bad fixes" done. Do you possibly also have an older Arduino version you can test? The code I posted was tested with IDE v1.0.5 and v.1.6.4, so I think, everything in between should be OK.

But after I see this weird "LiquidCrystal fixes. Thanks @newbie15" in the release notes for v1.6.5, I possibly have to install and check my code and hardware with v.1.6.5, too.

I'll have to install v1.6.5 and then search and install some LCD and encoder to an Arduino board, as the hardware is currently not ready here.

So stay tuned - may take a day or two to test it with v1.6.5 and the "fixed" Liquidcrystal library in that version.

Thanks so far. Can i enter/test the editor mode whithout a the cursor ?

jurs: Oh, miracle! At least one person has actually loaded AND tested the rotary encoder menu code I posted

I have loaded both codes you posted and work well, I've did some testing but found I selected to set date but nothing happened scrolled through got exit which worked. I used the I2C LCD library. I will see about getting it loaded back up over the next couple of days and start playing again. I did read it quite a lot to get a better understanding how your codes work and managed to add a couple of extra menus to your first sample

I should have replied earlier but been playing with another project will post results soon

Great share Jurs and I've learnt a lot from your sample

Steve

The same problem ?

I'm not sure if it was would have to reload code and see what happens and record it so I can report here has I can't quite remember the problem

BenI2C:
Thanks so far.
Can i enter/test the editor mode whithout a the cursor ?

Editing values without a visible cursor doesn’t make much sense.
So you’d need a visible cursor to mark the digit that is actually editable.

Do you have an RTC connected to the I2C bus?
Tested with an RTC test sketch and fully working?
The sketch is intended for an DS1307 or DS3231 RTC.

If you have no RTC, you’d better deactivate the RTC option.
Replace line defined option 1:

#define RTCOPTION 1  // 1= use RTC (DS1307 or DS3231 possible), 0= no RTC

with line defined option 0:

#define RTCOPTION 0  // 1= use RTC (DS1307 or DS3231 possible), 0= no RTC

In that case the sketch doesn’t try to use any RTC in the sketch.

I’m not able to create a test environment today. No hardware ready for testing.

The 1602 LCDs also offer two types of cursors: Underline cursor (non blinking) and block cursor (blinking).

My sketch currently uses the underline cursor only. But it should also be possible to use the blinking block cursor to indicate the digit that is currently active for editing. But that would require a small change in the code.

Perhaps tomorrow I can do some tests with hardware, the new Arduino 1.6.5 IDE and the menu code.

Stay tuned!

Yes, i did set the RTCOPTION to 0. I am waiting :)

BenI2C:
Yes, i did set the RTCOPTION to 0.
I am waiting :slight_smile:

I’ve just checked with my original download file that was attached to reply #15
and I must admit: You are right, this programming example is NOT fully working with value editing.

Somehow I must have managed to upload a wrong file. Sorrry, I don’t know how it could happen.

I include new rotary menu code (tested with Arduino 1.0.5, 1.6.4 and 1.6.5r5) with this posting.

To get things working for you easily, I’ve included your changed LCD and button settings as USEROPTION 2.

So if you like to test without RTC, set:

#define RTCOPTION 0  // 1= use RTC (DS1307 or DS3231 possible), 0= no RTC

And to create code for your LCD and button settings, set:

#define USEROPTION 2

With this code, the date an time editors should activate with a visible “underline” cursor at the position that is editable.

When in edit mode rotate cursor right to abort edit mode (value not saved)
When in edit mode to SAVE value, rotate to “OK” and press button

Is that code working?

menuRotary.zip (6.29 KB)

YES YES it's working! so far. Now i will look how the menu structure. Thanks

There is a little mistake in your new code :
line 57

#include <LiquidCrystal.h>

must before line 55.

A possible menu for doing settings, adapted for your application would be perhaps (not implemented yet, but could be done):

menuitem_t menuitems[]={
  {10, '2', ' ', (char*)"Set Voltage-1"}, // 2-digit voltage (V?) editing
  {11, '3', ' ', (char*)"Set Current-1"}, // 3-digit current (mA?) editing
  {20, '2', ' ', (char*)"Set Voltage-2"},
  {21, '3', ' ', (char*)"Set Current-2"},
  {30, '2', ' ', (char*)"Set Voltage-3"},
  {31, '3', ' ', (char*)"Set Current-3"},
  {40, '2', ' ', (char*)"Set Voltage-4"},
  {41, '3', ' ', (char*)"Set Current-4"},
  {50, '2', ' ', (char*)"Set Voltage-5"},
  {51, '3', ' ', (char*)"Set Current-5"},
  {88, 'B', ' ', (char*)"Emergency OFF: false"}, // boolean option setting (true/false)
  {99, ' ', ' ', (char*)"Exit"},        // exit menu option
};

That would require to add some new editors to the menu: - a 2-digit editor for volts - a 3-digit editor for milliamperes - a boolean value editor

Edited values are to be saved to EEPROM, so that the current settings are to be loaded after a power failure from EEPROM, before the program starts executing again, correct?

Such like that? Or can you better explain the details about what you want? [/quote]

Almost such like that. :) The voltage 3 digit like: 21.7 V 0-35.0 V The current also 3 digit like: 1.25 A 0-4.00 A

Is that possible ? Can / will you help me with that (the basic) ? :(

BenI2C:
There is a little mistake in your new code :
line 57

#include <LiquidCrystal.h>

must before line 55.

Yes, indeed. Either before the #if section, or within the branch of each USEROPTION like

#elif (USEROPTION==2)
  #include <LiquidCrystal.h>
  LiquidCrystal lcd(12,11, 10, 9,8, 7); // initialization for LCD Keypad Shield
  ...

I’d prefer to include the library within the USEROPTION, that way it would be easy to include and provide different “alternative” LiquidCrystal libraries in one source codes. Some programmers prefer the original LiquidCrystal library as provided by Arduino. Others may prefer an I2C-LCD and like it more to include an alternative LiquidCrystal_I2C library in some cases.

BenI2C:
Almost such like that. :slight_smile:
The voltage 3 digit like: 21.7 V 0-35.0 V
The current also 3 digit like: 1.25 A 0-4.00 A

Is that possible ?

Many things are possible. So from what you tell you rather need

  • editors for floating point numbers and
  • some possibility for range validation (that the user can only enter values in the valid range)

I will have to think a bit about it.

Most likely, the code needs some heavy rewrite to become a bit more structured when adding different new features, like editing whole numbers, float numbers with different digits, and range check validation.

BenI2C:
Can / will you help me with that (the basic) ? :frowning:

That should be possible. If I find some time the next days, I’ll give it a try to do some extended version with some features added. But as I told, the data structures and the code possibly need a heavy rewrite when adding features.

I have tested your last code tonight, and charmed of the really smooth control. So i wait till you have some extended version. I stay tuned :)