Anyone here has debugg UNO in vscode by simavr?

Why create one, you can already set breakpoints in the code and press the Run->Start Debugging.

You should also have a look at How to simulate serial port on debugger simulator? - #2 by maxgerhardt and the related topics.

The experience before mislead me, I tried debug in this way with Arduino extension for vs code, it didn’t work, so I have thought it should be avoided when I start to use extension platformIO.

Another question, I saw in other article, arduino extension maybe conflict with platformIO, so one should remove it before using platforIO extension. I saw this conflict prompt on windows 10, but I’m not sure if I could continuously verify Arduino code in vs code by platformIO, so I haven’t removed it till now. after all, all code were verified and uploaded bu Arduino extension.

1 Like

additionally, there was no prompt of extensions conflict in ubuntu, should I also remove it(Arduino extension for vs code) before I use platformIO extension ?

Disable the Arduino VSCode extension if you intend to use PlatformIO - it will cause you grief in the future. You have the choice of either disabling it on a per workspace level if you want to use it sometimes, disabling it completely, or uninstalling the extension.

Also, you should not have needed to install SimAVR at all - PlatformIO would have installed it’s own version (and probably did anyway, and will be using that instead of the version you installed) the first time you tried to debug the project.

In other words,

  1. install VS Code
  2. install “platformIO” extension in VS Code
  3. Add in “platformio.ini”:
[env:myenv]
platform = atmelavr
board = uno
debug_tool = simavr
  1. Set some breakpoints (click to the left of line number for that line to get the red dot).
  2. Start debugging (Debug sidebar icon -> Run arrow up the top or press F5 key)
  3. Press F5 again (or Continue debug control button) to continue past the Arduino int main() into your own code.

In vs code, when I clicked “Import Arduino Project” and after several settings, is was a blank page, where is my project imported?

The file explorer in the left sidebar should have the workspace that was imported.

1 Like

After doing an import, if you had nothing else open, your screen probably looks like this …

… with your Arduino souce code being located in the /src subfolder of the new project folder.

e.g.

I started to debug UNO code in vs code by simavr under PlatformIO.

I uninstalled Arduino extension, since it was said that this extension conflicted with PlatformIO.

When I opened a new project in PlatformIO, I copied code into /src/main.cpp, but there was a prompt:

c/c++ intenllisense service does not support .ino file.

and, if I renamed the main.cpp into main.ino, there was lots of errors - all the key words in Arduino IDE were not defined.

so I renamed the file into main.cpp again, this time, it was prompted:
{
“message”: “Arduino.h: No such file or directory”,
“source”: “gcc”,
}

when I changed the name from <> to “”, the prompt was still there.

Should I copy a Arduino.h into this PlatformIO folder ?

1 Like

Maybe I have resolved this error: solution was also the right open mode -->cd cd cd cd cd cd …
if one open it from GUI, the problem would recurrence。

Just as use Arduino extension in VS Code, you should always use CLI:
mkdir dir cd …then, code .(note, between code and ., there must a space, no space is not OK, more than one is still OK)

No, never. It is provided by the Arduino framework, so if it can’t be found, there is something seriously wrong with either your installation, or your configuration.

If you have never compiled something for the Arduino framework, it could be that the framework files haven’t been downloaded yet, meaning it’s a legitimate error at the time, but will be rectified at build time. Or your platformio.ini configuration may not have the 'framework = arduinoconfiguration parameter. Or perhaps yourframework-arduino` is corrupt, and needs re-installing.

Not quite sure what is happening here… sounds like you’re having some scope issues, when telling VSCode what folder to open. If you had a project at say ~/projects/MyProject, doing code ~/projects/MyProject would probably also work… not need to use cd to change to that directory.

I found this article could be helpful: Arduino In-circuit Debugging with PlatformIO, but I cannot open the link, could anyone transfer this file for me?

Don’t know why that’s not working for you, it’s on medium.com, and worked fine for me.

You should be able to download a saved version of the web page here:
https://transfer.sh/WAPlX/Arduino%20In-circuit%20Debugging%20with%20PlatformIO%20_%20by%20Manuel%20Bl.%20_%20Medium.html

I found debugging made by PLatformIO for Arduino is simulate, not emulate, that is to say, it could not debug behave on board. And I found it was because Atmel didn’t opened its related file.

So, I now start to try debug Arduino project in Atmel Studio by Atmel ICE.

1 Like

There’s two options for debugging atmelavr hardware with platformio… both extremely new so not extensively tested. There’s simavr (sim as in simluate), which you can do without the hardware, but it’s not 100% like the actual hardware. There is also avr-debugger, which you can find out more about in this thread, and runs on the actual hardware.

However, if you’ve switched to Atmel Studio so you can use your Atmel ICE, and it’s working for you, I’d stick with what you have, since it works :wink:

I want to try these 2 ones:

simulation (simulavr) and
debugging (avr-gdb, AVaRICE).

in PlatformIO for VS Code, how to do it ?

This is already the default and only debug tool.

As can be seen in the thread Atmega32 debugging with avarice and avr-gdb - #2 by mate910327, it’s possible but avarice seems to have bugs which prevents this from properly working.

I’ve used simavr to debug Uno code occasionally. It’s ok, but it’s easily confused when you get into interrupts etc. It also has problems if you step into the delay() function for some reason. It just hangs at that point for me.

Don’t get me wrong, it has helped me diagnose a problem or two, it’s just not as good as the hardware debugger I have for my STM32 Blue Pill. However, that is comparing apples and durian!

Cheers,
Norm.