This repository was archived by the owner on Dec 20, 2018. It is now read-only.
File tree 2 files changed +15
-3
lines changed
2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -84,7 +84,12 @@ def begin(self, samplerate=CFG_16SAMPLE):
84
84
self ._logger .debug ('Using samplerate value: {0:04X}' .format (samplerate ))
85
85
# Set configuration register to turn on chip, enable data ready output,
86
86
# and start sampling at the specified rate.
87
- self ._device .write16 (TMP006_CONFIG , TMP006_CFG_MODEON | TMP006_CFG_DRDYEN | samplerate )
87
+ config = TMP006_CFG_MODEON | TMP006_CFG_DRDYEN | samplerate
88
+ # Flip byte order of config value because write16 uses little endian but we
89
+ # need big endian here. This is an ugly hack for now, better to add support
90
+ # in write16 for explicit endians.
91
+ config = ((config & 0xFF ) << 8 ) | (config >> 8 )
92
+ self ._device .write16 (TMP006_CONFIG , config )
88
93
# Check manufacturer and device ID match expected values.
89
94
mid = self ._device .readU16BE (TMP006_MANID )
90
95
did = self ._device .readU16BE (TMP006_DEVID )
Original file line number Diff line number Diff line change 29
29
import Adafruit_TMP .TMP006 as TMP006
30
30
31
31
32
+ # Define a function to convert celsius to fahrenheit.
33
+ def c_to_f (c ):
34
+ return c * 9.0 / 5.0 + 32.0
35
+
36
+
32
37
# Default constructor will use the default I2C address (0x40) and pick a default I2C bus.
33
38
#
34
39
# For the Raspberry Pi this means you should hook up to the only exposed I2C bus
54
59
# Loop printing measurements every second.
55
60
print 'Press Ctrl-C to quit.'
56
61
while True :
57
- print 'Object temperature: {0:0.4F} *C' .format (sensor .readObjTempC ())
58
- print ' Die temperature: {0:0.4F} *C' .format (sensor .readDieTempC ())
62
+ obj_temp = sensor .readObjTempC ()
63
+ die_temp = sensor .readDieTempC ()
64
+ print 'Object temperature: {0:0.3F}*C / {1:0.3F}*F' .format (obj_temp , c_to_f (obj_temp ))
65
+ print ' Die temperature: {0:0.3F}*C / {1:0.3F}*F' .format (die_temp , c_to_f (die_temp ))
59
66
time .sleep (1.0 )
You can’t perform that action at this time.
0 commit comments