Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of GPIO

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

What is the use of GPIO? in view of this problem, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

What is GPIO?

GPIO is the abbreviation of General Purpose Input Output, that is, "general input and output". Raspberry Pi has two lines of GPIO pins through which Raspberry Pi makes some hardware extensions, interacts with sensors, and so on.

To put it simply, each GPIO pin has two modes: output mode (OUTPUT) and input mode (INPUT). The output mode is similar to a power supply. Raspberry Pi can control whether the power supply is supplied to the outside, such as turning on the external LED lights, and of course the most useful thing is to send a signal to the external device. The input mode is equivalent to the cathode of the power supply, or take the LED small lamp as an example, but this time the anode of the LED small lamp is connected to the external power supply, and a circuit will have current only when there is a voltage difference, so if you want to make the small light bright, you need to let the current flow into the Raspberry Pi. In contrast to the output mode, the input mode receives signals from external devices.

GPIO usually uses standard logic levels, that is, high and low levels, represented by binary zeros and ones. There is also a threshold level between these two values, that is, the boundary between high level and low level. Arduino will read-0.5V to 1.5V as low level, 3V to 5.5V as high level, and Raspberry Pi has not found any related data. GPIO can also be used for interrupt requests, that is, setting GPIO as the input mode and interrupting when the value reaches the corresponding requirements.

Related classes (Class)

Here by default you are object-oriented programmers, with a certain C # foundation, here only introduce what I think commonly used methods, the introduction will be reflected in the form of code comments.

The GPIO operation mainly depends on two classes: GpioController and GpioPin. These two classes are located under the System.Devices.Gpio namespace.

GpioController

GpioPin

Experiment of Human Infrared Sensor

Example address: https://github.com/ZhangGaoxing/dotnet-core-iot-demo/tree/master/src/PIR

Human infrared sensor is based on the infrared heat of the surrounding area to detect motion, also known as passive infrared sensor (Passive Infra-Red, PIR).

HC-SR501 is used here. When the human body is detected by the sensor, the LED light is on, and when the human body is not detected by the sensor, the LED light is off.

Sensor image

HC-SR501

Hardware name quantity HC-SR501x1LED small lamp x1220 Ω resistor x1 DuPont line several circuits

HC-SR501

VCC-5V

GND-GND

OUT-GPIO 17

LED

VCC & 220 Ω resistor-GPIO 27

GND-GND

Code

Open Visual Studio and create a new .NET Core console application with the project name "PIR".

Introduce the System.Devices.Gpio NuGet package.

Create a new class HCSR501 and replace the following code (here is a little concise, only necessary code, no custom events, see the example provided for details):

In Program.cs, replace the main function code as follows:

Publish, copy, change permissions, run

The answer to the question about the use of GPIO is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report