Raspberry Pi iButton system
|Over the years, I have come across various security door access systems such as keypad access, magnetic strip, RFID tags and iButtons. I have found ibuttons and RFID tags to be the most user-friendly. The basic iButton contains just a unique serial number and advanced models contain various amounts of EPROM, EEPROM, NVRAM, clocks, temperature sensors and so on. The iButton is a chip enclosed in a stainless steel can. The steel button can be mounted virtually anywhere because it is rugged enough to withstand harsh environments, indoors or outdoors. It is durable enough to attach to a key fob, ring, watch, or other personal items and used daily for applications such as access control to buildings and computers.
Activate the 1-wire bus driver and the GPIO
chmod a+w /sys/devices/w1_bus_master1/w1_master_slaves
chmod a+w /sys/devices/w1_bus_master1/w1_master_remove
chmod a+w /sys/devices/w1_bus_master1/w1_master_search
Connect an iButton probe to the Raspberry Pi as shown below. IButton probes are nothing fancy and can be made easily. I chose to buy one from Farnell. Most major online electronic shops sell them.

After the connections has been made, try an ibutton on the probe… and have a look in this folder of the raspberry pi:
/sys/devices/w1_bus_master1/w1_master_slaves
import os import time import datetime as date import sqlite3 as lite import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) print(time.strftime("%c")) os.system('modprobe wire timeout=1 slave_ttl=5') os.system('modprobe w1-gpio') os.system('modprobe w1-smem') GPIO.setup(24,GPIO.OUT) base_dir = '/sys/devices/w1_bus_master1/w1_master_slaves' delete_dir = '/sys/devices/w1_bus_master1/w1_master_remove' GPIO.output(24,False) while True: f = open(base_dir, "r") ID = f.read() f.close() inlist = lite.connect('in.db') data = lite.connect('accesslist.db') curs = data.cursor() curs.execute("SELECT * FROM user") cursin = inlist.cursor() now = time.strftime("%c") rows = curs.fetchall() if ID != 'not found.\n': print(ID) for row in rows: if str(ID) ==str(row[1])+"\n": print("Success0") cursin.execute('INSERT INTO listin(name, date) VALUES (?,?)',(row[0],now)) GPIO.output(24,True) inlist.commit() time.sleep(3) GPIO.output(24,False) break else: GPIO.output(24,False) if ID != 'not found.\n': d = open(delete_dir, "w") d.write(ID) inlist.close() data.close() GPIO.cleanup()
I will comment the code when I get some time. For now, happy programming internet people! 🙂
UPDATE
dtoverlay=w1-gpio,gpiopin=4
To speed the reading time:
Edit this file as Sudo
/etc/modprobe.d/w1.conf
Add this text:
options wire timeout=1 slave_ttl=3
We have now made a simplified updated post on the ibutton system. Check it out.
In which file do i put this code?
It’s a python script. So you have to create a .py file and type those code.. and then run it. 🙂
Hi
good example , I used a Rpi 2 is working but is very slow about 10 seconds each read
how you think?
best regards
Andrea
Hi Andrea,
The modprobe wire timeout=1 slave_ttl=5 commands should change it to 1 second as opposed to 10 secs. Try the command and then check whether your w1_master_timeout file contains 1 rather than 10. Keep us updated.
It is still 10 secs :/
We will look into it. It seems that the 1-wire interface has been changed in recent linux distro.
Edit this file as Sudo
/etc/modprobe.d/w1.conf
Add this text:
options wire timeout=1 slave_ttl=3
Hello, trying to run the file and it will not like the break line?? saying invalid syntax??
It difficult to see where the error arises without seeing your code. There could be one of many things wrong. Your indentation might be wrong. Remember that python is “indent-sensitive”. Or it could a syntax error prior to the break
We seem to of past the invalid sytax now and we need to set up the database. Thanks
Hello, any chance you can help me with the database set up by posting the lines to do that please?
Many Thanks
Hello,
I have the same problem, I want to reduce the time of each read
I tried to run the command ‘ modprobe wire timeout = 1 slave_ttl = 5 ‘ but no effect
also I can’t find the file ‘ /etc/modprobe.d/w1.conf ‘ to update it !!
Any help ?
thanks
Have you got a modprobe.d in the /etc/ location?
yes I have
Can you list all the files in your /modprobe.d/ ?
Sorry for the late, yes sure
files in /etc/modprobe.d
* blacklist-rtl8192cu.conf
* fbdev-blacklist.conf
* libpisock9.conf
* blacklist-rtl8xxxu.conf
* ipv6.conf
* raspi-blacklist.conf
Hmm.. it looks like your Pi is not configured for 1-wire. Try running this:
sudo modprobe w1-gpio
and see if you get the w1.conf
I did but always the same, no files added
Hi, thanks for the awesome post. Do you know is there a way to speed up iButton “removal lag”? What I mean is when I connect the iButton key to reader, it shows in file /sys/devices/w1_bus_master1/w1_master_slaves pretty quick (ttl=3). But when I disconnect my key, the serial number stays in that file for about a minute or so.
Hi there,
This is something that we worked on a while back. We will have a look and get back to you.
Thank you for this turotial!! This the error that i had:
Traceback (most recent call last):
File “/home/pi/Bureau/ibutton.py”, line 30, in
d = open(delete_dir, “w”)
IOError: [Errno 13] Permission denied: ‘/sys/devices/w1_bus_master1/w1_master_remove’
You need to try to run it as root. Try with sudo.
does this code support the devices not form Dallas/Maxim Integrated ???
I need to read from RFID but transmitting on 1-wire
Not tried it. We have not looked at the kernel for the 1-wire. Sorry.