Power with MakeCode

Now it's time to upload some code! For this we will be using Microsoft MakeCode for Adafruit, a web-based code editor. It provides a block editor, similar to Scratch or Code.org, and also a JavaScript editor for more advanced users.

If you haven't used MakeCode before, this guide is a good place to start.

Getting into Bootloader Mode

Your Circuit Playground Express board comes ready to work with CircuitPython. When you connect the board to your computer for the first time, it will appear as a flash (or thumb) drive named CIRCUITPY.

BUT...

We'd like to make it work with MakeCode, which is done by putting it into "bootloader mode". All that's required to do this is to connect the board to your computer with a micro USB cable and click the small reset button in the center of the board. 

The Code

Follow this link or enter the portal below to interact with the code used in this project.

How to upload code

To upload code, connect you Circuit Playground Express to your computer using the micro USB cable, click the Download button to download the .uf2 file to your computer, and drag 'n drop it onto the CPLAYBOOT drive. 

The drive will automatically eject itself. (Your computer may give you a "failed to eject drive correctly" error, you can ignore this.) The code is now on your Circuit Playground Express and ready to run!

What this code does

This sketch in MakeCode uses the light sensor on Circuit Playground Express to control the motors.

In the on start block we can see that there is a startup animation and a command to invert the direction of one of the motors is so they will both spin in the same direction when placed in parallel. There is also a graph command, which indicates the light level by illuminating more or fewer of the 10 neopixels on the CPX board. 

In the forever block there is an if / else statement, which gives the following instructions:

  • If light level goes above the specified value, start spinning the motors in tandem.
  • If light level goes below the specified value (in this case, 150), stop the motors. 

If you'd like to play with this code, click "Edit" and a new window will open in which you can create your own version.

You can test this out by holding your turtle under bright light and covering/uncovering the light sensor.

Light Sensor

The component that makes this possible is the tiny analog light sensor in the top left part of the board. This is used to detect ambient light with similar spectral response to the human eye.

With MakeCode we are able to use the readings coming from this light sensor to control the motors, but it's also possible, with some clever code, to use this as a color sensor or even a pulse sensor!

Making Changes

If you want to make changes to your program you can connect your CPX to your computer with a micro USB cable, download your adapted code, and drag the new .uf2 file onto your CPLAYBOOT drive.

It is recommended that you remove the turtle's flippers while making changes so the turtle doesn't run away on you.

Troubleshooting

Problem: My flippers aren't rotating!

Solution: Make sure that the small slide switch on the CRICKIT is set to "ON".

 

Problem: My Circuit Playground Express doesn't show up as CPLAYBOOT!

Solution: Your Circuit Playground Express board comes ready to work with CircuitPython, and will show up as a flash drive named CIRCUITPY the first time it's connected to your computer. To switch over to work with MakeCode, connect the board to your computer with a micro USB cable and click the small reset button in the center of the board.  

When Circuit Playground Express is in Bootloader mode, all the LEDs will flash red briefly, then turn green. Your computer should now show removable drive called CPLAYBOOT. Now you can copy the MakeCode file to the CPLAYBOOT flash drive.

This guide was first published on Jul 24, 2018. It was last updated on Jul 24, 2018. This page (Power with MakeCode) was last updated on May 19, 2019.