OneWire Device address to string ?

Hello ,

I am new to arduino.
I want to use ports 2 --> 11 as one wire bus.
and keep each one onewire id on each bus to its string. ( always one device in one bus)

i got managed to do some movements by examples but, since i m new to c, ( i m pascal coder)

i could not find any solution.

I just need unique device id codes in an array. not scratchpad or temp or anything.

if one wire is there i want to have id, if one wire plugged off, i want to see 0000000..

Any helps appreciated

Thanks

Here is my code :

//////////////////////////////////////////////////////////////////
//  This program is designed to read the temperature from Dallas sensors. It is originally designed for 
//  Dragino MT-DS temperature processing module, it can be used by other avr by re-define the ONE_WIRE_BUS[] array 
//  and NUMBER_OF_BUS
//  
//  This program will read the temperature from Dallas sensors and send the ID;value pair to Dragino MS12 via UART port. 
//  The code supports below Dallas sensors: 
//     DS18B20
//     DS1822
//     DS1820
//  This code doesn't consider the Parasite power mode on Dallas Temp. 
//
//  more info about MT-DS module please refer http://wiki.dragino.com
//
//   created Sep.28 2012
//   by Edwin Chen <edwin@dragino.com>.
//   Shenzhen, China
//
////////////////////////////////////////////////////////////////// 

#include <OneWire.h>
#include <DallasTemperature.h>

// Define the bus to connect to sensors and temperature precision. in MT-DS, we use 8 buses to connect to Dallas Sensors. 
const int ONE_WIRE_BUS[]={2,3,4,5,6,7,8,9,10,11};
#define TEMPERATURE_PRECISION 9
#define NUMBER_OF_BUS 10
#define POLL_TIME 100    //how long the avr will poll every sensors 

// Setup oneWire instances to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire *oneWire[NUMBER_OF_BUS];

// Pass onewire reference to Dallas temperatures. 
DallasTemperature *sensors[NUMBER_OF_BUS];

// arrays to hold device addresses
DeviceAddress tempDeviceAddress[10];

int numberOfDevices[NUMBER_OF_BUS];

String adr[10];


void setup(void)
{
  // start serial port
  Serial.begin(9600);

  delay(5000);   // avoid the serial interupt the booting of Dragino. 
  Serial.println(""); // add this so the first sending line can be shown in Dragino. 
  
  //check how many sensors are connect to MT-DS, normally the result won't showed in Dragion 
  //because Dragino has a longer boot time compare to avr, the code wil be useful when debug. 
  for(int i=0;i<NUMBER_OF_BUS; i++)   //search each bus one by one
  {
    oneWire[i] = new OneWire(ONE_WIRE_BUS[i]);
    sensors[i] = new DallasTemperature(oneWire[i]);
    sensors[i]->begin();
    numberOfDevices[i] = sensors[i]->getDeviceCount();
  
    for(int j=0;j<numberOfDevices[i]; j++)
    {
      // Search the wire for address
      if(sensors[i]->getAddress(tempDeviceAddress[j], j))
  {
    
    
    // set the resolution to TEMPERATURE_PRECISION bit (Each Dallas/Maxim device is capable of several different resolutions)
    sensors[i]->setResolution(tempDeviceAddress[j], TEMPERATURE_PRECISION);
  }else{
  
  }
    }
      delay(50);
  }
  
}

// function to print a device address
void printAddress(DeviceAddress deviceAddress,uint8_t m)
{
  adr[m]="";
  
  for (uint8_t i = 0; i < 8; i++)
  {
    // zero pad the address if necessary
    
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
    
    if (deviceAddress[i] < 16 ) adr[m]=adr[m]+0;
    adr[m]=adr[m]+(deviceAddress[i], HEX);
   
    
  }
  Serial.print("---");
  Serial.println(adr[0]);
}



void loop(void)
{ 
  for(int i=0;i<NUMBER_OF_BUS; i++)   // poll every bus
  {
     sensors[i]->begin();
     numberOfDevices[i] = sensors[i]->getDeviceCount();
     sensors[i]->requestTemperatures();
      // print the device information
    
    for(int j=0;j<numberOfDevices[i]; j++)    // poll devices connect to the bus
    {
      sensors[i]->getAddress(tempDeviceAddress[j], j);
      printAddress(tempDeviceAddress[j],i);      //print ID
 
      
     
    }
  }
  Serial.println();  
  delay(POLL_TIME);
}

and result is like ;

283B10E00500000B---16161616016016016016
28CA00A9040000EA---16161616016016016016
28C8C4E005000061---16161616016016016016

283B10E00500000B---16161616016016016016
28CA00A9040000EA---16161616016016016016
28C8C4E005000061---16161616016016016016

283B10E00500000B---16161616016016016016
28CA00A9040000EA---16161616016016016016
28C8C4E005000061---16161616016016016016

283B10E00500000B---16161616016016016016
28CA00A9040000EA---16161616016016016016
28C8C4E005000061---16161616016016016016

anyways i got this :smiley:

#include <OneWire.h>
#include <DallasTemperature.h>

// Define the bus to connect to sensors and temperature precision. in MT-DS, we use 8 buses to connect to Dallas Sensors. 
const int ONE_WIRE_BUS[]={2,3,4,5,6,7,8,9,10,11};
#define TEMPERATURE_PRECISION 9
#define NUMBER_OF_BUS 10
#define POLL_TIME 100    


OneWire *oneWire[NUMBER_OF_BUS];

// Pass onewire reference to Dallas temperatures. 
DallasTemperature *sensors[NUMBER_OF_BUS];

// arrays to hold device addresses
DeviceAddress tempDeviceAddress[10];

int numberOfDevices[NUMBER_OF_BUS];


String adr[10];

void setup(void)
{
 // start serial port
 Serial.begin(9600);

 delay(100);  
 Serial.println(""); 
 

 for(int i=0;i<NUMBER_OF_BUS; i++)   //search each bus one by one
 {
   oneWire[i] = new OneWire(ONE_WIRE_BUS[i]);
   sensors[i] = new DallasTemperature(oneWire[i]);
   sensors[i]->begin();
   numberOfDevices[i] = sensors[i]->getDeviceCount();
 
   for(int j=0;j<numberOfDevices[i]; j++)
   {
     // Search the wire for address
     if(sensors[i]->getAddress(tempDeviceAddress[j], j))
 {
   
   
   
   sensors[i]->setResolution(tempDeviceAddress[j], TEMPERATURE_PRECISION);
 }else{
 
 }
   }
     delay(50);
 }
 
}

// function to print a device address
void printAddress(DeviceAddress deviceAddress,uint8_t m)
{
 
 
 for (uint8_t i = 0; i < 8; i++)
 {
   // zero pad the address if necessary
   
 /*  if (deviceAddress[i] < 16) Serial.print("0");
   Serial.print(deviceAddress[i], HEX);*/
   
   if (deviceAddress[i] < 16 ) adr[m]=adr[m]+"0";
   adr[m]=adr[m]+String(deviceAddress[i], HEX);
   
  
   
 }
 

}



void loop(void)
{ 
 for(int i=0;i<NUMBER_OF_BUS; i++)   // poll every bus
 {
    sensors[i]->begin();
    numberOfDevices[i] = sensors[i]->getDeviceCount();
    sensors[i]->requestTemperatures();
     // print the device information
   
   for(int j=0;j<numberOfDevices[i]; j++)    // poll devices connect to the bus
   {
     sensors[i]->getAddress(tempDeviceAddress[j], j);
     printAddress(tempDeviceAddress[j],i);      //print ID

     
    
   }
 
 }
   for (int j=0;j<10; j++)
 {
   // zero pad the address if necessary
   
   Serial.print(String(j)+" -  ");
   Serial.println(adr[j]);

   
 }

   for (int j=0;j<10; j++)
 {

   adr[j]="";

   
 }
 delay(POLL_TIME);
}

I want to use ports 2 --> 11 as one wire bus.

Why? The whole point of a bus is that it can carry multiple passengers (devices in the OneWire bus case).

It makes no sense to limit a bus to one passenger.

its for a special device. it should be so. not because of limits, because of security.

thanks for posting