Pages: [1]   Go Down
Author Topic: Temperature ROM name to variable (solved!)  (Read 362 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm making temperature measurements with Dallas sensors. Code prints sensor's ROM name to serial port with following code:

Code:
 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:
 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:
ROM = 10 F9 F9 F9 1 8 0 75
« Last Edit: November 25, 2012, 12:50:55 pm by vkulmala » Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6619
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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'.
Logged

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.

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
char ROM [] = "10 F9 F9 F9 1 8 0 75";

But question is how?
Logged

Dee Why NSW
Offline Offline
Full Member
***
Karma: 5
Posts: 206
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
  // 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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 617
Posts: 49463
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This statement:
Code:
    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:
char sensorID[20];

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

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Paul, this code works like toilet of the train  smiley
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 617
Posts: 49463
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
this code works like toilet of the train
I hope that that is a good thing.
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6619
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

Pages: [1]   Go Up
Jump to: