Hardware Reference
In-Depth Information
From a programmatical point of view, the software is a simple to write as for any of the other protocols. In Python
you can use the standard library and write:
import spi
spi.initialize()
spi.transfer((1,2,3))
Or, with C, there is a test program from the Linux kernel itself at http://git.kernel.org/cgit/linux/kernel/
git/torvalds/linux.git/plain/Documentation/spi/spidev_test.c .
With Arduino Shields
Although it's true that the Arduino shields are a big selling point, it's not necessarily true to say that you must have an
Arduino to use them. Cooking Hacks ( http://www.cooking-hacks.com ) have produced a connection bridge that sits
atop of your Raspberry Pi and allows you to add Arduino shields to the Pi directly.
The bridge comes with the arduPi library that mimics the API of the Arduino; so all the traditional functions of
digitalRead and readBytes are still available. You can therefore write standard Arduino code, provided that you add
your own main function:
#include "arduPi.h"
// Insert your usual setup and loop methods here
int main (int argc, char *argv[]) {
setup();
while(1){
loop();
}
return (0);
}
The rest of the code can be copied directly from the original Arduino source, and then compiled and run in the
normal way.
N The arduPi library has been released under the GPL, and so is usable for other Linux machines, should you wish to
emulate the Arduino, test your software in another environment, or even try and to connect the shields to a desktop machine!
Note
The hardware component involves a little more work because the voltage level of the Raspberry Pi GPIO is 3.3v,
whereas the original Arduino uses 5v throughout. Unfortunately, the bridge doesn't handle this hardware conversion
as well as it does the software. Therefore, all 5v input signals need to be scaled down to 3.3v, which can be done with a
5K/10K potential divider circuit. Alternatively, look to the more recent versions of Arduino, and their clones, as many
of the new ones can be switched between 5v and 3.3v that eradicates this problem.
Similarly, the 3.3v digital output will need to be upgraded, perhaps with a transistor switching circuit as we saw
in Figure 2-5. For those with more exotic components, you can build a level shifter with two 2N7000 MOSFETs and a
circuit not dissimilar to http://www.hobbytronics.co.uk/mosfet-voltage-level-converter , or buy a prebuild level
converter such as http://www.skpang.co.uk/catalog/logic-level-converter-p-511.html .
 
Search WWH ::




Custom Search