Mercurial > code > home > repos > homeauto
comparison service/arduinoNode/devices.py @ 991:c6989dcf1f4f
temp sensor try to work with idle loop (but there are still stutters)
Ignore-this: d3d33548db6ce6c329f8aef2cd83403a
darcs-hash:20150708082102-312f9-ea553ff8ce011065b93ed3dae5dbc8fa057ca0d8
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Wed, 08 Jul 2015 01:21:02 -0700 |
parents | 11fff6301027 |
children | 6c6897a139da |
comparison
equal
deleted
inserted
replaced
990:11fff6301027 | 991:c6989dcf1f4f |
---|---|
217 DeviceAddress tempSensorAddress; | 217 DeviceAddress tempSensorAddress; |
218 #define NUM_TEMPERATURE_RETRIES 2 | 218 #define NUM_TEMPERATURE_RETRIES 2 |
219 | 219 |
220 void initSensors() { | 220 void initSensors() { |
221 sensors.begin(); | 221 sensors.begin(); |
222 sensors.setWaitForConversion(false); | |
222 sensors.getAddress(tempSensorAddress, 0); | 223 sensors.getAddress(tempSensorAddress, 0); |
223 sensors.setResolution(tempSensorAddress, 12); | 224 sensors.setResolution(tempSensorAddress, 9); // down from 12 to avoid flicker |
224 } | 225 } |
225 ''' % dict(pinNumber=self.pinNumber) | 226 ''' % dict(pinNumber=self.pinNumber) |
226 | 227 |
228 def generateSetupCode(self): | |
229 return 'initSensors();' | |
230 | |
227 def generatePollCode(self): | 231 def generatePollCode(self): |
228 return r''' | 232 return r''' |
229 for (int i=0; i<NUM_TEMPERATURE_RETRIES; i++) { | 233 for (int i=0; i<NUM_TEMPERATURE_RETRIES; i++) { |
230 sensors.requestTemperatures(); | 234 sensors.requestTemperatures(); |
235 // not waiting for conversion at all is fine- the temps will update soon | |
236 //unsigned long until = millis() + 750; while(millis() < until) {idle();} | |
231 float newTemp = sensors.getTempF(tempSensorAddress); | 237 float newTemp = sensors.getTempF(tempSensorAddress); |
238 idle(); | |
232 if (i < NUM_TEMPERATURE_RETRIES-1 && | 239 if (i < NUM_TEMPERATURE_RETRIES-1 && |
233 (newTemp < -100 || newTemp > 180)) { | 240 (newTemp < -100 || newTemp > 180)) { |
234 // too many errors that were fixed by restarting arduino. | 241 // too many errors that were fixed by restarting arduino. |
235 // trying repeating this much init | 242 // trying repeating this much init |
236 initSensors(); | 243 initSensors(); |
237 continue; | 244 continue; |
238 } | 245 } |
239 Serial.print(newTemp); | 246 Serial.print(newTemp); |
247 idle(); | |
240 Serial.print('\n'); | 248 Serial.print('\n'); |
249 idle(); | |
241 Serial.print((char)i); | 250 Serial.print((char)i); |
251 idle(); | |
242 break; | 252 break; |
243 } | 253 } |
244 ''' | 254 ''' |
245 | 255 |
246 def readFromPoll(self, read): | 256 def readFromPoll(self, read): |