Visual Thermometer with MakeCode: Adafruit Circuit Playground Express

Updated 29 March 2018

The Adafruit Circuit Playground Express comes packed with onboard sensors, in this tutorial we will learn about using the temperature sensor in MakeCode. MakeCode is great for a simple project because its block-based interface and pre-built functions do most of the work for you! While using MakeCode the thermometer can return the temperature in Celsius or Fahrenheit. 


Adafruit Circuit Playground Express Thermometer

Making the Code


Within MakeCode for the Circuit Playground Express, there are some great commands that make interfacing with the sensors easy and rewarding. The first of these is the graph command. We will be using the graph command to make the light wheel illuminate based on the temperature detected. To use the graph command, you set the upper constraint and put a variable in as the value. The NeoPixels illuminate to reflect the relative position of the variable value from 0. We have chosen an input block, “temperature in C” as our variable in the graph, and set the upper limit to 40 degrees.

MakeCode Screenshot, graph. Adafruit Circuit Playground Express

As you can see on the virtual Circuit Playground Express we have the current temperature graphed on the NeoPixels of the board. You can change the virtual temperature on the thermometer next to the board and see how it reacts. Let’s add an overheat animation to our program. We will first add an If-Else logic loop and then choose the greater than or less than comparison for the loop.

MakeCode Adafruit Circuit Playground Express Logic

The greater than comparison replaces the “True” in the if statement. If the temperature is greater than or equal to 40, then we have a light wheel command to turn all the lights red. If the temperature is not over 40 then we will see the graph of the temperature like before. This way we have a sort of overtemperature animation when the temperature has exceeded our set limits on the graph. 

MakeCode Adafruit Circuit Playground Express


Console

There is a console simulator within the virtual interface that creates a graph of the temperatures you’ve set in the console. Although that is a fun feature, it is not terribly useful in the real world. Luckily we are able to plot the real-time readings of the thermometer, in the same way, we just need to be using the Microsoft MakeCode Windows App, available on the Microsoft App store for free. This is a fully offline version of the web-based editor, and it is completely identical other than the option of a live console.

Adafruit Circuit Playground Express Serial Monitor

The same program in the Windows MakeCode App has a “Show console Device” option that allows you to see live readings from a connected Circuit Playground Express and export them as an Excel document! 

To put the code onto your Circuit Playground Express, simply hit the download button at the bottom of your editor. This will download your code as a .uf2 file. Connect your Circuit Playground Express to your computer and hit the reset button once to enter bootloader mode. Copy your downloaded .uf2 file into the CPLAYBOOT drive. Now your code is loaded, and you are ready to read some temperatures! For a full explanation of flashing code to your Circuit Playground Express, check out our MakeCode Introduction Tutorial.

If you want to learn more about the Adafruit Circuit Playground Express, check out the Circuit Playground Tutorials. This is just the beginning of what is possible on the Circuit Playground Express, there are so many different sensors the possibilities are practically endless. If you come up with a creative idea using the Circuit Playground Express and MakeCode please share it on our Forum!

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.