{"id":6141,"date":"2022-02-01T11:48:36","date_gmt":"2022-02-01T16:48:36","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2023\/?page_id=6141"},"modified":"2023-02-02T11:02:48","modified_gmt":"2023-02-02T16:02:48","slug":"class-6","status":"publish","type":"page","link":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2023\/class-notes\/class-6\/","title":{"rendered":"Class 6 &#8211; Thu Feb 2 &#8211; CircuitPython"},"content":{"rendered":"\n<p>Feb 2, 2023, 12:00PM to 1:50PM<\/p>\n\n\n\n<p>Welcome!   <\/p>\n\n\n\n<p>The main objectives for today are to introduce the <a rel=\"noreferrer noopener\" href=\"https:\/\/www.adafruit.com\/product\/4333\" target=\"_blank\">Adafruit Circuit Playground Bluefruit<\/a> microcontroller and <a rel=\"noreferrer noopener\" href=\"https:\/\/learn.adafruit.com\/welcome-to-circuitpython\" target=\"_blank\">CircuitPython<\/a> programming.  You will work in pairs for this learning activity today.<\/p>\n\n\n\n<p>You will need a laptop for today (one per pair).  Please try to install the free <a href=\"https:\/\/codewith.mu\/\">mu editor<\/a> (or equivalent tools) in advance for working with CircuitPython microcontrollers.  <\/p>\n\n\n\n<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">Contents<\/p><ul class=\"toc_list\"><li><a href=\"#Materials_for_Today\"><span class=\"toc_number toc_depth_1\">1<\/span> Materials for Today<\/a><\/li><li><a href=\"#Circuit_Playground_Bluefruit_Microcontroller\"><span class=\"toc_number toc_depth_1\">2<\/span> Circuit Playground Bluefruit Microcontroller<\/a><ul><li><a href=\"#Downloads\"><span class=\"toc_number toc_depth_2\">2.1<\/span> Downloads<\/a><\/li><li><a href=\"#Live_Demo\"><span class=\"toc_number toc_depth_2\">2.2<\/span> Live Demo<\/a><\/li><li><a href=\"#Setting_Up_Your_Hardware\"><span class=\"toc_number toc_depth_2\">2.3<\/span> Setting Up Your Hardware<\/a><\/li><li><a href=\"#Crickit\"><span class=\"toc_number toc_depth_2\">2.4<\/span> Crickit<\/a><\/li><li><a href=\"#Next_Steps\"><span class=\"toc_number toc_depth_2\">2.5<\/span> Next Steps<\/a><\/li><\/ul><\/li><\/ul><\/div>\n<h2><span id=\"Materials_for_Today\">Materials for Today<\/span><\/h2>\n\n\n\n<ul>\n<li>Bluefruit installed on Crickit<\/li>\n\n\n\n<li>5V 3A power adapter<\/li>\n\n\n\n<li>micro-USB cable for your laptop<\/li>\n\n\n\n<li>your personal laptop<\/li>\n\n\n\n<li>DC motor pump(s) with leads attached<\/li>\n\n\n\n<li>small flat screwdriver<\/li>\n<\/ul>\n\n\n\n<h2><span id=\"Circuit_Playground_Bluefruit_Microcontroller\">Circuit Playground Bluefruit Microcontroller<\/span><\/h2>\n\n\n\n<p>The motorized elements of our kinetic creations will be controlled using a microcontroller to measure sensors, operate actuators, and perform scripted actions. Today\u2019s objective is to help you get started with the tools.<\/p>\n\n\n\n<p>We will generally be following the hardware notes and sample code from the course technical guide.   But we\u2019ll go step by step at a novice level so no one gets left behind.<\/p>\n\n\n\n<p>The link to the guide can always be found under  <a href=\"https:\/\/courses.ideate.cmu.edu\/16-376\/s2023\/ref\/text\/index.html\">SOFTWARE AND MECHANISM RESOURCES<\/a> in the left-hand navigation bar of the course website.<\/p>\n\n\n\n<h3><span id=\"Downloads\">Downloads<\/span><\/h3>\n\n\n\n<p>If you have not already installed the&nbsp;<a href=\"https:\/\/codewith.mu\/\">mu Python editor<\/a>, please also download that now and run the installer.<\/p>\n\n\n\n<h3><span id=\"Live_Demo\">Live Demo<\/span><\/h3>\n\n\n\n<p>We first want to give you a quick preview of the end goal for the day.<\/p>\n\n\n\n<ol>\n<li>pump sequence demo<\/li>\n\n\n\n<li>mu editor<\/li>\n\n\n\n<li>editing\/running code<\/li>\n\n\n\n<li>interacting directly with the Python system<\/li>\n\n\n\n<li>attaching a motor pump to the Crickit<\/li>\n<\/ol>\n\n\n\n<h3><span id=\"Setting_Up_Your_Hardware\">Setting Up Your Hardware<\/span><\/h3>\n\n\n\n<ol>\n<li>connecting the board<\/li>\n\n\n\n<li>testing using mu \u2018Serial\u2019, the read-eval-print loop (REPL) window<br><code>2+2<\/code><br><code>3**201<\/code><br><code>import time<\/code><br><code>time.monotonic()<\/code><br><code>help('modules')<\/code><\/li>\n\n\n\n<li>testing the library<br><code>from adafruit_circuitplayground import cp<\/code><br><code>cp.red_led = True<\/code><br><code>cp.play_tone(440, 1.0)<\/code><\/li>\n\n\n\n<li>trying out&nbsp;<a href=\"https:\/\/courses.ideate.cmu.edu\/16-376\/s2023\/ref\/text\/code\/cpb-intro.html\">sample code<\/a><\/li>\n<\/ol>\n\n\n\n<h3><span id=\"Crickit\">Crickit<\/span><\/h3>\n\n\n\n<p>The Crickit baseboard include motor drivers, hobby servo ports, and additional capacitive touch sensors.  For today, we will use the <a href=\"https:\/\/courses.ideate.cmu.edu\/16-376\/s2023\/ref\/text\/code\/crickit-pump.html#pump-sequence\">sequence_motor.py sample code<\/a> as a starting point.<\/p>\n\n\n\n<ol>\n<li>Connecting a motor and running the sample code.<\/li>\n\n\n\n<li>Changing timing and pattern.<\/li>\n<\/ol>\n\n\n\n<h3><span id=\"Next_Steps\">Next Steps<\/span><\/h3>\n\n\n\n<p>CircuitPython lets you treat the microcontroller like a tiny data drive. Your code can be edited in-place, and saving will run it. But you\u2019ll need to work out a plan for copying final programs back to your computer for your documentation.<\/p>\n\n\n\n<ol>\n<li>editing code in place<\/li>\n\n\n\n<li>saving programs back to your computer<\/li>\n\n\n\n<li>exploring the Adafruit tutorials<\/li>\n\n\n\n<li>exploring the library documentation<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Feb 2, 2023, 12:00PM to 1:50PM Welcome! The main objectives for today are to introduce the Adafruit Circuit Playground Bluefruit microcontroller and CircuitPython programming. You will work in&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":5504,"menu_order":6,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2023\/wp-json\/wp\/v2\/pages\/6141"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2023\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2023\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2023\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2023\/wp-json\/wp\/v2\/comments?post=6141"}],"version-history":[{"count":15,"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2023\/wp-json\/wp\/v2\/pages\/6141\/revisions"}],"predecessor-version":[{"id":7667,"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2023\/wp-json\/wp\/v2\/pages\/6141\/revisions\/7667"}],"up":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2023\/wp-json\/wp\/v2\/pages\/5504"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/16-376\/s2023\/wp-json\/wp\/v2\/media?parent=6141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}