Raspberry Pi How to Log Sensor Reading to Adafruit.io
Analog Devices, known for their reliable and well-documented sensor chips - has a high precision and high resolution temperature sensor on the market place, and we've got a breakout to make information technology like shooting fish in a barrel to apply! TheAnalog Devices ADT7410 gets straight to the point - it'south an I2C temperature sensor, with 16-bit 0.0078°C temperature resolution and 0.5°C temperature tolerance. Wire it up to your microcontroller or single-lath reckoner to get reliable temperature readings with ease
This sensor tin can be put online using a Raspberry Pi, Python, and Adafruit IO. You lot'll be up and running in under 15 minutes!
If yous're looking for a way to precisely monitor and log temperature data to the cloud, follow along!
Thanks to Digi-Primal and Analog Devices for sponsoring the development of this guide - Adafruit has made the ADT7410 PCB "Digi-Fundamental red" in their honor!
Parts
Analog Devices, known for their reliable and well-documented sensor chips - has a high precision and high resolution temperature sensor on the market, and we've got a breakout to...
The Raspberry Pi 3 Model B is the virtually pop Raspberry Pi computer fabricated, and the Pi Foundation knows you can always make a good matter meliorate! And what could make the Pi 3...
These displays are small, only about 1" diagonal, but very readable due to the loftier dissimilarity of an OLED display. This display is made of 128x32 individual white OLED pixels, each...
This is the assembled version of the Pi T-Cobbler Plus. It simply works with the Raspberry Pi Model Nothing, A+, B+, Pi ii, Pi three & Pi 4! (Any Pi with 2x20...
Materials
You'll need the materials below to consummate this project. If you practise not have them, pick them up from the Adafruit Store.
Feed Setup
If y'all do not already have an Adafruit IO account set up up, head over to io.adafruit.com to link your Adafruit.com account to Adafruit IO.
The start step is to create a new Adafruit IO feed to hold the AD7410's temperature. Navigate to the feeds page on Adafruit IO. Then click Actions -> Create New Feed, and proper noun this feed temperature.
- If you do not already know how to create a feed, head over to Adafruit IO Basics: Feeds.
Dashboard Setup
Adjacent, pace is to create a dashboard to display the value read by the ADT7410 sensor.
- If you exercise not know how to create or use Dashboards in Adafruit IO, head over to the Adafruit IO Basics: Dashboards guide.
| | Select the Gauge block. |
| | Select the temperature feed created earlier. |
| | In the Block Settings step,gear up the Block Title to Temperature, fix the Estimate Min/Max Values to the upper and lower temperature thresholds yous want to measure out. You tin label the gauge by setting the Gauge Characterization - this example assumes temperature is to be measured in Degrees C. Uncomfortably hot/common cold?You tin can optionally prepare the judge alter colour to warn you if the temperature goes above (or below) a certain value. |
Later on calculation the gauge chemical element, your dashboard will look like the following:
You are also going to demand your Adafruit IO username and cloak-and-dagger API cardinal.
Navigate to your profile and click the View AIO Key button to retrieve them. Write them downward in a condom place, you'll need them for later.
Need a style to connect your Raspberry Pi to a breadboard? Check out the T-Cobbler Plus - this add-on prototyping board lets y'all easily connect a Raspberry Pi (Raspberry Pi Model Zero, A+, B+, Pi 2,Pi 3) to a solderless breadboard:
This is the assembled version of the Pi T-Cobbler Plus. It but works with the Raspberry Pi Model Naught, A+, B+, Pi two, Pi 3 & Pi 4! (Whatsoever Pi with 2x20...
The ADT7410 and the 128x32 OLED each have a unique address and tin be continued together as i2c devices, using the Raspberry Pi equally a i2c controller (For more information almost i2c addressing, check out the guide hither...)
Make the following connections between the Pi and the ADT7410:
- Pi three.3V to ADT7410 VIN
- Pi GND to ADT7410 GND
- Pi SCL to ADT7410 SCL
- Pi SDA to ADT7410 SDA
Make the following connections between the Pi and the OLED Display:
- Pi SCL to Display SCL
- Pi SDA toDisplay SDA
- Pi GPIO #21 toDisplay RST
- Pi 3.3V toDisplay VIN
- Pi GND toDisplay GND
This guide assumes that you've gotten your Raspberry Pi up and running, and have CircuitPython installed.
- If you lot take not done this still, visit the installation guidehere and come back when you're ready.
Installing Fonts
This projection uses a Microsoft TrueType Font. To install information technology, enter the following into the concluding on your Raspberry Pi:
sudo apt-get install ttf-mscorefonts-installer
Installing CircuitPython Libraries
Since CircuitPython is running on the Raspberry Pi - installing the libraries for this guide is quick and like shooting fish in a barrel.
Toinstall the library for the display,enter the following into the terminal
sudo pip3 install adafruit-circuitpython-ssd1306
Y'all'll likewise need to install the CircuitPython library to read data from the Analog Devices ADT7410:
sudo pip3 install adafruit-circuitpython-adt7410
The code for this project is beneath. Save information technology to the Raspberry Pi as adafruit_io_adt7410.py
# SPDX-FileCopyrightText: 2022 Brent Rubell for Adafruit Industries # # SPDX-License-Identifier: MIT """ 'adafruit_io_adt7410.py' ================================== Example of sending temperature values to an Adafruit IO feed using an ADT7410 breakout. Dependencies: - Adafruit_Blinka (https://github.com/adafruit/Adafruit_Blinka) - Adafruit_CircuitPython_SSD1306 (https://github.com/adafruit/Adafruit_CircuitPython_SSD1306) - Adafruit_CircuitPython_ADT7410 (https://github.com/adafruit/Adafruit_CircuitPython_ADT7410) """ # Import standard python modules import time # import Adafruit SSD1306 OLED from PIL import Image, ImageDraw, ImageFont import adafruit_ssd1306 # import Adafruit IO Residual customer from Adafruit_IO import Client # import Adafruit CircuitPython adafruit_adt7410 library import adafruit_adt7410 # import Adafruit Blinka import board import busio import digitalio # Filibuster between sensor reads, in seconds DELAY_SECONDS = thirty # Set to your Adafruit IO key. # Remember, your key is a cloak-and-dagger, # so make sure not to publish information technology when you publish this code! ADAFRUIT_IO_KEY = 'ADAFRUIT_IO_KEY' # Set to your Adafruit IO username. # (go to https://accounts.adafruit.com to find your username) ADAFRUIT_IO_USERNAME = 'ADAFRUIT_IO_USERNAME' # Create an example of the Remainder client aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY) # Gear up `temperature` feed pi_temperature = aio.feeds('temperature') # Set OLED i2c_bus = busio.I2C(board.SCL, board.SDA) oled_reset = digitalio.DigitalInOut(lath.D21) disp = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c_bus, reset=oled_reset) # Clear display. disp.fill(0) disp.prove() # Create blank prototype for cartoon. # Make sure to create paradigm with mode '1' for 1-bit color. width = disp.width height = disp.height prototype = Image.new('one', (width, height)) # Go cartoon object to draw on image. draw = ImageDraw.Draw(image) # `sudo apt-get install ttf-mscorefonts-installer` to go these fonts font_big = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf', sixteen) font_small = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf', 12) adt = adafruit_adt7410.ADT7410(i2c_bus, address=0x48) adt.high_resolution = Truthful time.sleep(0.25) # expect for sensor to boot upward and get first reading while True: # clear screen describe.rectangle((0, 0, width, height), outline=0, fill=0) # Read the temperature sensor tempC = adt.temperature tempC = round(tempC, 2) # display the temperature on the OLED draw.text((0, 0), "Temp: %0.2F *C" % tempC, font=font_big, fill=255) # Send temperature to Adafruit IO print('Sending temperature {0} C to Adafruit IO'.format(tempC)) draw.text((0, 16), "Sending...", font=font_small, fill=255) disp.image(image) disp.show() aio.transport(pi_temperature.key, tempC) describe.text((0, 16), "Sending...Done!", font=font_small, fill up=255) disp.paradigm(prototype) disp.prove() # Filibuster for DELAY_SECONDS seconds to avoid timeout from adafruit io time.slumber(DELAY_SECONDS) # SPDX-FileCopyrightText: 2022 Brent Rubell for Adafruit Industries # # SPDX-License-Identifier: MIT """ 'adafruit_io_adt7410.py' ================================== Case of sending temperature values to an Adafruit IO feed using an ADT7410 breakout. Dependencies: - Adafruit_Blinka (https://github.com/adafruit/Adafruit_Blinka) - Adafruit_CircuitPython_SSD1306 (https://github.com/adafruit/Adafruit_CircuitPython_SSD1306) - Adafruit_CircuitPython_ADT7410 (https://github.com/adafruit/Adafruit_CircuitPython_ADT7410) """ # Import standard python modules import time # import Adafruit SSD1306 OLED from PIL import Prototype, ImageDraw, ImageFont import adafruit_ssd1306 # import Adafruit IO REST client from Adafruit_IO import Client # import Adafruit CircuitPython adafruit_adt7410 library import adafruit_adt7410 # import Adafruit Blinka import board import busio import digitalio # Delay between sensor reads, in seconds DELAY_SECONDS = 30 # Set to your Adafruit IO key. # Remember, your key is a secret, # and then make certain not to publish information technology when you lot publish this code! ADAFRUIT_IO_KEY = 'ADAFRUIT_IO_KEY' # Prepare to your Adafruit IO username. # (go to https://accounts.adafruit.com to find your username) ADAFRUIT_IO_USERNAME = 'ADAFRUIT_IO_USERNAME' # Create an instance of the Residual client aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY) # Gear up `temperature` feed pi_temperature = aio.feeds('temperature') # Set up OLED i2c_bus = busio.I2C(lath.SCL, board.SDA) oled_reset = digitalio.DigitalInOut(board.D21) disp = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c_bus, reset=oled_reset) # Clear display. disp.make full(0) disp.show() # Create blank image for drawing. # Make sure to create image with fashion 'ane' for 1-fleck color. width = disp.width peak = disp.acme prototype = Image.new('one', (width, superlative)) # Get drawing object to draw on prototype. draw = ImageDraw.Draw(epitome) # `sudo apt-get install ttf-mscorefonts-installer` to get these fonts font_big = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf', 16) font_small = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf', 12) adt = adafruit_adt7410.ADT7410(i2c_bus, address=0x48) adt.high_resolution = True time.sleep(0.25) # wait for sensor to boot upwardly and get first reading while True: # articulate screen depict.rectangle((0, 0, width, height), outline=0, fill=0) # Read the temperature sensor tempC = adt.temperature tempC = round(tempC, 2) # brandish the temperature on the OLED draw.text((0, 0), "Temp: %0.2F *C" % tempC, font=font_big, fill=255) # Send temperature to Adafruit IO print('Sending temperature {0} C to Adafruit IO'.format(tempC)) draw.text((0, 16), "Sending...", font=font_small, fill=255) disp.image(epitome) disp.show() aio.send(pi_temperature.key, tempC) draw.text((0, sixteen), "Sending...Done!", font=font_small, fill=255) disp.image(image) disp.bear witness() # Delay for DELAY_SECONDS seconds to avoid timeout from adafruit io fourth dimension.sleep(DELAY_SECONDS) Earlier running the code, yous'll need to set the ADAFRUIT_IO_KEY to the Adafruit IO Cardinal we saved earlier and set the ADAFRUIT_IO_USERNAME to your Adafruit IO Username.
When both of these variables are inverse, save the file. You tin run the program by entering the following in your terminal:
python adafruit_io_adt7410.py
and Press the Enter Cardinal.
You should encounter the following print out in your final
Sending temperature 22.26 C to Adafruit IO Sending temperature 22.27 C to Adafruit IO Sending temperature 22.25 C to Adafruit IO Sending temperature 22.27 C to Adafruit IO Sending temperature 22.28 C to Adafruit IO
Sending temperature 22.26 C to Adafruit IO Sending temperature 22.27 C to Adafruit IO Sending temperature 22.25 C to Adafruit IO Sending temperature 22.27 C to Adafruit IO Sending temperature 22.28 C to Adafruit IO
| | The display should display the temperature read from the ADT7410 along with the status of the information being sent to Adafruit IO. |
| | Adjacent, nosotros're going to check that the data has been received past Adafruit IO. Nosotros can do this by visiting the Adafruit IO Monitor folio. Every xxx seconds, the page volition refresh with the latest values from the ADT7410. If you want to modify the delay, change the variable |
| | Navigate to the dashboard y'all created before to view the temperature gauge we added. Every 30 seconds, information technology'll update and display a new value. |
For more information near the ADT7410 CircuitPython library, check out the latest docs!
This guide was starting time published on Feb eleven, 2019. It was last updated on February eleven, 2019.
Source: https://learn.adafruit.com/iot-temperature-logger-with-python-and-adafruit-io?view=all
0 Response to "Raspberry Pi How to Log Sensor Reading to Adafruit.io"
Post a Comment