I have a process running where the kepad has become unresponsive. It’s a hit and miss affair depending (I assume) on what part of the loop in running.
I’m using some DS18b20 temp sensors which I think may be causing a delay in the loop while they return the temp values. I read that there is a method where you can sensors.setWaitForConversion(); and use a millis timer, such that the loop is not held up. Maybe this might solve the problem but I don’t know how to correctly implement it as the examples do not operate with fixed hex addresses.
Alternativly, I have read you can attach interrupts to the keypad, which sounds like better solution, but I have not been able to find a detailed tutorial on how to implement this.
Could someone please advise which route would be preferable and suggest an implementation.
Many thanks, Paul
Hi Paul.
What’s the current method that you’re using to read the keypad?
Using interrupts seems a good idea. But, I think the main issue might be the time that it takes to get a reading from the sensor. So, I would go first with trying to read the sensor asynchronously.
There is this example in the library:
Instead of getting the temperature by index (sensors.getTempCByIndex(0)), you can get the temperature by address.
For example, imagine this is your address:
DeviceAddress sensor1 = { 0x28, 0xFF, 0x77, 0x62, 0x40, 0x17, 0x4, 0x31 };
Then use the following to get the readings by address:
sensors.getTempC(sensor1);
I hope this helps.
Regards,
Sara
Hi Sara,
Thank you for your advice. My code already defines the sensors adresses, however I have not been able to understand or implement the setwaitforconversion examples which use two separate start and stop millis() in a way I have not seen, not including a reset.
Can you provide an example user waitforconversion with set addresses? Here is my code so far:-
uint8_t sensor1[8] = {0x28, 0x2B, 0xFA, 0x75, 0xD0, 0x01, 0x3C, 0xA2};
uint8_t sensor2[8] = { 0x28, 0x1D, 0x33, 0x75, 0xD0, 0x01, 0x3C, 0x2C};
uint8_t sensor3[8] = { 0x28, 0x0C, 0x14, 0x75, 0xD0, 0x01, 0x3C, 0xE9};// REPLACEMENT SENSOR 28 0C 14 75 D0 01 3C E9
unsigned long startTempSensorTimer = 0;
unsigned long stopTempSensorTimer = 0;
void setup()
//Start Temp Sensors DS18B20
sensors.begin();
if(sensors.isParasitePowerMode()) Serial.println(“DS18B20 in Parasitic power mode – ON”);
else Serial.println(“DS18B20 in Parasitic power mode – OFF”);
void loop()
if(millis() – temptimer > 10000)
{
display_handle();
startTempSensorTimer = millis();
sensors.setWaitForConversion(false); // makes it async
sensors.requestTemperatures();
ambientC = sensors.getTempC(sensor1); // Gets the values of the temperature
waterC = sensors.getTempC(sensor2); // Gets the values of the temperature
airoffC = sensors.getTempC(sensor3);
sensors.setWaitForConversion(true);
stopTempSensorTimer = millis();
Serial.println(ambientC);
Serial.println(waterC);
Serial.println(airoffC);
Serial.print(“float switch : “);
Serial.println(floatSwitchStatus);
Serial.print(“Master switch : “);
Serial.println(masterSwitchStatus);
temptimer =millis();
}
Hi Sara,
Thank you for your advice. My code already defines the sensors adresses, however I have not been able to understand or implement the setwaitforconversion examples which use two separate start and stop millis() in a way I have not seen, not including a reset.
Can you provide an example user waitforconversion with set addresses? Here is my code so far:-
uint8_t sensor1[8] = {0x28, 0x2B, 0xFA, 0x75, 0xD0, 0x01, 0x3C, 0xA2};
uint8_t sensor2[8] = { 0x28, 0x1D, 0x33, 0x75, 0xD0, 0x01, 0x3C, 0x2C};
uint8_t sensor3[8] = { 0x28, 0x0C, 0x14, 0x75, 0xD0, 0x01, 0x3C, 0xE9};// REPLACEMENT SENSOR 28 0C 14 75 D0 01 3C E9
unsigned long startTempSensorTimer = 0;
unsigned long stopTempSensorTimer = 0;
void setup()
//Start Temp Sensors DS18B20
sensors.begin();
if(sensors.isParasitePowerMode()) Serial.println(“DS18B20 in Parasitic power mode – ON”);
else Serial.println(“DS18B20 in Parasitic power mode – OFF”);
void loop()
if(millis() – temptimer > 10000)
{
display_handle();
startTempSensorTimer = millis();
sensors.setWaitForConversion(false); // makes it async
sensors.requestTemperatures();
ambientC = sensors.getTempC(sensor1); // Gets the values of the temperature
waterC = sensors.getTempC(sensor2); // Gets the values of the temperature
airoffC = sensors.getTempC(sensor3);
sensors.setWaitForConversion(true);
stopTempSensorTimer = millis();
Serial.println(ambientC);
Serial.println(waterC);
Serial.println(airoffC);
Serial.print(“float switch : “);
Serial.println(floatSwitchStatus);
Serial.print(“Master switch : “);
Serial.println(masterSwitchStatus);
temptimer =millis();
}