Ako pridat GPIO do RPi

The WiringPi project is a library that includes an application for easy GPIO access.
For PWM it allows to configure hardware modules for dedicated PWM pins as well as using a software PWM solution on other pins.
Install WiringPi (WiringPi uses git, a source code management system):
sudo apt-get install git-core
Download or „clone“ the WiringPi project and build it:
git clone git://git.drogon.net/wiringPi
If you have already downloaded it, you can update to the latest version:
cd wiringPi
git pull origin
In order to use the WiringPi application you need to know the pin assignments related to it, which are explained in this site: https://projects.drogon.net/raspberry-pi/wiringpi/pins/
Using a HW module for PWM. Connect an LED using a resistor between GPIO18 and GND. (Pin 1 for WiringPi)
Refer to the „man page“ of the recently installed WiringPi program called „gpio“:
man gpio
Notice that you can configure a pin to be in, out, pwm, up, down or tri.
According to it, configure GPIO18 (WiringPi Pin 1) in HW PWM Mode using the command shell:
gpio mode 1 pwm
Write a value to the PWM module (from 1 to 1023):
gpio pwm 1 500
To remove the configuration of the pin, use:
gpio unexport 1
To remove all configurations:
gpio unexportall
Feel free to use the gpio program to configure other pins as input or output (PWM is only for special function pins like GPIO18(WiringPi 1), other PWM pins are occupied by the 3.5mm audio connector.
Using wiringPi.h and softPwm.h with C.
This is a code example using wiringPi to configure a Soft-PWM pin.

Napísať komentár