PDA

View Full Version : RS485 - ibutton network



ccsparky
- 5th February 2005, 18:19
I have a couple of questions about setting up an RS485 network with multiple 16f88's to read DS1990a serial ibuttons.(Lock project for 5 doors)

As I understand the RS485 network I can have 32 nodes. The PC being the master and up to 31 16f88's as slaves.
No slave can initiate communication to the master(pc).
Each device has an address of 0 - 5 (The pc being 0 and all slaves are 1 - 5


What I am planning to do:

PC as the master
16f88's as slaves each has an ibutton reader attached to read serial number from DS1990a
Each 16f88 has a variable as ID VAR BYTE[8]
Each byte is set to all 0's
If an ibutton is read by a slave the 8 byte serial number is stored in id.
The PC poles (sends the address) to each slave and waits for a response, if the 8 bytes are all zeros the slave sends to the pc "255" for no data to send and the pc moves on to the next slave.
If a serial number has been read by a slave then once that slave is polled "254" is sent to the pc indicating data will be sent and then the id is sent.
Once the id has been sent the pc compares it to the serial numbers in my database. If a match is found "254" is sent to the slave, the lock is opened and each id byte is set to "0", "255" is sent back to the pc to tell it to move on to the next slave.
If no match is found "255" is sent to the slave the lock is not opened and all bytes are set to "0". The slave sends back "255" to tell the pc to move on.

Questions:
1) Am I completely off base hear, if so could someone provide an overview as I have attempted to do above. I'm not looking for code just an understanding how I need to go about this.
2)Once a slave sends "254" to the pc indicating data will be send. Do I need the pc to signal the slave to send the data or can data be sent after the "254"?
3)For the sake of understand how fast all of this can happen, if I have 31 slaves on the network how long will it take for a complete cycle of the loop to occur? The pc is dedicated to this project and will not be busy doing anything else.

Thanks in advance for any assistance
William

NavMicroSystems
- 5th February 2005, 23:44
William
if you can afford 3 wires to communicate to your slaves
I think you could simplify your hardware, save boardspace and money.

Just as a quick hint, have a look at: this Thread (http://www.picbasic.co.uk/forum/showthread.php?s=&threadid=382)

I'm a bit busy at the moment, but I'll get back to you with more details within the next days.

BobK
- 7th February 2005, 17:15
Hello CCSPARKY,
Just out of curiosity, is your lock project for a home or a commercial building? If it's for a commercial buidling what types of locks are you using? The reason I am asking is that if you are putting electric locks on doors in a commercial buidling there are specific building codes that must be complied with and the local authority having jurisdiction must be consulted first before planning any installation.

I submit this only as a heads up to possibly save you alot of time and aggravation in designing something that might get you into trouble.

BOBK.

ccsparky
- 11th February 2005, 01:24
BobK,
Thanks for the input. My project is for personnel use at my own home.
The project I have built at this time uses the 16f88, ds1307 (with battery), 24lc256, rs232, ibutton reader and a relay to activate the electric strike. I communicate with the pic using a program I have put together in Delphi.
I would like to build another reader that is networked removing the eeprom, ds1307 and other hardware. I will be using an old pc as the master to keep track of id's and activity.

I am the facilities supervisor for the city I live in and am very in tune to the local building codes.
My department is responsible for all forms of facility maintenance and construction. Everything is done following all federal, state and local building codes. Everything we do when warranted is done by permit giving our local authorities i.e. building, fire and risk management agencies an opertunity to review all submitted material. When hiring contractors they are required to have liscenses (contractor and business) with all insurance coverages in place. All products they supply will meet our specs or they don's step foot on the property.

Your reply is well taken and I believe one that all developers should consider! Just because we build it does not make it rated for use in residential or commercial applications!

ccsparky
- 11th February 2005, 01:26
Ralph,
I read the other post and am not sure that is the direction I am going in. But eagerly await for your reply! :-)
After reading more about RS485 I think I see a little clearer but am still not sure if I'm going in the right direction.

Thank you

William

BobK
- 11th February 2005, 02:34
Hi CCSPARKY,

I think you are on the right track with your plan as stated but you could take it one step further and make your system work faster if you set it up to have the iButton ID's stored in each 16F88. This way if anything happened to your PC, decisions regarding unlocking or denying access would strickly be up to the location micro. Setup your reader's micro to store a time stamp and button ID along with the actual activity that took place whether it was a valid access or invalid access. Then periodically you could use your PC to poll each reader micro and retreive the activity for review.

Just so you know, I have been an alarm company owner and installer for over 30 years. I deal with these types of systems all the time.

If I can be of further assistance, feel free to ask.

BobK

ccsparky
- 17th February 2005, 00:47
PC (Delphi)

var
Form1: TForm1;
i, n : integer;

procedure TForm1.Button1Click(Sender: TObject); //Click button to start
begin
if timer1.enabled = true then
begin
Vacomm1.Close; //Disconnect
timer1.enabled := false; //Disable timer
end
else
begin
Vacomm1.Open; //Connect
timer1.enabled := true; //Enable Timer
end;
timer1.interval := StrToInt(edit1.text); //Set Timer Interval as needed
i := 0; //PC is node 0
n := 0;
end;

procedure TForm1.Timer1Timer(Sender: TObject); //On Timer Event
var
s : string;
begin
VaComm1.ControlRts := rtsDisabled; //Enable Transmitter
inc(i); //increase i to next lock number
if i > 5 then i := 0; //Only using 5 Locks
s := '#' + IntToStr(i);
VaComm1.WriteText(s); //Sends '#0' lock numbers 0 - 4
VaComm1.ControlRts := rtsEnabled; //Disable Transmitter
Sleep(10);
end;

procedure TForm1.VaComm1RxChar(Sender: TObject; Count: Integer);
var
datain : string;
match : boolean;
id : array[0..7] of byte;
begin
datain := VaComm1.readtext; //Receive '#' or ID from PIC
if datain <> '#' then //If not '#' must be ID
begin
timer1.enabled := false; //Stop sending to other locks
id[n] := datain; //Add PIC id's to PC id's
inc(n);
end;
if datain = '#' then //Got '#' PIC finished sending
begin
VaComm1.ControlRts := rtsDisabled; //Enable Transmitter
//check data base for lock i for match to id
//(if found match is true, if not match is false)
if match = true then
VaComm1.WriteText('#$') //Send '$' to open lock
else
VaComm1.WriteText('#?'); //Send '?' to not ot open lock
timer1.enabled := true; //Start poling PICs again
n := 0;
end;

end;

---------------------------------------------------------------------------------------

'PIC

Define LOADER_USED 1
@ DEVICE XT_OSC
define OSC 4

Include "MODEDEFS.BAS"

CMCON=7
ADCON1=7
ANSEL=0
TRISA=%00100000
TRISB=%00000101

DP VAR PORTB.0
SERRX VAR PORTB.2
SERTX VAR PORTB.5
Relay VAR PORTB.1
TR VAR PORTB.4

ID VAR BYTE[8]
I VAR Byte
N VAR Byte

LOW TR 'Enable Receiver, Disable Transmitter

Main_Loop:
OWOUT DP, 1, [$33] 'Issue Read ROM command
OWIN DP, 0, [str ID\8] 'Read data into the 8-byte array "ID"
If ID[0] = $01 Then gosub Send 'If ID found then goto Send loop (Familiy Code)
goto Main_Loop 'Repeat until DS1990A read

Send:
LOW TR 'Enable Receiver, Disable Transmitter
Serin SERRX,T2400,["#"],i 'Wait for PC to pole this lock
if i <> 1 then goto Send '1 - 5 Five locks - This is lock 1
HIGH TR 'Enable Transmitter, Disable Receiver
For N = 0 To 7
Serout SERTX,T2400,[#ID[N]] 'Send ID
Next
Serout Sertx, T2400,["#"] 'Done sending ID, now send #
LOW TR 'Enable Receiver, Disable Transmitter
Serin SERRX, T2400,["#"],i 'Wait to see if open lock or not
if i = "$" then 'Pc sends $ if ID matchs PC database
High Relay 'Open lock
Pause 5000 'For 5 seconds
Low Relay 'Close lock
Return 'Go back to Main_Loop
endif
if i = '?' then Return 'Don't open lock and go back to Main_Loop

DynamoBen
- 6th June 2005, 21:48
I'm doing a similar project but using a magnetic card as the input method.

I tend to agree with the post about on-board memory. Originally, I designed my device to sit on RS-485 network and transmit the account number to a host computer which would respond with a pass or fail message.

Where this gets complicated is when you have more than one entry or the host PC goes offline. You run the risk that both devices will try to use the line at the same time or the PC will not respond at all. Because of this, I added an EEProm to act as an account code storage area (database). The local device determines if the account is good and if entry is allowed or denied. I then am able to poll for the last account code, add accounts, manually open doors, and download account databases all from the host PC.

The hardest part for me is figuring out a method for keeping track of the number of accounts on the EEProm vs Max number of accounts that can be written to that EEProm. This can be tricky after a power cycle.