Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Manufacturing Technology >> Manufacturing process

Compact DHT Temperature & Humidity Breakout for Raspberry Pi – ATtiny85 & DHT22/DHT11

Hardware components: Atmel ATTiny85 × 1 DHT22 Temperature Sensor × 1 DHT11 Temperature & Humidity Sensor × 1 SparkFun Tiny AVR Programmer × 1 Adafruit 4.7K Ω Resistor × 3 Adafruit 10K Ω Resistor × 1 Adafruit 100 Ω Resistor × 1 Adafruit Diffused Blue 3mm LED × 1 Adafruit Tactile Button Switch × 1 Adafruit Break-away 0.1″ 36-pin strip male header 1 piece @ length 6, 1 piece @ length 2 (total of 8 pins) × 1 Generic Jumper (0.1″) × 1 Arduino UNO & Genuino UNO Optional – used for debugging and testing. × 1 Software apps and online services: Microsoft Visual Studio 2015 Microsoft Windows 10 IoT Core Arduino IDE

 

STORY

Introduction

The DHT11 and DHT22 are popular temperature and humidity sensors due to their accuracy at a very low cost. One issue with them, though, is that they work over a proprietary one wire protocol that requires precise timing. These sensors have proven difficult to read on boards with non-real-time operating systems.

A while back, I posted an article titled “DHT11 /DHT22 Temperature Sensor” demonstrating how to use the Microsoft C++ sample code from C# to read these sensors. The library was able to get a reading but I had to add retry logic to make it more reliable. This proved to be successful for most but some people had issues getting this to work consistently.

Given the level of interest in using these sensors on the Raspberry Pi while running Windows 10 IoT Core, I decided  to create a second option that provides a very reliable method of reading these sensors while still maintaining a low cost.

Overview

The approach presented here is to attach the DHT sensor to an inexpensive ATtiny85 and setting it up as an I2C slave device. This is accomplished using the TinyWireS library and creating a set of registers that can be read from and written to interact with the device.

The device supports the follow functions:

The Source Code

There are three sets of code in this project. The main firmware for the board, an Arduino master sketch used to test and demonstrate the board while connected to an Arduino Uno and the Window 10 IoT Code application that demonstrates how to use the device from the Raspberry Pi. All of the code is available in the linked GitHub repository.

The Device/Circuit

The circuit is small and only uses a few inexpensive components. The ATtiny85 can be purchased from several vendors. I recommend picking up a few of them since they have many useful purposes.

The circuit has a six-pin header that allows it to be connected ether to another circuit or directly to the Raspberry Pi.  The pins are defined as follows:

There is also a two-pin header where a jumper can be added to enable, or removed to disable the on-board LED.

When utilizing this in a larger project, the circuit for the DHT Tiny can be merged or embedded into the projects existing circuit. In this case, the header pins and LED are optional.

The circuit can also be built on a separate board and connected to your Raspberry Pi with a few wires or a connecting cable.

Programming the ATtiny85

Load the sketch called DHT_Tiny_Breakout.ino onto the ATtiny85 using your AVR programmer. If you do not have a programmer, you can use an Arduino Uno (or similar board). Take a look at one or more of the articles listed below for help.

I use the SparkFun Tiny AVR Programmer to load my ATtiny85.

I am running my chip at 16 MHz. See my article titled “ATtiny @ 16MHz” for instructions on how to do this.

When using the ATtiny85, the slave sketch requires the TinyWireS library to be installed in your libraries folder. This library an be downloaded from https://github.com/rambo/TinyWire.

Breadboard the Circuit

The first step is to get the DHT Tiny up and running on a breadboard. Using a half-size breadboard build the circuit by following the schematic and breadboard diagrams included in the project.

Here are a couple of tips to help make it easier:

Below are some images of the breadboard version of my DHT Tiny.

Connecting the Arduino Uno

If your are interested in a quick test, a demonstration, or you are having trouble getting this to work with your Raspberry Pi, you can connect the DHT Tiny to an Arduino Uno (or similar device).

Load and run the sketch named DHT_Tiny_Master.ino. This sketch will display output in the Serial Monitor.

When connecting the I2C between the two boards it is important to have pull-up resistors on the SDA and SCL lines. In this circuit, there are two 4.7K Ω connected between the pins and 5V.

Below are some images of the DHT Tiny breadboard connected to the Arduino Uno.

Connecting to the Raspberry Pi

If your are interested in a quick test, a demonstration, or you are having trouble getting this to work with your Raspberry Pi, you can connect the DHT Tiny to an Arduino Uno (or similar device).

When connecting the I2C between the two boards it is important to have pull-up resistors on the SDA and SCL lines. In this circuit, there are two 4.7K Ω connected between the pins and 3V3.

VERY IMPORTANT! The DHT Tiny board will be powered by the 5V pin on the Raspberry Pi, but the pull-up resistors must be connected to the 3V3 pin on the Raspberry Pi (3V3 is on pins 1 and 17).

Below are some images of the DHT Tiny breadboard connected to the Raspberry Pi 3.

Running the Windows 10 Application

Get the code from the GitHub repository link at the bottom of the project and unzip it to your computer. Open the Universal Application source code in Visual Studio 2015 and either deploy it to the Raspberry Pi and launch it from the admin console or run it in debug mode from Visual Studio.

If this is the first-time you are running code frm Visual Studio for a Windows 10 IoT Core application, take a look at these articles from Microsoft:

Take a look at the video demonstration below to see the application running on a Raspberry Pi 3 while connected tot he DHT Tiny.

Application Highlights

The Windows 10 UWP application is a demonstration application that shows off all of the features of the DHT Tiny. The code will display the current temperature, humidity and other registers values from the device. The UI also provides a way to change the configuration of the device including the device address.

DHT Tiny Library

The sample  code uses a library written to interact with the DHT Tiny. This library is ready to use and can be included directly in all of your applications.

Get the Library from NuGet

If you do not want to include the project directly in your application, simply download the DHT Tiny library from NuGet using the command shown below. Open the Package Manager Console in Visual Studio and type the command.

PM> Install-Package IoT.DhtTiny

Scanning the i2c Bus for the Device

The DHT Tiny library includes a method that will search the i2c bus for any DHT Tiny devices and return a list of addresses. This list can be used to initialize one or more of the devices found. This especially comes in handy of you changed the address of the device but cannot remember what you set the address to. Note the callback method is optional.

// ***
// *** Enumerate the DHT Tiny devices on the i2c bus.
// ***
IEnumerable<byte> address = await DhtTiny.FindAllDhtTinyAsync(this.FindAllDhtTinyCallback);
// ***
// *** Call back method
// ***
private void FindAllDhtTinyCallback(I2cScanEventArgs e) 
{ 
	int percentComplete = (int)((double)e.CurrentIndex / (double)e.Total * 100.0d); 
	this.Status = string.Format("Locating devices [0x{0:X2}] [{1}%] [Found = {2:##0}]...", e.CurrentAddress, percentComplete, e.Items.Count());
} 

Schematics of DHT Tiny Breakout for the Raspberry Pi

Software Demonstration

This video demonstrates both the the Universal Application running on a Raspberry Pi 3 connected to the DHT Tiny on a breadboard.

[VIDEO COMING SOON]

Creating the Final Device

The easiest, and most cost effective way to create the board is to use a PCB prototype board such as the Perma-Proto Quarter-sized Breadboard PCB from Adafruit. The image below shows the the breakout using this prototype board. Note I used a dremel to take off the power rail sections of the board.

See More: DHT Tiny Breakout for the Raspberry Pi


Manufacturing process

  1. Thyristor Technology: From SCR to TRIAC, GTO, and UJT
  2. Professional Raspberry Pi Temperature Monitoring with DS18B20
  3. Building an Outdoor Weather Station with Raspberry Pi 2 and ADS‑WS1
  4. Top Accessories to Unlock Your Raspberry Pi's Full Potential
  5. SIGHT: Smart Glasses Empowering the Blind
  6. SparkFun Qwiic HAT for Raspberry Pi – Complete Hookup Guide
  7. PiCy: Build Your Own Tiny Raspberry Pi‑Powered Robot
  8. Top 4 Digital Transformation Challenges for Medical Device OEMs
  9. Efficient IoT Sensor Provisioning: Secure Connectivity & Credential Management
  10. A Heartfelt Farewell: My 40-Year Journey in Publishing