Guys, it’s a stupid question here… my DS18b20 read function is a copied code with minor corrections where i needed:
// Read Sensor1
void readIndoorTemp() {
ds1.reset();
ds1.select(ds1_addr);
ds1.write(0x44, 1); // start conversion, with parasite power on at the end
//delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = ds1.reset();
ds1.select(ds1_addr);
ds1.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds1.read();
}
// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
int16_t 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);
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 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
}
indoorTemp = (float)raw / 16.0;
}
Here //delay(1000); // maybe 750ms is enough, maybe not is done by me, but originally it was given a 1000ms delay.
I have to read from 3 individual channels (not BUS) of DS19b20 periodically via a function readTemps() in the main loop. I’m not that into reporting into Serial if not needed. Rather a faster code execution is more important for me. (Hence avoiding the 1000ms x 3 = 3 total seconds of code execution holding.).
debug is telling me that there are readings. But since originally it was asked to put, I’m not sure what to do. My sensors are connected to a 20ft cable (UTP CAT6) with 1k-ohm resistors.
But, if you issue a read request on the bus, all sensors will do so. You can go back 750 mS later and read them all. Sooner if you're not using 12 bit resolution.
Your post is barely coherent but we all learn, and the only thing that is truly stupid is the code, which is probably ancient and does not merit reading, although a read cycle of 750ms would come a close second. You will be far better off using the the DS18B20 library, so look here for an example, and there are other means similarly painless. While you are at it, you might consider why on earth you would want to read the sensor more frequently than once per second. If you really do, you probably have the wrong sensor anyway, and it is time start over somewhere else.
PerryBebbington:
It makes no sense to expect fast code execution and use delay in your code. Delay stops everything from happening for the duration of the delay.
Follow the examples for using millis for timing and doing several things at once.
hey
I know delay() keeps the whole thing (i mean anything after delay() ) waiting from further go forward for the given time. And hence "several things at once" became popular. But the thing is, as I said, I took the code from somewhere, and there it was given a delay() after the read of each sensor. Since delay() makes overall program execution slow (added delay in loop), I was trying to avoid it.
It's true a single measuring takes 750 ms. When using the ds8b20 libraries with all sensors connected to the same io-pin you can initiate the measuring of all sensors by a single command and then readout by a sensor by one command. So highest possible speed of repeated reading at 12bit resolution is 750 ms per reading.
Best regards Stefan
Send the command to start all DS18B20s doing their temperature measurement / conversion – and return WITHOUT WAITING FOR THEM
Use a millis() timer to determine when the DS18B20s are finished while doing useful stuff in the meantime (ala Blink without Delay, and Doing Several Things at a Time).
The OneWire protocol is slow enough already and the library blocks while doing the work. Don’t make it worse with superfluous delays.