how to discriminate between two 1-wire iButton devices

G'day folks,

I am using two 1-wire RFID readers on the same 1-wire bus.

The sketch (based on the iButton example sketch) reads in a loop and returns the address of a tag when detected by either reader. That works.

What I can't figure out however is whether there is a simple way to know which reader actually saw the badge.

Thank you!

Every OneWire device has a distinct address. I'm quite sure you need it to read the values. As you hide the necessary code (= your complete sketch including links to used libraries) from us you have to find the relevant piece of code yourself.

Hello Pylon and thank you

See the code below.
I am familiar with 1-wire devices such as DS18b20 temperature sensors but this case seems a bit different because unless an RFID tag is brought close to a RFID reader, no device is found in the code. If a tag is detected by the reader, it is the tag address which is returned by the ds.search() function, not the reader’s address.

Cheers
Loic

#include <stdio.h>
#include <string.h>
#include <OneWire.h>

OneWire  ds(A2);
byte addr[8];
String keyStatus="";

//Unique ID of known RFID tag
byte badge[6] = {205,30,189,0,3};

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);

  pinMode(2, OUTPUT);//Red LED 
  pinMode(3, OUTPUT);//Green LED

  digitalWrite(2,HIGH);//Red LED Off
  digitalWrite(3,HIGH);//Green LED Off

}

void loop() {
  // put your main code here, to run repeatedly:
  getKeyCode();

  if(keyStatus=="ok")
  {
      byte i;
      for( i = 5; i >0; i--) {
           Serial.print(addr[i],HEX);
           if(i>1) Serial.print(":");  
      }
      Serial.print('\n');
      
        if(CompareID(addr, badge))
        {
          digitalWrite(3,LOW);
          delay(500);
          digitalWrite(3,HIGH);
        }
        else
        {
          digitalWrite(2,LOW);
          delay(500);
          digitalWrite(2,HIGH);
        }
    
      Serial.print('\n');
  }
  else if (keyStatus!="") { Serial.print(keyStatus);}


  
  delay(500);
}

bool CompareID(byte *Buff1, byte *Buff2)
{
  bool Result = true;
  byte i;
  for( i = 5; i >0; i--) 
  {
    if(Buff1[i] != Buff2[i-1])
      return false;  
  } 
  return true;
}

void getKeyCode(){
  byte present = 0;
  byte data[12];
  keyStatus="";
  
  if ( !ds.search(addr)) {
      ds.reset_search();
      return;
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      keyStatus="CRC invalid";
      return;
  }
  
  if ( addr[0] != 0x01) {
      keyStatus="not DS1990A";
      return;
  }
  keyStatus="ok";
  ds.reset();
}

If a tag is detected by the reader, it is the tag address which is returned by the ds.search() function, not the reader's address.

That's quite special, this reader seems to emulare a DS1990 OneWire Serial Button using the RFID tags. As the reader is not addressable you cannot know which reader got a tag if you have multiple readers on the same bus. So if you need to know which reader has read a specific tag, use a separate bus for each reader.

pylon:
this reader seems to emulare a DS1990 OneWire Serial Button using the RFID tags

Indeed, and that is exactly how it is advertized. So the question could also apply to iButtons. Using separate buses for each reader would not be an issue in an Arduino project but in this case I am only using the Arduino to make a POC. The final implementation will be based on an industrial 1-Wire platform and I don't have several buses options on the platform.

Thanks anyways.

The final implementation will be based on an industrial 1-Wire platform and I don't have several buses options on the platform.

Then you don't have the possibility to know which reader got the RFID tag.

So the question could also apply to iButtons.

Yes, but there you don't have a reader, you just have kind of a plug that makes the OneWire connection. You never know which plug was used if they all connect to the same bus.

Thank you