Categories

Raspberry Pi and touch button

RaspberryPi and touch button

Quick start guide presented how to connect RaspberryPi and touch button.

 

In this example we used the following elements:

 

Connection with the RaspberryPi

You need to connect both devices at the table

 

GPIO Raspberry PiTouch button
5 VVCC
GNDGND

1

OUT

 


Wiring diagram for touch buttons with RaspberryPi.

Service

In order to use GPIO pins in the Raspberry we need a library that permits us to do it. For this we will use the library wiringPi. Description how to download and install find here. Simply copy the following command. In the end, to test your install enter:

 

  • gpio readall

After this command we should see the following table:

 

 

Now we will write a simple program. Create a file dotykowy.cpp

 

  • nano dotykowy.cpp

 

The file should contain the following programs:

#include  
#include  
using namespace std; 

int sensor = 1; //GPIO1 pin associated with the signal czujnikia 

int main(void) 
{ 
 wiringPiSetup(); 
 pinMode(sensor, INPUT); //adjustment the contact of the RaspberryPi as the entrance 

 cout<<endl<<"---- TEST TOUCH BUTTON ----"<<endl<<endl; 


 while(1) 
 { 
 int war = digitalRead(sensor); //read the value from the sensor 
 if (war == LOW) //display information on the screen 
 { //status low means that the detection of the touch, the high status - it is not 
 cout<<" Found contact"<<endl; 
 } 
 else 
 { 
 cout<<"free"<<endl; 
 } 
 delay(200); //delay between consecutive readings 
 } 
} 

 

Then save the changes to the file and close it. To compile the file you created, use the command:

 

  • g++ -Wall -o touch.on dotykowy.cpp -lwiringPi

     

The program is run using the following command:

 

  • sudo ./touch.on

 

The result of the program can be viewed on the monitor:

 

 

The screen of the monitor.