Personally I use a lot of Arduino Ethernets. I have the type of program, serial number, version and machine type (In what kind of machine) it is installed programmed as MAC address. So whenever the units send a UDP message, it's included.
But perhaps this information is a bit to project specific...
Try it with a small subroutine, if a certain string is received by serial or something else, output the data your want (Serial, version and such...)
Whoosh, appreciated your replies, but that was the sound of your answers going above my head
I may be going about this the wrong way, perhaps I'm being simple in thinking I could connect the 'duino then run the interface and check what was loaded that (somehow) ?
I think I can see where you are coming from but I've not got to grips with the serial interface yet..
Thanks. M<cP.
By adding a piece of code to your sketch, it can return a string of characters to your interface with the device name and whatever you want to add.
For example:
const char check = 'A'; //If the input from serial monitor is the same as this, do something!
byte input; //A container to hold the incoming data.
void setup() {
Serial.begin(9600); //Set the baud rate
}
void loop() {
if(Serial.available()) //Listen to the serial port, if there is a (or more) bytes available, execute next command
input = Serial.read(); //Put the first byte that is in the serial buffer into the container
if(input==check) //If the byte in the container is exactly the one from the check,
{
Serial.println("This is a test, nothing more!"); //Then execute this!
input = 0; //And this! empty out the container or it will run constantly!
}
}
(Just something I threw together...)
This listens to the serial port and if there is a byte ready, it reads it. Then, if the byte is equal to the check ('A' in this example), it outputs a string that can contain anything you want.
If instead of that string you input something of your own, you can always check the program you have written to the device.
You could also expand the input. If for example the character 'A' is a frequent character that is send to the device, have something with more characters in the check.
RobMcp:
thinking I could connect the 'duino then run the interface and check what was loaded that (somehow) ?
You can't do that. The code that is uploaded to the Arduino is a series of numbers that are meaningless to a human. You can (with a bit of effort) download that code but it would be very difficult to make sense of it.
What others have been suggesting is to include a few lines of code in your programs so that they identify themselves when they are started. Obviously that is something you must do before you upload a program and if you have already uploaded a program without including some identification code there is no easy way to know what that program is.
This is probably trying to close the stable door after the horse has bolted, but I take a different approach.
I created directory structure that helps me quickly find the code I want to use.
Each piece of code is named after its function/application and features of the code.
Something like : Function_for_BoardType_with_CodeFeatures
For example : SH-RF_for_iBoard-ex_with_Rx_SDCard_Serial.ino
and as a comment at the top of the file I list all the hardware and model # it is written for.
I use 2 main directories for filing code viz test and project.
Under test I file snippets used to test/build bits of code for a project.
Under project I file working code for specific applications.
I have about 10 different boards, so in this way I don't care what is on which board, I simply select the code I need and flash the board I want to use.
But to directly address your question, I have another question (to which I don't know the answer) but someone else might.
If I recall correctly, Nick Gammon created a utility to upload a HEX file to an Arduino rather than programming through the IDE (or something like that). So my question is, is it not possible to download/extract a hex file from an Arduino, which can then be read in the IDE.
It's partially true. There is a function in AVRdude to "check" the HEX file of the uC to one you supply, if the correct fuses are not set. It's also possible to store the HEX file.
But i'm not 100% sure if the HEX file can be read with an application to create a readable code.
I use a version control system with branches and tags for important projects. When I put software onto an Arduino that is going away to someone else, I create a tag for "This version given to Bill."
That way if Bill has a problem in the future, I can always go back and grab his exact code and load it onto one of my test boards.
I also create tags for each revision of the hardware: "This version tested on PCB 1.1"
Even the unimportant projects get saved in version control although not always with branches and tags. If I need to go back to the "First attempt at demo sketch for 4.3" LCD" then I can.
C-F-K:
It's partially true. There is a function in AVRdude to "check" the HEX file of the uC to one you supply, if the correct fuses are not set. It's also possible to store the HEX file.
But i'm not 100% sure if the HEX file can be read with an application to create a readable code.
Could that be a "Maybe" rather than a resounding "No"?
I would have thought that if one is able to check a loaded file against another file and determine that they are the same, then that would be tantamount to having found out "what the last program was that was uploaded to an Arduino".
The caveat of course being one would have to have a matching file to get a definitive answer.
From C-F-K's post it seems this may also only work "if the correct fuses are not set".
Could that be a "Maybe" rather than a resounding "No"?
Given that the OP said the answers were going over his head it is a resounding No.
Given another 6 to 12 months of study in this subject the OP will maybe understand it can be done but it is plainly not worth doing. All that need to be done is to load in the sketch you want to use. It is far far quicker to do this than to extract a code dump, edit it and then go and compare to the compiled versions of everything he has in the hope of identifying what sketch it was.
You can easily dump the flash with AVRDude (you can't dump the EEPROM quite as easily, since the Arduino bootloaders don't support doing that, though you can get it with an external in system programmer like a USBAsp).
But that will just give you a .hex file, that probably isn't very useful - the only useful bit of data you can get from it is probably that you can see how much of the code space is used (ie, by seeing what portion has data, and how much is blank)... This is probably not enough to tell you anything useful, though.
The question "which sketch is uploaded to this Arduino" can be answered definitely, provided that
all sketches have been retained in source code
the flash can be read back
Then one can create the hex files of all sketches, for the given board, and compare these against the read-out of the flash.
A decompiler also is feasible, I wrote my first C decompiler 30 years ago. Question is whether it will help the user, lacking names of all subroutines and variables. Only the identifiers in standard libraries can be recovered.
If the op is uploading code, then put something identifying in the setup section like below to send to the serial monitor when the arduino boots up. Trying to decompile unknown code will be a problem.
void setup()
{
myservo.attach(7, 400, 2600); //servo control pin, and range if desired
Serial.begin(9600);
Serial.println("serial servo incremental test code");
Serial.println("type a character (s to increase or a to decrease)");
Serial.println("and enter to change servo position");
Serial.println("use strings like 90x or 1500x for new servo position");
Serial.println();
}