RaspberryPi and touch button
A short guide showing how to connect the RaspberryPi and the touch button.
The following elements are used in the example:
Connection with RaspberryPi
The two devices shall be combined as shown in the table below
GPIO Raspberry Pi | Touch button |
---|---|
5 V | VCC |
GND | GND |
1 |
OUT |
Diagram of how to connect a touch button to RaspberryPi.
Operation
To use the GPIO pins in Raspberry we need a library that allows us to do so. For this we will use the wiringPi library. Description how to download and install it can be found here. Just copy the next commands. Finally, to check the correctness of the installation, type in:
-
gpio readall
After this command we should see the table below:
Now we will write a simple program. We create a touch file.cpp
-
nano touch.cpp
The file should contain the following program:
#include#include using namespace std; int sensor = 1; //pin GPIO1 connected to the signal from the sensor int main(void) { wiringPiSetup(); pinMode(sensor, INPUT); // setting the RaspberryPi pin as input cout<
Then save the changes to the file and close it. To compile the created file we use the command:
-
g++ -Wall -o touch.o touch.cpp -lwiringPi
The program is started with the following command:
-
sudo ./contact.o
The result of the program can be viewed on the monitor:
Screenshot of the monitor.