OneWire without DallasTemperature and using DeviceAddress

I see lots of example online of the OneWire being used to get a DS18B20 DeviceAddress, and others using the OneWire and DallasTemperature libraries where the DeviceAddress is used to identify multiple sensors on the same input pin.

Is it possible to use the DeviceAddress without the DallasTemperature library, with multiple sensors on the same pin ?

I am busy adding some functions to a 3D printer, and wanting to add 3 temperature sensors to the code.

I do have them working in the code with the 2 libraries, but the delay in waiting for a response from the sensors is causing a brief interruption ( pause of around 500ms ) in the printing.

I believe ( if I understand it correctly ) that if I use OneWire, I am able to send the sensor/s a command to get the temperature, and then continue with my main loop, and then after 750 - 1000ms, go back and read the value.

Advice please.

The library has the option of waiting for the reading, or not. It has the option of checking for there being something ready to read. Use them!

PaulS:
The library has the option of waiting for the reading, or not. It has the option of checking for there being something ready to read. Use them!

Hi Paul

Thanks for the reply.

Are you talking about the OneWire Library, or the DallasTemperature library ?

Do you possible have a link to where I should be looking, and any pointers to the function / call name ?

Appreciate the assistance, Regards.

Are you talking about the OneWire Library, or the DallasTemperature library ?

The DallasTemperature library has these methods:

 // sets/gets the waitForConversion flag
void setWaitForConversion(bool);
bool getWaitForConversion(void);
// sets/gets the checkForConversion flag
void setCheckForConversion(bool);
bool getCheckForConversion(void);

They look to me like they do what you want.

Set wait to false, then, periodically check for completion.

Thank You Paul. I will go look for those.

@PaulS

Thank You. I got it working using only the OneWire library and this code that I found online.

Really appreciate you pointing me in the right direction. Thanks.

#include <OneWire.h>

OneWire myds(57);

byte DSreadstage;
byte DSresolution = 10;
unsigned long DSstarttime;

float DStempA;
byte LocalTemp1[8] = {0x28,0xCC,0xD1,0xE1,0x02,0x00,0x00,0xE6}; // temp sensor 1 at TOP of case - unique address


void setup(void) {

	dssetresolution(myds,LocalTemp1,DSresolution);

}


void loop(void) {

	if (DSreadstage == 0){
		if(millis() > DSstarttime + 3000){
			DSstarttime = millis();
			dsconvertcommand(myds,LocalTemp1);
			DSreadstage = 1;
		}
	} else {
		if (myds.read()) {
			DStempA = dsreadtemp(myds,LocalTemp1, DSresolution);  // DAtempA will contain the value from the sensor
			DSreadstage = 0;
		}
	}

}


void dssetresolution(OneWire myds, byte addr[8], byte resolution) {

	byte resbyte = 0x1F;	// Get byte for desired resolution
	if (resolution == 12){
		resbyte = 0x7F;
	} else if (resolution == 11) {
		resbyte = 0x5F;
	} else if (resolution == 10) {
		resbyte = 0x3F;
	}
	myds.reset();	// Set configuration
	myds.select(addr);
	myds.write(0x4E);         // Write scratchpad
	myds.write(0);            // TL
	myds.write(0);            // TH
	myds.write(resbyte);         // Configuration Register
	myds.write(0x48);         // Copy Scratchpad

}


void dsconvertcommand(OneWire myds, byte addr[8]){
  	myds.reset();
	myds.select(addr);
	myds.write(0x44);         // start conversion
}


float dsreadtemp(OneWire myds, byte addr[8], byte resolution) {
  	byte present = 0;
	int i;
	byte data[12];
	byte type_s;
	float celsius;
	float fahrenheit;
	switch (addr[0]) {
		case 0x10:
		type_s = 1;		//Serial.println(F("  Chip = DS18S20"));  // or old DS1820
		break;
	case 0x28:
		type_s = 0;		//Serial.println(F("  Chip = DS18B20"));
		break;
	case 0x22:
		type_s = 0;		//Serial.println(F("  Chip = DS1822"));
		break;
		default:
		Serial.println(F("Device is not a DS18x20 family device."));
	}
	present = myds.reset();
	myds.select(addr);
	myds.write(0xBE);         // Read Scratchpad
	for ( i = 0; i < 9; i++) {           // we need 9 bytes
		data[i] = myds.read();
	}
	// convert the data to actual temperature
	unsigned int raw = (data[1] << 8) | data[0];
	if (type_s) {
		raw = raw << 3; // 9 bit resolution default
		if (data[7] == 0x10) {
			// count remain gives full 12 bit resolution
			raw = (raw & 0xFFF0) + 12 - data[6];
		} else {
			byte cfg = (data[4] & 0x60);
			if (cfg == 0x00) raw = raw << 3;  // 9 bit resolution, 93.75 ms
			else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms
			else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms
			// default is 12 bit resolution, 750 ms conversion time
		}
	}
	celsius = (float)raw / 16.0;
	fahrenheit = celsius * 1.8 + 32.0;
	return celsius;
}