{"id":169,"date":"2023-09-07T17:39:31","date_gmt":"2023-09-08T00:39:31","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=169"},"modified":"2023-09-08T08:54:30","modified_gmt":"2023-09-08T15:54:30","slug":"raspberry-wiringpi","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/raspberry\/wiringPi\/","title":{"rendered":"Using WiringPi library with Raspberry PI cross-compiler"},"content":{"rendered":"<p>This tutorial shows how to develop a blinking LED project for Raspberry Pi in Visual Studio using the WiringPi library and our cross-toolchain.<\/p>\n<p>Before we begin, ensure that <a href=\"\/download\">VisualGDB<\/a> is installed.<\/p>\n<ol>\n<li>If you do not have a LED prepared to connect to the expansion connector on the Raspberry Pi, please follow the steps 1-8 of our <a href=\"\/tutorials\/raspberry\/LED\/\"> other blinking LED tutorial<\/a> to prepare and connect a LED.<\/li>\n<li>Now create a basic Raspberry Pi cross-compilation project with VisualGDB by following <a href=\"\/tutorials\/raspberry\/crosscompiler\/\">this tutorial<\/a>. If you are familiar with the classic Visual Studio C++ projects, we recommend using MSBuild (shown in this tutorial). Otherwise, try using <a href=\"https:\/\/visualgdb.com\/documentation\/projects\/cmake\/\">Advanced CMake<\/a>.<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/01-prj-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8301\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/01-prj-1.png\" alt=\"\" width=\"1030\" height=\"691\" \/><\/a><\/li>\n<li>Next we install the wiringPi library on the Raspberry. Open <strong>VisualGDB Project Properties -&gt; Proejct Settings<\/strong>, locate the <strong>Deployment Machine<\/strong> setting and click the console button next to it:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/02-ssh.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8302\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/02-ssh.png\" alt=\"\" width=\"1030\" height=\"691\" \/><\/a><\/li>\n<li>We follow the <a href=\"http:\/\/wiringpi.com\/download-and-install\/\">official installation steps<\/a>.\n<pre class=\"\">sudo apt-get install git-core\r\ngit clone https:\/\/github.com\/WiringPi\/WiringPi\r\ncd WiringPi\r\n.\/build<\/pre>\n<p><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/03-wiring.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8304\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/03-wiring.png\" alt=\"\" width=\"786\" height=\"593\" \/><\/a>This will build all the necessary files and install the libraries and include files into the corresponding directories on your Raspberry PI. The next step would be to import them to the cross-compiler.<\/li>\n<li>Go back to Visual Studio. Right-click on the project in Solution Explorer and choose VisualGDB Project Properties. Go to the <strong>MSBuild Settings<\/strong> (or <strong>CMake Build Settings<\/strong> page if you are using CMake) and click &#8220;Synchronize Sysroot&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/04-sync.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8305\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/04-sync.png\" alt=\"\" width=\"874\" height=\"571\" \/><\/a><\/li>\n<li>This will download the include and library directories from your Raspberry PI to the corresponding directories in the cross-compiler toolchain so that the cross-compiler can use your newly installed wiringPi library:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/05-mismatching.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8306\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/05-mismatching.png\" alt=\"\" width=\"786\" height=\"443\" \/><\/a><\/li>\n<li>In order to use <strong>wiringPi<\/strong> in your application, you would need to reference the <strong>=\/usr\/local\/include<\/strong> header directory (&#8216;=&#8217; refers to the toolchain&#8217;s sysroot) and the <strong>wiringPi<\/strong> library. Although you can do it directly via VisualGDB Project Properties or MSBuild\/CMake Properties, in this tutorial we will show how to let VisualGDB discover the missing dependencies automatically. Replace the source with the following.\n<pre class=\"\">#include &lt;wiringPi.h&gt;\r\n\r\nint main(int argc, char *argv[])\r\n{\r\n    wiringPiSetup();\r\n    const int pinNumber = 2;\r\n\r\n    pinMode(pinNumber, OUTPUT);\r\n\r\n    for (;;)\r\n    {\r\n        digitalWrite(pinNumber, HIGH);\r\n        delay(100);\r\n        digitalWrite(pinNumber, LOW);\r\n        delay(100);\r\n    }\r\n    return 0;\r\n}<\/pre>\n<\/li>\n<li>VisualGDB will immediately report that <strong>wiringPi.h<\/strong> is missing. Click the <strong>Review<\/strong> button:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/07-missing.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8308\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/07-missing.png\" alt=\"\" width=\"1030\" height=\"691\" \/><\/a><\/li>\n<li>In the <a href=\"https:\/\/visualgdb.com\/tutorials\/intellisense\/headers\/\">header discovery<\/a> popup, click &#8220;<strong>Search in another location<\/strong>&#8221; and point VisualGDB to the toolchain directory (e.g. <strong>c:\\SysGCC\\raspberry<\/strong>):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/08-search.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8309\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/08-search.png\" alt=\"\" width=\"1030\" height=\"691\" \/><\/a><\/li>\n<li>VisualGDB will discover the missing file in <strong>&lt;sysroot&gt;\/usr\/local\/include<\/strong> and will suggest referencing it. Click &#8220;<strong>Add selected directories<\/strong>&#8221; to automatically fix the project:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/09-add.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8310\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/09-add.png\" alt=\"\" width=\"1030\" height=\"691\" \/><\/a><\/li>\n<li>Try building the project. It will complain about missing <strong>wiringPiSetup()<\/strong> and a few other functions. Click &#8220;Review&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/10-undef.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8311\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/10-undef.png\" alt=\"\" width=\"1030\" height=\"691\" \/><\/a><\/li>\n<li>VisualGDB will show a list of missing symbols and will offer several troubleshooting options. Click &#8220;<strong>Search common library directories<\/strong>&#8220;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/11-search.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8312\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/11-search.png\" alt=\"\" width=\"786\" height=\"429\" \/><\/a><\/li>\n<li>VisualGDB will successfully locate the <strong>wiringPi<\/strong> library that provides the missing symbols. You can reference it automatically by clicking &#8220;Resolve&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/12-found.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8313\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/12-found.png\" alt=\"\" width=\"786\" height=\"431\" \/><\/a><\/li>\n<li>You can review or modify the settings that were just discovered via VisualGDB Project Properties (<strong>MSBuild<\/strong> and <strong>GNU Make<\/strong> projects):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/13-settings-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8314\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/13-settings-1.png\" alt=\"\" width=\"874\" height=\"571\" \/><\/a><\/li>\n<li>Another option would be to use VS project properties (<strong>MSBuild<\/strong> and <strong>CMake<\/strong> projects):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/14-msbuild.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8315\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/14-msbuild.png\" alt=\"\" width=\"1030\" height=\"691\" \/><\/a><\/li>\n<li>If your Raspberry Pi does not allow accessing hardware from the regular user account, you can configure VisualGDB to run the program as root via <strong>VisualGDB Project Properties -&gt; Debug Settings<\/strong>:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/15-root.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8316\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/15-root.png\" alt=\"\" width=\"1020\" height=\"597\" \/><\/a><\/li>\n<li>Set a breakpoint as shown and start debugging. Step through the code and watch how the LED turns on and off:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/16-bkpt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8317\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/16-bkpt.png\" alt=\"\" width=\"1030\" height=\"691\" \/><\/a><a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/raspberry\/wiringPi\/led_on.JPG\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-12\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/raspberry\/wiringPi\/led_on.JPG\" alt=\"led_on\" width=\"700\" height=\"468\" \/><\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to develop a blinking LED project for Raspberry Pi in Visual Studio using the WiringPi library<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[64,79,33,85],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/169"}],"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=169"}],"version-history":[{"count":3,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/169\/revisions"}],"predecessor-version":[{"id":8318,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/169\/revisions\/8318"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=169"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=169"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}