Does .Net Core 3.1 have an event driven method of detecting GPIO pin changes? - linux

I'm creating a .Net Core 3.1 console app to read to and write from GPIO pins on an Orange Pi Zero (similar to a Raspberry Pi Zero). It is running Armbian Focal (Ubuntu). I'm using .Net Core's System.Device.Gpio library.
I have managed to get the reading to and writing from the GPIO pins working - no problem. But the way I am reading the pins is by doing a gpioController.Read() inside a loop. I was wondering if System.Device.Gpio has an event driven method of reading a GPIO pin? In other words, if a pin goes from high to low, or low to high, that an event - let's call it "gpioPinStateChanged" - is triggered. Is there such a thing?
I know I could create my own even notification system, but I was wondering if .Net Core perhaps had something built in? I've looked at a dozen code samples, and none of them have anything like that, so I'm guessing there isn't...
Thanks

Following 0andriy's comments, I saw that you can indeed register events to detect GPIO pin state changes. Thanks to his post, I also found another great post of someone doing the same. He uses GPIO pin change events to calculate the RPM of a fan.
http://blog.timwheeler.io/building-a-pwm-fan-controller-with-dotnet-iot/

Related

Has anyone used bleak to connect multiple BLE devices and receive notifications from all of them simultaneously?

I am able to use bleak and get data from all 5 BLE sensors. But the problem is that I am unable to identify which data is from which device. I mean i need a string representing the address of the device alongwith the data itself.
I was able to get data simultaneously from all the BLE modules using bleak in Windows, as well as on raspberry pi.
The only problem with Windows is that if you use Bluetooth 4.2 adapter & above. It will be much better for the high speed data rate, and proper devices connection handling. As with the 4.0 adapter, I have always gone through one or two exceptions each time i started the script, and the maximum number of connections I got was 3.
When i tried this script on Raspberry pi 3b+, it has on-board chip of Bluetooth 4.2. It was able to give high speed data rate, and my 5 sensors were connected to it simultaneously.
Also, The two_devices examples in bleak source code on Github, is very good example for starting with further coding.
And if you run the script and found the data on console, but you were unable to get that which data is from device. Then you need to use functools, (what it does is it will inject the client you're connected to at present, with the callback function, and it will make the work much easier).
Check this out on Github: https://github.com/hbldh/bleak/issues/601

Register Platform Device in Linux

I'm trying to use the pps-gpio module for an NTP time server on an embedded Linux platform (Olimex imx233) and need to register a GPIO pin as a platform device. I've gathered from googling that I need to create a platform_device struct and use platform_device_register(pdev) to register the pin. Most documentation says this is normally done when the board is initialized, but I can't find where I would even put a call to platform_device_register to initialize this. Is it even necessary to register the device during startup, or can I just execute C code to register the device from console? My plan would be then to use modprobe to load the module that needs the device after that has been done.
Sorry if this is a non-sensical question, I had no experience working with Linux drivers until two days ago and Google has been my greatest teacher so far! Thanks

Rasperry Pi - Control circuit through website

I got my Raspberry Pi 3 quite recently and have made some basic projects. I'm looking for a method to create a website (on my laptop) and control my raspberry pi through that - well, more just a circuit attached to it. Would that be possible? If so, how would I approach it?
Depending on the language you want to use for the project, you will want to find a gpio library to control the GPIO pins. You would then want to wrap the calls in a webserver. Some examples of the libraries:
https://pypi.python.org/pypi/RPi.GPIO
https://www.npmjs.com/package/pi-gpio
http://wiringpi.com/

Arduino Bluetooth N64 Controller - Writing a Linux Driver?

I'm working on a little Arduino project to create a bluetooth N64 joystick for my Ubuntu box.
I managed to find a sketch to output the controllers state via serial and it works great. Also sending the TX and RX to the little CSR bluetooth module I have works fine.
When I pair with the device I have to use "rfcomm bind" to see the device in my dev directory and 'cat'ing the output shows all the data is coming through as well.
My question is this, what are my next steps for getting Linux to recognize this device as a joystick - i.e. /dev/js0. If I know what I need to do to achieve this I can read up on the necessary steps but at the moment I have absolutely no clue where to start - having not done anything like this in the past. Should I be looking into creating a Kernel Module?
Any information or pokes in the right direction at all would be greatly appreciated - even if it's just an observation.
Writing custom kernel code is definitely not the way to go here.
To make your project appear as a joystick device in Linux you'll want to present it using the Bluetooth HID profile. With that in place everything should "just work" on the client side and you'll see an entry in /dev. The HID profile is pretty comprehensive and is used by most Bluetooth interface devices - keyboards, mice, game controllers etc. the Bluetooth part of this is actually mostly just a thin wrapper around the USB HID protocol.
From the sounds of things your device is currently not advertising itself using that profile.

How to determine the power status of a monitor/TV in Linux

I asked this same question a few months ago, but I've run into another roadblock and I'm hoping someone will have a flash of insight. The is the previous thread: Detecting if the monitor is powered off
I'm trying to figure out the power status of a monitor, in particular a TV that is plugged in via HDMI. I'm running Ubuntu 10.10 with nVidia ION video cards. These PCs will be running some digital signage and I need to make sure the power is on to the TV during business hours. I have a working Python script controlling an IR transmitter to turn the TV off and on. The last piece of the puzzle is to know the current state of the TV.
In my previous thread, I found I could use ddccontrol to get information from the monitor. That worked great for a traditional Asus monitor plugged in via HDMI. However, the Vizio TV says it doesn't support DDC.
I've also tried using get-edid to get live resolution and color information, but that fails to return any information from the TV.
I've tried udevadm monitor but an event only fires on the initial monitor plugin.
I have a feeling that the nVidia drivers are blocking these calls to the monitor, but I can't confirm that.
Ultimately, all I'm looking for is a single byte of information that changes when the monitor turns off.
EDIT: So, I'm coming to the conclusion that this may not be possible. At least not consistently possible across various combinations of video cards and monitors/TVs. The next idea I have is to monitor power usage on an outlet. I first looked at Kill A Watts, but they are completely stand alone. After several hours of searching, I came across Digi and their XBee radios. I ordered one of XBee's Smart Plugs from Digi and a XBee radio and USB adapter from Spark Fun. My current plan is to use a Python script that polls the Smart Plug for power usage.
The plug and radio were kind of expensive. Does anybody know of a power meter that plugs in? Everything I found was wireless. I'd like to be able to connect to it via USB, ethernet, or serial.
EDIT 2:
I could never get the XBee plug to work. It's incredibly difficult to configure the plug unless you buy one of Digi's gateways.
I ended up building my own current sensor. It's Arduino based and cost about $60 in parts. I wrote about it here: http://trafficlightads.net/2011/09/06/an-arduino-current-sensor/
I have a couple of Watts up? .Net models that have USB and Ethernet for monitoring devices and controlling devices. The .Net model adds Ethernet and an internal relay to turn the attached device on and off. This could be used to eliminate the possibility of IR being blocked and not being able to transition the state of the TV.
Watts up? .Net Product Link
They aren't cheap, but they are well-built. I recommend getting the international model if you want the most flexibility in outlet type. This allows you to use your own in and out cords. In the USA model the input cord is hard-wired/integrated.
Good luck.

Resources