Go Down

Topic: Temperature ROM name to variable (solved!) (Read 435 times) previous topic - next topic

vkulmala

Nov 25, 2012, 12:36 pm Last Edit: Nov 25, 2012, 06:50 pm by vkulmala Reason: 1
I'm making temperature measurements with Dallas sensors. Code prints sensor's ROM name to serial port with following code:

Code: [Select]

 Serial.print("ROM =");
   for( i = 0; i < 8; i++) {
   Serial.write(' ');
   Serial.print(addr[i], HEX);
 }


How can I change the code so that sensor's ROM name goes to variable and I can use it later also?

Something like this:

Code: [Select]

 char ROM [] = for( i = 0; i < 8; i++) {
 write(' ');
 print(addr[i], HEX);
 }
 Serial.print(ROM);
 Serial.print(" = ");


I know this code is not working but this maybe tells you what I try to do... :-)

Edited:
Output of the code is now like this:

Code: [Select]

ROM = 10 F9 F9 F9 1 8 0 75


dc42

1. Please use code tags (the # button) when posting your code, it makes it easier to read and prevent your code from getting garbled, e.g. the [ i ] after addr got dropped from your code and made the rest italic instead.

2. You already have the sensor address stored in variable 'addr'.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

vkulmala

Thanks for the reply.

Full ROM name of the sensor is not stored in variable 'addr'. There is only 1/8 part of the ROM, for example 10 or F9 or 75.

What I need is to get this full ROM name to variable like this:

Code: [Select]

char ROM [] = "10 F9 F9 F9 1 8 0 75";


But question is how?

NickPyner

Your code looks like a bastardised version of the standard one wire address finder.  This is used once in order to get the address out of the DS18B20 and that information then goes into your sketch. I understand there are detail differences among the various Dallas sensors but I don't know if that extends to the address access. If you are using the DS18B20, do you have some special need to use it differently?

vkulmala

My aim is to make a system which dynamically detects how many sensors I have and then sends the temperatures to Cosm (aka Pachube). Name of the sensor would be the name of the ROM. So in future I just can add new sensors without code change. This Dallas temperature code is dynamical which detects the all sensors and I try to add the Cosm code to work with this. All other are working but I need ROM names to Cosm code.

There is part of Cosm code:

Code: [Select]

  // Define the strings for our datastream IDs
  char sensorId[] = "sensor_reading";
  CosmDatastream datastreams[] = {
  CosmDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
  };


So the name of sensor ("sensor_reading") should be the same than temperature sensor's ROM name.

Maybe there is some other ways also how to solve the problem but my code is almost ready, just this ROM name issue is missing.

PaulS

This statement:
Code: [Select]
    Serial.print(addr[i], HEX);
shows that the address (what you seem to think is a name) is ALREADY in a variable (an array).

If you want the string that appears on the serial monitor when that code is executed in a char array, that is a different story.

Code: [Select]
char sensorID[20];

    sensorID[0] = '\0';
    for( i = 0; i < 8; i++)
    {
       char buff[4];
       sprintf(buff, "%02X", addr[i]);
       strcat(sensorID, buff);
    }


vkulmala

Thanks Paul, this code works like toilet of the train  :)

PaulS

Quote
this code works like toilet of the train

I hope that that is a good thing.

dc42


Thanks for the reply.

Full ROM name of the sensor is not stored in variable 'addr'. There is only 1/8 part of the ROM, for example 10 or F9 or 75.


You haven't shown how you declared 'addr', but from the code you have shown, it ought to be an 8-byte array, and the full ROM name is stored in the array as a whole.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Go Up