1-wire support


The information in this guide refers to Squidge running on an Omnima SKU16140, however it should be readily adapted to almost any router running OpenWrt with a GPIO pin (one that can be configured for input or output).

GPIO pin

For the sake of this example, we will be using the negative pin of the LED labelled D9 on the board (pin ID 17). For an explanation of how to find appropriate GPIO pins, see the GPIO page.

Pull-up resistors

You weren't going to forget your pull-up resistor were you? 1-wire is a single-wire protocol and relies on devices allowing the line to be 'pulled high' by a pull-up. I've used a value of 6.5kohms when running a DS1820 from 3.3v supply. This seems to work well enough with the Omnima board. Some devices may conceivably have the pull-up built-in. Check the documentation for your device.

Required Modules

You will need to install at a minimum wire, w1-gpio and w1-gpio-custom:

opkg install kmod-w1-gpio-custom

Should do the trick and pull in the necessary dependencies. The packages attempt to load the relevant modules. They will fail, because we need to supply some arguments giving the GPIO pins to use. Don't worry.

Configuring for GPIO Pins

You will see in /etc/modules.d that some new files have been created by the installation of the modules. The one of interest has a name of the form <load sequence>-w1-gpio-custom. Open this file with vi:

vi /etc/modules.d/55-w1-gpio-custom

(or another editor if you want to install it), and make it contain:

w1-gpio-custom bus0=0,17,0

(Only one line). This tells the w1-gpio-custom module to create a new w1 (1-wire) bus with an ID of zero, using Pin ID 17, not open-drain. The open-drain option should be set to '1' if your hardware supports this output mode. It should make little difference, although there have been reports of some OpenWrt systems experiencing errors when switching ports quickly between input and output. This does not seem to be a problem with the Omnima.

Note that you can include several bus definitions up to a maximum of four, i.e.:

w1-gpio-custom bus0=0,17,0 bus1=1,18,0 ....

However if you do this make absolutely sure the busses have different IDs. This error condition didn't seem to be handled very well when I tried, and I was forced to reboot after making this mistake!

Reboot after changing the /etc/modules.d file and the kernel should then load all the modules without error.

Detecting devices

The 1-wire subsystem runs a kernel thread which checks for the presence of devices on the bus every 10 seconds. This period can be changed or even stopped altogether if devices will never be removed. Control is via files in the /sys/devices/w1_bus_master<n> directory, although there isn't much need to change the defaults.

When a slave device is detected, a directory will appear like this:


The directory name is the 64-bit ID of the device. There will probably be an error message from the kernel to tell you that the device has not been associated with a driver.

Device Communication

Communication with devices is via a file called 'rw' found in the slave device directory. I have yet to work out how to do this, however I'll update this HOWTO when I do.

email: bifferos@@@yahoo.co.uk