multiple ds2413 - how to select address??

Hi!

I'm pretty new to all that :) For an art installation I'd like to control a few hundred relays.

With one ds2413 I'm able to switch the relay, but if I connect two ds2413 it won't work anymore.

How do I select a specific address??? I don't get it :(

I just try to figure out how this code works https://github.com/adafruit/Adafruit_DS2413/blob/master/DS2413.pde#L1

Thanks for help :)

Hi, welcome to the forum.

When you ask a question like that, you gonna get questions like these in return:

  • What are the relays for ? Perhaps there is an easier to achieve what you want.
  • At what distance are the relays apart ?
  • Are you planning hundreds of DS2413 in a single OneWire line ?
  • Which Arduino board do you want to use ?

The library from Adafruit stops searching after just one DS2413 is found.

It is based on the OneWire library from pcjr : http://www.pjrc.com/teensy/td_libs_OneWire.html The "search()" searches for the next device. The "reset_search()" starts searching from the start.

When you want to remember the ID of hundreds of devices, you have to remember hundreds times 8 bytes. That might be too much for an Arduino Uno.

Thanks Peter :slight_smile:

I want to switch 230V. The Relays are 5V high current ones.
The Relays are in a circle of about 15m.
I think I’d like to have around 100 DS2413 in a single line.
At the Moment I’m using a Arduino Uno.
External 5V.

starry-eyed artist ^^

Maybe I should use a Raspi… I know more about Python…
Well I give it a try… not bad to learn new things :slight_smile:

… so now I get both IDs, but I don’t get it how to use them :frowning:

#include <OneWire.h>

#define DS2413_ONEWIRE_PIN  (8)

#define DS2413_FAMILY_ID    0x3A
#define DS2413_ACCESS_READ  0xF5
#define DS2413_ACCESS_WRITE 0x5A
#define DS2413_ACK_SUCCESS  0xAA
#define DS2413_ACK_ERROR    0xFF

OneWire oneWire(DS2413_ONEWIRE_PIN);
uint8_t address[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };

byte read(void)
{		
  bool ok = false;
  uint8_t results;

  oneWire.reset();
  oneWire.select(address);
  oneWire.write(DS2413_ACCESS_READ);

  results = oneWire.read();                 /* Get the register results   */
  ok = (!results & 0x0F) == (results >> 4); /* Compare nibbles            */
  results &= 0x0F;                          /* Clear inverted values      */

  oneWire.reset();
  
  // return ok ? results : -1;
  return results;
}

bool write(uint8_t state)
{
  uint8_t ack = 0;
  
  /* Top six bits must '1' */
  state |= 0xFC;
  
  oneWire.reset();
  oneWire.select(address);
  oneWire.write(DS2413_ACCESS_WRITE);
  oneWire.write(state);
  oneWire.write(~state);                    /* Invert data and resend     */    
  ack = oneWire.read();                     /* 0xAA=success, 0xFF=failure */  
  if (ack == DS2413_ACK_SUCCESS)
  {
    oneWire.read();                          /* Read the status byte      */
  }
  oneWire.reset();
    
  return (ack == DS2413_ACK_SUCCESS ? true : false);
}

void setup(void) 
{
  Serial.begin(9600);  
  
  Serial.println(F("Looking for a DS2413 on the bus"));
  
}

void loop(void) {
  byte i;
  byte present = 0;
  byte data [12];
  byte address [8];

  
  /* Try to find a device on the bus */
  if (!oneWire.search(address)) {
    Serial.print("No more addresses. \n");
    oneWire.reset_search();
    delay(250);
    return;
  }
  
  for ( i = 0; i < 8; i++ ) {
    Serial.print(address[i], HEX);
    Serial.print("");
  }
  Serial.print("\n");
    
  /* Check the CRC in the device address */
  if (OneWire::crc8(address, 7) != address[7]) 
  {
    Serial.println(F("Invalid CRC!"));
    return;
  }
  
  
  /* Make sure we have a DS2413 */
  if (address[0] != DS2413_FAMILY_ID) 
  {
    Serial.println(F(" is not a DS2413!"));
    return;
  }
  
  oneWire.reset();
  oneWire.select(address);    
  oneWire.write(0x1);
  delay(100);
  oneWire.write(0x0);

}

Cheers
Jonesi

What is high current ? 1A or 100A ? 50000A ? http://www.youtube.com/watch?v=Oyl8F23uXHc

You would need an 5V power supply for the relays. Is the sound of the relays part of the project ?

With a Solid State Relay, a 5V power supply is no longer needed for the relays, and they don't make sound. SSR-25DA : http://www.ebay.com/sch/i.html?_nkw=ssr-25da More current ? SSR-40DA : http://www.ebay.com/sch/i.html?_nkw=ssr-40da

The Adafruit code uses read() and write(). You have to study the datasheet. The two lowest bits with the write() are for the outputs. Datasheet : "The other 6 bits of the new state byte do not have corresponding PIO pins. These bits should always be transmitted as "1"s. To switch the output transistor on, the corresponding bit value is 0. To switch the output transistor off (non-conducting) the bit must be 1."

In hex : write(0xFF); // everything off In binary : write( B11111111); // everything off First relay on : write ( B11111110 ); // first relay on Second relay on : write ( B11111101 ); // second relay on

You should make a function around that, to switch a relay on or off.

lol.... If I would know that :D ... I think we are talking about max. 1A. Yep. I already have a power supply. Sound is part of the project. I pickup the sound of the relay with a piezo element.

Thanks for the examples!

OK…
Now I’m on a good way I guess :slight_smile:

SerialMonitor:

Looking for a DS2413 on the bus
R=3A 68 F5 12 0 0 0 B6 
Wire failed
R=3A 6 1B 13 0 0 0 91 
No more addresses.
R=3A 68 F5 12 0 0 0 B6 
Wire failed
R=3A 6 1B 13 0 0 0 91 
No more addresses.
R=3A 68 F5 12 0 0 0 B6 
Wire failed
#include <OneWire.h>

#define DS2413_ONEWIRE_PIN  (8)

#define DS2413_FAMILY_ID    0x3A
#define DS2413_ACCESS_READ  0xF5
#define DS2413_ACCESS_WRITE 0x5A
#define DS2413_ACK_SUCCESS  0xAA
#define DS2413_ACK_ERROR    0xFF

OneWire oneWire(DS2413_ONEWIRE_PIN);
uint8_t address[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };

void printBytes(uint8_t* addr, uint8_t count, bool newline=0) 
{
  for (uint8_t i = 0; i < count; i++) 
  {
    Serial.print(addr[i]>>4, HEX);
    Serial.print(addr[i]&0x0f, HEX);
    Serial.print(" ");
  }
  if (newline)
  {
    Serial.println();
  }
}

byte read(void)
{ 
  bool ok = false;
  uint8_t results;

  oneWire.reset();
  oneWire.select(address);
  oneWire.write(DS2413_ACCESS_READ);

  results = oneWire.read();                 /* Get the register results   */
  ok = (!results & 0x0F) == (results >> 4); /* Compare nibbles            */
  results &= 0x0F;                          /* Clear inverted values      */

  oneWire.reset();
  
  // return ok ? results : -1;
  return results;
}

bool write(uint8_t state)
{
  uint8_t ack = 0;
  
  /* Top six bits must '1' */
  state |= 0xFC;
  
  oneWire.reset();
  oneWire.select(address);
  oneWire.write(DS2413_ACCESS_WRITE);
  oneWire.write(state);
  oneWire.write(~state);                    /* Invert data and resend     */    
  ack = oneWire.read();                     /* 0xAA=success, 0xFF=failure */  
  if (ack == DS2413_ACK_SUCCESS)
  {
    oneWire.read();                          /* Read the status byte      */
  }
  oneWire.reset();
    
  return (ack == DS2413_ACK_SUCCESS ? true : false);
}

void setup(void) 
{
  Serial.begin(9600);  
  
  Serial.println(F("Looking for a DS2413 on the bus"));
}
  
void loop(void) {
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];
  
  if ( !oneWire.search(address)) {
    Serial.print("No more addresses.\n");
    oneWire.reset_search();
    delay(250);
    return;
  }
  
  Serial.print("R=");
  for( i = 0; i < 8; i++) {
    Serial.print(address[i], HEX);
    Serial.print(" ");
  }

  if ( OneWire::crc8( address, 7) != address[7]) {
      Serial.print("CRC is not valid!\n");
      return;
  }
  
  if ( address[0] != DS2413_FAMILY_ID) {
      Serial.print("Device is not a DS2413 family device.\n");
      return;
  }

  // The DallasTemperature library can do all this work for you!

   bool ok = false;
  //ok = write(B11111101);
  //if (!ok) Serial.println(F("Wire failed"));
  //delay(100);
  ok = write(0xAA);
  if (!ok) Serial.println(F("Wire failed"));
  delay(100);
  ok = write(0xFF);
  if (!ok) Serial.println(F("Wire failed"));
  delay(100);
}

Before the first relay was not working at all while the second relay was plugged in.

Ahhh now I got it :smiley: … I have for every relay one relay board with one ds2413.
And the Problem is that I can only switch the first board… see picture → picture

Interesting website : http://www.108relays.ca/art_cable.html

The DS2413 can only sink 20mA. I think the relay needs more than 20mA. Can you tell the type ?

relay is working... it's a Omron G2R-1-E 6V but I'm switching to the Takamisawa JS 5 MN-KT needs ≥ 10 mA

The only problem is addressing the ds2413. I don't know how I could get the the address in a variable

like byte ds1[8] = { 0x3A, 0x6, 0x1B, 0x13, 0x0, 0x0, 0x0, 0x91 }; byte ds2[8] = { 0x3A, 0x68, 0xF5, 0x12, 0x0, 0x0, 0x0, 0xB6 };

??

and then oneWire.reset(); oneWire.select(ds1) ... write...

oneWire.reset(); oneWire.select(ds2); ... write ...

Thanks :)

I think that Omron needs 73mA at 5V. The DS2413 might be broken by now. According to the datasheet, the Fujitsu/Takamisawa needs 45mA. That is still too much.

With 20mA you can drive a led or a small reed relay.

In the Adafruit source code : https://github.com/adafruit/Adafruit_DS2413/blob/master/DS2413.pde#L1 There is only one global "address[8]" array to hold the identifier for just one sensor. You need a lot of those. In the function "read()", that one global address is used to select it : oneWire.select ( address ) ; You need to be able to select the chip you want. So you have to add a parameter with the address (identifier) to the "read()" function.

I have been searching for a better library. There are other libraries, but I didn't find any better ones. I suggest strongly to use the pcjr (Paul Stoffregen) OneWire library as a base : http://www.pjrc.com/teensy/td_libs_OneWire.html The Adafruit library uses that.

I would like to know what you want to create. Making 'click' noises can be done with piezo elements as well, it doesn't have to be relais. Or you can use solenoids, if you don't need to switch something on. The OneWire can be long and can have many devices connected to it. It is a good choice for devices in a circle of 15 meters. A serial communication could also work. The DS2413 can turn two leds on, that's great, but useless. You can add darlington transistors or mosfets or even an Arduino in every module. What are the allowed costs for a single module ? Do you have them made for you or are you going to make a pcb board for them ?

When you have groups of arrays, you could make a module for a group and add an Arduino to every module and use serial communication. That would simplify things a lot. However, I'm not convinced that you actually need relays.

What I'm saying here: take a step back and let's start all over again.

:astonished:

the JS-5MN-KT Relay datasheet min. switching load 10mA 5VD

the problem is that I amplify the relay tone with a little TDA7052... else I would just use mosfets.

budget is good :D ... I'm an fine art student ... I quit drinking for this ^^ Before I just used uln2003a ... so darlington to drive the relays. But I want to get rid of the cable salad, that would be an installation it self :D .. can only fit 6 relays in one lan cable... when I hop from one module to the next... yeah I could place the control unit more central....

Maybe I try it with an raspberry... looks easier to me... i2c to 1-wire and OWFS... but then I get a problem, because I also want to use some piezos as knock sensors.... to get an interactive installation ^^ Thank God... I have time till mid April....

I read in the datasheet that a 5V-type relay has 112 ohm coil resistance. So at 5V, the current is 44mA.

You give a little bit of information in every post. Now the TDA7052 come in and knock sensors. But I still don't know what you want to switch with the relays, or if you want an TDA7052 with every relay or just one. The DS2413 can not drive a normal relay. But I still don't know if you need relays at all. Projects like this have been made before. Someone used serial communication and a number of equal modules with an Arduino that switches a bunch of things. I'm sorry, but I still don't have a clue where this is going. I can't help any further.

light bulbs...

I got it :) A little BC 556A Transistor helped well...

Thanks again for your help Peter!

Cheers!