{"id":4100,"date":"2018-09-24T11:40:02","date_gmt":"2018-09-24T18:40:02","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=4100"},"modified":"2018-10-01T09:19:44","modified_gmt":"2018-10-01T16:19:44","slug":"developing-arduino-projects-with-visual-studio","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/arduino\/","title":{"rendered":"Developing Arduino Projects with Visual Studio"},"content":{"rendered":"<p>This tutorial shows how to use the Advanced Arduino Project Subsystem of VisualGDB to easily develop Arduino projects with Visual Studio.\u00a0While VisualGDB also supports Arduino-compatible boards based on ARM, ESP8266 and ESP32 platforms, this tutorial covers the classic Arduino Uno board based on the AVR platform. We will create a basic &#8220;Blinking LED&#8221; project and will show how\u00a0to use various Arduino-related features of VisualGDB to develop it conveniently.<\/p>\n<p>Before you begin, install VisualGDB 5.4 Preview 4 or later. Although you can install the Arduino IDE to\u00a0use the\u00a0Arduino platforms and libraries shipped with it, this is not necessary as VisualGDB will automatically download the necessary Arduino packages if they are\u00a0not already installed.<\/p>\n<ol>\n<li>Start Visual Studio and open the VisualGDB Arduino Project Wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-prjname.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4101\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-prjname.png\" alt=\"01-prjname\" width=\"936\" height=\"514\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-prjname.png 936w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-prjname-300x165.png 300w\" sizes=\"(max-width: 936px) 100vw, 936px\" \/><\/a><\/li>\n<li>On the first page of the wizard select &#8220;Create a new &#8216;Blinking LED&#8217; project&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-led.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4102\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-led.png\" alt=\"02-led\" width=\"856\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-led.png 856w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-led-300x243.png 300w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a><\/li>\n<li>On the next page of the wizard, choose your Arduino device. In this tutorial we will select &#8220;Arduino\/Genuino Uno&#8221;. If you have not created any projects for the selected\u00a0Arduino platform, VisualGDB will suggest automatically installing the necessary packages. Click &#8220;Install&#8221; to proceed:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-getuno.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4103\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-getuno.png\" alt=\"03-getuno\" width=\"856\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-getuno.png 856w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-getuno-300x243.png 300w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a><\/li>\n<li>Once the package installation succeeds, ensure the correct board is selected, plug it into your computer and pick the corresponding COM port:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/04-comport.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4104\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/04-comport.png\" alt=\"04-comport\" width=\"856\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/04-comport.png 856w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/04-comport-300x243.png 300w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a>Note that some boards will not appear in the list until you install the corresponding package. This happens because the Arduino package lists do not include all boards that are actually provided by the packages. If\u00a0you\u00a0cannot find your board in the list, try\u00a0selecting a similar board, installing the package and check for your board again.<\/li>\n<li>In this tutorial we will focus on building the project, using libraries and programming the FLASH memory, so select &#8220;Built-in GDB simulator&#8221; as the debug method:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/05-dummydebug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4105\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/05-dummydebug.png\" alt=\"05-dummydebug\" width=\"856\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/05-dummydebug.png 856w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/05-dummydebug-300x243.png 300w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a><\/li>\n<li>Press &#8220;Finish&#8221; to\u00a0generate the project. VisualGDB will create a basic\u00a0project with a single Arduino sketch. Build it by pressing Ctrl-Shift-B:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/06-build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4106\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/06-build.png\" alt=\"06-build\" width=\"1133\" height=\"723\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/06-build.png 1133w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/06-build-300x191.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/06-build-1024x653.png 1024w\" sizes=\"(max-width: 1133px) 100vw, 1133px\" \/><\/a>Note that the Advanced Arduino\u00a0projects get the project structure directly from the Arduino build tools, so VisualGDB will always show the\u00a0precise list of source files used by the various project&#8217;s libraries and will configure IntelliSense to see the code exactly the same as the compiler does (including the automatic generation of Arduino function prototypes for sketch files).<\/li>\n<li>Now you can program the\u00a0built project into the FLASH memory. Simply right-click on the project in Solution Explorer and select the corresponding\u00a0command:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/07-program.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4107\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/07-program.png\" alt=\"07-program\" width=\"1133\" height=\"723\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/07-program.png 1133w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/07-program-300x191.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/07-program-1024x653.png 1024w\" sizes=\"(max-width: 1133px) 100vw, 1133px\" \/><\/a><\/li>\n<li>VisualGDB will invoke the Arduino tools to program the memory using the Arduino bootloader and will display a confirmation once the memory is programmed:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/08-uploaded.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4108\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/08-uploaded.png\" alt=\"08-uploaded\" width=\"1254\" height=\"831\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/08-uploaded.png 1254w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/08-uploaded-300x199.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/08-uploaded-1024x679.png 1024w\" sizes=\"(max-width: 1254px) 100vw, 1254px\" \/><\/a><\/li>\n<li>Now we will show how to\u00a0reference\u00a0libraries from your sketches. Start typing <strong>#include &lt;SoftwareSerial.h&gt;<\/strong> and wait for the IntelliSense suggestion to appear:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/09-serial.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4109\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/09-serial.png\" alt=\"09-serial\" width=\"1254\" height=\"831\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/09-serial.png 1254w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/09-serial-300x199.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/09-serial-1024x679.png 1024w\" sizes=\"(max-width: 1254px) 100vw, 1254px\" \/><\/a>The advanced Arduino projects\u00a0are aware of\u00a0the libraries available\u00a0on the selected platform and can suggest the related header files automatically. Once you include the header file and save the source file, VisualGDB will automatically find the library, show it in Solution Explorer and configure IntelliSense to handle it properly:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/10-inst1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4119\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/10-inst1.png\" alt=\"10-inst\" width=\"1254\" height=\"831\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/10-inst1.png 1254w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/10-inst1-300x199.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/10-inst1-1024x679.png 1024w\" sizes=\"(max-width: 1254px) 100vw, 1254px\" \/><\/a><\/li>\n<li>Replace the contents of the main sketch file with\u00a0the following code:\n<pre class=\"\">#include &lt;SoftwareSerial.h&gt;\r\n\r\nSoftwareSerial serial(10, 11);\r\n\r\nvoid setup()\r\n{\r\n    pinMode(LED_BUILTIN, OUTPUT);\r\n \r\n    Serial.begin(57600);\r\n    while (!Serial)\r\n    {\r\n    }\r\n}\r\n\r\nint g_Iteration;\r\n\r\nvoid loop()\r\n{\r\n    digitalWrite(LED_BUILTIN, HIGH);\r\n    delay(1000);\r\n    digitalWrite(LED_BUILTIN, LOW);\r\n    delay(1000);\r\n \r\n    char tmp[32];\r\n    sprintf(tmp, \"Iteration %d\\r\\n\", g_Iteration++);\r\n    Serial.write(tmp);\r\n}<\/pre>\n<p>Then build the project:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/10-inst.png\"><br \/>\n<\/a> <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/11-code.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4111\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/11-code.png\" alt=\"11-code\" width=\"1254\" height=\"831\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/11-code.png 1254w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/11-code-300x199.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/11-code-1024x679.png 1024w\" sizes=\"(max-width: 1254px) 100vw, 1254px\" \/><\/a><\/li>\n<li>Right-click on the project in\u00a0Solution Explorer and\u00a0click VisualGDB Project Properties. Then go to the Arduino Serial Terminal page and enable the\u00a0terminal (ensure the baud rate matches the 57600 bits per second configured in the code):<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/12-comport.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4112\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/12-comport.png\" alt=\"12-comport\" width=\"863\" height=\"685\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/12-comport.png 863w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/12-comport-300x238.png 300w\" sizes=\"(max-width: 863px) 100vw, 863px\" \/><\/a><\/li>\n<li>Program the device FLASH memory again and open the serial terminal via\u00a0the context menu in Solution Explorer:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/13-openterm.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4113\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/13-openterm.png\" alt=\"13-openterm\" width=\"1254\" height=\"831\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/13-openterm.png 1254w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/13-openterm-300x199.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/13-openterm-1024x679.png 1024w\" sizes=\"(max-width: 1254px) 100vw, 1254px\" \/><\/a><\/li>\n<li>VisualGDB will display the output from your sketch in a\u00a0terminal pane inside the Visual Studio window:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/14-termopened.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4114\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/14-termopened.png\" alt=\"14-termopened\" width=\"1254\" height=\"831\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/14-termopened.png 1254w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/14-termopened-300x199.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/14-termopened-1024x679.png 1024w\" sizes=\"(max-width: 1254px) 100vw, 1254px\" \/><\/a>Note that you can use the <a href=\"https:\/\/en.wikipedia.org\/wiki\/ANSI_escape_code\">ANSI escape sequences<\/a> if you want to add colors to your sketch output.<\/li>\n<li>VisualGDB automatically indexes the sources of all libraries used by the sketch. This way you can use the &#8220;Go to definition&#8221; command to locate the definitions of various functions or methods (e.g. write()), or Code Map to\u00a0visualize the code structure:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/15-goto.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4115\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/15-goto.png\" alt=\"15-goto\" width=\"1254\" height=\"831\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/15-goto.png 1254w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/15-goto-300x199.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/15-goto-1024x679.png 1024w\" sizes=\"(max-width: 1254px) 100vw, 1254px\" \/><\/a><\/li>\n<li>You can use the VisualGDB Embedded Memory Explorer to analyze the memory\u00a0used by your sketch:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/16-eme.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4116\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/16-eme.png\" alt=\"16-eme\" width=\"1254\" height=\"831\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/16-eme.png 1254w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/16-eme-300x199.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/16-eme-1024x679.png 1024w\" sizes=\"(max-width: 1254px) 100vw, 1254px\" \/><\/a><\/li>\n<li>Click &#8220;Explore details&#8221; to switch to the detailed view:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/17-emebrief.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4117\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/17-emebrief.png\" alt=\"17-emebrief\" width=\"1254\" height=\"831\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/17-emebrief.png 1254w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/17-emebrief-300x199.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/17-emebrief-1024x679.png 1024w\" sizes=\"(max-width: 1254px) 100vw, 1254px\" \/><\/a><\/li>\n<li>Now you can see the\u00a0contribution to the memory footprint of the\u00a0individual sections, source files, or functions.\u00a0VisualGDB will also\u00a0display\u00a0the sizes directly in the code, so you can make changes to your code and quickly see how it affects the footprint:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/18-emedetail.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4118\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/18-emedetail.png\" alt=\"18-emedetail\" width=\"1254\" height=\"831\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/18-emedetail.png 1254w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/18-emedetail-300x199.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/18-emedetail-1024x679.png 1024w\" sizes=\"(max-width: 1254px) 100vw, 1254px\" \/><\/a><\/li>\n<\/ol>\n<p>You can also configure VisualGDB to debug your AVR-based Arduino board. See <a href=\"https:\/\/visualgdb.com\/tutorials\/arduino\/avr\/debug\/\">this tutorial<\/a> for a detailed list of steps.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to use the Advanced Arduino Project Subsystem of VisualGDB to easily develop Arduino projects with Visual<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[169],"tags":[170,126],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4100"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=4100"}],"version-history":[{"count":4,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4100\/revisions"}],"predecessor-version":[{"id":4226,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4100\/revisions\/4226"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=4100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=4100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=4100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}