{"id":471,"date":"2021-02-18T22:45:37","date_gmt":"2021-02-18T22:45:37","guid":{"rendered":"https:\/\/tbekk.com\/devstream\/?p=471"},"modified":"2021-02-18T22:54:13","modified_gmt":"2021-02-18T22:54:13","slug":"iot-exploration-with-vs-code-python-and-the-device-simulator-express","status":"publish","type":"post","link":"https:\/\/tbekk.com\/devstream\/2021\/02\/18\/iot-exploration-with-vs-code-python-and-the-device-simulator-express\/","title":{"rendered":"IoT exploration with VS Code, Python, and the Device Simulator Express"},"content":{"rendered":"\n<ul class=\"wp-block-list\" id=\"block-8404459e-edd8-4728-a8a5-d4e34b67bf75\"><li><em>Published at:<\/em> <a href=\"https:\/\/devblogs.microsoft.com\/python\/iot-exploration-with-vs-code-python-and-the-device-simulator-express\/\"><em>https:\/\/devblogs.microsoft.com\/python\/iot-exploration-with-vs-code-python-and-the-device-simulator-express\/<\/em><\/a><\/li><li><em>Author:<\/em> <a href=\"https:\/\/devblogs.microsoft.com\/python\/author\/luabudmicrosoft-com\/\"><em>Luciana de Melo e Abud<\/em><\/a><\/li><li><em>Publication date:<\/em> <em>2020, August 27th<\/em><\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>The explosion of devices in&nbsp;the IoT&nbsp;space is more than a little overwhelming.&nbsp;Where&nbsp;do&nbsp;you&nbsp;start?&nbsp;<\/p>\n\n\n\n<p>Why choose hardware when you can experiment entirely in software?&nbsp;That\u2019s the power of the Device Simulator Express (DSE).&nbsp;&nbsp;<\/p>\n\n\n\n<p>The DSE comes out of the Microsoft Garage internship program \u2013 two separate&nbsp;teams&nbsp;worked on the simulator over the past year. The development was&nbsp;done&nbsp;<a href=\"https:\/\/github.com\/microsoft\/vscode-python-devicesimulator\" target=\"_blank\" rel=\"noreferrer noopener\">on GitHub<\/a>&nbsp;and is open to contributors.&nbsp;<\/p>\n\n\n\n<p>You can start experimenting with&nbsp;programming Python on&nbsp;IoT devices without buying anything \u2013 in fact, there\u2019s nothing to buy at all. Everything you need is open-source&nbsp;and free. Just download:&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Visual Studio Code (<a href=\"https:\/\/code.visualstudio.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/code.visualstudio.com\/<\/a>)&nbsp;<\/li><li>Python 3.7+ (<a href=\"https:\/\/www.python.org\/downloads\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.python.org\/downloads\/<\/a>)&nbsp;<\/li><li>Device Simulator Express (<a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-python.devicesimulatorexpress\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/marketplace.visualstudio.com\/items?itemName=ms-python.devicesimulatorexpress<\/a>)&nbsp;<\/li><\/ul>\n\n\n\n<p>When you install the Device Simulator Express, it will automatically install the Python Visual Studio Code Extension,&nbsp;if it\u2019s not already present.&nbsp;<\/p>\n\n\n\n<p>And now you\u2019re ready to start experimenting!&nbsp;<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"simulating-devices-in-visual-studio-code\">Simulating devices in&nbsp;Visual&nbsp;Studio Code&nbsp;<\/h1>\n\n\n\n<p>There are three different simulators in the Device Simulator Express as of&nbsp;writing. The first is the&nbsp;<strong>Adafruit Circuit Playground Express<\/strong>,&nbsp;a circular device with two buttons, ten RGB&nbsp;NeoPixel&nbsp;LED lights,&nbsp;and a host of other sensors.&nbsp;&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_7974\"><a href=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2020\/08\/cpx-img.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2020\/08\/cpx-img.png\" alt=\"Adafruit's Circuit Playground Express device.\" class=\"wp-image-7974\"\/><\/a><figcaption>The Adafruit Circuit Playground Express.<\/figcaption><\/figure>\n\n\n\n<p>In the DSE, you see a graphical representation of the device, and&nbsp;all of&nbsp;the buttons and touchpads work with mouse clicks. You write code in Python to control the Circuit Playground Express and then experiment with the simulation.&nbsp;In Visual Studio Code, you\u2019ll see your code in one pane alongside the graphical device,&nbsp;so you experience the rapid-fire \u201cwrite a line of code, run it, make changes\u201d cycle that makes programming fun and easy to understand.&nbsp;&nbsp;<\/p>\n\n\n\n<p>And when you\u2019re ready to experiment on hardware, the&nbsp;Device Simulator Express extension&nbsp;makes it easy to push your code via USB into the&nbsp;IoT&nbsp;hardware.&nbsp;<\/p>\n\n\n\n<p>And the Circuit Playground Express is not the only device in the simulator!<\/p>\n\n\n\n<p>The&nbsp;<strong>BBC&nbsp;micro:bit<\/strong>&nbsp;is a small rectangular device with a five-by-five grid of LEDs, two buttons,&nbsp;and&nbsp;several&nbsp;other sensors.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_7975\"><a href=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2020\/08\/microbit_combined_image.png.250x250_q85.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2020\/08\/microbit_combined_image.png.250x250_q85.png\" alt=\"The BBC micro:bit device.\" class=\"wp-image-7975\"\/><\/a><figcaption>The BBC micro:bit<\/figcaption><\/figure>\n\n\n\n<p>The matrix of LEDs makes it easy to create simple graphical images, characters,&nbsp;and even animations.&nbsp;One of the more&nbsp;popular&nbsp;demo apps for the&nbsp;micro:bit&nbsp;is a dice simulation \u2013 you shake the device&nbsp;triggering the accelerometer&nbsp;(which you can do with your mouse in the DSE) and the&nbsp;micro:bit&nbsp;LEDs blink until they stop on a one-to-six die pattern.&nbsp;<\/p>\n\n\n\n<p>Next up is the&nbsp;<strong>Adafruit CLUE<\/strong>, which&nbsp;is much like the&nbsp;micro:bit, but adds an LCD display instead of the&nbsp;matrix of&nbsp;LEDs.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_7976\"><a href=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2020\/08\/clue.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2020\/08\/clue.png\" alt=\"The Adafruit CLUE device.\" class=\"wp-image-7976\"\/><\/a><figcaption>The Adafruit CLUE<\/figcaption><\/figure>\n\n\n\n<p>Now you\u2019ve got some serious graphical power available with the&nbsp;1.3 inch&nbsp;IPS LCD color display \u2013 the canonical example project on the CLUE is the game Snake.&nbsp;You can make compact, old-school, 8-bit style video games on the Adafruit CLUE.&nbsp;<\/p>\n\n\n\n<p>With all the programming done in Python inside Visual Studio Code, you can experiment with moving your applications between&nbsp;the various&nbsp;hardware simulations and see how each device functions a bit differently, with different API calls needed.&nbsp;<\/p>\n\n\n\n<p>The power of being able to experiment without buying hardware first provides a chance to explore what device is best for your&nbsp;particular application.&nbsp;More simulations added to the Device Simulator Express project will expand the number of choices for experimentation.&nbsp;<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"a-powerful-tool-for-learning-python\">A powerful tool for learning Python&nbsp;<\/h1>\n\n\n\n<p>But perhaps the most exciting thing to do with the DSE is&nbsp;teaching&nbsp;new programmers. There\u2019s no better form of the \u201cHello World\u201d app than a blinking LED.&nbsp;&nbsp;<\/p>\n\n\n\n<p>By being able to simulate the IoT hardware, you eliminate&nbsp;a significant&nbsp;barrier of entry to programming&nbsp;IoT devices&nbsp;\u2013 both the cost and the time it takes to get the&nbsp;specific hardware.&nbsp;With&nbsp;a pure&nbsp;software implementation, it doesn\u2019t take long to get to learning programming.&nbsp;<\/p>\n\n\n\n<p>And where there is a limited amount of hardware available, an entire class can continue to experiment with their software in the simulation and share the&nbsp;devices&nbsp;around to have the experience of running their code on a device \u2013 because a real blinking LED is even better!&nbsp;<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"a-community-led-project\">A community-led project&nbsp;<\/h1>\n\n\n\n<p>The Device Simulator Express project is just over a year old \u2013 and there\u2019s so much more&nbsp;that can be done.&nbsp;&nbsp;<\/p>\n\n\n\n<p>There is an opportunity to build simulations of more devices&nbsp;\u2013 for example, the Adafruit FLORA, designed as an IoT device to be incorporated into clothing, would be a relatively simple addition to the project since it is&nbsp;quite&nbsp;similar to the Circuit Playground Express.&nbsp;&nbsp;<\/p>\n\n\n\n<p>And there are more elaborate IoT devices available out there. Building the simulations would be more&nbsp;challenging, but&nbsp;would also open the door to more advanced experimentation of hardware in software, speeding development with the rapid code iteration cycles that are possible when not needing to push apps onto devices.&nbsp;<\/p>\n\n\n\n<p>The front-end parts of the Device Simulator Express that provide the hardware visualizations&nbsp;are coded with&nbsp;React and TypeScript, working with the Visual Studio Code Extension API to&nbsp;facilitate&nbsp;integration.&nbsp;<\/p>\n\n\n\n<p>The&nbsp;back-end&nbsp;is a Python-based simulation library, which does have some underlying C code (as&nbsp;domost&nbsp;Python libraries). Ultimately, the back-end services are simulations, not emulations, and so there are differences&nbsp;when you dig deep. But if you\u2019re into that sort of thing, you\u2019ll see that in some cases, the existing implementations of the DSE include&nbsp;some&nbsp;\u201cunintended behaviors\u201d of the actual hardware. Yes,&nbsp;the Device Simulation Express&nbsp;include&nbsp;simulation of the hardware&nbsp;bugs.&nbsp;<\/p>\n\n\n\n<p>If you\u2019d like to learn more about contributing to the Device Simulator Express project, check out the GitHub&nbsp;repository&nbsp;<a href=\"https:\/\/github.com\/microsoft\/vscode-python-devicesimulator\" target=\"_blank\" rel=\"noreferrer noopener\">microsoft\/vscode-python-devicesimulator<\/a>.<\/p>\n\n\n\n<p>Beyond coding on the&nbsp;project&nbsp;itself, there are many opportunities to build&nbsp;excellent training material using the DSE. Videos, walk-through, code samples \u2013 all tools to help more people discover the power of programming and the fun of&nbsp;exploring the world of IoT applications.&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Published at: https:\/\/devblogs.microsoft.com\/python\/iot-exploration-with-vs-code-python-and-the-device-simulator-express\/ Author: Luciana de Melo e Abud Publication date: 2020, August 27th The explosion of devices in&nbsp;the IoT&nbsp;space is more than a little overwhelming.&nbsp;Where&nbsp;do&nbsp;you&nbsp;start?&nbsp; Why choose hardware when&#8230; <a class=\"read-more-link\" href=\"https:\/\/tbekk.com\/devstream\/2021\/02\/18\/iot-exploration-with-vs-code-python-and-the-device-simulator-express\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,9],"tags":[104,74,105],"class_list":["post-471","post","type-post","status-publish","format-standard","hentry","category-development","category-news","tag-iot","tag-py","tag-vs-code"],"_links":{"self":[{"href":"https:\/\/tbekk.com\/devstream\/wp-json\/wp\/v2\/posts\/471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tbekk.com\/devstream\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tbekk.com\/devstream\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tbekk.com\/devstream\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tbekk.com\/devstream\/wp-json\/wp\/v2\/comments?post=471"}],"version-history":[{"count":4,"href":"https:\/\/tbekk.com\/devstream\/wp-json\/wp\/v2\/posts\/471\/revisions"}],"predecessor-version":[{"id":475,"href":"https:\/\/tbekk.com\/devstream\/wp-json\/wp\/v2\/posts\/471\/revisions\/475"}],"wp:attachment":[{"href":"https:\/\/tbekk.com\/devstream\/wp-json\/wp\/v2\/media?parent=471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tbekk.com\/devstream\/wp-json\/wp\/v2\/categories?post=471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tbekk.com\/devstream\/wp-json\/wp\/v2\/tags?post=471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}