Difference between revisions of "EBC Exercise 31 Dallas 1-Wire"

From eLinux.org
Jump to: navigation, search
m (Reading the DS18B20: Fixed 1000 errors.)
m (Software Setup: Updated for 4.19 kernel)
Line 23: Line 23:
  
 
=== Software Setup ===
 
=== Software Setup ===
The DS18B20 can be attached to any GPIO pin, but we're attaching it to P9_12.
+
The DS18B20 can be attached to any GPIO pin, but there's a device tree already created to attach it to P9_12.  
The default device tree has P9_12 configured as a GPIO.
+
==== Finding the device tree ====
We need to remove that configuration so it can be used with the DS18B20.
+
<code>/lib/firmware</code> contains many device treesLet's see which ones work with one-wire interface
==== Unconfiguring P9_12 ====
+
  bone$ '''ls /lib/firmware/*W1*'''
First see if it is configured.
+
  /lib/firmware/BB-W1-P9.12-00A0.dtbo
  bone$ '''config-pin -q P9_12'''
+
Looks like there is one setup for P9_12Let's check the source code. The Bone should already have the source files
P9_12 Mode: default Direction: in Value: 1
+
loaded.
If you get the response above, you need to unconfigure it.  First find which device tree you are using.
 
  bone$ '''export SLOTS=/sys/devices/platform/bone_capemgr/slots'''
 
  bone$ '''cat $SLOTS'''
 
  0: PF----  -1
 
  1: PF----  -1
 
  2: PF----  -1
 
  3: PF----  -1
 
  4: P-O-L-  0 Override Board Name,00A0,Override Manuf,''univ-emmc''
 
The last part of the last line tells you which device tree you are usingIn my case it '''univ-emmc'''.
 
Next:
 
 
  bone$ '''cd /opt/source/bb.org-overlays'''
 
  bone$ '''cd /opt/source/bb.org-overlays'''
  bone$ '''ls src/arm'''
+
  bone$ '''ls'''
Look for the file that begins with the name you found above and ends in '''.dts'''.  
+
COPYING  dtc-overlay.sh  include    jenkins_build.sh  Makefile          readme.md  src
It's '''univ-emmc-00A0.dts''' in my caseNow edit it.
+
debian  examples        install.sh  Jenkinsfile      readme-legacy.md scripts    tools
  bone$ '''vi src/arm/univ-emmc-00A0.dts'''
+
If the <code>cd</code> fails you will have to clone the repository.
Comment out all the lines containing P9.12 (1) and P9_12 (16).
+
  bone$ '''git clone https://github.com/beagleboard/bb.org-overlays'''
  bone$ '''make'''
+
  bone$ '''cd bb.org-overlays'''
  bone$ '''make install'''
+
Either way
  bone$ '''reboot'''
+
  bone$ '''cd src/arm'''
  bone$ '''config-pin -q P9_12'''
+
  bone$ '''ls *W1*'''
  P9_12 pinmux file not found!
+
BB-W1-P9.12-00A0.dts
cape-universala overlay not found
+
  bone$ '''less *W1*'''
  run "config-pin overlay cape-universala" to load the cape
+
Page down a ways to see
 +
        fragment@3 {
 +
                target-path="/";
 +
                __overlay__ {
 +
   
 +
                        onewire {
 +
                                status = "okay";
 +
                                pinctrl-names = "default";
 +
                                pinctrl-0 = <&dallas_w1_pins>;
 +
   
 +
                                compatible = "w1-gpio";
 +
                                gpios = <&gpio1 28 GPIO_ACTIVE_HIGH>;
 +
                        };
 +
                };
 +
        };
 +
};
  
==== Configuring P9_12 ====
+
gpio3, pin 28 is P9_12.
Good, the P9_12 pin is not configured. Let's configure it.
 
bone$ '''export SLOTS=/sys/devices/platform/bone_capemgr/slots'''
 
bone$ '''echo BB-W1-P9.12 > $SLOTS'''
 
bone$ '''dmesg -H | tail'''
 
[Oct26 10:04] bone_capemgr bone_capemgr: part_number 'BB-W1-P9.12', version 'N/A'
 
[  +0.000046] bone_capemgr bone_capemgr: slot #5: override
 
[  +0.000024] bone_capemgr bone_capemgr: Using override eeprom data at slot 5
 
[  +0.000024] bone_capemgr bone_capemgr: slot #5: 'Override Board Name,00A0,Override Manuf,BB-W1-P9.12'
 
[  +0.020178] bone_capemgr bone_capemgr: slot #5: dtbo 'BB-W1-P9.12-00A0.dtbo' loaded; overlay id #1
 
[  +0.039562] Driver for 1-wire Dallas network protocol.
 
Good, it looks like it's configured.
 
  
 
=== Reading the DS18B20 ===
 
=== Reading the DS18B20 ===

Revision as of 11:48, 24 October 2019

thumb‎ Embedded Linux Class by Mark A. Yoder


The DS18B20 is an interesting temperature sensor that uses Dallas Semiconductor's 1-wire based interface. The data communication requires only one wire! (However you still need wires for ground and 3.3V.) You can wire it to any GPIO port.

SparkFun sells a DS18B20 that's in a waterproof probe. You'll need it and maybe a 4.7kΩ pull up resistor.

Attach the leads a follows.

DS18B20 Lead Attach to
Red 3.3V
Black ground
White P9_12

You may also need to attach the 4.7kΩ resistor between P9_12 and 3.3V.

Software Setup

The DS18B20 can be attached to any GPIO pin, but there's a device tree already created to attach it to P9_12.

Finding the device tree

/lib/firmware contains many device trees. Let's see which ones work with one-wire interface

bone$ ls /lib/firmware/*W1*
/lib/firmware/BB-W1-P9.12-00A0.dtbo

Looks like there is one setup for P9_12. Let's check the source code. The Bone should already have the source files loaded.

bone$ cd /opt/source/bb.org-overlays
bone$ ls
COPYING  dtc-overlay.sh  include     jenkins_build.sh  Makefile          readme.md  src
debian   examples        install.sh  Jenkinsfile       readme-legacy.md  scripts    tools

If the cd fails you will have to clone the repository.

bone$ git clone https://github.com/beagleboard/bb.org-overlays
bone$ cd bb.org-overlays

Either way

bone$ cd src/arm
bone$ ls *W1*
BB-W1-P9.12-00A0.dts
bone$ less *W1*

Page down a ways to see

       fragment@3 {
               target-path="/";
               __overlay__ {

                       onewire {
                               status = "okay";
                               pinctrl-names = "default";
                               pinctrl-0 = <&dallas_w1_pins>;

                               compatible = "w1-gpio";
                               gpios = <&gpio1 28 GPIO_ACTIVE_HIGH>;
                       };
               };
       };
};

gpio3, pin 28 is P9_12.

Reading the DS18B20

bone$ cd /sys/bus/w1/devices
bone$ ls
28-00000829ed85  w1_bus_master1

You should see two directories, the first will have a different number than mine. The number is the serial number of your DS18B20, which is unique to each device.

bone$ cd 28-00000829ed85
bone$ ls
driver  id  name  power  subsystem  uevent  w1_slave
bone$ cat w1_slave 
87 01 4b 46 7f ff 09 10 48 : crc=48 YES
87 01 4b 46 7f ff 09 10 48 t=24437

The t=24437 is the temperature in C times 1000, that is, divide this number by 1000 to get the temp in C.

Warm up the probe and see what happens to the temp.

Using a Different GPIO Pin

You can use pins other than the P9_12. Follow the unconfiguring instructions for the GPIO pin of your choice. Then

bone$ cd /opt/source/bb.org-overlays/sr/arm
bone$ cp BB-W1-P9.12-00A0.dts BB-W1-P9.14-00A0.dts

Substitute your pin number for P9.14. Then edit your newly created file and switch all the occurrences of P9_12 and P9.12 to the new pin number.

bone$ cd /opt/source/bb.org-overlays
bone$ make install
bone$ echo BB-W1-P9.14 > $SLOTS

Wire your DS18B20 to the new pin and test it.



thumb‎ Embedded Linux Class by Mark A. Yoder