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 [2026/02/03 21:14]
gray update by using AI
products:sbc:common:applications:gpio:40pin-header [2026/02/23 21:18] (current)
gray old revision restored (2024/08/12 03:08)
Line 3: Line 3:
 ====== GPIO Header ====== ====== GPIO Header ======
  
-====== GPIO Usage Examples ======+====== GPIO usage examples ======
  
 <WRAP important > <WRAP important >
-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]]. +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.
 </WRAP> </WRAP>
  
-Once you have identified the correct GPIO number (e.g., 465), follow these steps to control it via the sysfs interface.+When you get the GPIO number, you can follow the steps below to control it. Here we take GPIO number ''465'' as an example.
  
 ===== 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 GPIO Direction =====+===== Set-up GPIO direction =====
  
-Configure the GPIO as either an input or an output:+We can configure direction as input or output.
  
 ```shell ```shell
-# Set GPIO output +$ echo out | sudo tee /sys/class/gpio/gpio465/direction # Set GPIO output 
-$ echo out | sudo tee /sys/class/gpio/gpio465/direction  +$ echo in  | sudo tee /sys/class/gpio/gpio465/direction # Set GPIO input
- +
-# 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
-# Set GPIO output high +$ echo 1 | sudo tee /sys/class/gpio/gpio465/value # Set GPIO output high 
-$ echo 1 | sudo tee /sys/class/gpio/gpio465/value  +$ echo 0 | sudo tee /sys/class/gpio/gpio465/value # Set GPIO output low
- +
-# Set GPIO output low +
-$ echo 0 | sudo tee /sys/class/gpio/gpio465/value +
 ``` ```
  
-===== Read GPIO Input value =====+===== Get GPIO value =====
  
-If configured as an input, read its current logic level: 
 ```shell ```shell
-$ cat /sys/class/gpio/gpio465/value+$ cat /sys/class/gpio/gpio465/value # Get GPIO input 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 57: Line 46:
  
 ===== 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