FriendlyArm NanoPC-T2/T3 GPIO Turn LED On Example

While scouting about looking for information about the FriendlyArm's NanoPC-T2 GPIO pins and using some of their source - I noticed that the documentation regarding how to setup an LED for example was missing from their forums etc... Here is a quick example:

root:openwrt:/sys/class/gpio# for i in gpiochip* ; do  echo `cat $i/label`: `cat $i
/base` ; done                                                                  
GPIOA: 0                                                                        
GPIOE: 128                                                                      
GPIOALV: 160                                                                    
GPIOB: 32                                                                      
GPIOC: 64                                                                      
GPIOD: 96                  

The above lists the BASE value for which you add YOUR PIN ID - see the below table borrowed from the FriendlyArm wiki

Pin# Name Pin# Name
1 SYS_3.3V 2 DGND
3 UART2_TX/GPIOD20 4 UART2_RX/GPIOD16
5 I2C0_SCL 6 I2C0_SDA
7 SPI0_MOSI/GPIOC31 8 SPI0_MISO/GPIOD0
9 SPI0_CLK/GPIOC29 10 SPI0_CS/GPIOC30
11 UART3_TX/GPIOD21 12 UART3_RX/GPIOD17
13 UART4_TX/GPIOB29 14 UART4_RX/GPIOB28
15 GPIOB31 16 GPIOB30
17 GPIOC4 18 GPIOC7
19 GPIOC8 20 GPIOC24
21 GPIOC28 22 GPIOB26
23 GPIOD1/PWM0 24 GPIOD8/PPM
25 GPIOC13/PWM1 26 AliveGPIO3
27 GPIOC14/PWM2 28 AliveGPIO5
29 VDD_5V 30 DGND

For example, if we want to use the above pin (GPIOB26), this means that the base value of 32 (and the 26 value from GPIOB26) is added together, equalling the PIN we want to use - SO PIN 58.

To demonstrate, I setup an LED with a 1k resistor on a breadboard (picture to follow, but has the addition of a switch) - the positive connected to GPIOB26 and the ground to DGND (pin 30 on the bottom right - see silk screening on the PCB). The following commands will demonstrate the process easily enough.

root-openwrt:/sys/class/gpio# ls                                                  
export        gpiochip128  gpiochip32   gpiochip96    
 gpio59       gpiochip0    gpiochip160  gpiochip64   unexport      

The above shows the existing pins (or something similar), now we need to export our PIN

root-openwrt:/sys/class/gpio# echo 58 > /sys/class/gpio/export

root-openwrt:/sys/class/gpio# ls                                                  
export        gpiochip128  gpiochip32   gpiochip96  gpio58    
gpio59       gpiochip0    gpiochip160  gpiochip64   unexport      

We can now see we now have the pin successfully exported. However, we need to designate the direction.

root-openwrt:/sys/class/gpio# echo out > /sys/class/gpio/gpio58/direction

Next, to turn the pin "on" - aka set it to active and turn ON the LED

root-openwrt:/sys/class/gpio# echo 1 > /sys/class/gpio/gpio58/value

Next, to turn the pin "off" - aka set it to active and turn OFF the LED

root-openwrt:/sys/class/gpio# echo 0 > /sys/class/gpio/gpio58/value                

Alternatively, if we have a switch and we want to detect that the circuit is completed (aka the button is depressed), then we do the following:

root-openwrt:/sys/class/gpio# echo in > /sys/class/gpio/gpio58/direction

Press the button and watch the LED go off and see the value change

root-openwrt:/sys/class/gpio# cat /sys/class/gpio/gpio58/value
0
root-openwrt:/sys/class/gpio# cat /sys/class/gpio/gpio58/value
1

I hope this was useful

Blog tags: 

AttachmentSize
Image icon IMG_20160914_104402.jpg2.38 MB

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <python> <c>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.