# OneWire on RaspberryPi3



## Phishfry (Jan 7, 2018)

I have the RPi3 running on FreeBSD -CURRENT r327524 with the onewire driver.
There are two ways I have found to enable OneWire on RPi3.
Simplest is to use the GNU device tree source file and alter one setting. phandle hex address.

Here is the GNU DTS:
https://github.com/krzk/tizen-tv-rp...rch/arm/boot/dts/overlays/w1-gpio-overlay.dts

On Line 16 you must edit and change this:
<&gpio 4 0>
to this:
<0xc 4 0>
This represents 'phandle' 0xc which is the gpioc0 controller. "4" being the pin used and "0" sets the state.

So the device tree overlay method works but 2 drawbacks.
#1 You cannot change the gpio pin in the /boot/msdos/config.txt file that is used for overlays. 
So while your modifying the overlay feel free to use another pin.
I prefer to use GPIO 17(header pin 11). So you must change all instances of "4" in the w1-gpio-overlay.dts.

So now its time to save your overlay file on the RPi3.
It should be named this: /boot/msdos/overlays/w1-gpio-overlays.dts
Now to compile it.
`cd /boot/msdos/overlays/`
`dtc -I dts -O dtb -o w1-gpio-overlay.dtbo w1-gpio-overlay.dts`

Now to add the overlay to your environment:
`echo "dtoverlay=w1-gpio-overlay" >>/boot/msdos/config.txt`

So one problem here. You can only use pin4. The overlay method on does not work correctly here.
You should be able to specify a pin like this in your /boot/msdos/config.txt

```
dtoverlay=w1-gpio-overlay,gpiopin=17
```
Unfortunately it does not use the gpiopin=* number specified. It defaults to pin 4.

Now add the Onewire modules to load on boot:
`echo "owc_load="YES">>/boot/loader.conf`
`echo "ow_load="YES">>/boot/loader.conf`
`echo "ow_temp_load="YES">>/boot/loader.conf`

#2 The second major problem is that I can only create 1 onewire bus via the overlay method.
Whereas you should be able to create multiple pins/buses in the config.txt like this:

```
dtoverlay=w1-gpio-overlay,gpiopin=17
dtoverlay=w1-gpio-overlay,gpiopin=27
dtoverlay=w1-gpio-overlay,gpiopin=22
```
It does not work correctly and only uses the first line and only uses gpio pin 4.
You can modify the above overlay to use other pins.
You can also create additional overlay files for each pin/bus.(See below for example)
https://www.raspberrypi.org/forums/viewtopic.php?t=156734

There is another harder way I will show in my next post. Better suited to multiple pins.
_Decompiling the dtb_


----------



## Phishfry (Jan 7, 2018)

This post covers another method, decompiling the dtb.
Here is the 6 OneWire bus settings I am using:


```
}
        onewire0 {
                compatible = "w1-gpio";
                gpios = <0xc 17 1>;//HeaderPin=11//
        };
        onewire1 {
                compatible = "w1-gpio";
                gpios = <0xc 27 1>;//HeaderPin=13//
        };
        onewire2 {
                compatible = "w1-gpio";//HeaderPin=15//
                gpios = <0xc 22 1>;
        };
        onewire3 {
                compatible = "w1-gpio";
                gpios = <0xc 10 1>;//HeaderPin=19//
        };
        onewire4 {
                compatible = "w1-gpio";
                gpios = <0xc 9 1>;//HeaderPin=21//
        };
        onewire5 {
                compatible = "w1-gpio";
                gpios = <0xc 11 1>;//HeaderPin23//
        }
```

So the first step is to decompile the RaspberryPi3 device tree binary file.
`cd /boot/msdos/`
`cp bcm2710-rpi-3-b.dtb bcm2710-rpi-3-b.dtb.orig`//file backup//
`dtc -I dtb -O dts bcm2710-rpi-3-b.dtb -o bcm2710-rpi-3-b.dts`
`cp bcm2710-rpi-3-b.dts bcm2710-rpi-3-b.dts.orig`//file backup//

Now you have an editable dts file to add the one wire pins to. I used the above code:
`ee bcm2710-rpi-3-b.dts`
I inserted the above code block at line 801.

```
clock-frequency = <0x2faf0800>;
                        phandle = <0x21>;
                };
        }
        onewire0 {
                compatible = "w1-gpio";
                gpios = <0xc 17 1>;//HeaderPin=11//
        };
        onewire1 {
                compatible = "w1-gpio";
                gpios = <0xc 27 1>;//HeaderPin=13//
        };
        onewire2 {
                compatible = "w1-gpio";//HeaderPin=15//
                gpios = <0xc 22 1>;
        };
        onewire3 {
                compatible = "w1-gpio";
                gpios = <0xc 10 1>;//HeaderPin=19//
        };
        onewire4 {
                compatible = "w1-gpio";
                gpios = <0xc 9 1>;//HeaderPin=21//
        };
        onewire5 {
                compatible = "w1-gpio";
                gpios = <0xc 11 1>;//HeaderPin23//
        };
        __symbols__ {
```

Now save and recompile back the work into the device tree binary.
`dtc -I dtb -O dts bcm2710-rpi-3-b.dtb -o bcm2710-rpi-3-b.dts`

Thats it. Add the modules to load at boot if needed.
`echo "owc_load="YES">>/boot/loader.conf
echo "ow_load="YES">>/boot/loader.conf
echo "ow_temp_load="YES">>/boot/loader.conf`

Now you should reboot and check `dmesg|grep ow` and  `sysctl dev.ow` to see the status.


----------



## Phishfry (Jan 8, 2018)

I might have spoke too soon. It seems I have the OneWire bus up and running but I am having issues getting the temp sensor to read:

```
gpiobus0: <OFW GPIO bus> on gpio0
owc0: <FDT GPIO attached one-wire bus> at pin 17 on gpiobus0
ow0: <1 Wire Bus> on owc0
oops, starting over
oops, starting over
oops, starting over
oops, starting over
oops, starting over
oops, starting over
```


----------



## aonishenko (May 24, 2018)

Hi!



Phishfry said:


> This post covers another method, decompiling the dtb.
> Here is the 6 OneWire bus settings I am using:
> 
> 
> ...



Hi!

I use CURRENT version and RPI3
Made, as you wrote, but nothing happens. 
I modified config.txt and placed tdb file to overlay directory also. 
What can be wrong?


----------



## aonishenko (May 24, 2018)

aonishenko said:


> Hi!
> 
> 
> 
> ...



I mean that dmesg shows no ow devices. 
Also, I have /boot/efi instead /boot/msdos


----------



## Phishfry (May 24, 2018)

As you can see I never got them working under RPi3.
I will say that since these instructions -CURRENT has changed an no longer uses config.txt on RPI3.
No 100% sure though, I am taking a break from Arm for a while.


----------



## aonishenko (May 24, 2018)

Phishfry said:


> As you can see I never got them working under RPi3.
> I will say that since these instructions -CURRENT has changed an no longer uses config.txt on RPI3.
> No 100% sure though, I am taking a break from Arm for a while.


Ouch... thanks. Going to research)


----------

