Stupid question on DS18b20

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.

I'm not clear what you're asking.

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.

Rather a faster code execution is more important for me.

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.

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.

Arduino 1-Wire Tutorial this seems a bit better than my one though...

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

If you use the right library...

sensors.setWaitForConversion(false);

Leo..

aq_mishu:
Arduino 1-Wire Tutorial this seems a bit better than my one though...

That is a an understatement...
There is nothing wrong with using delays when using DS18B20s in the normal manner.

Nick_Pyner:
There is nothing wrong with using delays when using DS18B20s in the normal manner.

Unless, of course, you want your processor to be doing something useful while waiting for the DS18B20s to finish their work. Things like:

  • Responding to user input
  • Blinking LEDs
  • Updating an LCD Display
  • Handling Serial I/O
  • Polling other sensors
  • Sending / Reciving data via nRF24L01
  • Running a web page
  • etc, etc ,etc

In that case, using a delay to block execution for ~750ms waiting for the DS18B20s will make your project perform like crap.

So, if you’d prefer not to burry your head in the sand for almost a second, use non-blocking techniques:

The OneWire protocol is slow enough already and the library blocks while doing the work. Don’t make it worse with superfluous delays.