Raspberry Pi iButton System- Updated

Reading ibuttons using a Raspberry Pi can be a lot easier than you think. We published a post about a Raspberry Pi iButton System a while ago and we were overwhelmed how popular the post was. So we decided to write an updated tutorial on the Raspberry Pi iButton System. This post describes the most basic method of reading an ibutton and the obtained ibutton identification number / Serial number is displayed on an LCD screen. To get started, please refer to our original post.
Raspberry Pi Ibutton

Data from the DS1990 ibutton is transferred serially through the 1-Wire protocol, which requires only a single data lead and a ground return. The 1-wire interface on a raspberry pi can be access by using the w1-gpio kernel on Linux running on the raspberry pi.

Activate the 1-wire Bus Driver and the GPIO

First of all, install the latest version of Raspbian on an SD card and then power and boot your Pi. In the latest Linux kernel, the 1-wire feature is disabled by default. To enable it, add the following line to /boot/config.txt and reboot the Pi.


Use the following command to active the 1-wire bus driver and the GPIO:

sudo modprobe w1-gpio
sudo modprobe w1-smem

And set the permissions for the 1-wire bus folder:

sudo chmod a+w /sys/devices/w1_bus_master1/w1_master_slaves
sudo chmod a+w /sys/devices/w1_bus_master1/w1_master_remove
sudo chmod a+w /sys/devices/w1_bus_master1/w1_master_search


For this post, we decided to connect an LCD to display the ID of the ibutton. For detailed connections for the LCD, please visit our previous post.
Raspberry Pi Ibutton connections
The center of the ibutton probe is connected to the GPIO-4 of the Pi, with a 1k pull-up resistor between the GPIO-4 and the 3.3V pin and the outer contact is connected to the Pi’s ground.

Python script

The following python script allows the Ibutton to be read and the results is displayed on the LCD for 3 seconds. Most of the code is to drive the LCD and the core ibutton reading code is labelled “# iButton Read

#  Rasbperry Pi ibutton with LCD Test Script
# Author : BehindTheSciences
# Date   : 15/02/2017
# https://behindthesciences.com
import os
import time
import RPi.GPIO as GPIO

from BTSLCDPi import BTSLCD

LCD_LINE_1 = 1
LCD_LINE_2 = 2

# GPIO to LCD mapping
LCD_RS            = 14
LCD_EN            = 18
LCD_D4            = 24
LCD_D5            = 23
LCD_D6            = 8
LCD_D7            = 25

os.system('modprobe wire timeout=1 slave_ttl=5')
os.system('modprobe w1-gpio')
os.system('modprobe w1-smem')
os.system('chmod a+w /sys/devices/w1_bus_master1/w1_master_slaves')
os.system('chmod a+w /sys/devices/w1_bus_master1/w1_master_remove')
os.system('chmod a+w /sys/devices/w1_bus_master1/w1_master_search')
base_dir = '/sys/devices/w1_bus_master1/w1_master_slaves'
delete_dir = '/sys/devices/w1_bus_master1/w1_master_remove'

#Create LCD class
def main():

  # Initialise display
  while True:
    # iButton Read
	f = open(base_dir, "r")
	ID = f.read()
	if ID != 'not found.\n':
		LCD.lcd_string("iButton ID = ",LCD_LINE_1)
		d = open(delete_dir, "w")
if __name__ == '__main__':
  except KeyboardInterrupt:

The python script can also be downloaded here.
By default, the 1-wire kernel only reads the GPIO-4 every 10 seconds. To speed the reading time;
Edit this file as Sudo


Add this text:

options wire timeout=1 slave_ttl=3

Here is a few photos; we did not have a spare ibutton probe for this post, hence used 2 wires to make the contact.
Raspberry Pi Ibutton LCD
Raspberry Pi Ibutton LCD

    • behindthesciences
    • behindthesciences

Add a Comment

Your email address will not be published. Required fields are marked *

Show Buttons
Hide Buttons