简体   繁体   English

尝试使用 Orange Pi Zero 上的 .Net Core 5 检测 GPIO 引脚的上升和下降。 引脚上升有时仅与引脚下降一起检测

[英]Trying to detect GPIO pin rise and falls using .Net Core 5 on Orange Pi Zero. Pin rise sometimes only detected together with Pin fall

I am trying to detect a change in a GPIO pin of an Orange Pi Zero (basically the same as the Raspberry Pi).我正在尝试检测 Orange Pi Zero 的 GPIO 引脚的变化(基本上与 Raspberry Pi 相同)。 it is running Armbian Buster (ie Debian 10)它正在运行 Armbian Buster(即 Debian 10)

I created a simple.Net Core 5 console app, using.Net's builtin System.Device.Gpio library, to detect this:我使用.Net 的内置System.Device.Gpio库创建了一个简单的.Net Core 5 控制台应用程序来检测:

public class GpioComms
{        
    GpioController _controller = new GpioController();

    public GpioComms()
    {
        _controller.OpenPin(10, PinMode.Input);
        _controller.RegisterCallbackForPinValueChangedEvent(10, PinEventTypes.Rising, onSignalPinRiseEvent);
        _controller.RegisterCallbackForPinValueChangedEvent(10, PinEventTypes.Falling, onSignalPinFallEvent);
    }

    private void onSignalPinRiseEvent(object sender, PinValueChangedEventArgs args)
    {
        Console.WriteLine(DateTime.Now + " " + args.PinNumber + " pin up");
    }

    private void onSignalPinFallEvent(object sender, PinValueChangedEventArgs args)
    {
        Console.WriteLine(DateTime.Now + " " + args.PinNumber + " pin down");
    }
}

I then wired a push button to GPIO pin 10 (physical pin 26 on the Orange Pi Zero) and ran the program.然后我将一个按钮连接到 GPIO 引脚 10(Orange Pi Zero 上的物理引脚 26)并运行程序。 When I push the button in, about half the time it detects this immediately.当我按下按钮时,大约有一半的时间它会立即检测到这一点。 When I release the push button, it always detects this immediately.当我松开按钮时,它总是会立即检测到这一点。 But about half the time, it doesn't detect the pushing of the button, and only when I release the button, does the onSignalPinRiseEvent even fire (together with the onSignalPinFallEvent event)但是大约有一半的时间,它没有检测到按钮的按下,只有当我释放按钮时,onSignalPinRiseEvent 才会触发(连同 onSignalPinFallEvent 事件)

In other words, about half the time, the pushing of the button (ie the rising of the GPIO pin) is only detected together with the releasing of the button (ie the falling of the GPIO pin), instead of being detected immediately when the button is pressed.换句话说,大约有一半的时间,按钮的按下(即 GPIO 引脚的上升)仅与按钮的释放(即 GPIO 引脚的下降)一起被检测到,而不是在按下按钮时立即被检测到。按钮被按下。

The strange thing is that I included a time stamp, and most of the time, even though I hold the button in for 3 seconds before releasing, the time stamp of the rising and falling are the same (but not always - there have been some rare occurrences where, even though both the rising and falling events only fired when I released the button, the timestamps displayed were 3 seconds apart).奇怪的是我包含了一个时间戳,而且大多数情况下,即使我在松开按钮前按住按钮 3 秒,上升和下降的时间戳都是相同的(但并非总是 - 有一些极少数情况下,即使上升和下降事件仅在我释放按钮时触发,显示的时间戳也相隔 3 秒)。

I then tried registering only a single event handler for both rising and falling detection instead of two separate handlers:然后我尝试只为上升和下降检测注册一个事件处理程序,而不是两个单独的处理程序:

_controller.RegisterCallbackForPinValueChangedEvent((int)Settings.GpioPin.Read, PinEventTypes.Rising | PinEventTypes.Falling, onSignalPinValueChangedEvent);

private void onSignalPinValueChangedEvent(object sender, PinValueChangedEventArgs args)
{
    Console.WriteLine(DateTime.Now + " - Pin " + args.PinNumber + " is "  + args.ChangeType);
}

But it made no difference.但这并没有什么不同。

This is a sample output - I was pushing the button in for about 3 seconds, then releasing for about 3 seconds:这是一个示例 output - 我按下按钮约 3 秒,然后释放约 3 秒:

2/20/2021 9:36:25 AM - Pin 10 is Rising
2/20/2021 9:36:25 AM - Pin 10 is Falling

2/20/2021 9:36:31 AM - Pin 10 is Rising
2/20/2021 9:36:31 AM - Pin 10 is Falling

2/20/2021 9:36:37 AM - Pin 10 is Rising
2/20/2021 9:36:37 AM - Pin 10 is Falling

2/20/2021 9:36:40 AM - Pin 10 is Rising
2/20/2021 9:36:43 AM - Pin 10 is Falling

2/20/2021 9:36:49 AM - Pin 10 is Rising
2/20/2021 9:36:49 AM - Pin 10 is Falling

2/20/2021 9:36:52 AM - Pin 10 is Rising
2/20/2021 9:36:55 AM - Pin 10 is Falling

2/20/2021 9:37:01 AM - Pin 10 is Rising
2/20/2021 9:37:01 AM - Pin 10 is Falling

2/20/2021 9:37:07 AM - Pin 10 is Rising
2/20/2021 9:37:07 AM - Pin 10 is Falling

2/20/2021 9:37:10 AM - Pin 10 is Rising
2/20/2021 9:37:13 AM - Pin 10 is Falling

2/20/2021 9:37:16 AM - Pin 10 is Rising
2/20/2021 9:37:18 AM - Pin 10 is Falling

2/20/2021 9:37:22 AM - Pin 10 is Rising
2/20/2021 9:37:24 AM - Pin 10 is Falling

2/20/2021 9:37:30 AM - Pin 10 is Rising
2/20/2021 9:37:30 AM - Pin 10 is Falling

In the above, the pairs that have the same timestamp are the problem ones.在上面,具有相同时间戳的对是有问题的对。 Those are the ones where nothing was written to the console when I pushed the button in, and then, three seconds later when I released the button, it wrote two lines (Rising and Falling) with the same timestamp at the same time.那些是当我按下按钮时没有写入控制台的那些,然后,三秒钟后,当我释放按钮时,它同时写了两行(上升和下降)具有相同的时间戳。

Any ideas?有任何想法吗?

I would try to set the PinMode to "PinMode.InputPullUp", as i have had better success with that我会尝试将 PinMode 设置为“PinMode.InputPullUp”,因为我在这方面取得了更好的成功

暂无
暂无

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

相关问题 .Net Core 似乎以大约 1000 / 秒的速度读取 GPIO 引脚。 go 如何更快? - .Net Core seems to max out reading GPIO pin at about 1000 / second. How to go faster? 使用 GetRSAPrivateKey 和 .net 内核以编程方式设置智能卡 PIN - Setting smartcard PIN programmatically using GetRSAPrivateKey and .net core .Net Core 3.1 是否在 Orange Pi Zero 上运行? - Does .Net Core 3.1 run on an Orange Pi Zero? Dotnet iot System.Device.Gpio 无法使用 Output 模式打开引脚 - Dotnet iot System.Device.Gpio cannot open pin with Output mode Raspberry Pi上的.Net Core 2.1 GPIO filesystemwatcher - .Net Core 2.1 GPIO filesystemwatcher on Raspberry Pi 使用 IBM.Data.DB2.Core 连接到 DB2 - 尝试打开连接时出错 - 长度不能小于零。 (参数“长度”) - Using IBM.Data.DB2.Core to connect to DB2 - ERROR when trying to open connection - Length cannot be less than zero. (Parameter 'length') 带有 Raspbian 的 Raspberry Pi 4 上的 .Net Core? - .Net Core on Raspberry Pi 4 with Raspbian? 在.Net Core 控制台应用程序中一起使用 NLog 和控制台日志记录 - Using NLog & Console Logging Together in .Net Core Console App .net Ubuntu 20.10 上的核心控制台应用程序在尝试执行程序时在树莓派 4 上给出 No such file or directory - .net Core console app on Ubuntu 20.10 on raspberry pi 4 give No such file or directory when trying to execute the program 带有 .Net Core 的 Raspberry Pi 3 上的串行端口 - Serial port on Raspberry Pi 3 with .Net Core
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM