TO BE UPDATED. GUIDE MIGHT STILL WORK.
Library to control GPIO / PWM on the Raspberry Pi using wiringPi
Steps on this page are derived from http://wiringpi.com/download-and-install/
No additional packages are required
Note: As compilation-process of the library polls several hardware features, the library itself cannot be crosscompiled and needs to be build on the RPi itself.
src
dir of rootfs
.
XCS~$ cd ~/rpi/rootfs/usr/src
XCS~$ git clone git://git.drogon.net/wiringPi
rootfs
. The upcoming build process does not create it, while it is needed for cmake to build and cross-compile code depending on wiringPi.
XCS~$ cp ~/rpicross_notes/hello/wiringpi/wiringpi.pc ~/rpi/rootfs/usr/share/pkgconfig/
rootfs
to RPi
XCS~$ ~/rpicross-notes/scripts/sync—vm-rpi.sh
XCS~$ ssh rpizer-local
RPI~$ cd /usr/src/wiringPi
RPI~$ sudo ./build
XCS~$ ~/rpicross-notes/scripts/sync-rpi-xcs.sh
Testing the compiled and installed wiringPi libraries with a PWM signal.
Prerequisites:
Steps:
To see a fading LED, you should connect a LED to GPIO18. How to connect the LED is described here.
XCS~$ mkdir -p ~/rpi/build/hello/wiringpi
XCS~$ cd ~/rpi/build/hello/wiringpi
XCS~$ cmake \
-D CMAKE_TOOLCHAIN_FILE=/home/pi/rpicross_notes/rpi-generic-toolchain.cmake \
~/rpicross_notes/hello/wiringpi
XCS~$ make
XCS~$ scp wpi rpizero-local:~/
XCS~$ ssh -X rpizero-local
RPI~$ sudo ./wpi
Raspberry Pi wiringPi PWM test program
Iteration: 5/ 5 - Brightness: 0/1024
Done
When an application uses both wiringPi
and requires Xserver to run the application, errors might be encountered when using sudo
:
...
X11 connection rejected because of wrong authentication.
...
This error means that the created connection to Xserver does not allow root
to setup a window. Presumably, the original connection to the RPi was created by the user pi
:
XCS~$ ssh -X pi@rpizero-local
When connecting via SSH as root
does not pose a (security) problem, this might solve the problem:
XCS~$ ssh -X root@rpizero-local
Luckily, a simple and more secure solution exists:
XCS~$ ssh -X pi@rpizero-local
RPi~$ su -pc ./flashcam
This will execute the application with root-privileges, while maintaining the current environment variables (and hence the XAUTHORITY
settings of the pi
user).
A more secure way is to allow root
to use the same XAUTHORITY
settings as the pi
-user:
bashrc
of root
: XCS~$ ssh -X pi@rpizero-local
RPi~$ su - root
RPi~root$ nano ~/.bashrc
export XAUTHORITY=/home/user/.Xauthority
RPi~root$ exit
RPi~$ su
RPi~root$ ./flashcam
RPi~root$ exit