Direct addressing temperaturesensors


#1

The makers example program for reading DS18B20 sensors, starts with a search for the Rom of the different sensors, and after that, the program is asking each sensor in a fixed order to give the actual temperature.
This means that, if you change a sensor, the whole sequence is changed.
I’d like to change my program to read only the sensor I define with the known rom-adress.
I searched for hours (read days) without finding a solution.
Can somebody give me a sollution ?
THX
jk


#2

If you are using the DS18B20 library:

Normally, when you use search(addr) it fills in an array of 8 bytes:

uint8_t  addr[8];

You don’t have to search for it, you can just statically define it:

uint8_t sensor1[8] = { 0x28, 0xdc, 0xbd, 0x48, 0x09, 0x00, 0x00, 0x76 };

And skip the search step and just look up that temperature using a specific address:

float tempC = getTemperature(sensor1);

#3

Hey,
thx for your answer. Sorry for this late reaction, but I wasn’t home for a couple of days.

Following your instructions, I added the Ds18B20 library. The Onewire library was maintained.
I also filled up a table with the ROm-adresses of the sensors. I put this table in the SETUP. Or is it better to insert in BEFORE the SETUP ?

I didn’t succeed to make the command "float TempC = getTemperature(sensor1) working : the getTemperature-command is refused as “is not declared in this scope”. Please can you explain how I can solve this problem ?

On beforehand THX for your appreciated help.
wkr
jk


#4

This should probably be ds18b20.getTemperature(sensor1); (where ds18b20 is the name of the object you created via DS18B20 ds18b20(pin, true);)


#5

Sorry, yes there should be an object. I copied that code from a class that’s a subclass of DS18B20, so it didn’t need the DS18B20 object to reference the getTemperature method.


#6

THX for your comments.
But I’m still in trouble : the command “ds18b20.getTemperature(sensor1)”; is not working. I wrote DS18B20 in capitals. This seems better, but now I get the message : “expected primary-expression before ‘.’ token.”

By trial and error I wrote some alternatives, but until now without a breaktrough.
Again, Can somebody help me ?

On beforehand THX !!!


#7

Post your code then we can say more.


#8

As asked for I’ll post my code.Maybe in a separate reply.

My aim is :

  • to read the nine sensors of my floor-heating system
  • print the results in the correct place on an LCD-screen 20x4
  • to count the number of Data-reading errors and to print that number to the LCD.
    -to calculate the % of false readings as a % of the total number of readings.
    (just to optimize the value of the resistors and optimize the wiring)

As the existing code reading the sensors in a fixed sequence is giving troubles I want to have a direct addressing of them. (in a lot of cases the actual search address routine is forgetting one of more sensors, so the search has to restart until the nine sensors are identified.This is not giving errors in the LCD-screen, but I would like to avoid that)
Here you have a picture of the LCD-screenI’llLCD%20temperatures%20and%20statistics The two upper lines are giving the temperatures (+1 figure on the right) and on the bottom of the screen you’ll find :

  • identifier of the currentsensor (0-8) being read
  • number of ROM-errors
  • number of data errors
  • total number of readings (up to 25.000 a day)
  • percentage of errors (1.75 % is a very bad day. Normally between 0.65 and 1.

I could not go further in the new .ino-file because the getTemperature command is refused

Remember, I’m not a professionnal…
THX and kind regards
jv


#9

#10

I see I made a mistake in the program I was sending : the lines (for i=1 to 8…) for the reading of the HEX temperature data were canceled with //. Those lines have to stay activated of course.

I’m only looking for the correct environnement making the command “DS18B20.getTemperature(sensor1)” working. After that I can, by trial and error, continue to finalize the new program myself.

Thx
wkr
Jk