We will take temperature readings with the thermometer and print out the readings to a serial monitor, and illuminate the Neopixel ring, all using CircuitPython!

Transcript

Hi there, Steven here from Core Electronics. I'm here today to talk to you about making a visual thermometer on the Adafruit circuit playground Express using circuit Python.

If we look at look at the board, there's a lot of sensors on it but the thermometer is located in the upper right and it's not truly a thermometer it's a thermistor, which is it's a sensor that reads temperature by changing its resistance and it has a set resistance, so it will return an analog value of an amount between zero and just under 7,000. So, we'll need to convert in our code that into a usable temperature but luckily, thanks to the libraries built in two circuit python, most of that works already done for us.

As you can see the board's running the code already and it we're going to have a wheel of lights that indicate the current temperature, with zero degrees being no lights on and forty degrees being all the lights on and if it exceeds 40 degrees all the tight lights will turn red, is kind of an overheat indication.

If we look at the code we have here the MU editor, which is the editor we recommend for using the circuit python. It works great with the circuit playground Express. That the start of the code, we have we import our libraries. If you need any help learning about how to add libraries onto your board, check out our tutorial on getting started with circuit python we go over that there, but we include the Adafruit thermistor library, the we import the board, so we can interface with sensors on the board, import time and neopixels so we can use the neopixels on the board.

So, if we look at our next block of code, we are going to initialize our thermistor and set up our parameters, for thermistor so it'll come from raw analog data, into a usable temperature in Celsius. So, if we look at this thermistor initializer to break down what's going on inside the brackets here, the first field is the input of the thermistor, which is the in this case the onboard thermistor, on the circuit playground express. The next field is the resistance, the serial resistance of the thermistor which is 10,000 ohms, for this resistor. The nominal resistance of the thermistor which is 10,000 ohms and then we have, the nominal temperature of the thermistor. So, this is normally 25 but on this particular board we're getting more accurate readings at 22 and then the last number is the beta coefficient of the thermistor, which is something you'd get from the datasheet, where you could calculate in this case this 39, 50.

So after that we set up our neopixels and make sure they're all turned off and we identify a few of our variables, our number of pixels, our minimum and maximum temperature and we could change the temperature range here, say it never gets below 10 degrees Celsius where you're reading so you want a wider spread across your neopixels for the range, that you want them you could set your minimum temperature to 10.

I'm going to look at our next piece of code, we have a block here devoted to creating a colour wheel, so what this does is it you input basically a 0 to 255 number and it returns a colour on the wheel, so this is what allows our neopixels to transition from blue into red as it goes around the wheel and that's utilized later on in the code, within our loop and then we have an operation here to convert our different ranges of values. So, we have first data coming in that's a temperature, that can be any sort of range right now it's from 0 to 40 but we needed to output on our neopixels as 0 to 10 neopixels, so although 0 to 40 to 0 to 10 is simple change. It could be any range, so we have this operation here to do that conversion for us.

If we look at our loop the main body of code, first we take a reading off our thermistor, which is now going to output degrees in Celsius and we have that print to our serial monitor. We save our we save our thermistor reading as a variable temp and then we do a little calculation to calculate the height of the pixel ring based on the temperature and then we have a little bit of logic here for colouring in the pixels in a rainbow gradient, up to the correct point.

So first of all the first if-statement is if, the height isn't on the pixels at all then they're all off, then we have a else if that turns all the pixels red if it exceeds the range of the 10 pixels, so that it goes over 40 in this case but over whatever your limit is set to and then we have, if those two conditions aren't met then it will map the colour wheel to whatever position is relative to the temperature it's reading and then we have a short rest of 0.5 seconds, so we don't constantly update, so let's take a look at the code in action.

We'll open up our serial monitor and hit control D to started and as you can see we have every half a second and new temperature reading coming up currently reading about 27 degrees, and I've got a heat gun here, just so we can have a closer look at what it's like when it's reading some actual heat, I'm going to be careful not to put too much heat on it because we don't want to cook our board, but as you can see on the serial monitor and the lights on the board as it gets warmer the lights climb and if it breaks 40 degrees, then they all turn red and as you can see on the serial monitor it's reading 42 degrees now. Now the heats taken away it's dropping back down it will drop slowly because it probably heated up the board a little bit.

That concludes our project on making a visual thermometer using circuit Python for the Adafruit circuit playground Express, check out our tutorials section for more tutorials on the Adafruit circuit playground Express, that utilize the different sensors and features of the board and we also have tutorials up for doing the same thing in make code and circuit python.

Thanks for watching.

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.