{"id":615,"date":"2017-05-27T11:00:55","date_gmt":"2017-05-27T03:00:55","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/iotdev\/?p=615"},"modified":"2019-02-15T10:27:14","modified_gmt":"2019-02-15T02:27:14","slug":"debug-your-arduino-code-with-visual-studio-code","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/iotdev\/debug-your-arduino-code-with-visual-studio-code\/","title":{"rendered":"Debug your Arduino code with Visual Studio Code"},"content":{"rendered":"<p>Debugging Arduino application is\u00a0a challenging task as the debugging feature has not been officially supported in Arduino IDE.<\/p>\n<p>Many modern IDEs have debug support that developers are used to, using Breakpoints, Steps, Call Stack, Watch, Local\/Global Variables, etc. Arduino developers often have to explore many alternative methods and tools to debug Arduino code.\u00a0If the board has JTAG interface support, with the help of extra hardware, developer can do the debugging. For Atmel MCU, DebugWire. Some have to rely on Serial Monitor to print necessary messages for debugging. For those enterprise users, there are more paid options such as Visual Micro for Visual Studio, etc.<\/p>\n<p>There is a new release from <strong><a href=\"https:\/\/aka.ms\/arduino\">Arduino Extension for Visual Studio Code<\/a><\/strong>, with modern debugging features to help Arduino developers easily perform the debugging tasks within Visual Studio Code, without the need of extra hardware or extra lines of print messages.<\/p>\n<p>Here is a sample debugging session to help Arduino developers get started:<\/p>\n<ol>\n<li>assuming developers have been using\u00a0<span> <\/span><strong><a href=\"https:\/\/aka.ms\/arduino\">Arduino Extension for Visual Studio Code<\/a><\/strong>\u00a0for developing Arduino code.<\/li>\n<li>open a *.ino file with device connected. Here we used <strong><a href=\"https:\/\/aka.ms\/azure-iot-developer-kit\">Microsoft Azure IoT Developer Kit<\/a><\/strong> as test board, which is an Arduino compatible MCU board. Click debug button or (Ctrl+Shift+D), to enter debug view:<img decoding=\"async\" width=\"1116\" height=\"853\" class=\"alignnone size-full wp-image-645\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step1-1.png\" \/><\/li>\n<li>follow this screen to add Arduino debugging configuration (F5)\n<img decoding=\"async\" width=\"405\" height=\"321\" class=\"alignnone size-full wp-image-715\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step2.png\" srcset=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step2.png 405w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step2-300x238.png 300w\" sizes=\"(max-width: 405px) 100vw, 405px\" \/><\/li>\n<li><img decoding=\"async\" width=\"913\" height=\"303\" class=\"alignnone size-full wp-image-705\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step3.png\" srcset=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step3.png 913w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step3-300x100.png 300w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step3-768x255.png 768w\" sizes=\"(max-width: 913px) 100vw, 913px\" \/><\/li>\n<li>Switch back to the *.ino file you are developing, and click before the line number to set desired break points:<img decoding=\"async\" width=\"1116\" height=\"853\" class=\"alignnone size-full wp-image-686\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step5-1.png\" \/><\/li>\n<li>Click the &#8220;start&#8221; button or press F5 to start the debugging session. It will first verify the code, then upload the binary to the board.<img decoding=\"async\" width=\"633\" height=\"305\" class=\"alignnone size-full wp-image-685\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step6.png\" srcset=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step6.png 633w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step6-300x145.png 300w\" sizes=\"(max-width: 633px) 100vw, 633px\" \/><\/li>\n<li>Once pause at the first break point, you can do the regular debugging tasks using short-cut keys or GUI controls to do the regular continue, step-over, step-in, step-out, restart, stop actions. Meanwhile the debugging panel will display the local variables and values, call stack and watch if you set any.<img decoding=\"async\" width=\"1115\" height=\"853\" class=\"alignnone size-full wp-image-656\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step7.png\" srcset=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step7.png 1115w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step7-300x230.png 300w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step7-768x588.png 768w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step7-1024x783.png 1024w\" sizes=\"(max-width: 1115px) 100vw, 1115px\" \/><img decoding=\"async\" width=\"1114\" height=\"853\" class=\"alignnone size-full wp-image-675\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step8.png\" srcset=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step8.png 1114w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step8-300x230.png 300w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step8-768x588.png 768w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step8-1024x784.png 1024w\" sizes=\"(max-width: 1114px) 100vw, 1114px\" \/><\/li>\n<li>you can dynamically change the local variable or global variable values. You can also open the Serial Monitor at the same time to print out messages:<img decoding=\"async\" width=\"1116\" height=\"853\" class=\"alignnone size-full wp-image-716\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step12.png\" srcset=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step12.png 1116w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step12-300x229.png 300w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step12-768x587.png 768w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step12-1024x783.png 1024w\" sizes=\"(max-width: 1116px) 100vw, 1116px\" \/><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><strong>The boards we tested to work with new debugging features:<\/strong><\/p>\n<ul>\n<li><strong><a href=\"https:\/\/aka.ms\/azure-iot-developer-kit\">Microsoft Azure IoT Developer Kit<\/a>\u00a0(AZ3166)<\/strong><\/li>\n<li>Arduino Zero Pro<\/li>\n<li>Arduino M0 PRO<\/li>\n<li>Adafruit WICED WiFi Feather<\/li>\n<li>Addafruit Feather M0<\/li>\n<li>more to come&#8230;<\/li>\n<\/ul>\n<p><strong>What the current version of debugging doesn&#8217;t support:<\/strong><\/p>\n<ul>\n<li>listing global variables and values in debugging panel. You can instead type the global variable in debug console to see the value, or mouse over the variable of interest in your code while in debug mode to get the current value:<img decoding=\"async\" width=\"798\" height=\"244\" class=\"alignnone size-full wp-image-665\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step9.png\" srcset=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step9.png 798w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step9-300x92.png 300w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2017\/05\/step9-768x235.png 768w\" sizes=\"(max-width: 798px) 100vw, 798px\" \/><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>Please download the latest\u00a0<strong><a href=\"https:\/\/aka.ms\/arduino\">Arduino Extension for Visual Studio Code<\/a><\/strong>\u00a0to try the debugging feature. If you don&#8217;t have a supported board yet for testing out the debugging feature, please check out<strong>\u00a0<a href=\"https:\/\/aka.ms\/azure-iot-developer-kit\">Microsoft Azure IoT Developer Kit<\/a><\/strong>\u00a0page to register and request a kit.<span><\/span><\/p>\n<p>We have built many <strong><a href=\"https:\/\/catalog.azureiotsuite.com\/getstarted\">getting started tutorials and code samples<\/a><\/strong> for your reference.<\/p>\n<p>We welcome your feedback and you can join our discussion at <a href=\"https:\/\/gitter.im\/Microsoft\/vscode-arduino\"><strong>chat on gitter<\/strong><\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Debugging Arduino application is\u00a0a challenging task as the debugging feature has not been officially supported in Arduino IDE. Many modern IDEs have debug support that developers are used to, using Breakpoints, Steps, Call Stack, Watch, Local\/Global Variables, etc. Arduino developers often have to explore many alternative methods and tools to debug Arduino code.\u00a0If the board [&hellip;]<\/p>\n","protected":false},"author":531,"featured_media":1836,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[3,4,7,9,10,33],"class_list":["post-615","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-iot-dev","tag-arduino","tag-arduino-debug","tag-azure-iot-hub","tag-debug","tag-debug-arduino","tag-visual-studio-code"],"acf":[],"blog_post_summary":"<p>Debugging Arduino application is\u00a0a challenging task as the debugging feature has not been officially supported in Arduino IDE. Many modern IDEs have debug support that developers are used to, using Breakpoints, Steps, Call Stack, Watch, Local\/Global Variables, etc. Arduino developers often have to explore many alternative methods and tools to debug Arduino code.\u00a0If the board [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/posts\/615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/users\/531"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/comments?post=615"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/posts\/615\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/media\/1836"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/media?parent=615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/categories?post=615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/tags?post=615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}