{"id":2432,"date":"2021-02-10T12:03:22","date_gmt":"2021-02-10T11:03:22","guid":{"rendered":"https:\/\/www.pschatzmann.ch\/home\/?p=2432"},"modified":"2021-03-24T18:33:39","modified_gmt":"2021-03-24T17:33:39","slug":"using-arduino-libraries-on-the-pico","status":"publish","type":"post","link":"https:\/\/www.pschatzmann.ch\/home\/2021\/02\/10\/using-arduino-libraries-on-the-pico\/","title":{"rendered":"Using Arduino Libraries on the Pico"},"content":{"rendered":"<p>I am quite enthusiastic about the <a href=\"https:\/\/www.raspberrypi.org\/documentation\/pico\/getting-started\/\">new Raspberry Pico<\/a>. However I find the C SDK not very friendly and I prefer to have something as simple as the Arduino API. I did not want to wait for the official Arduino support &#8211; so I started <a href=\"https:\/\/github.com\/pschatzmann\/pico-arduino\">my own project<\/a>.<\/p>\n<p>So the question is, can we use any <strong>Standard Arduino Libraries<\/strong> with this and the answer is yes we can!<\/p>\n<p>We just need to use a little bit of <strong>cmake<\/strong> magic for this. For the example I am using my <a href=\"https:\/\/github.com\/pschatzmann\/SpektrumSatellite\">Spektrum Satellite Arduino Library<\/a>:<\/p>\n<h3>Download the Library From Github<\/h3>\n<p><strong>cmake<\/strong> has some <a href=\"https:\/\/cmake.org\/cmake\/help\/latest\/module\/ExternalProject.html\">ExternalProject<\/a> functionality. Unfortunately it is executed on build and assumes that the project is a cmake project which contains a CMakeList.txt as well &#8211; which is not the case for most of the existing Arduino libraries. Fortunately there is also a command which is executed on configuration: <a href=\"https:\/\/cmake.org\/cmake\/help\/latest\/module\/FetchContent.html\">FetchContent<\/a><\/p>\n<p>With the following code we can execute a <strong>&#8220;git clone&#8221; command<\/strong> in order to get the library into the current build directory:<\/p>\n<pre><code>include(FetchContent)\n\nFetchContent_Declare( spektrum_satellite \n    GIT_REPOSITORY https:\/\/github.com\/pschatzmann\/SpektrumSatellite.git\n    GIT_TAG  master\n)\nFetchContent_MakeAvailable(spektrum_satellite)\n\n<\/code><\/pre>\n<p>Of cause you can skip this step if you have the source code already anywhere on your system.<\/p>\n<h3>Include Header Files<\/h3>\n<p>Next we need to make sure that the compiler finds the new header files. We just include the source code of the downloaded library with <a href=\"https:\/\/cmake.org\/cmake\/help\/latest\/command\/include_directories.html\">include_directories<\/a>:<\/p>\n<pre><code># Define include directories\ninclude_directories(\n    \"${spektrum_satellite_SOURCE_DIR}\/src\/\"\n    ...\n)\n\n<\/code><\/pre>\n<h3>Define .cpp Files<\/h3>\n<p>Finally &#8211; if the Arduino Project is not header only and contains .c or .cpp source files &#8211; we need to make them known. So first we collect them in a variable  with the help of the <a href=\"https:\/\/cmake.org\/cmake\/help\/latest\/command\/file.html\">file(GLOB)<\/a> command. In our case we use <strong>LIB_SRC<\/strong>. To keep things consistent we also get the all the source files from the current source directory into the variable <strong>CURRENT_SRC<\/strong>. This covers the current Arduino sketch:<\/p>\n<pre><code>file(GLOB LIB_SRC \"${spektrum_satellite_SOURCE_DIR}\/src\/*.cpp\")\nfile(GLOB CURRENT_SRC  ${CMAKE_CURRENT_SOURCE_DIR}\/*.cpp )\n\n<\/code><\/pre>\n<p>Now we are ready to add all source files to the <a href=\"https:\/\/cmake.org\/cmake\/help\/latest\/command\/add_executable.html\">add_executable<\/a>:<\/p>\n<pre><code>add_executable(example_sketch ${CURRENT_SRC} ${LIB_SRC} )\n<\/code><\/pre>\n<h3>Buiding the Project<\/h3>\n<p>We just process the same steps as always from the sketch directory:<\/p>\n<pre><code>mkdir build\ncd build \ncmake ..\nmake\n<\/code><\/pre>\n<p>The <a href=\"https:\/\/github.com\/pschatzmann\/pico-arduino\/tree\/main\/examples\/example_with_arduino_library\">full example can be found on Github<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am quite enthusiastic about the new Raspberry Pico. However I find the C SDK not very friendly and I prefer to have something as simple as the Arduino API. I did not want to wait for the official Arduino support &#8211; so I started my own project. So the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2416,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[20,24],"tags":[],"class_list":["post-2432","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","category-pico"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Using Arduino Libraries on the Pico - Phil Schatzmann<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pschatzmann.ch\/home\/2021\/02\/10\/using-arduino-libraries-on-the-pico\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using Arduino Libraries on the Pico - Phil Schatzmann\" \/>\n<meta property=\"og:description\" content=\"I am quite enthusiastic about the new Raspberry Pico. However I find the C SDK not very friendly and I prefer to have something as simple as the Arduino API. I did not want to wait for the official Arduino support &#8211; so I started my own project. So the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pschatzmann.ch\/home\/2021\/02\/10\/using-arduino-libraries-on-the-pico\/\" \/>\n<meta property=\"og:site_name\" content=\"Phil Schatzmann\" \/>\n<meta property=\"article:published_time\" content=\"2021-02-10T11:03:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-03-24T17:33:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/01\/pico.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"266\" \/>\n\t<meta property=\"og:image:height\" content=\"190\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"pschatzmann\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"pschatzmann\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/02\\\/10\\\/using-arduino-libraries-on-the-pico\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/02\\\/10\\\/using-arduino-libraries-on-the-pico\\\/\"},\"author\":{\"name\":\"pschatzmann\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"headline\":\"Using Arduino Libraries on the Pico\",\"datePublished\":\"2021-02-10T11:03:22+00:00\",\"dateModified\":\"2021-03-24T17:33:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/02\\\/10\\\/using-arduino-libraries-on-the-pico\\\/\"},\"wordCount\":339,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/02\\\/10\\\/using-arduino-libraries-on-the-pico\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/pico.jpeg\",\"articleSection\":[\"Arduino\",\"Pico\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/02\\\/10\\\/using-arduino-libraries-on-the-pico\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/02\\\/10\\\/using-arduino-libraries-on-the-pico\\\/\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/02\\\/10\\\/using-arduino-libraries-on-the-pico\\\/\",\"name\":\"Using Arduino Libraries on the Pico - Phil Schatzmann\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/02\\\/10\\\/using-arduino-libraries-on-the-pico\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/02\\\/10\\\/using-arduino-libraries-on-the-pico\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/pico.jpeg\",\"datePublished\":\"2021-02-10T11:03:22+00:00\",\"dateModified\":\"2021-03-24T17:33:39+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/02\\\/10\\\/using-arduino-libraries-on-the-pico\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/02\\\/10\\\/using-arduino-libraries-on-the-pico\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/02\\\/10\\\/using-arduino-libraries-on-the-pico\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/pico.jpeg\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/pico.jpeg\",\"width\":266,\"height\":190},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/02\\\/10\\\/using-arduino-libraries-on-the-pico\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using Arduino Libraries on the Pico\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\",\"name\":\"Phil Schatzmann Consulting\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\",\"name\":\"pschatzmann\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"width\":305,\"height\":305,\"caption\":\"pschatzmann\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using Arduino Libraries on the Pico - Phil Schatzmann","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pschatzmann.ch\/home\/2021\/02\/10\/using-arduino-libraries-on-the-pico\/","og_locale":"en_US","og_type":"article","og_title":"Using Arduino Libraries on the Pico - Phil Schatzmann","og_description":"I am quite enthusiastic about the new Raspberry Pico. However I find the C SDK not very friendly and I prefer to have something as simple as the Arduino API. I did not want to wait for the official Arduino support &#8211; so I started my own project. So the [&hellip;]","og_url":"https:\/\/www.pschatzmann.ch\/home\/2021\/02\/10\/using-arduino-libraries-on-the-pico\/","og_site_name":"Phil Schatzmann","article_published_time":"2021-02-10T11:03:22+00:00","article_modified_time":"2021-03-24T17:33:39+00:00","og_image":[{"width":266,"height":190,"url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/01\/pico.jpeg","type":"image\/jpeg"}],"author":"pschatzmann","twitter_card":"summary_large_image","twitter_misc":{"Written by":"pschatzmann","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/02\/10\/using-arduino-libraries-on-the-pico\/#article","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/02\/10\/using-arduino-libraries-on-the-pico\/"},"author":{"name":"pschatzmann","@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"headline":"Using Arduino Libraries on the Pico","datePublished":"2021-02-10T11:03:22+00:00","dateModified":"2021-03-24T17:33:39+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/02\/10\/using-arduino-libraries-on-the-pico\/"},"wordCount":339,"commentCount":0,"publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/02\/10\/using-arduino-libraries-on-the-pico\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/01\/pico.jpeg","articleSection":["Arduino","Pico"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pschatzmann.ch\/home\/2021\/02\/10\/using-arduino-libraries-on-the-pico\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/02\/10\/using-arduino-libraries-on-the-pico\/","url":"https:\/\/www.pschatzmann.ch\/home\/2021\/02\/10\/using-arduino-libraries-on-the-pico\/","name":"Using Arduino Libraries on the Pico - Phil Schatzmann","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/02\/10\/using-arduino-libraries-on-the-pico\/#primaryimage"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/02\/10\/using-arduino-libraries-on-the-pico\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/01\/pico.jpeg","datePublished":"2021-02-10T11:03:22+00:00","dateModified":"2021-03-24T17:33:39+00:00","breadcrumb":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/02\/10\/using-arduino-libraries-on-the-pico\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pschatzmann.ch\/home\/2021\/02\/10\/using-arduino-libraries-on-the-pico\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/02\/10\/using-arduino-libraries-on-the-pico\/#primaryimage","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/01\/pico.jpeg","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/01\/pico.jpeg","width":266,"height":190},{"@type":"BreadcrumbList","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/02\/10\/using-arduino-libraries-on-the-pico\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pschatzmann.ch\/home\/"},{"@type":"ListItem","position":2,"name":"Using Arduino Libraries on the Pico"}]},{"@type":"WebSite","@id":"https:\/\/www.pschatzmann.ch\/home\/#website","url":"https:\/\/www.pschatzmann.ch\/home\/","name":"Phil Schatzmann Consulting","description":"","publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pschatzmann.ch\/home\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1","name":"pschatzmann","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","width":305,"height":305,"caption":"pschatzmann"},"logo":{"@id":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png"}}]}},"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/2432","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/comments?post=2432"}],"version-history":[{"count":33,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/2432\/revisions"}],"predecessor-version":[{"id":2723,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/2432\/revisions\/2723"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media\/2416"}],"wp:attachment":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media?parent=2432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/categories?post=2432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/tags?post=2432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}