Hardware Reference
In-Depth Information
Compile the arduPi library and a program using it
As arduPi is a C++ library, we will use g++ to compile it. You can compile the arduPi
library to obtain an object file ( .o ) and use this file to link your program: g++ -c ardu
Pi.cpp -o arduPi.o .
Once you have already compiled the arduPi library, you can run:
$ g++ -lrt -lpthread my_program.cpp arduPi.o -o my_program
If the arduPi library is not yet compiled, you can compile both it and your program and
link them in a single step:
$ g++ -lrt -lpthread my_program.cpp arduPi.cpp -o my_program
The -lrt flag is necesary because the library uses the function clock_gettime
(time.h) . The -lpthread option is needed because attachInterrupt() and detachIn
terrupt() functions use threads.
Run your program
Now, to run your program, you must have the right permissions in order to use GPIO
so that /dev/mem can be accessed on the Raspberry Pi. Then you simply run the fol-
lowing command:
sudo ./my_program
GPIO input
GPIO peripherals vary quite widely. In some cases, they are simple: a group of pins
that can be switched as a group to either input or output. The input and output voltages
are typically, though not universally, limited to the supply voltage of the device with
the GPIOs on and may be damaged by greater voltages.
Some GPIOs have 5 V tolerant inputs, and even on low-supply voltages the device can
accept 5 V without damage. For the Raspberry Pi, you must adapt the voltage level of
a 5 V sensor to prevent possible damage. If you don't have an assortment of parts
readily available, you can reproduce these instructions with the contents of Cooking
Hacks' Starter Kit for Raspberry Pi, A/V Edition .
GPIO voltage levels are 3.3 V and are not 5 V tolerant. There is no over-voltage
protection on the board. Digital inputs use a 3.3 V logic level and are not tolerant
of 5 V levels, such as you might find on a 5 V powered Arduino. Use extreme caution
when working with GPIO. You might damage your Raspberry Pi or your other
equipment and potentially shock yourself.
 
Search WWH ::




Custom Search