Simple Sensirion Sht 11 Code
NWCCTV
Posts: 3,629
For the Basic Stamp there is code that simply displays the Temperature and Humidity. I am looking for something like this in Spin. All of the demos seem to have all sorts of data displayed that I do not need. Before I start modifying the demos, I thought I would ask if anyone already has code that will display the current temperature and humidity only. Thanks.

Comments
There are two demos. The first simply shows how to read the values and display them using Parallax Serial Terminal. A second demo shows how to change the resolution at run time, and how to turn on and off the heater (which is hardly ever useful in practice).It also shows the conversion times in milliseconds, so that you can assess the difference in speed between the modes.
''============================================================================= '' '' @file SensirionDemo '' @target Propeller '' '' Display Sensirion SHT-11 values from 2 sensors every 20 seconds on a VGA/TV display '' and into PST through the serial port. Values are also logged to SD using the '' fsrwFemto object in a csv format file called "SHT11.log". '' Floating point routines are used to calculate temp and RH according to the '' Sensirion datasheet and application notes. All low level functions for '' communicating with SHT-11 are contained in the Sensirion object. '' '' ───SHT11_Multi_VGA_SD_002 '' ├──Sensirion '' ├──vga_text (or tv_text) '' ├──FloatString '' ├──Float32 '' ├──FullDuplexSerialPlus.spin2 '' └──fsrwFemto.spin '' └───sdspiFemto.spin '' '' @author Andrew Williams, WBA Consulting '' '' Some portions: '' @author Cam Thompson, Micromega Corporation '' Copyright (c) 2006 Micromega Corporation '' See end of file for terms of use. '' '' Some Portions adapted from: '' ** SD INTERFACE TRAINER ** '' ** By Jeff Ledger ** '' '' '' @version V1.2 - 9/29/09 '' @changes '' - 01 Adapted from V1.4 of Multi_TV code, added SD OBJ, CONS, VAR '' - 02 Used SD writing code from SD_Trainer to create logging section of main ''============================================================================= CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 ' SHT_DATA = 1 ' SHT-11 data pin SHT_CLOCK = 0 ' SHT-11 clock pin CLS = $0 ' clear screen CR = $D ' carriage return Deg = $B0 ' degree symbol '' SD Configuration spiDO = 3 spiClk = 4 spiDI = 5 spiCS = 6 VAR byte SHT_DATA long ioControl[2] ''** Variable required for SD Routines ** byte buff[32] '' buffer for SD OBJ term : "vga_text" 'term : "tv_text" sht : "Sensirion" fp : "FloatString" f : "Float32" debug : "FullDuplexSerialPlus" ''Used for interaction with the Propeller sd : "fsrwFemto" ''SD Software used in FemtoBASIC PUB main | rawTemp, rawHumidity, tempC, rh, dewC, i, name, r, data debug.start(31,30,0,115200) '' Open serial communication with PST, 115200 waitcnt(clkfreq*10 + cnt) '' delay (so you can get PST active), 10 secs debug.tx(Debug#CLS) debug.str(string("Running SHT11 Multi Program",13)) term.start(16) ' start VGA terminal 'term.start(12) ' start TV terminal f.start ' start floating point object sd.start(@ioControl) '' ** Start the SD Routines ** term.out(CLS) ' ' read and display SHT-11 sensor readings every 2 seconds repeat setColor(3) displayString(0, 0, string(" Cold enough for ya? ", CR)) ' display title setColor(0) term.str(string("│ Sensor │ Temp F │ RH % │", CR)) term.str(string("├──────────┼─────────┼───────┤", CR)) 'start of repeating sensor sequence repeat i from 1 to 2 '2 sensors on P1, P2 sht.start(i, SHT_CLOCK) rawTemp := f.FFloat(sht.readTemperature) rawHumidity := f.FFloat(sht.readHumidity) tempC := celsius(rawTemp) term.str(string("│ ")) name := lookup(i: string("Internal"), string("External")) term.str(name) ' sensor name variable term.str(string(" │ ")) term.str(fp.FloatToFormat(fahrenheit(tempC), 5, 1)) term.str(string(deg, " │")) rh := humidity(tempC, rawHumidity) term.str(fp.FloatToFormat(rh, 5, 1)) term.str(string(" │", CR)) debug.str(string(13,"** Sending information to SD",13)) sd.mount(spiDO,spiClk,spiDI,spiCS) '' Mount the SD sd.popen(string("SHT11.log"),"a") '' Open logfile for append 'sd.str(name),(string(",")),(fp.FloatToFormat(fahrenheit(tempC), 5, 1),(string(",")),(fp.FloatToFormat(rh, 5, 1)),(string(", done",13,10)) sd.str(name) sd.str(name) sd.str(string(",")) sd.str(fp.FloatToFormat(fahrenheit(tempC), 5, 1)) sd.str(string(",")) sd.str(fp.FloatToFormat(rh, 5, 1)) sd.str(string(13)) sd.pclose '' Close the file sd.unmount '' Unmount the SD debug.str(string(13,"** Routine Finished",13)) term.str(string("└──────────┴─────────┴───────┘")) debug.str(string(13,"Waiting...")) waitcnt(clkfreq*20 + cnt) ''20 seconds between reading sequences debug.str(string(13,"Starting in 5 seconds...",13)) waitcnt(clkfreq*5 + cnt) ''5 seconds debug.str(string(16)) PUB displayString(row, col, s) setPosition(row, col) term.str(s) PUB setPosition(row, col) if row => 0 term.out($B) term.out(row) if col => 0 term.out($A) term.out(col) PUB setColor(c) term.out($C) term.out(c) PUB celsius(t) ' from SHT1x/SHT7x datasheet using value for 3.5V supply ' celsius = -39.66 + (0.01 * t) return f.FAdd(-39.66, f.FMul(0.01, t)) PUB fahrenheit(t) ' fahrenheit = (celsius * 1.8) + 32 return f.FAdd(f.FMul(t, 1.8), 32.0) PUB humidity(t, rh) | rhLinear ' rhLinear = -4.0 + (0.0405 * rh) + (-2.8e-6 * rh * rh) ' simplifies to: rhLinear = ((-2.8e-6 * rh) + 0.0405) * rh -4.0 rhLinear := f.FAdd(f.FMul(f.FAdd(0.0405, f.FMul(-2.8e-6, rh)), rh), -4.0) ' rhTrue = (t - 25.0) * (0.01 + 0.00008 * rawRH) + rhLinear return f.FAdd(f.FMul(f.FSub(t, 25.0), f.FAdd(0.01, f.FMul(0.00008, rh))), rhLinear) DAT title byte CR, " Sensirion SHT-11 Readings",0 {{ ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ TERMS OF USE: MIT License │ ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation │ │files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, │ │modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│ │is furnished to do so, subject to the following conditions: │ │ │ │The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.│ │ │ │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE │ │WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR │ │COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │ │ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ }}degF := rht.ReadTemperature * 9 / 500 + 32.
There is a bit of roundoff bias in that. Is it good enough? If you want it to 0.1 degF, use
degF := rht.ReadTemperature * 9 / 50 + 320