I'm trying to get the actual device address of multiple temp sensors. I found a sub the gets the address but it prints to the screen. I want to return it in a variable that I am going to concat to send to a url. How to I get this sub to return the device id xxx in a variable instead of serial.print to the screen. Sorry I'm a little new to this.
string xxx = Serial.print(deviceAddress[i], HEX); doesn't seem to work.
Thank you in advance for any help.
void returnDeviceAddress(DeviceAddress deviceAddress)
{
for (uint8_t i = 0; i < 8; i++)
{
if (deviceAddress[i] < 0x10) Serial.print("0");
Serial.print(deviceAddress[i], HEX);
}
return deviceAddress(xxxx);
}
1. The DS18B20 Digital Temperature Sensor contains a 64-bit (8-byte) identification/ROM Code (Fig-1) which can be read and put in a named unsigned long long myAddress (uint64_t myAddress) variable.
#include<OneWire.h>
OneWire ds(5); //Signal in is DPin-10.
union myData
{
unsigned long long myAddress;//hold 64-bit ROM Code
byte myAddressArray[8];//to hold 64-bit ROM Codes; lower byte first
};
myData data;
void setup()
{
Serial.begin(9600);
ds.reset();
ds.search(data.myAddressArray);
for (int i = 0; i < 8; i++)
{
byte y = data.myAddressArray[i];
if (y < 0x10)
{
Serial.print('0'); //show leading zero
}
}
Serial.print(y, HEX);//Lower byte first);
}
void loop(){}