Welcome to Raspberry Pi 4B repository
3.Pin output level
!Note:
The maximum continuous input and output voltage of the Raspberry Pi's GPIO pin is 3.3V. Do not connect it directly with other electronic components, otherwise it will damage the Raspberry Pi.
Step 1:Create a file to store the project
nano gpio.c
Step 2: Writing code
#include<stdio.h>
#include<wiringPi.h> //Import wiringPi.h library
#define GPIO0 0 //Define GPIO0 as pin 0 of wPi, corresponding to GPIO0
int main()
{
printf("This is an example of controlling the high and low levels of GPIO pin outputn");
wiringPiSetup(); //Initialize wiringPi
pinMode(GPIO0,OUTPUT); //Set GPIO0 to output mode
printf("Set GPIO0 : Hn");
digitalWrite(GPIO0,HIGH); //GPIO0 output high level
//printf("Set GPIO0 : Ln");
//digitalWrite(GPIO0,LOW); //GPIO0 output low level
while(1)
{
}
return 0;
}
After writing, press Ctrl + X to exit this file.
The system will prompt you whether you need to save, press Y to save and exit.
Step 3: Compile this .c file.
gcc gpio.c -o gpio -lwiringPi
Step 4: Run this code
./gpio
Step 5: Press Ctrl + C
Step 6: Check the pin status of the Raspberry Pi.
gpio readall
We can know that the GPIO0 is OUT mode, and V (state) is 1 (high level).
Step 7: Modify code
#include<stdio.h>
#include<wiringPi.h> //Import wiringPi.h library
#define GPIO0 0 //Define GPIO0 as pin 0 of wPi, corresponding to GPIO0
int main()
{
printf("This is an example of controlling the high and low levels of GPIO pin outputn");
wiringPiSetup(); //Initialize wiringPi
pinMode(GPIO0,OUTPUT); //Set GPIO0 to output mode
//printf("Set GPIO0 : Hn");
//digitalWrite(GPIO0,HIGH); //GPIO0 output high level
printf("Set GPIO0 : Ln");
digitalWrite(GPIO0,LOW); //GPIO0 output low level
while(1)
{
}
return 0;
}
After writing, press Ctrl + X to exit this file.
The system will prompt you whether you need to save, press Y to save and exi
Step 3: Compile this .c file.
gcc gpio.c -o gpio -lwiringPi
Step 4: Run this code
./gpio
Step 5: Press Ctrl + C
Step 6: Check the pin status of the Raspberry Pi.
gpio readall
We can know that the GPIO0 is OUT mode, and V (state) is 0 (low level).