{"id":4139,"date":"2018-10-08T10:37:08","date_gmt":"2018-10-08T17:37:08","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=4139"},"modified":"2018-10-08T10:37:08","modified_gmt":"2018-10-08T17:37:08","slug":"developing-esp32-arduino-projects-with-visual-studio","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/arduino\/esp32\/","title":{"rendered":"Developing ESP32 Arduino Projects with Visual Studio"},"content":{"rendered":"<p>This tutorial shows how to develop and debug Arduino projects for the ESP32-based boards using Visual Studio and the Advanced Arduino Project Subsystem of VisualGDB.\u00a0We will create a basic &#8220;Blinking LED&#8221; project for the SparkFun ESP32 Thing board and will show how\u00a0to navigate the code and debug the project.<\/p>\n<p>Before you begin, install VisualGDB 5.4 Preview 4 or later.<\/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-newprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4140\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-newprj.png\" alt=\"01-newprj\" width=\"941\" height=\"622\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-newprj.png 941w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-newprj-300x198.png 300w\" sizes=\"(max-width: 941px) 100vw, 941px\" \/><\/a><\/li>\n<li>Proceed with the default &#8220;Blinking LED&#8221; project:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-blink.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4141\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-blink.png\" alt=\"02-blink\" width=\"856\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-blink.png 856w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-blink-300x243.png 300w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a><\/li>\n<li>On the next page select your ESP32 board. If you don&#8217;t see your board in the list, select any other ESP32-based board and click &#8220;Install&#8221; to automatically get the ESP32 Arduino core along with an up-to-date board list:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-sparkfun.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4142\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-sparkfun.png\" alt=\"03-sparkfun\" width=\"856\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-sparkfun.png 856w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-sparkfun-300x243.png 300w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a><\/li>\n<li>Once you selected your board, connect it to the USB port and pick the COM\u00a0corresponding to it below:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/04-comport1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4143\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/04-comport1.png\" alt=\"04-comport\" width=\"856\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/04-comport1.png 856w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/04-comport1-300x243.png 300w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a><\/li>\n<li>Debugging ESP32 boards requires a JTAG debugger (e.g. Olimex ARM-USB-OCD-H or Segger J-Link). You can find detailed board-specific wiring instructions in our <a href=\"https:\/\/visualgdb.com\/w\/tutorials\/tag\/esp32\/\">ESP32 tutorials <\/a>\u00a0(see\u00a0 <a href=\"https:\/\/visualgdb.com\/tutorials\/esp32\/\">this tutorial<\/a> for SparkFun ESP32 Thing instructions).\u00a0Connect your debugger to the board and plug it into the USB port. Select it in the &#8220;USB Devices&#8221; view to automatically configure it for debugging:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/05-jlink.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4144\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/05-jlink.png\" alt=\"05-jlink\" width=\"856\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/05-jlink.png 856w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/05-jlink-300x243.png 300w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a><\/li>\n<li>Press &#8220;Finish&#8221; to generate the project. VisualGDB will generate an Advanced Arduino Project including both a basic sketch and the ESP32 Arduino core. Build it via Ctrl-Shift-B:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/06-build1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4145\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/06-build1.png\" alt=\"06-build\" width=\"1251\" height=\"786\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/06-build1.png 1251w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/06-build1-300x188.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/06-build1-1024x643.png 1024w\" sizes=\"(max-width: 1251px) 100vw, 1251px\" \/><\/a>Note that the build is done using the Arduino builder tool, so the result will be the same as\u00a0when using the Arduino IDE. VisualGDB also queries the\u00a0detailed code model from the Arduino builder that allows\u00a0displaying the precise list of source files used by the project and various libraries, and also configures IntelliSense to see the code exactly as the compiler does.<\/li>\n<li>Once the project is built, press F5 to start debugging it:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/07-program1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4146\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/07-program1.png\" alt=\"07-program\" width=\"1251\" height=\"786\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/07-program1.png 1251w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/07-program1-300x188.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/07-program1-1024x643.png 1024w\" sizes=\"(max-width: 1251px) 100vw, 1251px\" \/><\/a>VisualGDB will automatically program the\u00a0FLASH memory and begin running the project. The on-board LED will start blinking as expected.<\/li>\n<li>Set a breakpoint inside the loop() function and wait for it to trigger:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/08-stop.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4147\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/08-stop.png\" alt=\"08-stop\" width=\"1251\" height=\"786\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/08-stop.png 1251w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/08-stop-300x188.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/08-stop-1024x643.png 1024w\" sizes=\"(max-width: 1251px) 100vw, 1251px\" \/><\/a>Once the breakpoint triggers, you will be able to debug\u00a0the code as any other Visual Studio project.<\/li>\n<li>VisualGDB will automatically disable optimization when compiling the sketch (but not the platform or the libraries) when building the debug configuration, to ensure the best debugging experience.\u00a0You can alter this behavior via the first page of VisualGDB Project Properties:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/optim.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4158\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/optim.png\" alt=\"optim\" width=\"1069\" height=\"700\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/optim.png 1069w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/optim-300x196.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/optim-1024x671.png 1024w\" sizes=\"(max-width: 1069px) 100vw, 1069px\" \/><\/a><\/li>\n<li>As VisualGDB indexes all the source files used by the project, you can use commands like Go To Definition, Peek Definition, Code Map, etc. to easily explore the\u00a0code of your sketches, the Arduino core and the related libraries:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/09-def.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4148\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/09-def.png\" alt=\"09-def\" width=\"1251\" height=\"786\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/09-def.png 1251w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/09-def-300x188.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/09-def-1024x643.png 1024w\" sizes=\"(max-width: 1251px) 100vw, 1251px\" \/><\/a><\/li>\n<li>Now we will show how to use the Arduino API for the serial port. Include the &lt;HardwareSerial.h&gt; file from your sketch:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/10-serial.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4149\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/10-serial.png\" alt=\"10-serial\" width=\"1251\" height=\"786\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/10-serial.png 1251w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/10-serial-300x188.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/10-serial-1024x643.png 1024w\" sizes=\"(max-width: 1251px) 100vw, 1251px\" \/><\/a>Note how VisualGDB shows the header files of available libraries with a special package icon. Including those header\u00a0files will automatically reference the corresponding libraries once you save the sketch file.<\/li>\n<li>Replace the contents of your sketch file with the following code:\n<pre class=\"\">#include &lt;HardwareSerial.h&gt;\r\n\r\nvoid setup()\r\n{\r\n    pinMode(LED_BUILTIN, OUTPUT);\r\n    Serial.begin(115200);\r\n}\r\n\r\nint g_Iter = 0;\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_Iter++);\r\n    Serial.write(tmp);\r\n}<\/pre>\n<p>Then build your project by pressing Ctrl-Shift-B:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/11-build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4150\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/11-build.png\" alt=\"11-build\" width=\"1251\" height=\"786\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/11-build.png 1251w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/11-build-300x188.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/11-build-1024x643.png 1024w\" sizes=\"(max-width: 1251px) 100vw, 1251px\" \/><\/a><\/li>\n<li>Open VisualGDB Project Properties and go to the Arduino Serial Terminal page. Enable the serial terminal and ensure that the baud rate matches the\u00a0one\u00a0configured in the sketch file:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/12-terminal.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4151\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/12-terminal.png\" alt=\"12-terminal\" width=\"861\" height=\"543\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/12-terminal.png 861w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/12-terminal-300x189.png 300w\" sizes=\"(max-width: 861px) 100vw, 861px\" \/><\/a><\/li>\n<li>Press F5 to begin debugging. Now you will see the\u00a0output from the <strong>Serial<\/strong> API\u00a0in the terminal pane inside Visual Studio:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/13-output.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4152\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/13-output.png\" alt=\"13-output\" width=\"1251\" height=\"786\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/13-output.png 1251w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/13-output-300x188.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/13-output-1024x643.png 1024w\" sizes=\"(max-width: 1251px) 100vw, 1251px\" \/><\/a><\/li>\n<li>You can set breakpoints and step through your code as usual. Since the debugging is done via the JTAG interface, it will not interfere with the serial port output:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/14-bkpt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4153\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/14-bkpt.png\" alt=\"14-bkpt\" width=\"1251\" height=\"786\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/14-bkpt.png 1251w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/14-bkpt-300x188.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/14-bkpt-1024x643.png 1024w\" sizes=\"(max-width: 1251px) 100vw, 1251px\" \/><\/a><\/li>\n<li>You can also program the FLASH memory without debugging and open the serial terminal via the context menu in Solution Explorer:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/15-program.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4154\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/15-program.png\" alt=\"15-program\" width=\"1251\" height=\"786\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/15-program.png 1251w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/15-program-300x188.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/15-program-1024x643.png 1024w\" sizes=\"(max-width: 1251px) 100vw, 1251px\" \/><\/a><\/li>\n<li>If you encounter problems programming the FLASH memory using OpenOCD, select &#8220;Program FLASH using Arduino tools&#8221; on the Debug Settings page of VisualGDB Project Properties.\u00a0This will configure VisualGDB to\u00a0program the FLASH memory using esptool.py and the ESP32 bootloader instead of the OpenOCD FLASH programming logic:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/16-tools.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4155\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/16-tools.png\" alt=\"16-tools\" width=\"949\" height=\"612\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/16-tools.png 949w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/16-tools-300x193.png 300w\" sizes=\"(max-width: 949px) 100vw, 949px\" \/><\/a><\/li>\n<li>Run the View-&gt;Embedded Memory Explorer command to see an overview of memory utilization for your ESP32 board:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/17-eme.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4156\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/17-eme.png\" alt=\"17-eme\" width=\"1251\" height=\"786\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/17-eme.png 1251w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/17-eme-300x188.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/17-eme-1024x643.png 1024w\" sizes=\"(max-width: 1251px) 100vw, 1251px\" \/><\/a><\/li>\n<li>Click &#8220;explore details&#8221; to view the detailed information about each function, method and global variable and also highlight their sizes and the memory type where they are placed directly in the code: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/18-memories.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4157\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/18-memories.png\" alt=\"18-memories\" width=\"1251\" height=\"786\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/18-memories.png 1251w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/18-memories-300x188.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/18-memories-1024x643.png 1024w\" sizes=\"(max-width: 1251px) 100vw, 1251px\" \/><\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to develop and debug Arduino projects for the ESP32-based boards using Visual Studio and the Advanced<\/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,138],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4139"}],"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=4139"}],"version-history":[{"count":3,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4139\/revisions"}],"predecessor-version":[{"id":8915,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4139\/revisions\/8915"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=4139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=4139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=4139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}