{"id":7973,"date":"2020-08-27T08:16:37","date_gmt":"2020-08-27T16:16:37","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/python\/?p=7973"},"modified":"2020-08-27T08:16:37","modified_gmt":"2020-08-27T16:16:37","slug":"iot-exploration-with-vs-code-python-and-the-device-simulator-express","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/python\/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":"<p><span data-contrast=\"none\">The explosion of devices in\u00a0the IoT\u00a0space is more than a little overwhelming.\u00a0Where\u00a0do\u00a0you\u00a0start?<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">Why choose hardware when you can experiment entirely in software?\u00a0That\u2019s the power of the Device Simulator Express (DSE).\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">The DSE comes out of the Microsoft Garage internship program \u2013 two separate\u00a0teams\u00a0worked on the simulator over the past year. The development was\u00a0done\u00a0<\/span><a href=\"https:\/\/github.com\/microsoft\/vscode-python-devicesimulator\"><span data-contrast=\"none\">on GitHub<\/span><\/a><span data-contrast=\"none\">\u00a0and is open to contributors.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">You can start experimenting with\u00a0programming Python on\u00a0IoT devices without buying anything \u2013 in fact, there\u2019s nothing to buy at all. Everything you need is open-source\u00a0and free. Just download:<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"3\" aria-setsize=\"-1\" data-aria-posinset=\"1\" data-aria-level=\"1\"><span data-contrast=\"none\">Visual Studio Code (<\/span><a href=\"https:\/\/code.visualstudio.com\/\"><span data-contrast=\"none\">https:\/\/code.visualstudio.com\/<\/span><\/a><span data-contrast=\"none\">)<\/span><span data-ccp-props=\"{&quot;134233279&quot;:true,&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"3\" aria-setsize=\"-1\" data-aria-posinset=\"2\" data-aria-level=\"1\"><span data-contrast=\"none\">Python 3.7+ (<\/span><a href=\"https:\/\/www.python.org\/downloads\/\"><span data-contrast=\"none\">https:\/\/www.python.org\/downloads\/<\/span><\/a><span data-contrast=\"none\">)<\/span><span data-ccp-props=\"{&quot;134233279&quot;:true,&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"3\" aria-setsize=\"-1\" data-aria-posinset=\"3\" data-aria-level=\"1\"><span data-contrast=\"none\">Device Simulator Express (<\/span><a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-python.devicesimulatorexpress\"><span data-contrast=\"none\">https:\/\/marketplace.visualstudio.com\/items?itemName=ms-python.devicesimulatorexpress<\/span><\/a><span data-contrast=\"none\">)<\/span><span data-ccp-props=\"{&quot;134233279&quot;:true,&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><span data-contrast=\"none\">When you install the Device Simulator Express, it will automatically install the Python Visual Studio Code Extension,\u00a0if it\u2019s not already present.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">And now you\u2019re ready to start experimenting!<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h1 aria-level=\"1\"><span data-contrast=\"none\">Simulating devices in\u00a0Visual\u00a0Studio Code<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h2>\n<p><span data-contrast=\"none\">There are three different simulators in the Device Simulator Express as of\u00a0writing. The first is the\u00a0<\/span><b><span data-contrast=\"none\">Adafruit Circuit Playground Express<\/span><\/b><span data-contrast=\"none\">,\u00a0a circular device with two buttons, ten RGB\u00a0NeoPixel\u00a0LED lights,\u00a0and a host of other sensors.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><figure id=\"attachment_7974\" aria-labelledby=\"figcaption_attachment_7974\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2020\/08\/cpx-img.png\"><img decoding=\"async\" class=\"wp-image-7974 size-full\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2020\/08\/cpx-img.png\" alt=\"Adafruit's Circuit Playground Express device.\" width=\"233\" height=\"231\" srcset=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2020\/08\/cpx-img.png 233w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2020\/08\/cpx-img-150x150.png 150w\" sizes=\"(max-width: 233px) 100vw, 233px\" \/><\/a><figcaption id=\"figcaption_attachment_7974\" class=\"wp-caption-text\">The Adafruit Circuit Playground Express.<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p><span data-contrast=\"none\">In the DSE, you see a graphical representation of the device, and\u00a0all of\u00a0the buttons and touchpads work with mouse clicks. You write code in Python to control the Circuit Playground Express and then experiment with the simulation.\u00a0In Visual Studio Code, you\u2019ll see your code in one pane alongside the graphical device,\u00a0so you experience the rapid-fire \u201cwrite a line of code, run it, make changes\u201d cycle that makes programming fun and easy to understand.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">And when you\u2019re ready to experiment on hardware, the\u00a0Device Simulator Express extension\u00a0makes it easy to push your code via USB into the\u00a0IoT\u00a0hardware.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">And the Circuit Playground Express is not the only device in the simulator!<\/span><\/p>\n<p><span data-contrast=\"none\">The\u00a0<\/span><b><span data-contrast=\"none\">BBC\u00a0micro:bit<\/span><\/b><span data-contrast=\"none\">\u00a0is a small rectangular device with a five-by-five grid of LEDs, two buttons,\u00a0and\u00a0several\u00a0other sensors.\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_7975\" aria-labelledby=\"figcaption_attachment_7975\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2020\/08\/microbit_combined_image.png.250x250_q85.png\"><img decoding=\"async\" class=\"wp-image-7975 size-full\" 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.\" width=\"250\" height=\"206\" \/><\/a><figcaption id=\"figcaption_attachment_7975\" class=\"wp-caption-text\">The BBC micro:bit<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p><span data-contrast=\"none\">The matrix of LEDs makes it easy to create simple graphical images, characters,\u00a0and even animations.\u00a0One of the more\u00a0popular\u00a0demo apps for the\u00a0micro:bit\u00a0is a dice simulation \u2013 you shake the device\u00a0triggering the accelerometer\u00a0(which you can do with your mouse in the DSE) and the\u00a0micro:bit\u00a0LEDs blink until they stop on a one-to-six die pattern.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">Next up is the\u00a0<\/span><b><span data-contrast=\"none\">Adafruit CLUE<\/span><\/b><span data-contrast=\"none\">, which\u00a0is much like the\u00a0micro:bit, but adds an LCD display instead of the\u00a0matrix of\u00a0LEDs.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_7976\" aria-labelledby=\"figcaption_attachment_7976\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2020\/08\/clue.png\"><img decoding=\"async\" class=\"wp-image-7976 size-full\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2020\/08\/clue.png\" alt=\"The Adafruit CLUE device.\" width=\"245\" height=\"281\" \/><\/a><figcaption id=\"figcaption_attachment_7976\" class=\"wp-caption-text\">The Adafruit CLUE<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p><span data-contrast=\"none\">Now you\u2019ve got some serious graphical power available with the\u00a01.3 inch\u00a0IPS LCD color display \u2013 the canonical example project on the CLUE is the game Snake.\u00a0You can make compact, old-school, 8-bit style video games on the Adafruit CLUE.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">With all the programming done in Python inside Visual Studio Code, you can experiment with moving your applications between\u00a0the various\u00a0hardware simulations and see how each device functions a bit differently, with different API calls needed.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">The power of being able to experiment without buying hardware first provides a chance to explore what device is best for your\u00a0particular application.\u00a0More simulations added to the Device Simulator Express project will expand the number of choices for experimentation.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h2><span class=\"TextRun SCXW87992533 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW87992533 BCX8\" data-ccp-parastyle=\"heading 1\">A powerful tool for learning Python<\/span><\/span><span class=\"EOP SCXW87992533 BCX8\" data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h2>\n<p><span data-contrast=\"none\">But perhaps the most exciting thing to do with the DSE is\u00a0teaching\u00a0new programmers. There\u2019s no better form of the \u201cHello World\u201d app than a blinking LED.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">By being able to simulate the IoT hardware, you eliminate\u00a0a significant\u00a0barrier of entry to programming\u00a0IoT devices\u00a0\u2013 both the cost and the time it takes to get the\u00a0specific hardware.\u00a0With\u00a0a pure\u00a0software implementation, it doesn\u2019t take long to get to learning programming.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">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\u00a0devices\u00a0around to have the experience of running their code on a device \u2013 because a real blinking LED is even better!<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h2><span class=\"TextRun SCXW9834213 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW9834213 BCX8\" data-ccp-parastyle=\"heading 1\">A community-led project<\/span><\/span><span class=\"EOP SCXW9834213 BCX8\" data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h2>\n<p><span data-contrast=\"none\">The Device Simulator Express project is just over a year old \u2013 and there\u2019s so much more\u00a0that can be done.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">There is an opportunity to build simulations of more devices\u00a0\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\u00a0quite\u00a0similar to the Circuit Playground Express.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">And there are more elaborate IoT devices available out there. Building the simulations would be more\u00a0challenging, but\u00a0would 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.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">The front-end parts of the Device Simulator Express that provide the hardware visualizations\u00a0are coded with\u00a0React and TypeScript, working with the Visual Studio Code Extension API to\u00a0facilitate\u00a0integration.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">The\u00a0back-end\u00a0is a Python-based simulation library, which does have some underlying C code (as\u00a0domost\u00a0Python libraries). Ultimately, the back-end services are simulations, not emulations, and so there are differences\u00a0when 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\u00a0some\u00a0\u201cunintended behaviors\u201d of the actual hardware. Yes,\u00a0the Device Simulation Express\u00a0include\u00a0simulation of the hardware\u00a0bugs.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">If you\u2019d like to learn more about contributing to the Device Simulator Express project, check out the GitHub\u00a0repository\u00a0<\/span><a href=\"https:\/\/github.com\/microsoft\/vscode-python-devicesimulator\"><span data-contrast=\"none\">microsoft\/vscode-python-devicesimulator<\/span><\/a>.<\/p>\n<p><span data-contrast=\"none\">Beyond coding on the\u00a0project\u00a0itself, there are many opportunities to build\u00a0excellent 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\u00a0exploring the world of IoT applications.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The explosion of devices in\u00a0the IoT\u00a0space is more than a little overwhelming.\u00a0Where\u00a0do\u00a0you\u00a0start?\u00a0Why choose hardware when you can experiment entirely in software?\u00a0That\u2019s the power of the Device Simulator Express (DSE).\u00a0\u00a0Keep on reading to learn how you can start experimenting with\u00a0programming Python on\u00a0IoT devices without buying anything!<\/p>\n","protected":false},"author":1064,"featured_media":7977,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,6],"tags":[],"class_list":["post-7973","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-visual-studio-code"],"acf":[],"blog_post_summary":"<p>The explosion of devices in\u00a0the IoT\u00a0space is more than a little overwhelming.\u00a0Where\u00a0do\u00a0you\u00a0start?\u00a0Why choose hardware when you can experiment entirely in software?\u00a0That\u2019s the power of the Device Simulator Express (DSE).\u00a0\u00a0Keep on reading to learn how you can start experimenting with\u00a0programming Python on\u00a0IoT devices without buying anything!<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/posts\/7973","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/users\/1064"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/comments?post=7973"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/posts\/7973\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/media\/7977"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/media?parent=7973"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/categories?post=7973"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/tags?post=7973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}