DHT11 Temperature and Humidity Measurement

Slides:



Advertisements
Similar presentations
What is Arduino?  Arduino is a ATMEL 168 micro-controller kit designed specially for small projects  User friendly IDE(Integrated Development Environment)
Advertisements

1 Lab 3 Objectives  Case study: “Hello world” program on motes  Write you first program on mote.
PIC Programming with Logicator
ABSTRACT The goal of this project was to create a more realistic and interactive appliance interface for a Usability Science class here at Union. Usability.
HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver.
Over-view of Lab. 1 For more details – see the Lab. 1 web-site There will be a 20 min prelab quiz (based on Assignment 1 and 2) at the start of the lab.
1 CSI 101 Elements of Computing Fall 2009 Lecture #4 Using Flowcharts Monday February 2nd, 2009.
Digital I/O Connecting to the Outside World
Lecture – 7 Basic input and output
Shell and Flashing Images Commands and upgrades. RS-232 Driver chip – ST3232C Driver chip is ST3232C Provides electrical interface between UART port and.
Colorado Space Grant Consortium Gateway To Space ASEN 1400 / ASTR 2500 Class #12 Gateway To Space ASEN 1400 / ASTR 2500 Class #12 T-58.
Part 1 Using the ARM board And start working with C Tutorial 5 and 6
HD44780 LCD programming From the Hardware Side
Arduino. What is it? A open-source software suite and single-board microcontroller. Allows easy and affordable prototyping of microcontroller applications.
SE3910 Week 2, Class 1 Today Basic Circuits Other ??? Tomorrow Lab 2, S365 (Complete prelab BEFORE) Thursday See ScheduleSchedule SE-2811 Slide design:
Logic Analyzer ECE-4220 Real-Time Embedded Systems Final Project Dallas Fletchall.
A brief introduction to javadoc and doxygen. What’s in a program file? 1. Comments 2. Code.
Control System Design Process Planning Documentation.
Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.
Copyright © 2007 by Pearson Education 1 UNIT 6A COMBINATIONAL CIRCUIT DESIGN WITH VHDL by Gregory L. Moss Click hyperlink below to select: Tutorial for.
Case Study #1 Microcontroller System. What is a microcontroller? A microcontroller can be considered a self-contained system with a processor, memory.
Fan Assembly Driven by Magnetic Fields
Lecture 7 Datalogger Programming Using Arduino – Part 2
OPERATING SYSTEM CONCEPT AND PRACTISE
A step-by-Step Guide For labels or merges
RASPBERRY PI WORKSHOP.
Design and Documentation
Environment Temperature Monitor
Enable Talk Prepared By: Alaa Mayyaleh Shurouq Abu salhiah.
A bit of C programming Lecture 3 Uli Raich.
UNIT – Microcontroller.
DIGITAL CALCULATOR USING 8051
An Introduction to Programming and VB.NET
CS 3305 System Calls Lecture 7.
The Linux Operating System
Lecture 9 Uli Raich UCC semester 2017/2018
Practical example of C programming
UART and UART Driver B. Ramamurthy.
Drill Translate the following message:
Datalogger Programming Using Arduino – Part 2
Intro to PHP & Variables
Explain what touch develop is to your students:
PLC Hardware Components.
Internet-of-Things (IoT)
Introduction to javadoc
Computer Science I CSC 135.
UART and UART Driver B. Ramamurthy.
Number and String Operations
Serial EEPROM (Atmel 24C-512)
EET 2261 Unit 14 INCOMPLETE Analog-to-Digital Conversion (ADC) & Digital-to-Analog Conversion (DAC) Read. Homework #13 and Lab #13 due next week. Quiz.
CSCI1600: Embedded and Real Time Software
CSCI1600: Embedded and Real Time Software
Introduction to Wiring Logic Gates
ECE 3567 Microcontroller Lab
Text / Serial / Sequential Files
HD44780 LCD programming From the Hardware Side
HD44780 LCD programming From the Hardware Side
Enable Talk Prepared By: Alaa Mayyaleh Shurouq Abu salhiah.
Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.
CSCI1600: Embedded and Real Time Software
Introduction to javadoc
ECE 352 Digital System Fundamentals
UNIT 7: INFRARED SENSORS
UNIT 8 OTHER SENSORS.
CSCI1600: Embedded and Real Time Software
Chapter 13: I/O Systems.
UNIT 7: INFRARED SENSORS
Course Code 114 Introduction to Computer Science
Chapter 1: Creating a Program.
I/O Experiments Assignment 1.
Presentation transcript:

DHT11 Temperature and Humidity Measurement Lecture 8 Uli Raich UCC Semester 2017/2018

A single GPIO pin We have seen how we can drive an LED from a single GPIO pin programmed as output pin or how we can read its state through another GPIO pin, programmed as input pin. Can one do more with a single pin?

DHT11 pinout The DHT11 has only 3 pins: Vcc Ground one data pin Be careful: the pinout of the DHT11 board in our sensor kit is different

Serial Protocol How can we, with a single pin initiate a measurement read humidity and temperature data make sure the data are correct? The answer is: a serial protocol And the DHT11 implements its own serial protocol

Reading and understanding the data sheet Let’s have a look at the DHT11 data sheet:

Resistive Humidity Measurement

Resistive Humidity Measurement(2) Variations in relative humidity produce changes variations of resistivity, which is measured The resistance of certain hygroscopic materials such as hygroscopic salts have such a property These materials are mounted as thin films on the substrate with metal contacts The devices can be very small

The NTC Thermistor

A processor on chip In order to convert these measurements into numeric values and send them to the end user through a serial protocol, a preprogrammed micro-controller must be implemented on the chip. In the case of the DHT11 this is an 8 bit micro- controller which does the conversion into binary and which creates the serial protocol

Text from the data sheet

Precision

How to connect the device

Powering the device As we can see from the specs below, the DHT11 power line can be directly connected to the cobbler 3.3V (or the 5V) line

Single Wire two way interface

Overall Communication Process

How to initiate a Measurement?

What does this mean for our program? We must: Program the GPIO pin onto which we connected our DHT11 as output We must pull this line done (send a login level zero) and keep it low for a minimum of 18 ms We must pull it high again and wait for another 20-40 μs Finally we must re-program the pin as input and wait for the DHT11 to respond.

Response from DHT11

A zero bit

A one bit

Complicated? Wow, this looks complicated. How can we write a program to do all this?

What the user of the device wants The user of the device would like to have a library which hides all these details. He wants functions to Initialize the device Start a measurement Make sure the checksum is ok Read temperature and humidity values Maybe know when the measurement was made

The library How do we write a library? A library consist of min. 2 files: an include file (dht11.h) and implementation file (dht11.c) Very often you have a single include but several implementation files.

The include file of the dht11 library

dht11.h (2)

The library code dht11Init simply calls wiringPiSetup() dht11Measurement Programs the gpio pin as output and sends the start sequence Switches back the gpio pin to input and reads the data coming from the dht11 every 5 µs and saves the data into an array Analyses the data and extracts temperature, humidity and the checksum Calculates the checksum and compares it with the one coming from the device If checksums are ok, sends the data to “validData” Keeps the time stamp of the measurement

Reading the final data dht11GetValidTemperature() dht11GetValidHumidity() dht11getValidMeasTime() dht11getChecksum() dht11getDeviceChecksum()

Starting the measurement The data pin has been programmed as output earlier You can print these data and have a look at them with gnuplot. Try analyzing be hand.

Analyzing the data This is the tricky bit and you are invited to give it a try. I have written a routine reading a single bit, which is called 40 times for all the 40 bits in the data. Please note one nasty problem: Linux is a multi-tasking system and permanently receives interrupts. While these interrupts are treated the DHT11 data are continuing to flow but are not taking into account, leading to corrupt data. Since the duration of the protocol takes ~ 4 ms the probability is non negligible and the checksum test in obligatory to make sure the data are consistent. In case of a checksum error you must repeat the measurement.

Creating a shared library The Makefile says it all:

Where is the include file, where the binary of the shared lib? I installed the include file in /opt/ucc/include and the library in /opt/ucc/lib. These are non-standard directories and must be declared in the Makefile -I /opt/ucc/include for the include file in CFLAGS -L /opt/ucc/lib for the library path Since the shared library is loaded separately when running the main program, it must be found by the system: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/uc c/lib

Documentation When writing a library that is supposed to be used by other people, documentation is of utmost importance I use the doxygen in code documentation system which allows to generate documentation from the source layout and comments in the code with special tags. It creates html of latex doc