Simulating arduino board

Is there a possibility to programm sketch without connecting arduino board to my pc.

In order to just debug some calling functions ?

I don't think so.

But it could be really great to have some kind of simulator, it would make debugging much easier. I have been programming AVR using Bascom AVR, and this IDE has a very good simulator, now when moving to Arduino the only thing I am missing is a simulator.

Here is a screenshot of Bascom AVR simulator.

Is there a possibility to programm sketch without connecting arduino board to my pc.

You can use the compile > button to see if your sketch is syntactically correct. And you can press the SHIFT key while pressing compile and you get even more output.

In order to just debug some calling functions ?

Generally* you can't,

*however functions without Arduino specific calls may be testable in a standard C++ environment e.g. Visual Studio 2008. But as ints, floats, doubles, RAM etc may have other sizes, this creates its own pitfalls. ==> don't do it

Generally* you can't,

*however functions without Arduino specific calls may be testable in a standard C++ environment e.g. Visual Studio 2008. But as ints, floats, doubles, RAM etc may have other sizes, this creates its own pitfalls. ==> don't do it

Is it something that could be done, I mean in future releases of the Arduino IDE, or is it simply impossible to do due to some technical stuff in the compiler?

Regards Thomas

quote]Is it something that could be done,[/quote]
Yes in theory it can be done BUT (a very big one) it is a difficult an big job and I do not expect it to become part of the IDE in a very long time.

imho the main problem for building a simulator is that Arduino interacts with hardware - motor, servo, temp or pressure sensor, LED's etc often interrupt driven - and if you want to simulate this all it becomes at least a very big job, imagine the code for simulating a relative simple temp sensor like a DS18B20 1 wire device.

There are functions you could test e.g. in VS2008 like lookup-tables, a numeric integration, a formula for converting AD readout's to Voltages or cubic inches whatever. But most Arduino code I have seen on this forum and beyond interacts with hardware ...

But don't let my opinion stop you from building an Arduino simulator :slight_smile:

In theory there is no difference between theory and practice but in practice there is

No, not equipment, just using loop to display Serial messages on console.

OK, I interpreted the question different, second try check if I do understand your question correctly:
you want to debug a sketch running on an Arduino that is not connected to a PC?

If that is the question you could use a simple serial display connected to the TX pin. Or another Arduino that checks if serial output of Arduino 1 is OK.

Could you give an example of code you want to debug?

NO

I just want that :

Mycomputer--------x(usb disconnected)-----arduino

And running my sketch to see only ouput serial messages.
loop()
{

Serial.println("foo")
}
Seeing foo on my console.

my console.

And what kind of device is your console?

something like this - Arduino Playground - SerialLCD

I was not thinking about simulating external hardware.

What I was thinking was something like epanda wrote, something like registers, variables, i/o pins, and be able to step thru code to see everything works as you expect, add breakpoints and so on.

I am a noob regarding C++ thats why I could use this, C is not the easiest language to learn :slight_smile: And believe me if I could program a simulator, I would :slight_smile:

As it is now you have to print your variables to Serial to check that your sketch is doing what you expect it to do, this gives a lot of extra coding, and this code must be removed again. I just think a simulator could be a very useful feature, not only for begginers but also for the more driven programmers.

Thomas

And what kind of device is your console?

console for me (french) is the Serial Monitor.

I just want to see trace output without loading the sketch into the arduino board.

I was not thinking about simulating external hardware.

What I was thinking was something like epanda wrote, something like registers, variables, i/o pins, and be able to step thru code to see everything works as you expect, add breakpoints and so on.

How do you imagine to test I/O pins without external hardware? A simple bouncing switch is very hard to simulate, as different switches have different characteristics. Simulating hardware makes me allways think of the saying: In theory there is no difference between theory and practice but in practice there is!

I just want to see trace output without loading the sketch into the arduino board.

As far as I know it cannot be done as there is nothing that "runs" the code.

What I am thinking about is something like you can see on the above picture.

As you can see, here you can step through the source code (sketch) while keeping an eye on your variables, locals and more, this is very usefull when debugging complicated calculations, string handling and more (At least I think that :wink: )

You can set breakpoints to stop the code in specific places to check to see if everything is as you expected at this point.

The hardware simulation is a minor thing in this matter, the I/O pins can be set to 0 or 1 by a click with the mouse, nothing more, I think this simple I/O control is good enough to test many things. A simple Analog input indicator with selectable analog port. With these "simple" hardware simulation features you can come a long way.

The above simulator is a screenshot of Bascom-AVR, and if you would like to how it works you can download a demo version (can only compile 4 Kb code)

Maybe I am the only one who will find this feature usefull, especialy as a beginner to Arduino/C++.

And just to be clear, I am not complaining about Arduino, I think Arduino is just awsome, but everything can be better :wink:

Maybe this kind of simulator I am talking about is impossible to make due to some technical issues in the Arduino IDE, the Compiler or other things, I don't know but I think it could be awesome to have it.

Thansen

I agree that simulators are of great value including as a learning tool.

The fact that this AVR simulator exist - and looks good btw - proofs a simulator can be made, even with switches and analog input. But afaik no simulator for Arduino exists.

The main point I wanted to make is that a good simulator should have:

  • bouncing switches
  • pot meters that are read out slightly differently every time
  • digital temp sensors that heat up a little bit
  • servo's that hick up
  • power supply that drop just a bit influencing ADC
    etc

It is this kind of noise that makes the difference between the analog world and the digital simulation. To handle this noise one often needs extra code or hardware. And the ultimate proof is allways in the pudding test, not in the recipe :slight_smile: