I button 2nd key Help ?

1968neil

Senior Member
Hi Guy's,

Just started experimenting with the Dallas ibutton.
The following code works great and does what it does well.
My question is :

How can i get it to read a second key to open the same lock.
The idea is i want access to my workshop and want the second key as a spare but you cant buy another key with the same code ! (or the system would be pointless i suppose).
I am also not sure if the code will all fit into an 08M the basic single key does.
Any advice greatfully received.

Regards
Neil

My code:


main:

let b6 = 0 'reset family code to 0
low 0 'Button LED off
low 1 'Output off


Neilsloop:

toggle 0 ' LED on or off on i probe
if pin3 = 0 then open 'switch pushed
pause 250 'wait 250ms
readowsn 4 'read serial number on input4
if b6 <> 0 then test 'i button detected
goto Neilsloop

' ibutton detected so check code
' if wrong code jump back to start




test:

sound 2,(100,10) 'beep
high 0 'i button probe LED on


if b6 <>$01 then main 'digit pair 8
if b7 <>$43 then main 'digit pair 7
if b8 <>$23 then main 'digit pair 6
if b9 <>$77 then main 'digit pair 5
if b10 <>$13 then main 'digit pair 4
if b11 <>$00 then main 'digit pair 3
if b12 <>$00 then main 'digit pair 2
if b13 <>$94 then main 'digit pair 1

'everything is ok so switch output on for 5 seconds

open:

sound 2, (123,10,124,15,125,10,126,15)
high 1
pause 5000
low 1

goto main
 

Andrew Cowan

Senior Member
I don't know if it will fit, but you would want the first if statment to seeif it is he other button. If b6=whatever then button2. There would the rest of the checks there.

A
 

nickpatts

Member
you can try the following and see if it works then you can add more keys when needed. replace ibutton2 with your own key codes.

Syntax check successful!

Memory used = 92 bytes out of 256


Code:
main:

let b6 = 0 'reset family code to 0 
low 0 'Button LED off
low 1 'Output off


Neilsloop:

toggle 0 ' LED on or off on i probe
if pin3 = 0 then open 'switch pushed 
pause 250 'wait 250ms 
readowsn 4 'read serial number on input4
if b6 <> 0 then test 'i button detected 
goto Neilsloop

' ibutton detected so check code
' if wrong code jump back to start




test:

sound 2,(100,10) 'beep
high 0 'i button probe LED on


if b6 =$01 and b7 =$43 and b8 =$23 and b9 =$77 and b10 =$13 and b11 =$00 and b12 =$00 and b13 =$94 then open 'ibutton 1
if b6 =$03 and b7 =$23 and b8 =$43 and b9 =$74 and b10 =$10 and b11 =$00 and b12 =$00 and b13 =$90 then open 'ibutton 2

goto main

'everything is ok so switch output on for 5 seconds


open:

sound 2, (123,10,124,15,125,10,126,15)
high 1
pause 5000
low 1

goto main
 
Last edited:

eclectic

Moderator
I'm not sure how Pin3 is connected in the original circuit.
if pin3 = 0 then open

goes straight to the
open sequence.

I've just tried this with three DS18B20 devices.
Two have their numbers programmed in.
Works OK.

If I plug in the third, it sounds the "nasty" signal.

Code:
'Forum 28 07 09

main:

let b6 = 0 'reset family code to 0 

low 1 'Output off


Neilsloop:

toggle 0 ' LED on or off on i probe
; if pin3 = 0 then open 'switch pushed ; ************
;   sends program to open if pin3 is not connected

pause 250 'wait 250ms 
readowsn 4 'read serial number on input4
if b6 <> 0 then test 'i button detected 

goto Neilsloop


test:

 if b6 =40 and b7 = 236 and b8 = 86 and b9 = 188 and b13 = 192 then
 sertxd ("key number 1",cr,lf) ;remove after test
 goto open 

elseif b6 =40 and b7 = 60 and b8 = 78 and b9 = 188 and b13 = 70 then
sertxd ("key number 2",cr,lf) ;remove after test
goto open

endif
sound 2,(100,10) 'beep
Sertxd ("INCORRECT KEY",cr,lf)
goto main

open:

sound 2, (123,10,124,15,125,10,126,15)
high 1
pause 5000
low 1

goto main
Plenty of room left after removing Sertxd tests

e
 

hippy

Senior Member
If short on code space one can take the values in b6 to b13 ( w3 to w6 ), add them together and see if the sum matches what it should be.

ReadOwsn 4
w0 = w3 + w4 + w5 + w6
If w0 = XXXX Goto Matched
If w0 = YYYY Goto Matched
Goto ReleaseTheDogs

That has a higher security risk because there's a greater chance of two iButtons adding up to the same. You can go halfway between this lax check and the full one by doing a lax check and checking a few of b6 to b13 explicitly. You could go even more lax by just checking one word or one byte matches.

How you 'add' the bytes/words together also has an effect; some methods are less likely to causes matches than other ( polynomial checksums ) but take up more code space.
 

1968neil

Senior Member
Wow, Thanks guys

Thanks again guys,
Wasnt expecting that much info !
Ill give the ideas a go over the weekend and let you know how it goes.
these i buttons are awesome !
Regards

neil
 

Colinpc

New Member
I had some time to kill over the weekend and came up with the attached. It is commented with a description of how it works.

It allows multiple iButtons to be used. You can add more upto the amount of spare memory left after writing the program.

It has only been run on the simulator but did everything I ecpected.

Freddagg

PS: have just looked at this post and seen it is not actually part of the post. How does one insert as a scrolling window??
 

Attachments

Last edited:

nickwoodrow

New Member
Thank you for your effort Colinpc. Might be just what i needed, If i can make sense of it in my own tiny head.


#rem
iButton read version 1.0


Read Ibutton serial number and check for correct serial number.
Setup to check 2 keys.

Loop until a key is applied then check if key is allowed.

The readowsn command reads the serial number and then puts the family code
in b6, the serial number in b7 to b12, and the checksum in b13

This part of the program uses 117 bytes. If used to simply activate a lock, there is
plenty of storage to save more serial numbers. Change symbol numkeys to suit.

#endrem



symbol numkeys = 2 'number of key serial numbers stored in EEPROM

symbol ibuttin = b2 'iButton read on this input

symbol cntkey = b3 'count for keys being checked

symbol keygood = b4 'a good key has been read flag

'Save iButtons serial number values in EEPROM.
'These numbers are to test on Simulator. The second set will pass test.

EEPROM 0,($01,$11,$22,$33,$44,$55,$00,$11,$22,$33,$44,$55)


main:

'read a key and check it

keygood = 0 'clear the flag to start
b6 = 0 'reset family code to 0

loop1: readowsn ibuttin 'read serial number on input pin

if b6 = 0 then loop1 'loop here until the family code (b6) is no longer 0

'if b12 is FF, it means that the device was not read correctly

if b12 = $FF then loop1 'continue if everything is ok

cntkey = 0 'clear key count

b0 = 0 'start check for serial number

test2: read b0,b1 'read value from EEPROM into b1
if b7 <> b1 then nextkey 'check digit pair 7 from iButton

inc b0 'next digit
read b0,b1
if b8 <> b1 then nextkey 'check digit pair 6 from iButton

inc b0 'next digit
read b0,b1
if b9 <> b1 then nextkey 'check digit pair 5 from iButton

inc b0 'next digit
read b0,b1
if b10 <> b1 then nextkey 'check digit pair 4 from iButton

inc b0 'next digit
read b0,b1
if b11 <> b1 then nextkey 'check digit pair 3 from iButton

inc b0 'next digit
read b0,b1
if b12 <> b1 then nextkey 'check digit pair 2 from iButton

keygood = 1 'a good key has been found

goto continue

nextkey:
inc cntkey 'was not correct iButton

if cntkey = numkeys then continue 'exit test as wrong iButton again

b0 = 6 * cntkey 'digit pair 7 of next iButton in EEPROM

goto test2 'try second iButton
continue:


if keygood = 1 then process 'do whatever you want


goto main

process: '


end
Code:
#rem
iButton read    version 1.0


Read Ibutton serial number and check for correct serial number.
Setup to check 2 keys.   

Loop until a key is applied then check if key is allowed.

The readowsn command reads the serial number and then puts the family code
in b6, the serial number in b7 to b12, and the checksum in b13

This part of the program uses 117 bytes. If used to simply activate a lock, there is
plenty of storage to save more serial numbers. Change symbol numkeys to suit.

#endrem



symbol     numkeys     = 2    'number of key serial numbers stored in EEPROM

symbol    ibuttin    = b2    'iButton read on this input

symbol    cntkey    = b3    'count for keys being checked

symbol     keygood    = b4    'a good key has been read flag

'Save iButtons serial number values in EEPROM.
'These numbers are to test on Simulator. The second set will pass test.

EEPROM 0,($01,$11,$22,$33,$44,$55,$00,$11,$22,$33,$44,$55)     


main:

    'read a key and check it
    
    keygood = 0        'clear the flag to start
    b6 = 0             'reset family code to 0

loop1:    readowsn ibuttin         'read serial number on input pin
    
    if b6 = 0 then loop1    'loop here  until the family code (b6) is no longer 0
    
    'if b12 is FF, it means that the device was not read correctly
            
    if b12 = $FF then loop1    'continue if everything is ok
    
    cntkey  = 0        'clear key count
    
    b0 = 0              'start check for serial number
    
test2:    read b0,b1         'read value from EEPROM into b1
    if b7 <> b1 then nextkey     'check digit pair 7 from iButton
        
    inc b0             'next digit
    read b0,b1     
    if b8 <> b1 then nextkey     'check digit pair 6 from iButton
    
    inc b0             'next digit
    read b0,b1     
    if b9 <> b1 then nextkey     'check digit pair 5 from iButton
    
    inc b0             'next digit
    read b0,b1     
    if b10 <> b1 then nextkey     'check digit pair 4 from iButton
    
    inc b0             'next digit
    read b0,b1     
    if b11 <> b1 then nextkey     'check digit pair 3 from iButton
    
    inc b0             'next digit
    read b0,b1     
    if b12 <> b1 then nextkey     'check digit pair 2 from iButton
    
    keygood = 1        'a good key has been found
    
    goto continue
    
nextkey:   
    inc cntkey        'was not correct iButton
    
    if cntkey = numkeys then continue    'exit test as wrong iButton again

    b0 = 6 * cntkey        'digit pair 7 of next iButton in EEPROM
        
    goto test2        'try second iButton
continue:   
    

    if keygood = 1 then process    'do whatever you want


goto main

process:                '
    

end
 
Top