This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision | |||
|
products:sbc:common:applications:gpio:40pin-header [2024/08/12 03:08] william [Troubleshooting] |
products:sbc:common:applications:gpio:40pin-header [2026/02/03 21:14] (current) gray update by using AI |
||
|---|---|---|---|
| Line 3: | Line 3: | ||
| ====== GPIO Header ====== | ====== GPIO Header ====== | ||
| - | ====== GPIO usage examples | + | ====== GPIO Usage Examples |
| <WRAP important > | <WRAP important > | ||
| - | Please make sure that the GPIOs you want to use are not configured | + | Before using a GPIO, ensure it is not configured |
| </ | </ | ||
| - | When you get the GPIO number, | + | Once you have identified |
| ===== Export GPIO ===== | ===== Export GPIO ===== | ||
| + | Make the GPIO accessible to user space: | ||
| ```shell | ```shell | ||
| $ echo 465 | sudo tee / | $ echo 465 | sudo tee / | ||
| ``` | ``` | ||
| - | ===== Set-up GPIO direction | + | ===== Set GPIO Direction |
| - | We can configure direction | + | Configure the GPIO as either an input or an output: |
| ```shell | ```shell | ||
| - | $ echo out | sudo tee / | + | # Set GPIO output |
| - | $ echo in | sudo tee / | + | $ echo out | sudo tee / |
| + | |||
| + | # Set GPIO input | ||
| + | $ echo in | sudo tee / | ||
| ``` | ``` | ||
| ===== Set GPIO value ===== | ===== Set GPIO value ===== | ||
| + | If configured as an output, you can set its logic level: | ||
| ```shell | ```shell | ||
| - | $ echo 1 | sudo tee / | + | # Set GPIO output high |
| - | $ echo 0 | sudo tee / | + | $ echo 1 | sudo tee / |
| + | |||
| + | # Set GPIO output | ||
| + | $ echo 0 | sudo tee / | ||
| ``` | ``` | ||
| - | ===== Get GPIO value ===== | + | ===== Read GPIO Input value ===== |
| + | If configured as an input, read its current logic level: | ||
| ```shell | ```shell | ||
| - | $ cat / | + | $ cat / |
| ``` | ``` | ||
| + | The command returns 0 (low) or 1 (high). | ||
| ===== Unexport GPIO ===== | ===== Unexport GPIO ===== | ||
| + | When finished, release the GPIO: | ||
| ```shell | ```shell | ||
| $ echo 465 | sudo tee / | $ echo 465 | sudo tee / | ||
| Line 46: | Line 57: | ||
| ===== Troubleshooting ===== | ===== Troubleshooting ===== | ||
| - | + | If you encounter an error similar to the following when exporting, the GPIO pin is likely reserved | |
| - | If you got the similar error below, it means that the PIN you try to export | + | |
| ```shell | ```shell | ||
| - | $ echo 465 | sudo tee / | + | echo 465 | sudo tee / |
| tee: / | tee: / | ||
| ``` | ``` | ||
| + | |||
| + | **Solution**: | ||