Testing code without upload it?

I came from microchip pic world and one thing I really like on pic is there are lots of simulators to test my code without uploading it.On arduino every time I made a change and I want to test it I need to upload the code to the AVR micro.Is there any way I can test the code without uploading it?
My arduinos are starting get tired of receiving so many uploads just for debugging code

Google "Arduino simulator", I think there are a few.


Rob

HugoPT:
My arduinos are starting get tired of receiving so many uploads just for debugging code

Oh? I upload new sketches dozens of times a day to help support people on the forum. My Arduino doesn't look particularly "tired" yet. Emotional, maybe.

I am supposed to be able to upload to the flash 10,000 times. At 10 times a day for 365 days, that will still take almost 3 years to wear it out. And if you aren't doing what I am, helping people on a forum by trying different sketches every hour, you should probably have your code debugged by the time you get to version 10000.

And if you haven't? Yank the chip out and replace it for $5.

Simulators are all very well, but they don't simulate critical timing situations, like responding to an interrupt quickly enough. So you will quickly find that the time you spend debugging on the simulator is wasted because reality doesn't quite match up. And if you count your time as money, you will soon have spent that $5.

Not easily done on SMD chips... :frowning:

Words of wisdom. :slight_smile:
They also don't have any hardware attached to them, which is part of what you'll debug. Note that most of the stuff you'll have to debug are interfaces to other chips, etc... and apart from LEDs and buttons, it's a pain to simulate any other thing. Not that the simulators don't have a place in the world, but they're not designed to save flash counts on the chip.

Ahh, and as everything, the re-programming value is a conservative value I guess. So you may have more writes than those.

bubulindo:
Not easily done on SMD chips... :frowning:

Quite right. Although then you replace a $5 by a (say) $30 cost (every 3 years). And if your development environment is such that you are uploading 10000 versions of your code, over 3 years, then $30 to replace the board every few years is the least of your worries.

True. Chances are that three years later there will be different boards to try out thus diluting the investment. :slight_smile:

Another option is to pick up an AVR Dragon and use either jtag or DebugWire (depending upon ship being tested) and perform live debugging on your code running on the actual hardware with it hardware based i/o...

Worlds better than printf debugging... but no where near as easy as just using standard Arduino IDE

I can see from HugoPT point of view that once you have used a simulator, you can't see how you survived without one. Its more than just about the number of times you flash the memory.

You can use visual studio as a compiler. I believe it also steps through code

Having used Pic assembler, I often wonder if a 'simulator' isn't another crutch... Relying on a simulator to test a hypothesis is 'better/easier'? than knowing or learning what you need to accomplish and doing it or is... 'I think this might? be correct and saying "Hey teacher (simulator) is this right?... For the obvious... you cannot help but learn as the simulator 'teaches'. So If the simulator is unable to correctly model code... I refer here to a simulator that caused me grief for trying to make the simulation work rather than make the program work. I might add that the issue wasn't about simulating hardware or I/O, user or sensor. One of the reasons that the Arduino and other current operating platforms are so very powerful for learning tools is flash memory. When I was coding Pic assembler, chips came in two flavors, Prom and Eprom and a PIC16C57 cost about $6.00 a PIC16C57JW cost $23.00 and $39.00 for the eraser. The Programmer cost $89.00 (all prices are approximate but indicative of reality then). For the hours I spent in 'debugging' code on the simulator in such a manner as to make the sim happy I would have been way ahead by simply programming the Eprom'ed 'C57 and occasionally purchasing a new 16C57JW. I later found out that the simulator had issues with the weird paging that microchip used and a long jump. My point is that simulations are just that... simulations. Unfortunately the programmer is at the mercy of the conventions expressed in the simulator. Another issue is the models enforced by the lack of hardware or I/O simulations that conform to the required hardware model particularly in the area of timing and the necessary inflexibility inherent in hardware simulation of I/O. With 'flash' devices one can write and test modules in real time, function and method can be tested individually for the scenario's that don't fit standard solutions and the inclusions of those results are easier to use than fixing simulator issues before code can be tested.
I have yet to see a reference for a simulator advertised anywhere free or otherwise for the Arduino family... and I can't help but think there is a reason for that, as if there was a chance to make money or fame, Someone would have taken best advantage of the 'need'...?
IMO

Doc

Docedison:
I have yet to see a reference for a simulator advertised anywhere free or otherwise for the Arduino family... and I can't help but think there is a reason for that, as if there was a chance to make money or fame, Someone would have taken best advantage of the 'need'...?
IMO

Doc

I suspect you don't see such advertised (though I am aware of a couple), since the primary AVR development software (AVR Studio) includes a simulator for their chips.

I don't use AVR Studio, I was specifically referring to Arduino related products or something I might see as an addition to Arduino's IDE. AVR is a mighty big world Arduino is but a small part of it, referring directly to 5? different processors, the '168 - 328 and Mega 1280, 2560. If I am not too far wrong the above mentioned devices are a small part of the AVR family, I quote from the original... "My arduinos are starting get tired of receiving so many uploads just for debugging code", Yes as much as I can be interested in other products that don't really relate to my immediate task in hand. I am aware of other products but I fail to see the relevancy to Arduino, specifically... Can I load a sketch and 'simulate' it in the product you mentioned?. Somehow I don't think so. Or it might have more public exposure to those of us that know just enough to 'load a sketch'. I might also observe that I have yet to see any reference to it in this forum and from that 'oversight' infer that it would be of small utility to a person just beginning to learn "Arduino" and then in parallel learn the fundamentals of both "C" and "C++. My total knowledge of the language could be written legibly on the head of a pin. I am here because I am retired and I need something besides the 'usual' methods for passing time. I think that current entertainment somehow is superior to my small intellect because I draw little from it beyond a sore posterior and there are enough people in my little world that do just that already. Education taken in digestible 'doses' seems somehow to fill my needs, for now my needs are related to Arduino as I find that it is easier to learn if I restrict my learning to what is relative to my task in hand rather than bounding off at the first diversion. IMO

Doc

It's hard to imagine disparaging a simulator once you've actually gotten used to running it. Zero upload times. Ability to test out sketches without even having hardware around (on a plane, in a coffee shop, at in-law's house). Inspect pin values. Set pin values, see what happens. Step through code without having to bother with AVR Dragon (or tote one more fragile connection around). My bug turnaround rate in software-only environment is something like 10x over running on hardware.

I must admit that a simulator would be useful for testing something like "does sprintf handle floats correctly?". Since that isn't at all timing dependent. Maybe I'll take a look at the AVR Studio one to see how well it works. Haven't needed to so far.

However remember AVR Studio runs exclusively on Windows (as far as I know) so if you happen to be a Mac or Linux user, you are out of luck.

My personal experience over the years has been that: debuggers are useful in certain limited circumstances.

And just to demonstrate that I am not opposed to debuggers, per se, I did a lengthy write-up on gdb:

Having said that, I regard a debugger as a last resort, in a complex situation, where you simply can't work out why certain bizarre things are happening. For example, when debugging a server for an online game where a complex set of prerequisites has to be satisfied before the bug manifests itself.

Docedison:
I don't use AVR Studio, I was specifically referring to Arduino related products or something I might see as an addition to Arduino's IDE. AVR is a mighty big world Arduino is but a small part of it, referring directly to 5? different processors, the '168 - 328 and Mega 1280, 2560. If I am not too far wrong the above mentioned devices are a small part of the AVR family, I quote from the original... "My arduinos are starting get tired of receiving so many uploads just for debugging code", Yes as much as I can be interested in other products that don't really relate to my immediate task in hand. I am aware of other products but I fail to see the relevancy to Arduino, specifically... Can I load a sketch and 'simulate' it in the product you mentioned?. Somehow I don't think so. Or it might have more public exposure to those of us that know just enough to 'load a sketch'. I might also observe that I have yet to see any reference to it in this forum and from that 'oversight' infer that it would be of small utility to a person just beginning to learn "Arduino" and then in parallel learn the fundamentals of both "C" and "C++. My total knowledge of the language could be written legibly on the head of a pin. I am here because I am retired and I need something besides the 'usual' methods for passing time. I think that current entertainment somehow is superior to my small intellect because I draw little from it beyond a sore posterior and there are enough people in my little world that do just that already. Education taken in digestible 'doses' seems somehow to fill my needs, for now my needs are related to Arduino as I find that it is easier to learn if I restrict my learning to what is relative to my task in hand rather than bounding off at the first diversion. IMO

Doc

I have had no real issues testing arduino sketches with the simulator in AVR studio. Debugging is, by an large, an exercise in testing one's assumptions about the behavior of the code which we write. If you need/want to use a simulator with the Arduino, it seems the best current option--and since it is free is a strong reason that other options haven't received much development. For those who run linux (like myself) or MAC it is easy enough to use a virtualbox VM to have a version of windows running... In my case, I am simply using it to host a the windows that came installed on some of my machines before I rebuilt them with Linux.

Some people like IDE's, some hate them. I think it is the same with simulators (or other debugging methods). Certainly some environments have more need of sophisticated debugging than others. I personally prefer the Dragon for this, since it allows me to see the effect of sensors, which don't always produce predictable values, and which are difficult (or inpractical) to debug in other ways.

To each their own, eh... For me, the debugger is the first thing I use if the problem is not immediately obvious. Set a breakpoint where things are weird, inspect some memory, step through some code, fix the bug. That said, since the advent of test-driven development, my debugger use has plummeted.

Yeah and I will buy the first one that I can connect my BMP085 sketch to as If I could it would save me some time in including the device in another device I want to build but that one is hardware too and my Arduino isn't a very good adding machine I am certain I could make a Whiz-Bang calculator out of my Arduino with a good simulator, that is. Seriously... I apologize if my comments offended. I mean them only to point out that most of this world (Arduino) IS Hardware and simulators generate ideal world signals... something found usually only in simulators. Unfortunately the real world is under no such restriction.... One of the cardinal sins that I see here daily is a lack of proper bypassing and the attempts to 'fix it' in software, Analog signals that jump by 5 units only when the relay 'fires' Bypasses are Magic Bullets, You can never have too many. It is though, no great art to not have enough. This kind of issue can have an Electrical NOOB running around in circles because a sim will not show it. Nor have I ever seen modeling provisions in one to do just that, produce dirty or wrong values without a great deal of work. Simulators don't simulate poor power supplies or bad wiring or. They work very well in a static environment, one I rarely ever encounter. They do however make GREAT Teaching machines and for proving the math in various operations but this should have been checked long before the programmer began writing any and all calculations should have been diagrammed, tested.. modified if/as necessary.
The Idea is to "Plan Your Work and then Work Your Plan" this was a small part of my reasoning two posts back about the utility of simulators. If one has a simulator one is somewhat more likely to "Cowboy Code" and I was as guilty of it as anyone could possibly be. One Day I figured out 'with the help of my employer' that I was spending as much time simulating than I did writing. Some small introspection after hours brought me to the idea that trying to write code successfully on a sim was virtually impossible always because what you do is recode the issue, modify the documents and go on. You don't take the time to do a 'post mortem' to find out how the mistake got there in the first place and maybe rethink the reasons why the routine failed first. Granted we are not writing "mission critical" code here but I have found over the years that IF IT IS worth doing it is WORTH DOING RIGHT. Anything else has half in front and shouldn't be repeated in polite company and that I don't understand either as Everyone has one... It is My time and I prefer not to work at anything else but 100% of the best I "know" how to do... I make a lot of mistakes... but not too many twice. IMO

Doc

Just received an email from Google Alerts about this thread. Here is a link to our Arduino Simulator which was started at the beginning of the year and is doing well. What was that about fame and money - try fun - it can be a lot of fun writing a program which runs well and has a wide audience.

The Simulator Pro Licence is currently $7.99 and just about to go up to $9.99 when we reach 500 users (92% there today). There is a free trial version which has a 30s delay on opening a sketch and is code limited to 100 lines. Otherwise, we have made the v0.91 Pro Version available on the forum - visit the Free Version topic, but this version has less than 10% of the functionality of v0.96.

Overall, the reviews for the Simulator have been very favourable and the biggest issue is using Paypal to register the Pro licence, so we are looking at using a software registration company next. At present, we are getting about 5 emails a day so the Simulator is being used, and while there are a few bugs, they are mostly easily solved and caused more by omission than error.

I tried the Microchip simulator and it was good. Can't say the same about Microchip hardware - Microchip have some good products but the PIC micro is not one if them. Does BSF STATUS,RP1 sound familiar or having a perfect source file which still gives warnings. I tried to write a "Hello World" routine with the 16c54 and found it wasn't possible unless you had each character in a separate routine. The latest PICs may be better but once bitten twice shy.

Agreed, the banked RAM/register scheme of the smaller PICs is a real PITA.