{"id":169,"date":"2017-04-26T06:57:53","date_gmt":"2017-04-26T13:57:53","guid":{"rendered":"http:\/\/www.kenwalger.com\/blog\/?p=169"},"modified":"2017-07-11T16:12:40","modified_gmt":"2017-07-11T23:12:40","slug":"overview-micropython","status":"publish","type":"post","link":"https:\/\/www.kenwalger.com\/blog\/python\/overview-micropython\/","title":{"rendered":"An Overview of MicroPython"},"content":{"rendered":"<p>There are a lot of options available when one starts exploring the exciting field of the Internet of Things, or IoT. Not only are there many choices of <a href=\"https:\/\/medium.freecodecamp.com\/hardware-fundamentals-what-exactly-is-a-microcontroller-8a502a3650dc\">micro-controllers<\/a>, there are also a variety of languages in which to program these devices. Many times the micro-controllers are sold as being dependent on C or C++ as a language. That&#8217;s great, but I don&#8217;t know either of those. There is some great and amazing working being led\u00a0by <a href=\"https:\/\/www.twitter.com\/chalkers\">Andrew Chalkley<\/a> around using the <a href=\"https:\/\/www.javascript.com\/\">JavaScript<\/a> language for micro-controllers\u00a0over at <a href=\"http:\/\/thingssdk.com\/\">thingsSDK<\/a>. If JavaScript is your language, I&#8217;d highly recommend checking out their work. There are also lots of resources for using Java for IoT, <a href=\"ttp:\/\/twitter.com\/nathantippy\">Nathan Tippy<\/a>, for example, is an excellent resource.<\/p>\n<p>All those are great languages. What if you are a beginning developer just interested in playing around in IoT? Or what if you are a Pythonista and don&#8217;t want to pick up another programming language? Well, for many micro-controllers there\u00a0<strong>is<\/strong> a Python option which is, arguably easier to learn in many ways than Java, JavaScript, C or C++. That option being MicroPython. You can see that project&#8217;s <a href=\"http:\/\/micropython.org\">website here<\/a>.<\/p>\n<h3>Overview of MicroPython<\/h3>\n<p>MicroPython is a tiny, open source Python programming language interpreter that runs on embedded boards. It was originally developed in 2013 and released in 2014 by Dr. Damian P. George of Cambridge University. It implements <a href=\"http:\/\/www.python.org\">Python 3<\/a> and is designed specifically to run on devices with limited resources.<\/p>\n<p>As with many things in the IoT world, the use of a particular language is greatly influenced by the tools, libraries, and packages one has available. MicroPython comes with an interactive read-evaluate-print-loop (REPL) for quick prototyping. It\u00a0also fully supports loading MicroPython scripts onto a device to run as well. It supports an extensive Python based library and for lower level operations can be extended with C\/C++ functions as needed.<\/p>\n<p>Many of the tasks that beginning IoT folks start off with, such as blinking lights, reading switches, driving servos, etc. are all easy to do in MicroPython. Further, it is often incredibly easy to read as well, as it is all Python based. For example, if one has MicroPython installed on a <a href=\"https:\/\/www.amazon.com\/gp\/product\/B01N0B48NI\/ref=as_li_tl?ie=UTF8&amp;amp;tag=kenwalgersite-20&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;linkCode=as2&amp;amp;creativeASIN=B01N0B48NI&amp;amp;linkId=dc1e9f82e2beb42bca36616a22b8820d\">NodeMCU ESP8266<\/a> board, a popular and inexpensive board to start working in IoT, with a basic LED light connected to <a href=\"https:\/\/iotbytes.wordpress.com\/nodemcu-pinout\/\">GPIO Pin 5<\/a>\u00a0it is pretty simple to get the light to turn on (high state) and off (low state).<\/p>\n<pre>import machine\n\nled = machine.Pin(5, machine.Pin.OUT)\n# Turn on LED\nled.high()\n# Turn off LED\nled.low()\n<\/pre>\n<p>The machine\u00a0module is included with MicroPython and handles many of the hardware connections from software. \u00a0It allows access to things like GPIO pins, CPU frequency, I2C busses, etc. If it is low-level on the hardware, the\u00a0<em>machine<\/em> module is the way to go!<\/p>\n<h6>Platform Support<\/h6>\n<p>There are many devices that support MicroPython. The <a href=\"http:\/\/www.kenwalger.com\/blog\/iot\/micropython-and-nodemcu-esp8266\/\">NodeMCU<\/a> is one of them. But several other options are available such as the <a href=\"http:\/\/www.kenwalger.com\/blog\/iot\/lopy\/\">LoPy<\/a> or similar PyCom devices, the <a href=\"https:\/\/www.amazon.com\/gp\/product\/B01BKA8UR8\/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B01BKA8UR8&amp;linkCode=as2&amp;tag=kenwalgersite-20&amp;linkId=6df3aea7052d4165dfd6e5b3cdc465b6\" target=\"_blank\" rel=\"noopener\">PyBoard<\/a><img loading=\"lazy\" decoding=\"async\" style=\"border: none !important; margin: 0px !important;\" src=\"\/\/ir-na.amazon-adsystem.com\/e\/ir?t=kenwalgersite-20&amp;l=am2&amp;o=1&amp;a=B01BKA8UR8\" alt=\"\" width=\"1\" height=\"1\" border=\"0\" \/>, and many others.<\/p>\n<h3>Differences from Python 3<\/h3>\n<p>As one can imagine, cramming\u00a0<strong>everything<\/strong> from Python 3 into a micro-controller isn&#8217;t possible. But,\u00a0core data types and modules which make sense for embedded systems are included. Another limitation is that since Python is a high-level programming language it isn&#8217;t as fast or lean as C or C++. Many operations aren&#8217;t impacted by this. However, if your application requires tight timing or performance is of utmost importance, using MicroPython can be an issue. However, as stated earlier, one can extend MicroPython to use C\/C++ in these circumstances.<\/p>\n<p>Since MicroPython is open source, check it out on <a href=\"https:\/\/github.com\/micropython\/micropython\">GitHub<\/a>, one can further extend or adapt it specific use case scenarios. For example, if you need something specific to run at boot time you can include it in the package that is flashed to the device. Pretty handy and convenient.<\/p>\n<h3>Conclusion<\/h3>\n<p>Hopefully I have at least sparked your interest enough in using MicroPython for IoT to take a further look at it. The development site actually has a live, <a href=\"http:\/\/micropython.org\/live\/\">interactive device<\/a> where you can try out some code and see it run on a real world device. Give it a try and leave a comment below to share with others what you&#8217;ve done and built!<\/p>\n<p>Follow me on Twitter <a href=\"https:\/\/www.twitter.com\/kenwalger\">@kenwalger<\/a> to get the latest updates on my postings.<\/p>\n<a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-facebook nolightbox\" data-provider=\"facebook\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Facebook\" href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F169&#038;t=An%20Overview%20of%20MicroPython&#038;s=100&#038;p&#091;url&#093;=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F169&#038;p&#091;images&#093;&#091;0&#093;=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-content%2Fuploads%2F2017%2F04%2Fmicro-python-e1493094682987.png&#038;p&#091;title&#093;=An%20Overview%20of%20MicroPython\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"Facebook\" title=\"Share on Facebook\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.kenwalger.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/facebook.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-twitter nolightbox\" data-provider=\"twitter\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Twitter\" href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F169&#038;text=Hey%20check%20this%20out\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"twitter\" title=\"Share on Twitter\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.kenwalger.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/twitter.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-reddit nolightbox\" data-provider=\"reddit\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Reddit\" href=\"https:\/\/www.reddit.com\/submit?url=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F169&#038;title=An%20Overview%20of%20MicroPython\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"reddit\" title=\"Share on Reddit\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.kenwalger.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/reddit.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-linkedin nolightbox\" data-provider=\"linkedin\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Linkedin\" href=\"https:\/\/www.linkedin.com\/shareArticle?mini=true&#038;url=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F169&#038;title=An%20Overview%20of%20MicroPython\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"linkedin\" title=\"Share on Linkedin\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.kenwalger.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/linkedin.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-mail nolightbox\" data-provider=\"mail\" rel=\"nofollow\" title=\"Share by email\" href=\"mailto:?subject=An%20Overview%20of%20MicroPython&#038;body=Hey%20check%20this%20out:%20https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F169\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"mail\" title=\"Share by email\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.kenwalger.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/mail.png\" \/><\/a>","protected":false},"excerpt":{"rendered":"<p>There are a lot of options available when one starts exploring the exciting field of the Internet of Things, or IoT. Not only are there many choices of micro-controllers, there are also a variety of languages in which to program these devices. Many times the micro-controllers are sold as being dependent on C or C++ &hellip; <a href=\"https:\/\/www.kenwalger.com\/blog\/python\/overview-micropython\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;An Overview of MicroPython&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":197,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pmpro_default_level":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[27,28,7],"tags":[31],"yst_prominent_words":[572,347,249,425,360,362,353,357,345,358,350,356,355,257,351,359,349,352,348,354],"class_list":["post-169","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-iot","category-micropython","category-python","tag-iot","pmpro-has-access"],"jetpack_featured_media_url":"https:\/\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/04\/micro-python-e1493094682987.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8lx70-2J","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/posts\/169","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/comments?post=169"}],"version-history":[{"count":8,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/posts\/169\/revisions"}],"predecessor-version":[{"id":452,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/posts\/169\/revisions\/452"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/media\/197"}],"wp:attachment":[{"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/media?parent=169"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/categories?post=169"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/tags?post=169"},{"taxonomy":"yst_prominent_words","embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/yst_prominent_words?post=169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}