matmunk / DS18B20

Arduino library for the Maxim Integrated DS18B20 1-Wire temperature sensor.
MIT License
94 stars 32 forks source link

Cannot set resolution for more than one sensor #11

Closed LRDPRDX closed 1 year ago

LRDPRDX commented 1 year ago

I want both sensors to be set to resolution of 9 bits.

Here is the code (I think it explains everything):

#include <DS18B20.h>

DS18B20 ds(2);

void setup() {
  Serial.begin(9600);

  Serial.print( "Devices: " );
  Serial.println( ds.getNumberOfDevices() );

  Serial.println( "Before set" );
  while( ds.selectNext() )
  {
    Serial.println( ds.getResolution() );
  }

  while( ds.selectNext() )
  {
    ds.setResolution( 9 );
  }

  Serial.println( "After set" );
  while( ds.selectNext() )
  {
    Serial.println( ds.getResolution() );
  }
}

void loop() {
  // put your main code here, to run repeatedly:
}

and here is the serial output:

Devices: 2
Before set
9
12
After set
9
12

I expect that after set both should be 9 but only the first one has been set.

LRDPRDX commented 1 year ago

Closing this issue because it seems the problem was caused by sensors - not by the library.