树莓派2上开启SPI

树莓派2上开启SPI,第1张

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

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.

Start by running the following command :

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

Select the “SPI” option.

Set the option to “Yes”.

Select “OK”.

Select “Finish”.

Reboot for the changes to take effect :

SPI is now enabled.

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

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

Add the following line at the bottom :

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

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

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 :

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’ :

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

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).

第一步、两个树莓派在同一网络环境下。下载mpich2源码并解压

sudo apt-get install gfortran

sudo apt-get install mpich2

mpicc cpi.c -o cpi

----------------------------------------------------------

第二步、设置

vi /etc/hosts

添加

***.***.***.*** rpi2-1

***.***.***.*** rpi2-2

新建machinefile,并添加两台机器的ip

设置无密码登陆

 ssh-keygen -t rsa -C "your name"

 cat ~/.ssh/id_rsa.pub | ssh [email protected] "mkdir .sshcat >> .ssh/authorized_keys"

用ssh做下无密码登陆测试

第三步、测试

mpiexec -f machinefile -n 4 ./cpi

-----------------------------------------------------------------------------

写在后面,树莓派性能并不高,ARM架构的cpu和X86的还是没法比,即使多台并行运算编译代码的能力和速度还是不能和服务器相提并论


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/7695209.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-08
下一篇 2023-04-08

发表评论

登录后才能评论

评论列表(0条)

保存