can an arduino program itself?

Not sure if that is the best way to describe it. Let me start by saying I'm a total noob, I have never used an arduino or anything similar, I haven't purchased one yet either. I have spent the past several hours learning about them so I have some idea of their capabilities, I wonder about one thing though.

Here is my project in a nutshell. 6 relays, 7 switches. 6 of the switches are for presets and 1 switch is to enter program mode. Basically you hit the program switch then for example switch 1, this allows you to program switch 1 so you then hit switches 2, 4 and 5 then the program switch which then saves what you did. If you then hit switch 1 it would turn on relays 2, 4 and 5. You could reenter program mode at any time and change which relays are activated by which switch. Is this possible? There's more to what it would do then that but that's the part I'm not sure an arduino can do.

I know I can do it with a PIC, I've seen it done, but I know nothing about them either lol. Frankly the arduino route appeals to me more because there is so much else I can do with a smaller learning curve as I understand it..

There is no "Program mode". There is a USB, a PC and code. You change the code and reload it to the arduino and at the end of the transmission the arduino resets and runs the code. That is not a mode, it's a
cycle of tasks or events. I don't know of any "program mode". What you are talking about is a program that
revolves around reads and writes to the EEPROM, based on switch presses. The program has some kind of
user feedback like leds or lcd, and polls a switch to determine when to enter the user input (variable values) mode after which (by polling the EXIT switch) it exits program mode. Whether the user input is stored when it is entered or stored after exiting program mode is up the programmer. The program is always running and code never changes so I would hesitate to call it "Program mode" because you are not
modifying any program. A more accurate name would be "Variable Modify Mode" because what you are in
fact doing is modifying variables used by the program.

Such a program is possible but I wouldn't go so far as to say it is trivial. Obviously you have a limited EEPROM memory but you probably wouldn't need much. I can't help you with that code but others can. Good luck.

If you are serious about doing this the first thing you need to do is change your post title to "User-initiated
EEPROM memory storage" or "sw triggered EEPROM writes" to attract forum members who know how to do that (of which I am not).

Yes, an Arduino can program itself. That's actually what you're doing when you Upload.

However, in this case that's not what you want to do. The important word is EEPROM. This will allow you to store variables in the memory which isn't forgotten when the power goes off. That way the Arduino will remember the switch order you programmed, without having to upload new code.

Yes, an Arduino can program itself. That's actually what you're doing when you Upload.

Not to split hairs but I think calling the Upload process "self-programming " is a bit of a stretch. I think it
is obvious from the post title that the OP meant a lot more than that. I wouldn't go so far as to say he was
hinting at AI but certainly more than uploading a sketch.

thuktun:
Basically you hit the program switch then for example switch 1, this allows you to program switch 1 so you then hit switches 2, 4 and 5 then the program switch which then saves what you did. If you then hit switch 1 it would turn on relays 2, 4 and 5.

This sounds like you want the user to be able to enter a sequence of actions and for the Arduino to remember that sequence and play it back later.

That is perfectly feasible if a suitable program has already been uploaded to the Arduino. As others have said, if you want the sequence to be remembered when the Arduino is switched off it will need to be stored in the EEPROM memory.

As @raschemmel has said the Arduino program is probably not trivial and would require a lot of careful thought at the planning stage.

...R

I know I can do it with a PIC

I haven't used a PiC for some years now, but all were high-voltage programming devices with no self-programming capability whatsoever.

Yes, you can do that!

It's not really "programming itself"... You are going to write the program so the Arduino's behavior changes according to the buttons that are pushed and the data that's stored.

You only need the EEPROM if the information needs to be saved when you power-off. If you need that feature, you can add it later...

Take a look at some of the examples and read-through the [u]Programming Reference[/u]. You won't understand (or remember) everything in the Programming Reference, but you'll get an idea of what you can do (and it's not that much to read-through). Pay particular attention to variables and control structures...

Variables "remember" their value, or the value can be changed... We can say X = 5 or RelayOne = ON, and the program will store that value (or state).

Conditional execution (if-statements, etc.) are how computers "make decisions".

Conditional execution and loops (doing things over-and-over) are the two things that make programming worthwhile. Once you understand those concepts, you'll start to understand how programs work.

Start simple and build (or "develop") your program. Do NOT try to write the whole program at once! Start with one switch and one LED. Then add a 2nd switch & LED, etc. It will be easier if you develop your program using LEDs before adding the relays.

One simple thing you could do to get started is this: Have two buttons and one LED (you can use the pin-13 LED on the Arduino board). Write a program where Button-1 turns the LED on when pressed, and off when the button is released. Then, every time you push Button-2 the logic is reversed, so the LED is normally on and goes off when Button-1 is pushed... Push Button-2 again to go back to the original logic... If you can figure-out the logic to do that, I think you'll be on your way...

raschemmel:
Not to split hairs but I think calling the Upload process "self-programming " is a bit of a stretch.

I disagree: when uploading a sketch, the Arduino processor is running the bootloader program, reading in the new sketch, and programming internal flash with that new program. It really is programming itself, in so far as it is programming new code into the program flash memory space. That is a very valid meaning of the word "programming" and I think is very close to what the OP is asking.

There is the other meaning of "programming" which is an intellectual activity involved with developing the software that gets programmed into the program flash memory. Clearly, the Arduino is not programming itself in that sense of that word, and it would require a significant amount of artificial intelligence to do so. But I don't think the OP is looking to do anything even remotely like that.

The OP is new. He doesn't know all of the terms and when to use them. Looking at the description of his project, it's pretty clear that he's not looking to write some artificial intelligence to make the processor develop new software. He's not even looking for the software to modify or reprogram the program flash memory.

When he says programming, it looks to me that he's looking for non-volatile data storage. His application enters a "program mode" which allows the operator to define (or "program") a desired output pattern so that it can be played back in "normal mode" when the correct stimulus is received. This isn't "programming" in either sense of term discussed above. It's simply writing the desired pattern into EEPROM.

To the OP: Yes, the Arduino does have the ability to do what you want. You can write software to read patterns of inputs and use the EEPROM library to store those patterns. They will be remembered while the power is off, and can be recalled later when that pattern is needed.

For a new person with no programming experience, it will not be a trivial or simple project. You will have to do more than a little learning, studying, and experimenting, before you get it to work. But by the same token, it's not rocket science, either. You will be able to do it, just don't expect to be able to do it the first day. DVDdoug has good advice about starting slowly.

You guys are harsh lol, but thanks for the input. I said I didn't know what I was talking about. By programming mode I didn't mean within the arduino it having a mode, I meant that switch would be setup to allow me to save settings to the other switches, program mode for me basically.

Anyway, sounds like I can do it with the EEPROM so problem solved. Now to buy one and start learning. I expect a steep learning curve but no biggie, I've taught myself complicated things before.

It never occurred to me that you might have meant simple variable modification as DVDDOUG suggested.
I don't know why but I thought you meant modify values that would not change when power is turned off.
You haven't given any reason why you need that feature. I think you would be fine just incrementing variables with switches and possibly printing out the modified value to the serial monitor. Why not just do
that ? Why do you need the changed values to be saved after power off ? Just read the switches and modify the variables using a SWITCH/CASE routine.

I disagree: when uploading a sketch, the Arduino processor is running the bootloader program, reading in the new sketch, and programming internal flash with that new program. It really is programming itself, in so far as it is programming new code into the program flash memory space. That is a very valid meaning of the word "programming" and I think is very close to what the OP is asking.

I disagree. I don't think it is anything close to what the OP is asking because he clearly stated he wants to
modify variables using switches and store the modified values, which is clearly much more that downloading code, not to mention that downloading the code isn't going to get him anything if the code hasn't been modified (which can only be done in the IDE). Variables (either in RAM or EEPROM) he can modify with switches and store. Downloading the sketch doesn't get him anything , despite that it is technically "self-programming", it doesn't address the OP's goal is not relevant to this post unless you can tell us how he can make the arduino modify the binary code that has been downloaded by the IDE which has already compiled the C code in object files and then converted them to binary for downloading.

raschemmel:
I disagree. I don't think it is anything close to what the OP is asking because he clearly stated he wants to modify variables using switches and store the modified values, which is clearly much more that downloading code

We can agree to disagree. I have no problem with that. It's a matter of semantics: you said that uploading code is not "self programming" but in one meaning it is. However, it IS clearly NOT the OP's intent, I will definitely give you that.

I don't have an issue with the OP wanting to remember the "programmed" output in non-voltaile memory. It's a common requirement to not have to "reprogram" a "programmable" device every time the power is applied (using the OP's meaning of "program.") And storing non-volatile data is not at all "more more than downloading code." It's a relatively simple call to the EEPROM library. The EEPROM is a third memory region in the MCU (in addition to RAM and program flash) that is specifically designed for this purpose. It may not be a "this is my first day programming, let's' do this" type of concept, but it's not highly esoteric.

(Rant on) I think Shapeshifter is absolutly right in this case, Rasch..... is simply being picky and argumentative to a noob - pretty typical. (Rant off)

Now for the OPs question, think of his operation as setting the preset on the radio in your car... you "program" a button to recall a specific station when pressed. So, is this self programming? I think it could be viewed this way as you certainly do not plug in the laptop to change the persets in your car. So with this in mind the answer to the OPs question is YES it can do what he wants. The code required is above trivial but below extensive. I think it could be a good learning project as it would involve Eprom operations, button input actions, variable manipulation, most likely bitwise operations (define a byte to control the relays by button) and other I/O operations. I think it would be a great project...

R

I think we're on the same page about the best approach for the OP. As far as being "picky", I guess it comes down to the question " is storing variables" considered "self-programming". There's no point in debating that.

The OP is new and doesn't know the jargon. From his point of view (and from the viewpoint of the users of his project) the processor is being "programmed" when it is trained for the desired output. It doesn't matter so much what it's called. What matters is whether it can be done, and can we help him achieve that goal? I think the answer is yes on both accounts.

Agreed

raschemmel:
Agreed

+1

R

Apart from the question of scale and complexity there is no difference in principle between what the OP wants to do and the business of writing a Python interpreter for a PC. Python is a program. But nobody would use any word other than "programming" to describe the business of writing a Python program. In actual fact Python code is just data for another PC program (the Python interpreter). In the same way the OPs switch patterns are data for the underlying Arduino program. The Arduino uses its EEPROM in a similar way to which an PC uses a Hard disk.

...R