Oak Development Technologies
  • IcyBlue
  • Oak Blog
  • Prototyping
  • Livestream
  • Open Source Projects
  • Contact
Tutorials, Announcements, and More from...

Oak Development 
​Technologies

Connect with us on Facebook, Twitter & Instagram!

(Tutorial) Make A Simple Thermostat With An Adafruit BMP280 Breakout and SAMD21 Microcontroller

4/5/2021

0 Comments

 
Picture
In this tutorial we will go over how to make a simple thermostat using the up coming CP Sapling Rev B and the BMP280 Pressure and Temperature sensor from Adafruit. This simple thermostat will display three simple colors to let you know what the temperature is inside you home or in a specific room. Let's get started!

​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:
  1. CircuitPython compatible development board (CP Sapling Rev B used in this tutorial: CP Sapling m0 Development Board). You can also use either of the Adafruit Qt Py.
  2. MicroUSB data cable or USB-C if using a Qt Py.
  3. STEMMA QT Cable from Adafruit: www.adafruit.com/product/4210
  4. BMP280 Pressure and Temperature Sensor from Adafruit: www.adafruit.com/product/2651
  5. Mu Editor (Get that HERE)

​Getting Everything Wired Up

All you need to complete this tutorial is to simply plug the STEMMA QT cable into both the development board and the BMP280 sensor. After you do this, just plug your development board into your computer!

The Code:

Like most of the tutorials we have done, the code for this project is pretty simple. There are two main guides that we can use from Adafruit that help us understand how to use the sensors and devices we are using. For this project we will use the following guides to help us use both the onboard neopixel and the BMP280 sensor.
  1. NeoPixel UBERGUIDE:  learn.adafruit.com/adafruit-neopixel-uberguide?view=all#python-circuitpython 
  2. BMP280 Learn Guide: learn.adafruit.com/adafruit-bmp280-barometric-pressure-plus-temperature-sensor-breakout/circuitpython-test
​When we combine the examples together we should get something similar to the following:
# import all the libraries for our sensor
import board, adafruit_bmp280, time, neopixel

# create an i2c object for our sensor
i2c = board.I2C()

# load the sensor on our I2C bus
sensor = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)

# setup our neopixel to display temp ranges
np = neopixel.NeoPixel(board.NEOPIXEL,1)
# set a low brightness so it lasts a long time
np.brightness = 0.05

# use an infinite while loop to poll our sensor at a specific rate
while True:
    # using IF/ELSE statements to pick our color output
    # based on our current temperature
    if (sensor.temperature < 20.0):
        np[0] = (0,0,255)
        np.show()
        time.sleep(5)
        np[0] = (0,0,0)
        np.show()
    elif (sensor.temperature > 20) and (sensor.temperature < 25):
        np[0] = (0,155,0)
        np.show()
        time.sleep(1)
        np[0] = (0,0,0)
        np.show()
    else:
        np[0] = (255,0,0)
        np.show()
        time.sleep(5)
        np[0] = (0,0,0)
        np.show()
    # print the current temperature to the console
    print("Current Temp: {}F".format(sensor.temperature * (9/5) + 32))
    # then save power by sleeping for 5 seconds. (not quite deep sleep)
    time.sleep(5)

After running the code for a while, we can see a slow stream of output from the microcontroller as it processes the temperature from the BMP280 sensor, but also tests that temperature against ranges we define for the color vs temperature. After a minute or so you should see a nice range of values printed in the console.
Picture
The great thing about this example is that using the learn guides for the sensor we're using, we can make a variety of different tools that can be useful to the average person. In the next tutorial we do for this sensor, we will explore making a wearable altimeter.

Final Thoughts

Hopefully this tutorial has given you a few simple ideas of how you can take simple sensors and make useful tools for yourself and your home. Using more powerful boards with additional core modules in Circuitpython, you can make even more complex projects to show off to your family and friends.
0 Comments



Leave a Reply.

    Authors

    Seth is embedded software engineer and open source hardware developer. 

    Archives

    May 2021
    April 2021
    January 2021
    November 2020
    October 2020
    September 2020

    Categories

    All
    New Products
    Product Spotlight
    Tutorials

    RSS Feed

Powered by Create your own unique website with customizable templates.
  • IcyBlue
  • Oak Blog
  • Prototyping
  • Livestream
  • Open Source Projects
  • Contact