美文网首页
树莓派2上开启SPI

树莓派2上开启SPI

作者: 浪尖儿 | 来源:发表于2016-08-17 17:43 被阅读0次

树莓派2上面启用spi的方法和树莓派1不太一样。网上关于1代的设置方法很多,好不容易找到一个适合2代用的设置方法,相比起来简单了不少。最简单的方法当然是raspi-config!

树莓派2上开启SPI

The Raspberry Pi has a Serial Peripheral Interface (SPI) bus which can be enabled on Pins 19,21,23,24 & 26. It is a synchronous serial data link standard and is used for short distance single master communication between devices. As far as the Pi is concerned this is usually relevant to certain sensors and add-on boards.

There is more technical information about SPI on the SPI Wikipedia page if you are interested.
The default Raspbian image disables SPI by default so before you can use it the interface must be enabled. This can be done uses either of two methods. I’ll describe both methods but the first one is probably easier and quicker.

Method 1 – Enabling Using Raspi-config

Start by running the following command :

sudo raspi-config

This will launch the raspi-config utility. Select option 8 “Advanced Options”.

step1

Select the “SPI” option.

step2

Set the option to “Yes”.

step3

Select “OK”.

step4

Select “Finish”.

step5

Reboot for the changes to take effect :

sudo reboot

SPI is now enabled.

Method 2 – Enabling By Editing A File Manually

This process assumes you are using the latest Raspbian build from the official downloads page. You can update your current image using :

sudo apt-get update
sudo apt-get upgrade

To enable hardware SPI on the Pi we need to make a modification to a system file :

sudo nano /boot/config.txt

Add the following line at the bottom :

dtparam=spi=on

Use CTRL-X, then Y, then RETURN to save the file and exit. Reboot using the following :

sudo reboot

Checking If SPI Is Enabled (Optional)To check if the SPI module is loaded by the system run the following command :

lsmod

You should see “spi_bcm2708″ listed in the output. You can use the following command to filter the list and make it easier to spot the spi entry :

lsmod | grep spi_

SPI is now enabled.

Install Python SPI Wrapper (Optional)In order to read data from the SPI bus in Python we can install a library called ‘py-spidev’. To install it we first need to install ‘python-dev’ :

sudo apt-get install python2.7-dev

Then to finish we can download ‘py-spidev’ and compile it ready for use :

wget https://github.com/Gadgetoid/py-spidev/archive/master.zip
unzip master.zip
rm master.zip
cd py-spidev-master
sudo python setup.py install
cd ..

You should now be ready to either communicate with add-on boards using their own libraries (e.g. the PiFace) or other SPI devices (e.g. the MCP3008 ADC).

相关文章

  • 树莓派2上开启SPI

    树莓派2上面启用spi的方法和树莓派1不太一样。网上关于1代的设置方法很多,好不容易找到一个适合2代用的设置方法,...

  • 树莓派技术网站导航

    树莓派官网 安装 树莓派Mac OS X下安装系统开启ssh登陆 使用教程 树莓派实验室树莓派吧树莓派中文站 项目...

  • 尝试--树莓派i2c接口SHT30的使用

    给树莓派安装SHT30 由于买来的SHT30已经接好电路,直接用杜邦线连接树莓派即可。 完美 树莓派开启i2c 参...

  • vscode remote 远程在树莓派开发

    树莓派:开启树莓派的ssh服务 本地:1.vscode 安装 Remote-SSH 插件2.安装git3.git ...

  • 树莓派连接WiFi实现无线上网

    问题:我的树莓派怎么上网呢? 解答: 树莓派基金会于2016年2月发布了树莓派3,较前一代树莓派2,树莓派3的处理...

  • 树莓派针脚图

    树莓派40Pin引脚对照表 本表格适用于树莓派B+、树莓派2B、树莓派A+,并且兼容树莓派B,树莓派B为26Pin...

  • 树莓派上手资料

    树莓派开箱上手教程树莓派下载资料使用手机连接树莓派1使用手机连接树莓派2树莓派实验室无显示屏启动树莓派 如何用pu...

  • 12.树莓派SPI屏幕模块驱动安装教程

    树莓派SPI屏幕需要安装相应的驱动,软件,以及一些配置文件才可正常使用,相对稍许繁琐,之前本人制作的SPI屏幕集成...

  • 树莓派与笔记本直接通过wifi(无线)直接连接

    所需环境: 一台可以开启wifi热点的笔记本,树莓派 开启电脑热点后,树莓派连接电脑的热点就可以直接登...

  • python玩转树莓派(六) IIC 及 smbus2

    一. 开启IIC 树莓派的IIC默认是关闭的, 需要配置开启 1. 方法一. 图形界面 2. 方法二. 终端开启 ...

网友评论

      本文标题:树莓派2上开启SPI

      本文链接:https://www.haomeiwen.com/subject/cxgmsttx.html