简体   繁体   English

使用Raspberry Pi 2b GPIO引脚检查电压

[英]Check For Voltage With A Raspberry Pi 2b GPIO Pin

I want to build a simple (game)controller for my raspberry pi 2b. 我想为我的树莓派2b构建一个简单的(游戏)控制器。 My plan is to connect the 3.3 voltage output to a button and than to whatever GPIO pin. 我的计划是将3.3电压输出连接到按钮,而不是任何GPIO引脚。

Is it possible to check for voltage with the GPIO pin? 可以通过GPIO引脚检查电压吗? Or are there more smoother ways to build one (Analog to Digital)? 还是有更平滑的方法来构建一个(模拟到数字)?

Please respect that I am developing in Visual Studio 2015 C# and my RP-OS is Windows 10. 请注意,我正在Visual Studio 2015 C#中进行开发,我的RP-OS是Windows 10。

You can read the status of the pin (High/Low) or you can use interrupts to receive events when the status changes. 您可以读取引脚的状态(高/低),也可以在状态更改时使用中断来接收事件。

The button and LED project is the very first examples either on the Raspberry Pi site or Windows IoT site . Raspberry Pi站点Windows IoT站点上,按钮和LED项目是第一个示例。 The PushButton sample for C# uses interrupts to detect status changes. C#的PushButton示例使用中断来检测状态更改。

The OS or language doesn't matter so much as the fact that you are using an RPi. 操作系统或语言与使用RPi无关紧要。 In order to work with a pin, you need to open it, set its mode and then, either retrieve its value periodically ,or listen to an interrupt. 为了使用引脚,您需要先将其打开,设置其模式,然后定期检索其值或侦听中断。

In the sample, the following steps are taken: 在示例中,执行以下步骤:

  • Open the button pin: buttonPin = gpio.OpenPin(BUTTON_PIN); 打开按钮图钉: buttonPin = gpio.OpenPin(BUTTON_PIN);
  • Set it as input: buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp) ; 将其设置为输入: buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp) ;
  • Listen to the interrupt with an event handler: buttonPin.ValueChanged += buttonPin_ValueChanged; 使用事件处理程序监听中断: buttonPin.ValueChanged += buttonPin_ValueChanged;

Generally speaking, you should work with both Raspbian and Windows IoT to understand how RPi behaves: 一般来说,您应该同时使用Raspbian和Windows IoT来了解RPi的行为:

  • Windows IoT doesn't yet support RPi's full functionality yet so there are things that are far easier to do with Raspbian than Windows IoT, eg using temperature sensors or any device with 1-Wire support. Windows IoT尚不支持RPi的全部功能,因此与Windows IoT相比,使用Raspbian要做的事情要容易得多,例如使用温度传感器或任何具有1-Wire支持的设备。
  • Sensor manufacturers provide samples, code and even libraries for Rapsbian or Arduino. 传感器制造商为Rapsbian或Arduino提供示例,代码甚至库。 Getting the sensor to work is hard enough, you shouldn't have to translate from Raspbian to Windows IoT as well. 使传感器正常工作已经足够困难,您也不必从Raspbian转换为Windows IoT。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM