Hi all.I am very new to this so please bear with me.I am wanting to connect say 10 DS18B20 sensors.I will be using the lowest resolution of 9 but is there a way to stop reading them once a set point is reached i.e alarm state.
Thank you in advance any help is greatly appreciated.
You have no code yet?
Why do you think its a problem to decide whether to read or not based on a previous alarm state?
Just implement the logic you want...
Hi Mark,
Thank you for your reply.Yes I have some simple code.Here it is.The reads are a problem because I wish to control a stepper motor and the reads are interrupting it i.e it pauses during reads.
[/#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void loop() {
sensors.setResolution(9);
sensors.requestTemperatures();
Serial.print(sensors.getTempCByIndex(0));
if (sensors.getTempCByIndex(0) >= 25) {
Do stuff () ;code]
First thing is that you didn't post your code. You posted a snippet which almost useless.
Second thing is that setresolution only needs to be done once and should therefore be in setup, not in loop.
The main thing is that when you call requestTemperatures, in the absence of any other arrangements, the library waits for the conversion to finish before proceeding. Presumably that is where you are getting a delay. The Dallas library has a function which allows you to tell it not to wait for the conversion - which implicitly means that you are going to handle that yourself. In setup you would also set setWaitForConversion(false) and then in the loop, after you've called requestTemperatures, you can call isConversionComplete periodically to detect when the conversion is done at which time getTempCByIndex will return a valid temperature.
Pete
Hi Pete,
Thank you so much for your reply and very helpful it was too.Things are much clearer now.Sorry I thought that is all you would need as that is all the code I have regarding the sensors.My question is answered though and thank you again.