Notifications
Clear all

Identifying code loaded on Arduino

9 Posts
7 Users
7 Likes
896 Views
(@ozcraig)
Member
Joined: 4 years ago
Posts: 9
Topic starter  

Does anyone know of a method of being able to identify which code is loaded to an Arduino board? For example, I have several boards of the same type, and once I put them away in the box for a couple of days I don't know what code is on what board. Is there a way to connect the board to the laptop and identify the code on that board?


   
Quote
MadMisha
(@madmisha)
Member
Joined: 4 years ago
Posts: 340
 

An easy and simple way, not that I know of. If the security bit is not set then theoretically you can get the hex code off of it but it will not be the C++ you wrote. If I remember right, you would have to use something like avrdude.

 

I have always had the thought of including a label to print to serial with the name of what it is but I never do it. I probably should.

 

But with this in mind, it would be nice if there was a plugin for VSC that would log what you uploaded and can identify the last thing VSC uploaded to that Arduino. I'm not sure how it would recognize and track though. I suppose when compiling it could slip a code in that could act like a serial key. Increment up one each time and when pulling the machine code off, it could then identify it based on its own logs.


   
ReplyQuote
(@yurkshirelad)
Member
Joined: 3 years ago
Posts: 493
 

A very simplistic approach would be for your code to log a code to serial, that identifies the s/w functionality/purpose and version. You'd have to boot up the microcontroller and monitor the serial output to check each one though.


   
ReplyQuote
Centari
(@centari)
Member
Joined: 4 years ago
Posts: 44
 

@ozcraig, I've gotten to where I always start the serial routine and have it pass the program name back to the terminal.  The name I saved the program under.


   
ReplyQuote
TheOutlander
(@theoutlander)
Member
Joined: 3 years ago
Posts: 79
 

Good idea on serial output to ID the code. I added the hostname and IP address to the display of my temp/humidity sensor when it restarts (displays for a few seconds be temp/humidity is displayed). Awkward if project does not include a display!

 Sorry for the repeat, I think I posted this before. 

Would be easy to add another few seconds of displaying the program ID. 

Now...where did I put that code .........

"Hardware eventually fails. Software eventually works." - Michael Hartung


   
YurkshireLad reacted
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

@ozcraig

I always include the following as a minimum in my setup() routine:

String fileName="ProgramNameGoesHere.ino";
String codeVersion="1.0";

#define __FILENAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// Print splash sheet to monitor
Serial.print("Source file: ");
Serial.println(__FILENAME__); // Source file name
Serial.print("Version: ");
Serial.println(codeVersion);
Serial.print("Compile date: ");
Serial.println(__DATE__);
Serial.print("Compile time: ");
Serial.println(__TIME__);
Serial.print("\n");
}

Just substitute your program's name where I have "ProgramNameGoesHere" in the above code snippet. Then if you need to double check what code is actually running on your Arduino you can just connect up the serial monitor at 9600 baud to verify the code.  You'll even see the date and time you compiled the code.  And I got this tip from our own RoboPi.

SteveG


   
MadMisha, Centari, Photo Bud and 3 people reacted
ReplyQuote
KIMOSUBBY
(@kimosubby)
Member
Joined: 3 years ago
Posts: 14
 

@codecage

That idea is worth copying, thank you for sharing.  Up till now I usually put a string tied label with what code/project the Arduino was being used for. Sometimes I have more than 10 ATtiny on the go with different code and I need to know which does what and hence goes where. Many has been the time when I've plugged one in expecting one thing and an entirely different activity pops up.

Aye, Kim


   
ReplyQuote
(@ozcraig)
Member
Joined: 4 years ago
Posts: 9
Topic starter  

@codecage

Thanks to all for your feedback! Mr codecage, this looks like a pretty simple method which I will try out next time I am gadgeting. Cheers from Oz.


   
ReplyQuote
TheOutlander
(@theoutlander)
Member
Joined: 3 years ago
Posts: 79
 

@codecage Snuck this into a simple blink sketch since I had to pull apart a bunch of wires from my RPI today. Had some gibberish from one board, I'll look tomorrow.

Thanks for the code!

"Hardware eventually fails. Software eventually works." - Michael Hartung


   
ReplyQuote