24
\$\begingroup\$

Programs may, at times, have runtime errors. These are sometimes hard to find and can easily be missed. Is there any way to test the program before actually burning it onto the board ?

\$\endgroup\$
4
  • \$\begingroup\$ Might be related to arduino.stackexchange.com/q/84/25 \$\endgroup\$
    – powtac
    Apr 10, 2013 at 10:15
  • \$\begingroup\$ Also maybe related to arduino.stackexchange.com/questions/20/… \$\endgroup\$
    – Robert
    Apr 10, 2013 at 17:37
  • \$\begingroup\$ You may have the issue the error only occurs on a physical Arduino (I couldn't give an example, though). \$\endgroup\$
    – Polar
    Apr 10, 2013 at 23:13
  • \$\begingroup\$ @Polar In terms of program logic, I cant imagine how. Could you, maybe, post any example ? \$\endgroup\$
    – asheeshr
    Apr 11, 2013 at 12:56

3 Answers 3

19
\$\begingroup\$

There are a few Arduino Simulator projects out there.

Perhaps one of the more mature ones is the Virtronics Simulator for Arduino, YouTube video here.

Virtronics Arduino Simulator

The Virtronics page linked above also lists a few other Arduino simulators, both free and paid.

Given the interest the Arduino evokes, there are likely to be many more such simulators out there, so no point trying to list them all in an answer here.

What is worth noting is that there is also an Arduino Simulator iPhone app: This is not a recommendation, not having seen it in operation yet.


On a side note:

The Arduino is in itself a prototyping / experimentation board. It is ideal for programming experimental code, debugging it, modifying and then re-flashing fresh code, pretty much as many times as one likes. If the code hangs, reset and reflash with any changes.

Therefore, the merit of using a simulator, which can never perfectly emulate the various real-world timing or other issues an application might face, is questionable.

If the cost of the Arduino is the concern, there are a couple of options open:

  • Inexpensive Arduino Nano clones off eBay - I have several Meduino Nano Enhancement boards, they work excellently, and are priced at under $10 including world-wide shipping: Meduino Nano Enhancement
  • Make your own Arduino - The Arduino site walks you through making one on a breadboard, which does not even need you to solder anything!
\$\endgroup\$
2
  • \$\begingroup\$ Thanks for sharing the link to the Virtronics Simulator! \$\endgroup\$
    – powtac
    Apr 10, 2013 at 10:16
  • \$\begingroup\$ Yes, it is much easier to debug and reflash. ATMega328 flash is rated at 10000 rewrite cycles, so even if you rewrite it 10 times every single day you have more than two years of fun before you :-) Quite a lot of fun for an hobbyist. If you're just a bit more into it, you can use newer boards to do the debugging and when they start to wear out (say after 5000 cycles?) you can use them for stable applications an buy a new one for debugging. \$\endgroup\$ Jul 5, 2014 at 21:48
8
\$\begingroup\$

You can find runtime errors if you can manually step through your program with the Arduino connected and debug (after downloading code to the Arduino). This is available in Visual Micro although it requires Visual Studio. You can set breakpoints, evaluate variables, and change variable values. You can also get visualization of of memory over time:

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ Very neat. How mature is this project -- or, rather, has this IDE run smoothly in your experience? \$\endgroup\$
    – boardbite
    Apr 14, 2013 at 13:11
  • \$\begingroup\$ I haven't used it for profiling, and I've only used it briefly, but it integrates pretty well and runs fine for me. I really appreciate the ability to debug without resorting to Serial.print \$\endgroup\$
    – Robert
    Apr 14, 2013 at 20:48
4
\$\begingroup\$

One way to do this would be to create a wrapper program for the actual code which simulates all the inputs and accepts outputs (thereby creating a feedback loop) as per the real environment. This would take variable amount of effort depending on the type of program, degree of testing and number of inputs.

Keep in mind that while writing the wrapper program, you should follow a black-box approach.

enter image description here

Otherwise, your outer code may not test the program as well as possible as keeping in mind the actual code while creating the test code may bias you to ignore boundary cases or problem areas (This has been observed to happen while doing White-Box Testing which is the alternative).

\$\endgroup\$
2
  • \$\begingroup\$ Do you know of any examples? Most Arduino code I have seen lacks proper unit tests even for the parts that do not require input/output. \$\endgroup\$
    – Jakob
    Apr 10, 2013 at 17:55
  • \$\begingroup\$ @Jakob I usually write my own code for the testing. It is practical for small projects. \$\endgroup\$
    – asheeshr
    Apr 11, 2013 at 5:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.