User avatar
JohnBeardmore
Posts: 184
Joined: Thu Nov 15, 2012 11:03 pm
Location: Derbyshire UK.
Contact: Website

One wire w1-gpio and w1-gpio-custom

Thu Jan 02, 2014 10:23 pm

Help please ! Any pointers with any of this would be very welcome !

I'd like to interface a Pi to a lot of one wire devices, mostly to measure temperature (DS18B20), but maybe also to measure humidity.

To focus at the moment on the DS18B20, this seems to use kernel modules w1-gpio and w1-therm, of which I assume w1-gpio configures the gpio pin, and w1-therm makes the data available through /sys/bus/w1/devices/... Am I getting this right ?

I can't find any documentation which says how these two modules relate to each other.

It seems unlikely that I'll be able to get away with daisy-chaining through as many sensors as I need, as the route round the temperatures to be sensed will branch, so won't make a good transmission line.

This means I want to set up multiple one wire buses, possibly on all the GPIOs.

I've read that the w1-gpio that's mentioned on http://www.cl.cam.ac.uk/projects/raspbe ... mperature/ is hard coded to GPIO4, but that the source of the w1-gpio module might be edited to change the GPIO pin that's used. Other pages suggest that there is a module w1-gpio-custom where the GPIO pin can be passed as a parameter. http://www.rpural.net/thermometer for example, suggests that this might be configurable in /etc/modules by adding a line of the form "w1-gpio-custom bus0=0,4,0". I assume this is what they mean by passing a parameter ?

Does anybody know how to get the source for w1-gpio ? Is this something I can do in Raspbian with apt-get ? Similarly, where can I get w1-gpio-custom for Raspbian ?

If I want to set up multiple one wire buses on different GPIO pins, do I need to load multiple instances of w1-gpio for different GPIO pins, or put multiple "w1-gpio-custom bus0=0,3,0", "w1-gpio-custom bus0=0,4,0", "w1-gpio-custom bus0=0,5,0" etc lines into /etc/modules ?

If so, will I also need to load multiple instances of w1-therm ?

Thanks, J/.
Author of oBeMS open source Building energy Management System.
Automatic Meter Reading (AMR), Building Management System (BMS),
Building Energy Management System (BEMS), Infrastructure Control System (ICS).
See: http://t4sustainability.co.uk/oBeMS/

tdack
Posts: 2
Joined: Tue Feb 25, 2014 3:58 am

Re: One wire w1-gpio and w1-gpio-custom

Tue Feb 25, 2014 4:06 am

After spending too much time with Google and randomly browsing kernel code it looks like you can change the gpio pin.

But. It can only be done at boot time with a /boot/cmdline.txt entry.

Reading https://github.com/raspberrypi/linux/pull/457 it looks like if you add the following to /boot/cmdline.txt:

Code: Select all

bcm2708.w1_gpio_pin=8
Then your RPi will use GPIO-8 for 1-wire communication.

At this stage it doesn't look like there is any way to use more than one GPIO pin for 1-wire devices.

User avatar
JohnBeardmore
Posts: 184
Joined: Thu Nov 15, 2012 11:03 pm
Location: Derbyshire UK.
Contact: Website

Re: One wire w1-gpio and w1-gpio-custom

Tue Feb 25, 2014 5:28 pm

These were the conclusions I reached when I contacted people who had written these bits of the kernel.

The view seems widely held that the Pi has 'quite good' one wire support, but when you try to use a lot of it in anger, it isn't that great.

I know there alternative ways to do it, like bridging from the SPI bus, but as soon as you start to add extra hardware, I suspect t will become a lot harder to engage people who have only a casual interest in an open source project.

It looks as if the idea of using just the Pi and a lot of one wire sensors will have to lapse for now.

Many thanks, J/.
Author of oBeMS open source Building energy Management System.
Automatic Meter Reading (AMR), Building Management System (BMS),
Building Energy Management System (BEMS), Infrastructure Control System (ICS).
See: http://t4sustainability.co.uk/oBeMS/

fishfinger
Posts: 2
Joined: Sat Mar 01, 2014 7:25 pm

Re: One wire w1-gpio and w1-gpio-custom

Sat Mar 01, 2014 7:56 pm

Dear John....

I am running 4 different 1wire buses on a single pi via different GPIO pins with no
extra hardware. The big secret is a custom kernel, a few small changes in one of
the linux kernel source files to add the extra 1wire bus resources and it just works.

My version of the file linux/arch/arm/mach-bcm2708/bcm2708.c
contains a bit that looks like this (sorry can't do a diff but its based on kernel 3.6.11+ ):

Code: Select all

#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
static struct w1_gpio_platform_data w1_gpio_pdata = {
        .pin = W1_GPIO,
        .is_open_drain = 0,
};

static struct platform_device w1_device = {
        .name = "w1-gpio",
        .id = 0,
        .dev.platform_data = &w1_gpio_pdata,
};
static struct w1_gpio_platform_data w1_gpio_pdata1 = {
        .pin = 22,
        .is_open_drain = 0,
};

static struct platform_device w1_device1 = {
        .name = "w1-gpio",
        .id = 1,
        .dev.platform_data = &w1_gpio_pdata1,
};
static struct w1_gpio_platform_data w1_gpio_pdata2 = {
        .pin = 23,
        .is_open_drain = 0,
};

static struct platform_device w1_device2 = {
        .name = "w1-gpio",
        .id = 2,
        .dev.platform_data = &w1_gpio_pdata2,
};
static struct w1_gpio_platform_data w1_gpio_pdata3 = {
        .pin = 24,
        .is_open_drain = 0,
};

static struct platform_device w1_device3 = {
        .name = "w1-gpio",
        .id = 3,
        .dev.platform_data = &w1_gpio_pdata3,
};
#endif
This change adds 3 more 1wire buses at GPIO pins 22/23/24, no need to change anything else. It works
fairly well.

Code: Select all

pi@rasptemp /sys/bus/w1/devices $ ls
10-0008028a785f  28-00000452ee23  28-000004851799  28-00000485d5cb
10-0008028a8cf9  28-00000452efef  28-000004853efd  w1_bus_master1
28-00000451f186  28-0000045310b4  28-000004854766  w1_bus_master2
28-00000452c2c7  28-00000484d5bb  28-000004854853  w1_bus_master3
28-00000452c778  28-00000484f06f  28-00000485637a  w1_bus_master4
28-00000452d63f  28-00000484f396  28-00000485d487

ltpitt
Posts: 16
Joined: Thu Apr 04, 2013 11:11 pm

Re: One wire w1-gpio and w1-gpio-custom

Wed Apr 09, 2014 9:46 pm

I'd want this so bad...

I love linux but never compiled a kernel...

Are there any detailed info about how to use two w1-gpio at the same time?

I read your snippets but look quite arab to me :mrgreen:

User avatar
JohnBeardmore
Posts: 184
Joined: Thu Nov 15, 2012 11:03 pm
Location: Derbyshire UK.
Contact: Website

Re: One wire w1-gpio and w1-gpio-custom

Wed Apr 09, 2014 10:02 pm

I think the last post is really promising, but my sad life has been too busy to try it over the last few weeks. This is still something I really want to get working though.

I have tried building kernels before, but it's a frustrating business as there's no one right way to do it, every expert has their own take, preferred source and configuration, and there isn't necessarily a definitive latest version to use as a starting point.

I suggest you start by building a kernel with no changes first, but don't test it until you've backed up your SD card !

Once you've got a working kernel build process, try the suggestions in the previous messages to get multiple one wire buses.

A sensible starting point might be ask fishfinger which kernel source they built their kernel from, though it may be that you don't need anything esoteric.

Please keep asking for help and let us know how you get on. If I get a chance I'll try and get another look at it in a few weeks.

Cheers, J/.
Author of oBeMS open source Building energy Management System.
Automatic Meter Reading (AMR), Building Management System (BMS),
Building Energy Management System (BEMS), Infrastructure Control System (ICS).
See: http://t4sustainability.co.uk/oBeMS/

ltpitt
Posts: 16
Joined: Thu Apr 04, 2013 11:11 pm

Re: One wire w1-gpio and w1-gpio-custom

Thu Apr 10, 2014 12:20 pm

Hi there and thanks for sharing!

I've read better and it looks like on newer firmware versions this is possible at boot time modifying /boot/cmdline.txt

I did a successful rpi-update and then added at the beginning of my /booy/cmdline.txt :

bcm2708.w1_gpio_pin=18

The only effect was to let my ds18 to totally stop working :D

ltpitt
Posts: 16
Joined: Thu Apr 04, 2013 11:11 pm

Re: One wire w1-gpio and w1-gpio-custom

Thu Apr 10, 2014 12:40 pm

I only had to check my connection...

Everything works perfectly :)

All informations found here did the job:

http://www.raspberrypi.org/forums/viewt ... 59#p518859

User avatar
JohnBeardmore
Posts: 184
Joined: Thu Nov 15, 2012 11:03 pm
Location: Derbyshire UK.
Contact: Website

Re: One wire w1-gpio and w1-gpio-custom

Thu Apr 10, 2014 3:29 pm

But is this letting you use multiple one wire buses (handy, but not that useful), or is it letting you use multiple 1WBs ? I'm after multiple.

Cheers, J/.
Author of oBeMS open source Building energy Management System.
Automatic Meter Reading (AMR), Building Management System (BMS),
Building Energy Management System (BEMS), Infrastructure Control System (ICS).
See: http://t4sustainability.co.uk/oBeMS/

logg
Posts: 5
Joined: Thu Apr 10, 2014 8:01 pm

Re: One wire w1-gpio and w1-gpio-custom

Thu Apr 10, 2014 8:11 pm

hi gui,
i've a proble with my gpio 4 (time ago i damage it) now i want to connect i ds18b20 to my raspy i try to change 1-wire pin
editing /booy/cmdline.txt file but don't work,
someone can help me..some editing kernel or something.

tnksin addvance

dpenezic
Posts: 98
Joined: Sat Dec 22, 2012 2:36 pm

Re: One wire w1-gpio and w1-gpio-custom

Fri Apr 11, 2014 8:28 am

JohnBeardmore wrote:But is this letting you use multiple one wire buses (handy, but not that useful), or is it letting you use multiple 1WBs ? I'm after multiple.

Cheers, J/.
I am little bit out of kernel development , but in particular case you have option tu select different pin for 1 1-wire bus (multiple options i have in mind when i start changing kernel, but i didnt finish that solution).
Of course you may have multiple 1-wire devices on same 1-wire bus.

Regards,
Dubravko Penezic

dpenezic
Posts: 98
Joined: Sat Dec 22, 2012 2:36 pm

Re: One wire w1-gpio and w1-gpio-custom

Fri Apr 11, 2014 8:29 am

logg wrote:hi gui,
i've a proble with my gpio 4 (time ago i damage it) now i want to connect i ds18b20 to my raspy i try to change 1-wire pin
editing /booy/cmdline.txt file but don't work,
someone can help me..some editing kernel or something.

tnksin addvance
Hi,

may you provide your connection schematic, or connection picture ?

REgards,
Dubravko Penezic

logg
Posts: 5
Joined: Thu Apr 10, 2014 8:01 pm

Re: One wire w1-gpio and w1-gpio-custom

Fri Apr 11, 2014 2:09 pm

hi,
my schematic is pi ds18b20 pin 1 to ground, pin 2 to gpio 4 ,pin 3 to 3,3 volt and resistence of 4,7k betwen pin 2 and 3.
i'm shure that is connect right becouse before it work.i try also to use like output but do not work.
can you help me to change 1 wire pin?
tnks in addvance

dpenezic
Posts: 98
Joined: Sat Dec 22, 2012 2:36 pm

Re: One wire w1-gpio and w1-gpio-custom

Fri Apr 11, 2014 7:28 pm

logg wrote:hi,
my schematic is pi ds18b20 pin 1 to ground, pin 2 to gpio 4 ,pin 3 to 3,3 volt and resistence of 4,7k betwen pin 2 and 3.
i'm shure that is connect right becouse before it work.i try also to use like output but do not work.
can you help me to change 1 wire pin?
tnks in addvance
Hi,
please send picture of that connection, theoretically it is O.K. ... in most case people have some non obvious mistake.

For changing pin follow instruction on http://www.raspberrypi.org/forums/viewt ... 59#p518859 .

Regards,
Dubravko Penezic

logg
Posts: 5
Joined: Thu Apr 10, 2014 8:01 pm

Re: One wire w1-gpio and w1-gpio-custom

Sun Apr 13, 2014 12:30 pm

hi,
i follow instruction on post, but nothing .i start raspbian by berryboot (maybe isn't problem) i edit also cmdline.txt in berryboot configuration. in w1 folder there ins't any device (only master), when i boot webiopi i see than w1 devices are alway in pin 4.

this what i do:

sudo su -
nano /boot/cmdline.txt
add this line:
bcm2708.w1_gpio_pin=07

reboot
modprobe w1-gpio
modprobe w1-therm

right?
tnks in addvance

dpenezic
Posts: 98
Joined: Sat Dec 22, 2012 2:36 pm

Re: One wire w1-gpio and w1-gpio-custom

Sun Apr 13, 2014 2:57 pm

logg wrote:hi,
i follow instruction on post, but nothing .i start raspbian by berryboot (maybe isn't problem) i edit also cmdline.txt in berryboot configuration. in w1 folder there ins't any device (only master), when i boot webiopi i see than w1 devices are alway in pin 4.

this what i do:

sudo su -
nano /boot/cmdline.txt
add this line:
bcm2708.w1_gpio_pin=07

reboot
modprobe w1-gpio
modprobe w1-therm

right?
tnks in addvance
Hi,
pin 07 doesnt exist , if you mean GPIO7 , then you need to write bcm2708.w1_gpio_pin=7, and please be aware that value have BCM label of pin not pin position on JP5 header.

Regards,
Dubravko Penezic

logg
Posts: 5
Joined: Thu Apr 10, 2014 8:01 pm

Re: One wire w1-gpio and w1-gpio-custom

Sun Apr 13, 2014 7:17 pm

hi,
really nothing to do! strange things is than when i run it say me than gpio 4 there is 1-wire device,like if i don't change w1 pin.
may be is a configuration problem.Wath you can suggest me ?

many tanks

logg
Posts: 5
Joined: Thu Apr 10, 2014 8:01 pm

Re: One wire w1-gpio and w1-gpio-custom

Mon Apr 14, 2014 10:57 am

solved!
i install last version of raspbian and now working.

Holyhead
Posts: 1
Joined: Wed Jun 11, 2014 7:31 pm

Re: One wire w1-gpio and w1-gpio-custom

Wed Jun 11, 2014 7:37 pm

Thanks @fishfinger! :D
I've used your code stub to compile a patched 3.12.21 kernel implementing four 1-w busmasters.
For those interested, I've uploaded the patch file here http://holyhead.de/RaspberryPi/bcm2708- ... .12.21.txt.

User avatar
JohnBeardmore
Posts: 184
Joined: Thu Nov 15, 2012 11:03 pm
Location: Derbyshire UK.
Contact: Website

Re: One wire w1-gpio and w1-gpio-custom

Sat Jun 21, 2014 12:40 am

Thanks for this, but I've still got problems. Hopefully simple to solve.

A while back I downloaded kernel source, raspberrypi-linux-8fa2e19 which as far as I could see was the latest version.

This source has file called bcm2708.c but it doesn't contain the strings "W1_GPIO" or "one-wire". I assume then, that I've probably downloaded the wrong source.

Which source are you working from, and are there any good instructions for building the kernel and installing it ?

Thanks, J/.
Author of oBeMS open source Building energy Management System.
Automatic Meter Reading (AMR), Building Management System (BMS),
Building Energy Management System (BEMS), Infrastructure Control System (ICS).
See: http://t4sustainability.co.uk/oBeMS/

User avatar
JohnBeardmore
Posts: 184
Joined: Thu Nov 15, 2012 11:03 pm
Location: Derbyshire UK.
Contact: Website

Re: One wire w1-gpio and w1-gpio-custom

Sat Jun 21, 2014 12:42 am

Next question -

If the Pi is only to be used to talk to one wire temperature sensors, are there any GPIO pins which shouldn't be used as one-wire buses ?

Many thanks, J/.
Author of oBeMS open source Building energy Management System.
Automatic Meter Reading (AMR), Building Management System (BMS),
Building Energy Management System (BEMS), Infrastructure Control System (ICS).
See: http://t4sustainability.co.uk/oBeMS/

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: One wire w1-gpio and w1-gpio-custom

Sat Jun 21, 2014 1:02 am

Hi,
JohnBeardmore wrote:If the Pi is only to be used to talk to one wire temperature sensors, are there any GPIO pins which shouldn't be used as one-wire buses ?
No.
Just keep in mind on-board 1k8 pull-up resistors on I2C bus signals.


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

User avatar
JohnBeardmore
Posts: 184
Joined: Thu Nov 15, 2012 11:03 pm
Location: Derbyshire UK.
Contact: Website

Re: One wire w1-gpio and w1-gpio-custom

Sat Jun 21, 2014 7:46 pm

The usual pull-up is 4k7 if I remember correctly. How critical is it ? I think I've used 3k9 in the past when I couldn't find 4k7s. That seemed OK, at least with a lead length of a couple of meters.

Would I get away with 1k8 ?


Cheers, J/.
Author of oBeMS open source Building energy Management System.
Automatic Meter Reading (AMR), Building Management System (BMS),
Building Energy Management System (BEMS), Infrastructure Control System (ICS).
See: http://t4sustainability.co.uk/oBeMS/

impluse
Posts: 4
Joined: Thu Nov 27, 2014 4:42 pm

Re: One wire w1-gpio and w1-gpio-custom

Thu Nov 27, 2014 5:25 pm

fishfinger wrote:Dear John....

I am running 4 different 1wire buses on a single pi via different GPIO pins with no
extra hardware. The big secret is a custom kernel, a few small changes in one of
the linux kernel source files to add the extra 1wire bus resources and it just works.

My version of the file linux/arch/arm/mach-bcm2708/bcm2708.c
contains a bit that looks like this (sorry can't do a diff but its based on kernel 3.6.11+ ):

Code: Select all

#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
static struct w1_gpio_platform_data w1_gpio_pdata = {
        .pin = W1_GPIO,
        .is_open_drain = 0,
};

static struct platform_device w1_device = {
        .name = "w1-gpio",
        .id = 0,
        .dev.platform_data = &w1_gpio_pdata,
};
static struct w1_gpio_platform_data w1_gpio_pdata1 = {
        .pin = 22,
        .is_open_drain = 0,
};

static struct platform_device w1_device1 = {
        .name = "w1-gpio",
        .id = 1,
        .dev.platform_data = &w1_gpio_pdata1,
};
static struct w1_gpio_platform_data w1_gpio_pdata2 = {
        .pin = 23,
        .is_open_drain = 0,
};

static struct platform_device w1_device2 = {
        .name = "w1-gpio",
        .id = 2,
        .dev.platform_data = &w1_gpio_pdata2,
};
static struct w1_gpio_platform_data w1_gpio_pdata3 = {
        .pin = 24,
        .is_open_drain = 0,
};

static struct platform_device w1_device3 = {
        .name = "w1-gpio",
        .id = 3,
        .dev.platform_data = &w1_gpio_pdata3,
};
#endif
This change adds 3 more 1wire buses at GPIO pins 22/23/24, no need to change anything else. It works
fairly well.

Code: Select all

pi@rasptemp /sys/bus/w1/devices $ ls
10-0008028a785f  28-00000452ee23  28-000004851799  28-00000485d5cb
10-0008028a8cf9  28-00000452efef  28-000004853efd  w1_bus_master1
28-00000451f186  28-0000045310b4  28-000004854766  w1_bus_master2
28-00000452c2c7  28-00000484d5bb  28-000004854853  w1_bus_master3
28-00000452c778  28-00000484f06f  28-00000485637a  w1_bus_master4
28-00000452d63f  28-00000484f396  28-00000485d487

Dear fishfinger....
Can you explain step by step how can i have more than one pin for 1-wire bus on single pi
I really need to have more than one pin for 1-wire because I want to use many :o (more than 10) DS18B20 on Single pi

impluse
Posts: 4
Joined: Thu Nov 27, 2014 4:42 pm

Re: One wire w1-gpio and w1-gpio-custom

Sat Nov 29, 2014 6:32 am

Holyhead wrote:Thanks @fishfinger! :D
I've used your code stub to compile a patched 3.12.21 kernel implementing four 1-w busmasters.
For those interested, I've uploaded the patch file here http://holyhead.de/RaspberryPi/bcm2708- ... .12.21.txt.
hi...
Can you explain step by step how can i have more than one pin for 1-wire bus on single pi

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: No registered users and 14 guests