Assuming you're talking about an AVR based Arduino board such as Uno, Mega, Leonardo, etc., you could take a look at SimAVR.
Though I haven't looked at it closely, I suspect this won't be a very friendly process for the typical Arduino user but with some persistence it could be done.
mattmaxon: Dumbest question ever but here goes....
Is there a -simulator- that would execute the program code line by line ?
I know i know it gets compiled and sent to the Arduino
Probably doesn't exist but thought I'd ask anyway
Well, think about it for a bit. In assembly/assembler code, you get what you wrote. So a simulator could step through each assembler code one line at a time.
In C/C++, so much depends on what you write and how you write it. Think of you program with libraries defined first. How would you know what line of code was being executed?
added: If you use the debug capability of Serial.print to show the values going into a line of code and showing the results of that line of code, it's almost the same as a simulator.
mattmaxon: Is there a -simulator- that would execute the program code line by line ?
There are some Simulators for Arduino I know of.
This is a simulator for Arduino UNO: https://www.sites.google.com/site/unoardusim/ It is free and you can simulate simple sketches. It can execute the program line by line and you can watch how variable values change. Maybe it does what you want. You can also simulate LEDs, buttons and switches, servos and steppers, I2C, serial communication, SPi and more. But it is not "real time". May work for simple projects.
There is another simulator: http://virtronics.com.au/Simulator-for-Arduino.html This is not free but it can work with more complex projects. You can include external libraries. Have not tried this yet.
Simulators are of limited use only. But it may help you to understand some principles.
I'm with @Paul_KD7HB on this.
It would be all too easy to be swamped with too much information. Some lines of C++ code could result in hundreds of lines of assembler.
I've gotten a very negative impression of the accuracy of simulators; they frequently don't behave quite the same as the actual hardware, and we've had a few discussions here where people got sent down the wrong path by an inaccurate simulator.
There's really no substitute for uploading the code to the microcontroller and seeing what it does.
You can debug directly on the chip. The core of the Arduino came from the environment where a business would pay $5k-$10k per 'seat' for debugging software. With the appropriate hardware to plug into the debugging interface, it all can be done. You can stop and examine register contents and the output pin states at will.
However it's rarely done with Arduinos. Why pay $10000 for a small improvement in functionality on a $30 device? So we end up using brute-force methods of debugging. Serial.println() is your friend.
Sometimes when I really need line-by-line debugging then I'll put the following code at the line where I want to stop. Then I'll move it down one line and re-compile and re-run.
AVR, Keil etc provide such environments - and they work ( in my experience ) pretty well. You can look at all the registers, variables, memory etc. Breakpoints are handy.
But expensive, and for most arduino jobs over the top. To quote MorganS ' Serial.println() is your friend.'
Plus you'll get masses of other stuff - eg the millis() background task , and the loop() overhead.
If you're trying to squeak the last bit of performance from a processor, or need cycle-by cycle timing accuracy, you shouldn't be using the arduino IDE.
But for run-of the-mill jobs it's convenient , easy to use, and FREE!
@Morgan, thanks for the while idea... was obvious but didn’t think of it till now
Many many thanks for this.
I am aware of the limitations of simulators but I seem to be visually “wired” at least initially, this is all new to me
This will help me “see” what happens, making it easier to “internalize” it
I’m a visual learner as well. I find it useful to diagram my programs using boxes and connecting lines - a lot like the old style flow charts, but less rigorous. Mostly just a series of boxes for each step. Go through your code line by line, and then note what each line does to the variables, pins, etc. that it affects. Write that in the box, then on to the next box.
Pretty soon you’ll see patterns forming, and then Boom! there is your program.
You don’t need to pay $10000 for on chip debugging. Here you have an ATmega328P eval board with onboard debugger for $8.88:
You can use it with the free Atmel Studio IDE.
Ultimately, if you don’t want to spend $9 for the ‘328 mini xplained board, you can stil download Atmel Studio 7 for free, there is an AVR simulator built into the environment which I’m fairly certain is an accurate and fully functional implementation, just don’t expect to do anything with external devices ;-)
Load AS7->new project->import Arduino sketch, compile and have at it. If anyone says that’s too difficult, they haven’t tried it.
Will the AVR compiler understand all the arduino non-standard-C add-ons?
With Arduino.h it will, yes.
I've never tried it myself. I've never needed to breakdown the Arduino walled garden.