With our new CP Sapling, there is a world of possibilities that you can explore with the SAMD21 microcontroller. And thanks to the hard work of Adafruit, there is a ton of great examples that can be used to explore microcontroller functionality and make a few cool projects to impress your family this holiday season!
As always before we get started, if you have never used a CircuitPython board like the QT PY, be sure to check out Adafruit's learning site to quickly get started with your new board. --> Adafruit Learning Site: Getting Started With CircuitPython ​What you'll need:
To get started, you'll need the following parts:
Getting Everything Wired Up
The great thing about this tutorial is there is nothing to wire up. We are using the internal temperature sensor on the SAMD21E18A microcontroller!
The Code:
The code for this example is pretty simple. When we look in the CircuitPython Getting Started Documentation, we can utilize the internal microcontroller temperature sensor through a simple command! This command returns the value of the temperature in Celsius, though if you are in the United States and not comfortable with metric, we're including the conversion for Fahrenheit as well in this example.
First we will simply display the temperature in the serial window in the MU Editor.
This code allows us to print the temperature every second which you can see in the MU Serial Monitor. What we are really wanting to do is make a simple temperature check device that can tell us if a temperature is over a certain value. Adding a few if/else statements allows us to do just that. For reference, 37C is roughly 98.6F or the average human body temperature. Some people run hotter than 98.6 and some people run a little cooler.
We will turn the on board neopixel red if we detect a temperature hotter than or equal to 24C or about 76F, otherwise keep the neopixel green. This is because it might take a while to get the temperature up to a temperature above 37C if you're not sick.
We can observe that as the microcontroller is in the open air, as long as the temperature is below 24C we can see the green light coming from the neopixel. Once the temperature is equal to or crosses 24C, the neopixel is then changed to red.
Final Thoughts:
Using the internal temperature of the CPU is a fun way to measure temperature with SAMD21 microcontrollers. These projects can be expanded using some breakout modules like the temperature and humidity sensors sold by Adafruit! These could be used as a way to experiment with thermometers, and provide a fun project to understand the temperature fluctuations inside and outside your home and even experiment taking surface body temperatures.
0 Comments
Leave a Reply. |
AuthorsSeth is embedded software engineer and open source hardware developer. Archives
March 2023
Categories |