Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


products:sbc:common:applications:gpio:40pin-header

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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 as other functionsif they are, you can follow [[products:sbc:common:configurations:device-tree-overlay|Device Tree Overlay]] to configure them as normal GPIOs.+Before using a GPIO, ensure it is not configured for another function (e.g.I2C, SPI). If it is, you can reconfigure it as a standard GPIO by applying a [[products:sbc:common:configurations:device-tree-overlay|Device Tree Overlay]]. 
 </WRAP> </WRAP>
  
-When you get the GPIO number, you can follow the steps below to control it. Here we take GPIO number ''465'' as an example.+Once you have identified the correct GPIO number (e.g., 465), follow these steps to control it via the sysfs interface.
  
 ===== Export GPIO ===== ===== Export GPIO =====
  
 +Make the GPIO accessible to user space:
 ```shell ```shell
 $ echo 465 | sudo tee /sys/class/gpio/export $ echo 465 | sudo tee /sys/class/gpio/export
 ``` ```
  
-===== Set-up GPIO direction =====+===== Set GPIO Direction =====
  
-We can configure direction as input or output.+Configure the GPIO as either an input or an output:
  
 ```shell ```shell
-$ echo out | sudo tee /sys/class/gpio/gpio465/direction # Set GPIO output +# Set GPIO output 
-$ echo in  | sudo tee /sys/class/gpio/gpio465/direction # Set GPIO input+$ echo out | sudo tee /sys/class/gpio/gpio465/direction  
 + 
 +# Set GPIO input 
 +$ echo in  | sudo tee /sys/class/gpio/gpio465/direction 
 ``` ```
  
 ===== Set GPIO value ===== ===== Set GPIO value =====
 +If configured as an output, you can set its logic level:
  
 ```shell ```shell
-$ echo 1 | sudo tee /sys/class/gpio/gpio465/value # Set GPIO output high +# Set GPIO output high 
-$ echo 0 | sudo tee /sys/class/gpio/gpio465/value # Set GPIO output low+$ echo 1 | sudo tee /sys/class/gpio/gpio465/value  
 + 
 +# Set GPIO output low 
 +$ echo 0 | sudo tee /sys/class/gpio/gpio465/value 
 ``` ```
  
-===== Get GPIO value =====+===== Read GPIO Input value =====
  
 +If configured as an input, read its current logic level:
 ```shell ```shell
-$ cat /sys/class/gpio/gpio465/value # Get GPIO input value+$ cat /sys/class/gpio/gpio465/value
 ``` ```
 +The command returns 0 (low) or 1 (high).
  
 ===== Unexport GPIO =====  ===== Unexport GPIO ===== 
  
 +When finished, release the GPIO:
 ```shell ```shell
 $ echo 465 | sudo tee /sys/class/gpio/unexport $ echo 465 | sudo tee /sys/class/gpio/unexport
Line 46: Line 57:
  
 ===== Troubleshooting ===== ===== Troubleshooting =====
- +If you encounter an error similar to the following when exporting, the GPIO pin is likely reserved for another function (e.g.by the device tree):
-If you got the similar error belowit means that the PIN you try to export is used for another function, you need to edit [[products:sbc:common:configurations:device-tree-overlay|Device Tree Overlay]] configuration file to set the PIN as normal GPIO.+
  
 ```shell ```shell
-echo 465 | sudo tee /sys/class/gpio/export +echo 465 | sudo tee /sys/class/gpio/export
 tee: /sys/class/gpio/export: Invalid argument tee: /sys/class/gpio/export: Invalid argument
 ``` ```
 +
 +**Solution**: Modify the [[products:sbc:common:configurations:device-tree-overlay|Device Tree Overlay]] configuration to free the pin and define it as a standard GPIO.
  
Last modified: 2026/02/03 21:14 by gray