{"id":3127,"date":"2021-05-12T07:22:17","date_gmt":"2021-05-12T05:22:17","guid":{"rendered":"https:\/\/www.pschatzmann.ch\/home\/?p=3127"},"modified":"2021-12-14T15:18:06","modified_gmt":"2021-12-14T14:18:06","slug":"arduino-raspberry-pico-under-the-hood","status":"publish","type":"post","link":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/12\/arduino-raspberry-pico-under-the-hood\/","title":{"rendered":"Arduino Raspberry Pico &#8211; Looking Under the Hood"},"content":{"rendered":"<p>Today I had a look under the hood of the <strong>Standard Arduino<\/strong> implementation for the <strong>Raspberry Pico<\/strong>. I was surprised that they did not base their work on the Pico API but they based their work on <a href=\"https:\/\/os.mbed.com\/docs\/mbed-os\/v6.10\/introduction\/index.html\">ARM Mbed<\/a>.<\/p>\n<p>Here is a blink example using the <a href=\"https:\/\/os.mbed.com\/docs\/mbed-os\/v6.10\/apis\/ticker.html\">Ticker<\/a> from the Mbed API:<\/p>\n<h3>Mbed Ticker<\/h3>\n<pre><code>#include \"mbed.h\"\n\nusing namespace mbed;\n\nTicker ticker; \nDigitalOut led1(LED1);\n\nvoid blink(){\n     led1 = !led1;\n}\n\nvoid setup() {\n    ticker.attach(&amp;blink, 1);\n}\n\nvoid loop() {\n}\n<\/code><\/pre>\n<h3>Mbed Ticker &#8211; with Arduino Pin Names<\/h3>\n<p>In Arduino we do not want to introduce another set of pin names! Fortunately we can use the <strong>digitalPinToPinName()<\/strong> method to convert an Arduino PIN into a Mbed pin. So we can use the Arduino <strong>LED_BUILTIN<\/strong> like this:<\/p>\n<pre><code>#include \"mbed.h\"\n#include \"pinDefinitions.h\"\n\nusing namespace mbed;\n\nTicker ticker; \nDigitalOut led1(digitalPinToPinName(LED_BUILTIN));\n\nvoid blink(){\n     led1 = !led1;\n}\n\nvoid setup() {\n    ticker.attach(&amp;blink, 1);\n}\n\nvoid loop() {\n}\n\n<\/code><\/pre>\n<h3>Mbed PWM<\/h3>\n<p>Arduino has just a limited PWM functionality usually at just one predefined frequency. In Mbed we have the power to flexibly define the frequency as well:<\/p>\n<pre><code>#include \"mbed.h\"\n#include \"pinDefinitions.h\"\n\nusing namespace mbed;\n\nTicker ticker; \nPwmOut led(digitalPinToPinName(LED_BUILTIN));\n\nfloat value = 0;\nvoid setup() {\n  \/\/led.period(1.0f);   \/\/ 1 second period\n  \/\/led.period_ms(1);   \/\/ 1 millisecond period\n  led.period_us(1000);  \/\/ 1000 microseconds\n}\n\nvoid loop() {\n  value += 0.00001;\n  led.write(value); \/\/ between 0.0 and 1.0\n  if (value&gt;=1.0) {\n    value = 0;      \n  }\n}\n<\/code><\/pre>\n<h3>Mbed Threads<\/h3>\n<p>It is also possible to start new threads:<\/p>\n<pre><code>#include \"mbed.h\"\n\nusing namespace mbed;\n\nrtos::Thread thread;\nrtos::Semaphore semaphore(1);\n\nvoid runInThread() {\n    while(true){\n        semaphore.acquire();\n        Serial.println(\"hallo from thread\");\n        semaphore.release();      \n        delay(1000);\n    }\n}\n\nvoid setup() {\n  Serial.begin(115200);\n  thread.start(runInThread);\n\n}\n\nvoid loop() {\n    semaphore.acquire();\n    Serial.println(\"hallo from thread\");\n    semaphore.release();      \n\n    delay(1000);\n\n}\n<\/code><\/pre>\n<h3>Conclusion<\/h3>\n<p>It is good to know that if something is missing in the Arduino API, we have access to a richer API &#8211; that we can use if we are ready to sacrifice portability to other architectures&#8230;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I had a look under the hood of the Standard Arduino implementation for the Raspberry Pico. I was surprised that they did not base their work on the Pico API but they based their work on ARM Mbed. Here is a blink example using the Ticker from the Mbed [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3128,"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":[30],"class_list":["post-3127","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","category-pico","tag-back-to-basics"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Arduino Raspberry Pico - Looking Under the Hood - 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\/05\/12\/arduino-raspberry-pico-under-the-hood\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Arduino Raspberry Pico - Looking Under the Hood - Phil Schatzmann\" \/>\n<meta property=\"og:description\" content=\"Today I had a look under the hood of the Standard Arduino implementation for the Raspberry Pico. I was surprised that they did not base their work on the Pico API but they based their work on ARM Mbed. Here is a blink example using the Ticker from the Mbed [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/12\/arduino-raspberry-pico-under-the-hood\/\" \/>\n<meta property=\"og:site_name\" content=\"Phil Schatzmann\" \/>\n<meta property=\"article:published_time\" content=\"2021-05-12T05:22:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-14T14:18:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/05\/Arduino.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"225\" \/>\n\t<meta property=\"og:image:height\" content=\"225\" \/>\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\\\/05\\\/12\\\/arduino-raspberry-pico-under-the-hood\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/12\\\/arduino-raspberry-pico-under-the-hood\\\/\"},\"author\":{\"name\":\"pschatzmann\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"headline\":\"Arduino Raspberry Pico &#8211; Looking Under the Hood\",\"datePublished\":\"2021-05-12T05:22:17+00:00\",\"dateModified\":\"2021-12-14T14:18:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/12\\\/arduino-raspberry-pico-under-the-hood\\\/\"},\"wordCount\":182,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/12\\\/arduino-raspberry-pico-under-the-hood\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/Arduino.jpeg\",\"keywords\":[\"Back to Basics\"],\"articleSection\":[\"Arduino\",\"Pico\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/12\\\/arduino-raspberry-pico-under-the-hood\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/12\\\/arduino-raspberry-pico-under-the-hood\\\/\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/12\\\/arduino-raspberry-pico-under-the-hood\\\/\",\"name\":\"Arduino Raspberry Pico - Looking Under the Hood - Phil Schatzmann\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/12\\\/arduino-raspberry-pico-under-the-hood\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/12\\\/arduino-raspberry-pico-under-the-hood\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/Arduino.jpeg\",\"datePublished\":\"2021-05-12T05:22:17+00:00\",\"dateModified\":\"2021-12-14T14:18:06+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/12\\\/arduino-raspberry-pico-under-the-hood\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/12\\\/arduino-raspberry-pico-under-the-hood\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/12\\\/arduino-raspberry-pico-under-the-hood\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/Arduino.jpeg\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/Arduino.jpeg\",\"width\":225,\"height\":225},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/12\\\/arduino-raspberry-pico-under-the-hood\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Arduino Raspberry Pico &#8211; Looking Under the Hood\"}]},{\"@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":"Arduino Raspberry Pico - Looking Under the Hood - 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\/05\/12\/arduino-raspberry-pico-under-the-hood\/","og_locale":"en_US","og_type":"article","og_title":"Arduino Raspberry Pico - Looking Under the Hood - Phil Schatzmann","og_description":"Today I had a look under the hood of the Standard Arduino implementation for the Raspberry Pico. I was surprised that they did not base their work on the Pico API but they based their work on ARM Mbed. Here is a blink example using the Ticker from the Mbed [&hellip;]","og_url":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/12\/arduino-raspberry-pico-under-the-hood\/","og_site_name":"Phil Schatzmann","article_published_time":"2021-05-12T05:22:17+00:00","article_modified_time":"2021-12-14T14:18:06+00:00","og_image":[{"width":225,"height":225,"url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/05\/Arduino.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\/05\/12\/arduino-raspberry-pico-under-the-hood\/#article","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/12\/arduino-raspberry-pico-under-the-hood\/"},"author":{"name":"pschatzmann","@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"headline":"Arduino Raspberry Pico &#8211; Looking Under the Hood","datePublished":"2021-05-12T05:22:17+00:00","dateModified":"2021-12-14T14:18:06+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/12\/arduino-raspberry-pico-under-the-hood\/"},"wordCount":182,"commentCount":0,"publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/12\/arduino-raspberry-pico-under-the-hood\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/05\/Arduino.jpeg","keywords":["Back to Basics"],"articleSection":["Arduino","Pico"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pschatzmann.ch\/home\/2021\/05\/12\/arduino-raspberry-pico-under-the-hood\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/12\/arduino-raspberry-pico-under-the-hood\/","url":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/12\/arduino-raspberry-pico-under-the-hood\/","name":"Arduino Raspberry Pico - Looking Under the Hood - Phil Schatzmann","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/12\/arduino-raspberry-pico-under-the-hood\/#primaryimage"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/12\/arduino-raspberry-pico-under-the-hood\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/05\/Arduino.jpeg","datePublished":"2021-05-12T05:22:17+00:00","dateModified":"2021-12-14T14:18:06+00:00","breadcrumb":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/12\/arduino-raspberry-pico-under-the-hood\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pschatzmann.ch\/home\/2021\/05\/12\/arduino-raspberry-pico-under-the-hood\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/12\/arduino-raspberry-pico-under-the-hood\/#primaryimage","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/05\/Arduino.jpeg","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/05\/Arduino.jpeg","width":225,"height":225},{"@type":"BreadcrumbList","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/12\/arduino-raspberry-pico-under-the-hood\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pschatzmann.ch\/home\/"},{"@type":"ListItem","position":2,"name":"Arduino Raspberry Pico &#8211; Looking Under the Hood"}]},{"@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\/3127","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=3127"}],"version-history":[{"count":12,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/3127\/revisions"}],"predecessor-version":[{"id":3131,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/3127\/revisions\/3131"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media\/3128"}],"wp:attachment":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media?parent=3127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/categories?post=3127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/tags?post=3127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}