Homepage Wiki Forum Buy

1-wire

From GNUBLIN

severity (level) requirement Gnublin Family
Gnublin logo advanced.png 1-Wire knowledge, connect chips, loading kernel drivers All

This article explains how to connect an 1-wire temperature sensor (DS18B20) and an 1-wire serial-number-chip (DS2401) with an I2C-to-1-wire-bridge (DS2482) with the GNUBLIN board.


Contents

Preparation

Before you can start to communicate with the chips you need to wire up the hardware. The following diagram shows you how to connect the GNUBLIN with the 3 components (DS2401, DS2482, DS18B20).

1-wire.jpeg

  1. You can find the datasheet of the I2C-to-1-wire-bridge DS2482 here
  2. You can find the datasheet of the temperature sensor DS18B20 here
  3. You can find the datasheet of the serial-number-chip DS2401 here

You can find the Interfaces of the different GNUBLIN board and their location here

For Beginners with the Gnublin Distribution

The kernel modules are included as modules in the newest Gnublin Distribution.

Loading the modules

First you should load the modules.

modprobe ds2482
modprobe w1_therm (For temperature sensors e.g. DS1820)
modprobe w1_smem  (For serial-number-chip e.g. DS2401)


After this you should register the I2C-to-1-wire-bridge to the I2C-Bus. If you have wired everything like shown in the diagram above the I2C-address of the DS2482 is 0x18 and the following command registers the chip to the I2C-Bus:

echo ds2482 0x18 > /sys/bus/i2c/devices/i2c-1/new_device

The DS2482 driver scans the 1-wire bus every 10 seconds for new hardware connected to the bus and adds a new directory for each new device in the directory /sys/bus/w1/devices/w1 bus master .

Now you should change into the directory /sys/bus/w1/devices/w1 bus master with the following command:

cd /sys/bus/w1/devices/w1\ bus\ master

You can list the directories and the content with the command ls

01-000008e78344  w1_master_add              w1_master_remove
28-000001fece78  w1_master_attempts         w1_master_search
driver           w1_master_max_slave_count  w1_master_slave_count
power            w1_master_name             w1_master_slaves
subsystem        w1_master_pointer          w1_master_timeout
uevent           w1_master_pullup

Here you can see that the driver has found two 1-wire devices (01-000008e78344 , 28-000001fece78) and has created a directory for each device.

Read the temperature/serial-number

You can simply read the serial number of the DS2401. The serial number is just the sequence of numbers without the "01-" at the beginning.

Our Chip for example has the serial number000008e78344


Now we are going to read the temperature of the DS18B20, therefore we have to type the following command if we are in the directory /sys/bus/w1/devices/w1 bus master on the terminal(Change 28-000001fece78 to the number of your 1-wire device) :

cat 28-000001fece78/w1_slave

The output looks like this:

46 01 4b 46 7f ff 0a 10 85 : crc=85 YES
46 01 4b 46 7f ff 0a 10 85 t=20375

Here you can read the temperature in degrees Celsius right after the "t=".


For Advanced Users

Modules needed:

      <*> Dallas's 1-wire support  --->                                         
                  1-wire Bus Masters  --->
                       <M> Maxim DS2482 I2C to 1-Wire bridge
                  1-wire Slaves  ---> 
                       <M> Thermal family implementation                               <--- For temperature sensors e.g. DS18B20
                       <M> Simple 64bit memory family implementation                   <--- For serial-number-chip e.g. DS2401


1. Activate the kernel drivers, and make the zImage and modules. Copy them to your SD-Card.

2. Wire up the hardware (look at #Preparation)

3. Boot the board.

4. Loading the modules:

modprobe ds2482
modprobe w1_therm (Für Temperatursensoren z.B. DS1820)
modprobe w1_smem  (Für Seriennummernchip z.B. DS2401)


5. Register the device to the I2C-Bus:

echo ds2482 0x18 > /sys/bus/i2c/devices/i2c-1/new_device


The DS2482 driver scans the 1-wire bus every 10 seconds for new hardware connected to the bus and adds a new directory for each new device in the directory /sys/bus/w1/devices/w1 bus master .

cd /sys/bus/w1/devices/w1\ bus\ master
ls

should give you the following output:

01-000008e78344  w1_master_add              w1_master_remove
28-000001fece78  w1_master_attempts         w1_master_search
driver           w1_master_max_slave_count  w1_master_slave_count
power            w1_master_name             w1_master_slaves
subsystem        w1_master_pointer          w1_master_timeout
uevent           w1_master_pullup

You can simply read the serial number of the DS2401. The serial number is just the sequence of numbers without the "01-" at the beginning.

Our Chip for example has the serial number000008e78344

You can read the temperature with the following command (Change 28-000001fece78 to the number of your 1-wire device):

cat 28-000001fece78/w1_slave

The output looks like this:

46 01 4b 46 7f ff 0a 10 85 : crc=85 YES
46 01 4b 46 7f ff 0a 10 85 t=20375

Here you can read the temperature in degrees Celsius right after the "t=".

In other languages