解决树莓派新内核无法使用18B20和没有声音的问题

现在新版的树莓派内核由于为了兼容树莓派2和树莓派B+等以前的版本,采用了和原来不同的内核运行方式,使用了设备树的方式,更加灵活。但是由于可能不习惯这样的方式以及没太多相关这方面的介绍,导致很多用户更新了内核后出现比如接18B20无法读取设备信息,以及树莓派没有声音输出的问题。
在这里细心的用户就会发现在新内核boot分区下多了个overlays文件夹,里面有很多dtb文件,这些其实就是树莓派的设备树,打开README,就可以知道该怎么使用了。

下面是来自README的话:

Introduction
============
This directory contains Device Tree overlays. Device Tree makes it possible
to support many hardware configurations with a single kernel and without the
need to explicitly load or blacklist kernel modules. Note that this isn‘t a
"pure" Device Tree configuration (c.f. MACH_BCM2835) - some on-board devices
are still configured by the board support code, but the intention is to
eventually reach that goal.
On Raspberry Pi, Device Tree usage is controlled from /boot/config.txt. By
default, the Raspberry Pi kernel boots with device tree enabled. You can
completely disable DT usage (for now) by adding:
    device_tree=
to your config.txt, which should cause your Pi to revert to the old way of
doing things after a reboot.

如果要禁用设备树就直接在boot/config.txt里写device_tree=然后保存重启即可。
那么我们要怎么使用设备树呢?就拿启用W1来读取18B20数据来说,Readme里有这样一段:

Using Overlays
==============
Overlays are loaded using the "dtoverlay" directive. As an example, consider the
popular lirc-rpi module, the Linux Infrared Remote Control driver. In the
pre-DT world this would be loaded from /etc/modules, with an explicit
"modprobe lirc-rpi" command, or programmatically by lircd. With DT enabled,
this becomes a line in config.txt:
    dtoverlay=lirc-rpi
This causes the file /boot/overlays/lirc-rpi-overlay.dtb to be loaded. By
default it will use GPIOs 17 (out) and 18 (in), but this can be modified using
DT parameters:
    dtoverlay=lirc-rpi,gpio_out_pin=17,gpio_in_pin=13
Parameters always have default values, although in some cases (e.g. "w1-gpio")
it is necessary to provided multiple overlays in order to get the desired
behaviour. See the list of overlays below for a description of the parameters and their defaults.

也就是说,在使用config.txt里添加dtoverlay=【设备树名】来启动设备树,同样也可以在这里指定加载的设备树参数,实际上这个操作就和之前的内核在系统里添加模块类似,只不过这里是在内核启动的时候加载,之前的是在系统启动后加载。
那么我们就可以照搬添加w1到config.txt里面然后重启读取18B20了,Readme里也有相关参数说明:

Name:   w1-gpio
Info:   Configures the w1-gpio Onewire interface module.
        Use this overlay if you *don‘t* need a GPIO to drive an external pullup.
Load:   dtoverlay=w1-gpio,<param>=<val>
Params: gpiopin                  GPIO for I/O (default "4")
        pullup                   Non-zero, "on", or "y" to enable the parasitic
                                 power (2-wire, power-on-data) feature
Name:   w1-gpio-pullup
Info:   Configures the w1-gpio Onewire interface module.
        Use this overlay if you *do* need a GPIO to drive an external pullup.
Load:   dtoverlay=w1-gpio-pullup,<param>=<val>,...
Params: gpiopin                  GPIO for I/O (default "4")
        pullup                   Non-zero, "on", or "y" to enable the parasitic
                                 power (2-wire, power-on-data) feature
        extpullup                GPIO for external pullup (default "5")

这里提供了更多的参数进行选择,如果你打算采用寄生的连接方式这里也提供了参数实现内部上拉,当然如果你想保留原来的连接电路方式不进行电路改动的话那么我们就这样设置好了:
在config.txt里插入下面的内容:
dtoverlay=w1-gpio-pullup,gpiopin=4
这样就可以按照原来的电路连接方式连接18B20,保存重启后一样的载入w1-gpio和w1-therm后就可以读取到18B20数据了。
如果你要启用树莓派的音频的话,在里面添加一行
audio=on即可,新版的内核禁用了audio的原因是因为树莓派PWM和audio使用的是同一个接口,可能介于很多人希望使用树莓派的硬件PWM的原因,所以才这样灵活的设计让大家有更多自由使用的空间。
Readme关于audio和pwm的原文:

he Overlay and Parameter Reference
===================================
N.B. When editing this file, please preserve the indentation levels to make it simple to parse
programmatically. NO HARD TABS.
Name:   <The base DTB>
Info:   Configures the base Raspberry Pi hardware
Load:   <loaded automatically>
Params:
        audio                    Set to "on" to enable the onboard ALSA audio
                                 interface (default "off")

====================

Name:   pwm
Info:   Configures a single PWM channel
        Legal pin,function combinations for each channel:
          PWM0: 12,4(Alt0) 18,2(Alt5) 40,4(Alt0)            52,5(Alt1)
          PWM1: 13,4(Alt0) 19,2(Alt5) 41,4(Alt0) 45,4(Alt0) 53,5(Alt1)
        N.B.:
          1) Pin 18 is the only one available on all platforms, and
             it is the one used by the I2S audio interface.
             Pins 12 and 13 might be better choices on an A+, B+ or Pi2.
          2) The onboard analogue audio output uses both PWM channels.
          3) So be careful mixing audio and PWM.
          4) Currently the clock must have been enabled and configured
             by other means.
Load:   dtoverlay=pwm-2chan,<param>=<val>
Load:   dtoverlay=pwm,<param>=<val>
Params: pin                      Output pin (default 18) - see table
        func                     Pin function (default 2 = Alt5) - see above
        clock                    PWM clock frequency (informational)
Name:   pwm-2chan
Info:   Configures both PWM channels
        Legal pin,function combinations for each channel:
          PWM0: 12,4(Alt0) 18,2(Alt5) 40,4(Alt0)            52,5(Alt1)
          PWM1: 13,4(Alt0) 19,2(Alt5) 41,4(Alt0) 45,4(Alt0) 53,5(Alt1)
        N.B.:
          1) Pin 18 is the only one available on all platforms, and
             it is the one used by the I2S audio interface.
             Pins 12 and 13 might be better choices on an A+, B+ or Pi2.
          2) The onboard analogue audio output uses both PWM channels.
          3) So be careful mixing audio and PWM.
          4) Currently the clock must have been enabled and configured
             by other means.
Load:   dtoverlay=pwm-2chan,<param>=<val>
Params: pin                      Output pin (default 18) - see table
        pin2                     Output pin for other channel (default 19)
        func                     Pin function (default 2 = Alt5) - see above
        func2                    Function for pin2 (default 2 = Alt5)
        clock                    PWM clock frequency (informational)

更多信息大家自己去阅读/boot/overlays/README

时间: 2024-08-24 11:01:15

解决树莓派新内核无法使用18B20和没有声音的问题的相关文章

s3c2440液晶屏驱动新内核 linux-4.1.24

自带有一部分驱动的配置信息,只要修改这部分就能支援 不同的液晶屏 - /arch/arm/mach-s3c24xx/mach-smdk2440.c 另一部分在 /drivers/video/fbdev/s3c2410fb.c 先打开调试功能,这样内核在启动的时候,就可以输出这些信息,或者使用 dmesg 查看到这些信息.当然,你配置内核 make menuconfig 也可以打开,但是太麻烦了,不如这样. 1 #define CONFIG_FB_S3C2410_DEBUG 2 #define d

解决在IE8中无法使用原生JSON的问题

转自:http://www.iitshare.com/ie8-not-use-native-json.html 起因 在项目中要将页面上的js对象传给后台,想到可以用json转成字符串传递. 1 2 var obj = {"a":1 "b":2, "c":3}; var str = JSON.stringify(obj); 上述代码在firefox,chrome中测试都没问题,可是在ie8下确提示JSON Not Defined,google了一

centos升级新内核所遇问题。

今天在centos升级到内核linux.4.4.28的时候没有成功,中途报错大概如下: ***waiting for unfinished jobs...... make:INTERNAL:Exiting with 13 jobserver tokens available: should be 12! 如果出现以上报错是因为没有安装 openssl的原因,需要yum安装下openssl,操作如下: 1. 网络配通后配置好DNS. 2. yum  -y groupinstall "base&qu

12.解决CCScale9Sprite或者CCControlButton无法使用的问题。

问题: 使用CCScale9Sprite或者CCControlButton等控件的时候,会出现无法识别的情况. 解决方案: 1.include相应的头部,即#include "cocos-ext.h" 2.使用相应的命名空间,USING_NS_CC_EXT; 3.右击项目---->属性---->VC++目录---->包含目录---->添加extensions文件夹路径. 4.在属性面板展开C/C++的常规---->附加包含目录---->添加$(Sol

教你如何快速编译安装新内核

随着内核版本的更新换代,你是否有觉得自己的内核版本有些低了呢?如果有的话,没关系,今天小编就来教大家如何编译安装新的内核. 在编译安装内核之前先检查我们的虚拟机所在的磁盘空间,预留空间10G以上,不然编译安装内核无法完成.下面我们就开始内核的编译安装吧. (1)下载源码文件 先在内核官网(www.kernel.org/)上下载最新版本的内核到桌面上,然后rz拷到linux系统上,找到一个空目录如/app/tmp,将之移到/app/tmp中,然后再解包解压,就会生成一个目录 (2)准备文本配置文件

解决挂载新硬盘原有目录下文件消失的方法

新硬盘挂载目录后文件消失解决办法 版权声明:本文为博主原创文章,未经博主允许不得转载. 项目初期用户文件较少,全部存储在/home目录下,/home目录没有单独划开分区,随着项目网站做大,用户文件越来越多,/home目录不够空间,想挂载一个新硬盘来负责储存 但发现新挂载/home到新硬盘时,/home原来数据变空了,这个原因是由于Linux的VFS(虚拟文件系统)机制导致的,正常登录以后,所看到的各个目录,文件都是内核在加载时候构造在内存中的VFS目录树,而不是直接看到硬盘上的实际目录树.当你挂

linux设备上的Onvif 实现21:解决大华摄像头无法使用问题

好长时间没有再写该系列文章了,最近刚好摸索着解决了大华摄像头无法使用问题,记录下来,应该对其他博友有所帮助.之前虽然写了一大堆文章说明了如何使用gsoap连接摄像头,但这是针对一台海康的摄像头开发的,一旦使用了同品牌不同型号摄像头或者其他牌子的摄像头就可能出现兼容性问题,导致无法使用.我就是碰到了这个问题,测试过的多个品牌型号摄像头,有的能直接使用,有的不能使用,问题各部相同.本文就是针对大华摄像头的问题解决过程说明. 摄像头型号:DH-IPC-HDW130S-0600B MAC:90:02:A

Ubuntu 10.04下更行新内核

1. 查看需要更新的内核命令: apt-cache search linux    该命令将会显示所有可以获取的内核 2. sudo apt-get install linux-source-2.6.32  安装所选则的内核  或者去www.kernel.org下载 3. 在/usr/src/目录下会有下载下来的内核  解压缩并且配置内核 编译内核和模块 安装内核和模块(可以通过make help命令查看 make可以执行的动作) 4. cd /lib/modules/2.6.32.63+drm

给虚拟机中的ubuntu安装新内核

主机操作系统版本:Windows 10虚拟机版本:Workstation 12 Pro虚拟机操作系统:Ubuntu 14.04Linux内核:3.13.0gcc版本:4.8.2 最近学习linux内核,不少比较经典的书籍都是以2.6.x源码进行讲解的.所以打算在linux虚拟机中安装一个2.6.36的内核.步骤如下: (一)下载源码        内核下载官网:www.kernel.org        下载linux-2.6.36.tar.gz并解压到/usr/src目录下        进入