"IGpioPin" life cycle

ChrisChang 40 Reputation points

I am running the "GpioTestTool" "https://github.com/microsoft/Windows-iotcore-samples/tree/develop/BusTools/GpioTestTool" .

The example can control the GPIO well,

But once the program is terminated, all configuration to the specified GPIO are gone?

Any alternatives to hold the changed settings for the GPIO even the program is not running anymore?

A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,098 questions
0 comments No comments
{count} votes

Accepted answer
  1. Wesley Li-MSFT 4,346 Reputation points Microsoft Vendor


    When a program that has been manipulating GPIO pins terminates, the state of the GPIO pins is typically reset. This is because the GPIO settings are held in the memory space of the program, and when the program ends, its memory space is cleaned up by the operating system.

    The GPIO cleanup function in Python, for example, resets any ports you have used in the program back to input mode. This is a safety feature to prevent damage from a situation where you have a port set HIGH as an output and you accidentally connect it to GND (LOW), which would short-circuit the port and possibly fry it.

    If you want the GPIO settings to persist after the program has ended, you would need to write a separate program or script that runs at startup and sets the GPIO pins to your desired state. This program would need to run every time the system starts up to ensure the GPIO pins are always set correctly.

    However, please note that this is generally not recommended practice. The state of GPIO pins should be controlled by the program that is using them, and that program should clean up after itself when it’s done. This prevents conflicts between different programs trying to use the same GPIO pins and ensures that each program only changes the state of the GPIO pins it is using.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful