Learning (and remembering!) arduino programming :)

Hi!
I'm pretty new to arduino. I'm just doing it as a hobby :slight_smile:
I've got a business to run, plus 2 children so don't get as much time as I would like, to play around with it! I've got myself a book (Exploring Arduino) and also a starter kit that comes with a book. I'm really enjoying it, and I'm finding myself understanding the code, generally, but I'm buggered if I can remember it! Probably just cos I don't have that much time to practise and remember it.
I was thinking the other day that what I could do with is some sort of set of activities to run through, that kind of drums in the basics of the code, kind of like I'm at school lol.
Does anything like that exist?
Thanks!!

Lots of stuff about, start with this:-

The PDF found here is also a good one to follow:-
https://usermanual.wiki/Document/ArduinoBeginnersManual.57684979/html

The trick is not just to blindly follow what is put, but to give yourself a challenge about changing the behavior of each project, like can I add some flashing lights, or how can I make this code shorter.

Thanks Grumpy Mike! I will have a look at those :slight_smile:
And yes, good idea re changing the projects :slight_smile:

Another big help would be use use as many functions as possible in your program and add comments to remind you what the function does and what parameters are needed and what the returned result is. Then when you look at the program months later, you can say to yourself, "hey, I can use this function in my new program".

Paul

hanfromman:
but I'm buggered if I can remember it! Probably just cos I don't have that much time to practise and remember it.

I would not worry about failing to remember the details (such as the exact format of a digitalWrite() instruction) - you can always look that up on the web or in a book quickly. Maybe keep a notebook. I find that writing things down helps my memory - even without re-reading the notes.

What you do need to remember are the general concepts that are used to create a program - such as FOR loops and ARRAYs etc and what they are used for. Then you can approach a problem and say to your self "a FOR loop would be a good way to deal with this - I must look up the details of how to write a FOR loop". And the nice thing is that most of those concepts are applicable to most programming languages.

...R
Planning and Implementing a Program

Sorry hanfromman, I've forgotten what the question was! :confused:

Idahowalker:
https://www.w3schools.com/

Huh?

Robin2:
I would not worry about failing to remember the details (such as the exact format of a digitalWrite() instruction) - you can always look that up on the web or in a book quickly. Maybe keep a notebook. I find that writing things down helps my memory - even without re-reading the notes.

What you do need to remember are the general concepts that are used to create a program - such as FOR loops and ARRAYs etc and what they are used for. Then you can approach a problem and say to your self "a FOR loop would be a good way to deal with this - I must look up the details of how to write a FOR loop". And the nice thing is that most of those concepts are applicable to most programming languages.

...R
Planning and Implementing a Program

Yes this is exactly the sort of place I want to find myself - where I know the kind of coding I need for a project. I know that I could most likely find any code I wanted for any project and just copy and paste, but I want to be able to do it myself. I think my first project will be a robotic arm using servos and pots, and I would really like to be able to mostly write the code myself.
I think I will use a notebook as writing things down is the easiest way I remember things :slight_smile:

One of the most important parts of knowledge is knowing where you can look something up.

By learning C++ and writing some software you will quickly remember the main commands, the format of a for loop, if statements, etc. For many other things it's good enough to know about the existence of a command, so you can quickly look it up when you need it.

+1 for comments. Good comments are very important. Make sure you describe why you do something, not what you do. So not "setting output pin HIGH" (that's obvious from the digitalWrite(pin, HIGH) command) but "switching on the pump" (which is why you write HIGH to that pin). Some large projects I've been working on for a few years now, pieces of code remain untouched for long time, but my comments help me a lot in finding where to make a change later.

And indeed, start with the examples included with the IDE. They showcase many things the Arduino can do, and various coding techniques. Fool around with it, don't be afraid to break it, you can always fix it - and you will learn a lot doing both the breaking and the fixing, as long as you try to figure out and understand WHY it breaks and WHY it's fixed.

digitalWrite(pumpControlPin, HIGH);

would be even better, and would also probably eliminate the need for a comment. You could also go further and #define ON as HIGH so you could write

digitalWrite(pumpControlPin, ON);

or write a function to make it even more obvious what you are doing

void pump(byte state)
{
  digitalWrite(pumpControlPin, state);
}

and call it like this

pump(ON);

I've done the latter (create functions) in a project where pumps may be active high, active low, connected to an output pin or through a port extender... that was the only way to keep it manageable :slight_smile:

pin was maybe not the best name I could come up with. Naming variables for the function they do is another very good practice. As is adding the const keyword to variables that never change (and if you still try to, the compiler will complain).

The Arduino main site has a manual's worth of help pages to find and bookmark.

The main reference page:

The main link hub for most of the rest.

The link to the Foundations page has links to explain hardware and programming.

The Builtin Examples are in your IDE correct for your IDE version. The page for each has more explanation.

Whenever you bring up the Arduino IDE, also open a web browser with a tab set to the Reference Page and then whenever you see a command you don't completely know, look it up and refresh your memory with the right information and even the bits you knew anyway get reinforced. This is a neural thing, not a game, and never code when you're already tired as you'll screw your code and yourself up.

Open a tab to every page of help for your current sketch, be able to check quickly to have as clear a picture of what you're doing as possible.

What I like most about using web browser is zooming up the text. My eyes hardened a while back and books now require magnifiers to read but not my computer on 40" TV.

hanfromman:
I know that I could most likely find any code I wanted for any project and just copy and paste,

I suspect that is not nearly as likely as you think.

You would certainly be able to find examples that have similarities with your needs, or, better still, which demonstrate techniques that would be useful for you. But finding code that works in a new environment just with copy and paste is IMHO very unlikely. And, often, it is more trouble figuring out how some other person's code works (so you can adapt it) rather than writing your own code from scratch.

However you can learn a lot from studying the techniques used in other programs, even if the project may be very different from yours.

...R

Paul_KD7HB:
Another big help would be use use as many functions as possible in your program and add comments to remind you what the function does and what parameters are needed and what the returned result is.

+1

What I've been doing is summarizing right at the top any special techniques or features used in the sketch. This eliminates a lot of rummaging through each potential sketch, partially defusing the "I know it's around here somewhere." syndrome.

An example:

/*  PIN-CHANGE-IRQ-ENCODER

  Program to drive Buxton's encoder with pin change interrupts
  rather than external interrupts INT0 & INT1.

        Program Demonstrates:
        Pin change interrupts to encoder

  Lesson: Pin names are UNO board pin names, not AT328P names.
  A0 = 14, A1 = 15, etc.
*/

The worst mistake beginners make - is to approach a project as a single problem.

It takes time and discipline to STEP BACK, identify HOW your project is going to address the requirements - and then develop the individual pieces as individual mini projects.
They may not work together as-is, but you know HOW to approach the pieces of the puzzle!
S you gain experience, they will seem to fit together easier over time...!

To build a simple time based project which acts on a sensor to run a motor...
e.g. Set the time, check the sensor, turn on the motor, read the time, wait for something to happen...
These can all be developed and tested SEPARATELY, and only then combined to make a solution once they do what they’re supposed to...

As for LEARNING AND REMEMBERING the specific functions and statements - that’s just exposure and repetition while you’re making those small components of your project.

Start small and simple until you UNDERSTAND what each piece does, a
HOW it does it!

I found learning the basics of any language was important to me and doing the basic exercises.

I print out programs or sections of a programs for reference - sometimes I make extra notes about what and why or something I tried but did not work etc. and ALWAYS lots of comments and smart variable names

good luck