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 gfortransudo 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 ubuntu@192.168.3.18 "mkdir .sshcat >> .ssh/authorized_keys"
用ssh做下无密码登陆测试
第三步、测试
mpiexec -f machinefile -n 4 ./cpi-----------------------------------------------------------------------------
写在后面,树莓派性能并不高,ARM架构的cpu和X86的还是没法比,即使多台并行运算编译代码的能力和速度还是不能和服务器相提并论
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)