Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Makecode For Circuit Playground Express: Created by Peli de Halleux

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

MakeCode for Circuit Playground Express

Created by Peli de Halleux

Last updated on 2019-04-15 02:40:34 PM UTC


What is MakeCode?

Microsoft MakeCode for Adafruit is a web-based code editor for physical computing. It provides a block editor, similar
to Scratch or Code.org, and also a JavaScript editor for more advanced users. Try it now
at https://makecode.adafruit.com/ (https://adafru.it/wmd) !

Some of the key features of MakeCode are:

web based editor: nothing to install


cross platform: works in most modern browsers (https://adafru.it/wqe) from tiny phone to giant touch screens
compilation in the browser: the compiler runs in your browser, it's fast and works offline
blocks + JavaScript: drag and drop blocks or type JavaScript, MakeCode let's you go back and forth between
the two.
works offline: once you've loaded the editor, it stays cached in your browser.
event based runtime: easily respond to button clicks, shake gestures and more

MakeCode currently supports the Adafruit Circuit Playground Express. For other boards, like the Adafruit Metro M0,
try https://maker.makecode.com (https://adafru.it/BeY) .

Your browser does not support the video tag. Circuit Playground Express

© Adafruit Industries https://learn.adafruit.com/makecode Page 3 of 18


$24.95
IN STOCK
ADD TO CART

Circuit Playground Express - Base Kit

$29.95
IN STOCK
ADD TO CART

MakeCode works for the Express edition of the Circuit Playground, not the Classic.

© Adafruit Industries https://learn.adafruit.com/makecode Page 4 of 18


Editing Blocks
The block editor is the easiest way to get started with MakeCode. You can drag and drop blocks from the category list.
Each time you make a change to the blocks, the simulator will automatically restart and run the code. You can test your
program in the browser!

try our getting started tutorial (https://adafru.it/wmd) that helps you build a siren program
try one of our projects (https://adafru.it/wpD) to learn more about the features of the Circuit Playground.
take a deep dive in the documentation (https://adafru.it/wpE)

Blinky!
Let's show how MakeCode works by building a simple program that blinks the 10 awesome NeoPixels.

Creating a blink effect is done by setting all the ring LEDs to red, pause for a little, then turn them off, pause for a little,
then repeat forever.

Let's gather the blocks we need to convert the description above into Blocks that the Circuit Playground can
understand and run:

forever runs blocks in a loop with a 20ms pause in between (it is similar to Arduinoloop).
show ring sets the color on the 10 neopixels at once
pause blocks the current thread for 100ms. If other events or forever loops are running, they have the opporunity
to run at this time.

Do you want to select or change colors? The show ring block has a built-in color picker. Select the color from the
color wheel to select a color, then click one of the ten Neopixel rings to modify its color.

How do I disable a Neopixel? The grey dot in the middle of the color wheel indicates that the pixel is off. Select the
grey from the color wheel and then click the Neopixel ring.

You can see the Blinky block program in action in the MakeCode editor below. You can also see how the blocks are
"slotted together". Clicking the question marks on the box will pop-up a comment to explain what the block does.

© Adafruit Industries https://learn.adafruit.com/makecode Page 5 of 18


https://adafru.it/BAl
https://adafru.it/BAl

In the next section, we'll load the Blinky code onto the Circuit Playground Express!

© Adafruit Industries https://learn.adafruit.com/makecode Page 6 of 18


Downloading and Flashing
Getting your code into your device is very easy with MakeCode. You do not need to install any software on your
machine and the process takes two steps:

Step 1: Connect your board via USB and enter bootloader mode
Step 2: Compile and Download the .uf2 file into your board drive

We are going to go through these two steps in detail.

Step 1: Bootloader mode


Connect your board to your computer via a USB cable. Press the reset button once to put the board in bootloader
mode.

If it is your first time running MakeCode or if you have previously installed Arduino or CircuitPython, you may
need to double press the reset button to get your board into bootloader mode.

When the Circuit Playground Express is in Bootloader mode, all the LEDs will turn red briefly, then green. Verify your
status LED is also pulsing red. Your computer should show a new removable drive called "CPLAYBOOT"

If the LEDs are all red: Either the computer is still installing drivers (Please wait a minute, Windows takes some time to
install updates.) or you have a bad USB connection. If you keep getting red LEDs - try a new USB cable (you may want
to ensure your USB cable is not charge only, it needs to transfer data) or a different USB port.

© Adafruit Industries https://learn.adafruit.com/makecode Page 7 of 18


Once your LEDs are all green, you should see a CPLAYBOOT drive appear in your drive list in your file explorer.

We are now ready to compile our blinky code and download it to our board!

Step 2: Compile and Download

Let's first verify that our code compiles properly in MakeCode.

MakeCode has a built-in simulator that re-loads and re-runs code when restarted. This is an easy way to both ensure
that our code compiles and simulate it before moving it onto the board. The refresh button re-loads the simulator with
your latest version of block code.

If you receive a "we could not run this project" error, please check over your code for errors.

If your board is working in the simulator, it's time to download it to your actual board! Click the "Download" button. It
will generate a .uf2 file and download it to your computer (UF2 (https://adafru.it/vPE) is a file format designed to flash
microcontrollers over USB).

© Adafruit Industries https://learn.adafruit.com/makecode Page 8 of 18


General Steps to copy over your program (not specific to any Operating system)
1. Ensure your board is in bootloader mode.
2. Find the .uf2 file generated by MakeCode in your file explorer. Copy it to the "CPLAYBOOT" volume.
3. The status LED on the board will blink while the file is transferring. Once it's done transferring your file, the board
will automatically reset and start running your code (just like in the simulator!)

On a Mac, you can safely ignore the "Disk Not Ejected Properly" notification that may appear after copying
your .uf2 file.

Windows: Open Windows Explorer (Windows key + E key) and locate the "blinky.uf2" file you generated. It's probably
in your Downloads folder!

You can copy/paste the file to your CPLAYBOOT volume or you can drag/drop it like in the GIF below.

macOS: Open Finder and locate the "blinky.uf2" file. You can copy/paste this file to the "cplayboot" volume or
drag/drop it from the same finder window.

If you want to avoid the copying process: You can download your programs directly to the board. To do this: change
the download location in Chrome (https://adafru.it/wHA), Firefox (https://adafru.it/wHB), Safari (https://adafru.it/wHC), or
Opera (https://adafru.it/wHD)to the main directory of your "CPLAYBOOT" volume.

Running MakeCode that's Already Loaded


If you unplug your board and then plug it back in again to your computer, it may not run the program again
automatically. If it instead shows all green NeoPixels, just press the reset button and your program will start.

© Adafruit Industries https://learn.adafruit.com/makecode Page 9 of 18


Saving and Sharing
Want to change the Blinky program to display different colors, or make it play a sound? Editing the program on your
Circuit Playground is super easy!

Extracting your code from the Circuit Playground

The .uf2 file (CURRENT.UF2) you created by clicking on the Compile button in MakeCode also contains the source
code of your program!

You can open this file in MakeCode by dragging and dropping it into the browser to edit it.

Sharing
You can share your code by clicking on the share button. After confirmation, MakeCode will create a short unique URL
for your code. Anyone with that URL will be able to reload the code.

These URLs can also be used to embed the editor your blog or web pages! Just copy paste the URL in your text editor
and (if it supports oEmbed) it will automatically load it in your page.

© Adafruit Industries https://learn.adafruit.com/makecode Page 10 of 18


Editing JavaScript
If you already have some experience coding or you feel ready to take the next step, MakeCode features a fully-feature
JavaScript editor in the browser!

read the JavaScript docs

Give it a try!

You can also switch between blocks and JavaScript by clicking the button on the top.

https://adafru.it/BAn
https://adafru.it/BAn

© Adafruit Industries https://learn.adafruit.com/makecode Page 11 of 18


Apps
MakeCode also provides various apps to provide additional features not available in browsers.

Windows Store
The MakeCode for Adafruit Windows Store app.

Super fast HID-based flashing: no more drag and drop.


Reading debug message and surfacing them in the editor (debug messages are sent over HID not CDC
Uart/Serial)

Node.JS
The (open source) GitHub repo contains instructions to run a local node.js web server with HID flashing and serial
monitoring.

© Adafruit Industries https://learn.adafruit.com/makecode Page 12 of 18


WebUSB Uploading
One-Click Deploy
Are you tired of dragging and dropping your UF2 files over and over again? Well then WebUSB upload is for you! With
WebUSB, you can upload your code directly to your board without having to save a UF2 file and then dropping it onto
the flash drive. Just plug keep the USB cable plugged into your computer and upload code as many times as you
need!

Requirements!
You'll need to do a few things before you can use WebUSB

You will need to use the latest version of the Google Chrome (https://adafru.it/B-S) web browser. Firefox, Safari,
Opera, Edge, etc do not support WebUSB at this time. Only Chrome, only versions 68 or greater!
Run Windows 10, Latest Mac OS X or Linux. Windows 7 or 8 is not supported!

Update Bootloader
You will also need the latest bootloader firmware for Circuit Playground Express (which only needs to be done once).
We ship the newest bootloader on Circuit Playground Expresses as of July 2018 but in case you have an old one, it
doesn't hurt!

https://adafru.it/Bmg
https://adafru.it/Bmg

Updating the bootloader is as easy as flashing a MakeCode program. Simply enter the bootloader by pressing Reset
once (or twice) to get a green ring of NeoPixels. A flash drive called CPLAYBOOT will show up in your operating
system's file explorer/finder. Drag the update bootloader uf2 file you downloaded via the green button to the
CPLAYBOOT drive. This uf2 contains a program which will unlock the bootloader section, update the bootloader, and
re-lock it. It will overwrite your existing code such as CircuitPython or Arduino so make sure everything is backed up!

Special MakeCode URL


Once you have it up and running, you'll need to go to the special MakeCode link with WebUSB enabled. Use the green
button below or copy+paste the full URL into your browser: https://makecode.adafruit.com/?
webusb=1#editor (https://adafru.it/CLL)

https://adafru.it/CLL
https://adafru.it/CLL

Projects & Extensions


Your existing projects should remain in the MakeCode site so you don't need to copy anything over. However, if you
had any extensions installed, you will need to reinstall them. This can be done by clicking on the extension menu and
selecting the extension.

© Adafruit Industries https://learn.adafruit.com/makecode Page 13 of 18


First Time Setup
Once you have chrome and the makecode beta URL
open, you will need to download a blank program to the
Circuit Playground Express. With the programming area
blank, click the pink Download button in your project
window. Save the UF2 file to your hard drive. Place the
Circuit Playground Express into bootloader mode by
pressing the Reset button once (or twice) to get a green
ring of lights. Copy your UF2 file from your hard drive to
the CPLAYBOOT drive that appears on the list of your
computer's drives when the board was placed into
bootloader mode. When the UF2 file copies over, the
board will reset.

This is required in order to access the WebUSB functionality from Google Chrome. You only need to do this once, this
first time! After copying this UF2 over, hopefully it'll be the last time you'll drag and drop one to your device!

Pair Device
Once the initial UF2 has been copied over to the flash
drive, click on the cog wheel icon in the top right corner,
next to the Microsoft logo. Find the Pair Device link in
the menu and click it.

© Adafruit Industries https://learn.adafruit.com/makecode Page 14 of 18


Connect PXT Device
Once you've clicked on Pair device, a popup window
should appear below the browser URL input box. Click
the blue connect button to establish connection
between your PXT device and browser.

Device Paired!
You'll get a nice notification near the bottom of the
screen letting you know the device was successfully
paired. Give it a try and click on the big download button
to upload your code!

© Adafruit Industries https://learn.adafruit.com/makecode Page 15 of 18


Notes & Thoughts
You do not have to re-pair your device each time you
disconnect the USB cable. However, if you find the
upload button stops working or gets hung up, you can
attempt to pair the device again using the same
method. If you still can't get connection, try using a
different USB cable. It MUST be a USB "data" cable. If
you still are having issues, use the support link under
question mark icon next to the cog wheel icon in the top
right.

© Adafruit Industries https://learn.adafruit.com/makecode Page 16 of 18


Other Good Stuff
This guide is meant as a starter block but it's worth mentioning briefly about other feature of MakeCode...

GitHub packages
Additional blocks or drivers can be packaged in github repo and loaded in the editor via the Add Package dialog.
Packages can contain JavaScript, C++ and yes! ASM! https://makecode.adafruit.com/packages

We are Open Source on GitHub


Checkout https://makecode.com/about for more info about the various repos.

We have crowd-sourced translations


Whether you want to code in Klingon or your native non-English language, MakeCode supports crowd sourced
translations at https://makecode.adafruit.com/translate.

© Adafruit Industries https://learn.adafruit.com/makecode Page 17 of 18


See More MakeCode Projects
See More MakeCode Projects (https://adafru.it/Bwv)

© Adafruit Industries Last Updated: 2019-04-15 02:40:34 PM UTC Page 18 of 18

You might also like