Absolute Beginner Help with Menu Select

I was really looking for a beginners section but it looks like there isn't one. Anyway here we go and if the moderators feel it needs to posted into the dark recesses of the back and beyond then so be it.

I have a couple of UNO's and the LCD Keypad Shield modules which I want to use to control a mini precision Surface Grinder I have made. Basically it is a CNC Mill with X, Y and Z axis stepper motors. I am famiar with Microchip programming using GCB (Great Cow Basic) a coding environment.
These clone UNO's are as cheap as chips (I picked up 5 UNO's c/w Keypad Shields for £15 on AliB last night.

I realise this is a huge project but I am prepared to tough it out. I have found some code on here which allows me hit the five buttons and it translates the AD converter to write up, down, Left etc and print the output on the LCD

For my first task I want to create a menu structure to where the select key moves to the next option. There is a couple I have found but I cannot get them to compile or they use external Push Buttons.

As I said, I'm an absolute beginner with Arduino coding - so please be gentle with me.

There is plenty of beginner material on this forum (see Introductory Tutorials) and built into the Arduino IDE under File>Examples.

Experiment with some of them to start learning the programming language and the special features of the Arduino (reading sensors, sending digital commands, etc.).

If you don't, expect a great deal of frustration, as the C/C++ programming language bears little to no resemblance to Basic.

Hint: "Menu Select" is the very last thing to do. Get motor control working first.

Welcome to the forum

The Project Guidance section of the forum will do for now but the topic may get moved to the Programming section at some time as it progresses

Navigating through a menu system by reacting to button presses is fundamentally the same whether the button press detection is done by reading an analogue input as I suspect it will be for your shields, or by detecting a keypress of a button connected to a digital input

The important part is detecting the keypress then reacting to it using something like

if (upButtonPressed)  //LCD shield button
{
   //  code here to move up a menu level
}

or

if (digitalRead(upButton) == LOW)  //digital button
{
  // code here to move up a menu level
}

I invented the variable names, but you will find something similar in the sketches that you have

Thank you so much for the replies. It is good to know "Newbies" aren't treated with a hint of cynicism or contempt. Going to spend a bit of time with the Arduino IDE settings first.

Newbies are generally welcomed in the forum as long as they show some effort to do things for themselves, for which they are richly rewarded with help with problems

What rankles is a post entitled URGENT ! in which it turns out that an assignment is due to be handled in soon and towards which no effort has been made

That generally gets short shrift

Is your shield like the DFRobot "1602 LCD Keypad Shield For Arduino"?

You may have some trouble since the LCD uses seven pins, and the 5 buttons use pin A0, leaving not many for 3-axis CNC. It will be good for practice designing your user interface (menus). Note: They say '6 buttons' but one of those is a processor reset button so it's not very useful for menu selection.

For your actual CNC device you may need to switch to an I2C-interfaced LCD. They only use two data pins.

Assignment's Oh how I wish. My last assignment before my dissertation was when I was 53 and taking my masters in Computer Science at Sheffield Hallum as a distance learner. if my arithmetic is right that was 20 years ago. Time fly's when your having fun. Yes, your arithmetic is right I'm 73 years young.

As for my i/o lines I need 13 ports, 3 for each Stepper Driver Module, an E-Stop Line and three limit inputs. (I hope that I am reading my schematic correctly)

My Flow Diagram. Hope this displays correctly

Start
Edit Swing in mm Read EEProm-Display current value Numeric Count Up/Down - Save to EEProm
(Select to Move on)
Edit Sweeps Read EEProm-Display current value Numeric Count Up/Down - Save to EEProm
(Select to Move on)
Edit Y Drop/mm Read EEProm-Display current value Numeric Count Up/Down - Save to EEProm
(Select to Move on)
Run Sequence – Are you Sure – Y/N
Edit X Steps/mm Read EEProm-Display current value Numeric Count Up/Down Save to EEProm
(Select to Move on)
Edit Y Steps/mm Read EEProm-Display current value Numeric Count Up/Down Save to EEProm
(Select to Move on)
Edit Z Steps/mm Read EEProm-Display current value Numeric Count Up/Down Save to EEProm
(Select to Move on)
Return to Start
As for my conviction to the project. The only thing I can add is that I want to learn and with the help of you kind people I'm sure I will.

That sounds reasonable. The UNO has 20 pins that can be used for digital I/O. That include the two used for Serial I/O (0 and 1) and the six that can also be used for analog input (A0-A5). It is a good idea to retain Serial for I/O and debug logging.

If your CNC machine uses 13 and Serial uses 2 you only have 5 pins available. Unfortunately that is less than the 8 needed for an LCD Shield. If you get an I2C LCD (2 pins) you will have 3 pins left for buttons. You can use an analog input pin for a few buttons (maybe up to 8?).

Note: A 4x20 LCD doesn't cost much more than a 2x16 and might make the user interface easier.

I'm busy phaffing around with an I2C adapter which allows me to use an I2C output. I also have a 12864ZW GLCD which I would love to get up and running on this project. I don't seem to be able to find any project which has used this.

Just a comment:
The way this forum approaches "C++ code" there is lots of truth to the phrase, "bears little to no resemblance to Basic."

But, if a newbie with BASIC language knowledge starts with the Arduino language as provided in Language Reference then many of the Functions and Commands do have much in common and a beginner will not be overly intimidated.

What generally happens is that newbies want to jump into deep water and not take a regimented approach at learning Arduino; that is, something on the Internet has captured there curiosity or some posted Arduino project is something they would like to do but with more features. Beginners have an amazing misunderstanding of writing code: it is not a language issue, rather it is a lack of experience "issue."

Ray B.

Given up trying to get that 12864Z GLCD to crack into life - could be goosed as it has been rattling around in my goodies box for a fair while. Not to worry !

Time to crack on with my project and my very steep learning (re-learning) curve.

What I have decided is to ignore the port count restrictions for the time being and concentrate on the program until such time as I am ready to implement the module to the hardware (CNC Surface Grinder) and if the port count issue proves a problem then take a look at the Arduino Mega - That thing has more I/O Ports than you can shake a stick at !
Which begs another question, it says in the sales blurb that it will take the Keyboard Shield ??? Y/N

I need to know where I can find a list of the code instruction commands and a brief explanation of what they do. (GOTO, GOSUB, LOOP etc) I can imagine the function is the same as BASIC, but I making a rash statement there.

Could someone point out an example of how to write a variable, do I need to declare it?

What I want to do in the fullness of time is on line 2 (lcd.setCursor(5,1) ) show a numeric value read from EEProm and be able to increment or decrement with the ButtonUP and ButtonDOWN keys, then when the Select button is hit save the value back to EEProm and advance to the next option. I need to understand how it handles and displays numeric values first.

Apologise if there are more questions than answers. All replies and help are greatly appreciated.

The Arduino is programmed in C++ with extensions to interact with the chip hardware. Read up on C++ and look at the examples in the IDE and Arduino Reference - Arduino Reference as previously suggested

Thank you Bob, ( I hope that is right) Exactly what I'm looking for.

Could some kind person point out the errors of my ways and put me out of this misery.
Taking advise from above I have a 4x20 LCD Display hooked onto my Uno via an i2c serial adapter which works fine with simple lcd.print statements. Now what I am trying to do is couple some code in which will allow me to generate some special characters (mickey mouse stuff to start with)
What I think I have done wrong is either put Void Loop() in the wrong place or I have put a loop within a loop - Muppetry I know but as this my first week on the job I don't think I'm doing too bad.

The error I am getting when I go to compile is:-
"a function-definition is not allowed here before '{' token"

I have been over the code like a nasty big rash and for the life of me I cannot find the problem.

Here is the code:-


//*
//Arduino 4x20 LCD - LCD Special Char

//sketch created by Akshay Joseph
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F, 20, 4);   // 20x4 LCD Display

void setup()
{

  lcd.begin();


  lcd.backlight();
  lcd.clear();
  lcd.setCursor(2, 0);



  // smily face
  byte smiley[8] = {
    B00000,
    B10001,
    B00000,
    B00000,
    B10001,
    B01110,
    B00000,
  };
  // Battery Low sign
  byte battery_low[] = {
    B01110,
    B01010,
    B11011,
    B10001,
    B10001,
    B10001,
    B11111,
    B11111,
  };
  // Battery Full sign
  byte battery_full[] = {
    B01110,
    B01010,
    B11011,
    B10001,
    B11111,
    B11111,
    B11111,
    B11111,
  };

  // arrow right
  byte R_arrow[8] = {
    B00000,
    B00100,
    B00010,
    B11111,
    B00010,
    B00100,
    B00000,
    B00000,
  };
  // arrow left
  byte L_arrow[8] = {
    B00000,
    B00100,
    B01000,
    B11111,
    B01000,
    B00100,
    B00000,
    B00000,
  };
  // Ohm sign
  byte ohm[8] = {
    B00000,
    B01110,
    B10001,
    B10001,
    B10001,
    B01010,
    B11011,
    B00000,
  };
  // Heart
  byte heart[8] = {
    B00000,
    B01010,
    B10101,
    B10001,
    B10001,
    B01010,
    B00100,
    B00000,
  };
  int i = 0;
  void setup() {
    lcd.begin(16, 2);
    lcd.createChar(0, smiley);
    lcd.createChar(1, battery_low);
    lcd.createChar(2, R_arrow);
    lcd.createChar(3, L_arrow);
    lcd.createChar(4, ohm);
    lcd.createChar(5, heart);
    lcd.createChar(6, ohm);
    lcd.createChar(7, battery_full);
    for (int n = 0; n < 8; n++)
    {
      lcd.setCursor(n * 2, 0);
      lcd.write(n);
    }
  }
  void loop() {
  }    

If you Auto format your sketch in the IDE you will see that it ends like this

    for (int n = 0; n < 8; n++)
    {
      lcd.setCursor(n * 2, 0);
      lcd.write(n);
    }
  }
  void loop()
  {
  }

The problem here is that you don't seem to have a closing brace at the end of setup()

To add to this you appear to have 2 setup() functions !

what bob said.

Thank you so much for pointing that out to me (Muppetry absolute Muppetry on my behalf ! ) it compiles and displays correctly.

I don't know how I managed to miss out that second void setup()

Need to do some more research on void setup() and void loop(), I bought a book from Amazon C++ for Dummies but it is a bit vague on either of those keywords. Having said that it is just a tad bit smaller than "War and Peace" so it is probably in there somewhere.

Thanks again

The setup() and loop() functions as used in the Arduino environment will not get a mention in a general book on C++. You would be better off getting a book specifically about the Arduino to start with, even

I thought about that when I ordered it.........

"I'm sure if I fall into a barrel of Boobs, I'd come out sucking my thumb !"

I'll order that now. Thanks again.

That was not a recommendation, just an example. Others may have other suggestions

Note too that the Arduino is programmed in C++ so your other purchase was not wasted