Please enable javascript, or click here to visit my ecommerce web site powered by Shopify.
Jump to: navigation, search

Difference between revisions of "Rock/LED"

(LEDs as class devices)
(Rock/LED)
Line 1: Line 1:
The RR has 3 LEDs: green(172), blue(174), red(175).
+
The Radxa Rock has 3 LEDs on board.
  
All can be programmable.
+
{| class="wikitable" style="width:25%; white-space:nowrap; text-align:center"
 +
! scope="col" | LED
 +
! scope="col" | GPIO ref.
 +
! scope="col" | GPIO number
 +
|-
 +
! scope="row" | <span style="color: green;">Green</span>
 +
| GPIO0_B4 || 172
 +
|-
 +
! scope="row" | <span style="color: blue;">Blue</span>
 +
| GPIO0_B6 || 174
 +
|-
 +
! scope="row" | <span style="color: red;">Red</span>
 +
| GPIO0_B7 || 175
 +
|}
 +
 
 +
All are programmable using either LEDs class devices or GPIOs.
  
 
__TOC__
 
__TOC__
Line 14: Line 29:
  
 
The default status of the three on board leds are:
 
The default status of the three on board leds are:
    RED: On when there is power
+
* <span style="color: red;">Red</span>: On when there is power
    GREEN: Flash twice per second after the kernel booting, it's called heartbeat.
+
* <span style="color: green;">Green</span>: Flash twice per second after the kernel booting, it's called heartbeat.
    BLUE: Flash when the uSD card is reading/writing.
+
* <span style="color: blue;">Blue</span>: Flash when the uSD card is reading/writing.
 +
 
 +
You can change the behaviour of each LED by using the '''echo''' command on their '''trigger''' property.
 +
 
 +
    root@radxa:~ # echo none > /sys/class/leds/red/trigger
 +
    root@radxa:~ # echo default-on > /sys/class/leds/red/trigger
 +
    root@radxa:~ # echo timer > /sys/class/leds/red/trigger
 +
    root@radxa:~ # echo heartbeat > /sys/class/leds/red/trigger
 +
 
 +
You can use '''cat''' on the '''trigger''' property to list all the available values.
 +
 
 +
    root@radxa:~ # cat /sys/class/leds/red/trigger
 +
    none test_ac-online test_battery-charging-or-full test_battery-charging test_battery-full test_battery-charging-blink-full-solid mmc0 mmc1 timer [heartbeat] backlight gpio default-on sleep rfkill0
 +
 
 +
Here is the list of current triggers:
 +
* none
 +
* test_ac-online
 +
* test_battery-charging-or-full
 +
* test_battery-charging
 +
* test_battery-full
 +
* test_battery-charging-blink-full-solid
 +
* mmc0
 +
* mmc1
 +
* timer
 +
* heartbeat
 +
* backlight
 +
* gpio
 +
* default-on
 +
* sleep
 +
* rfkill0
  
 
= LEDs as GPIOs =
 
= LEDs as GPIOs =
  
On the previous kernel images, the LEDs can be controled as GPIOs.
+
On the previous kernel images, the LEDs can be controlled as GPIOs.
  
 
Below is program in different languages to flash the green led on RR.
 
Below is program in different languages to flash the green led on RR.

Revision as of 09:56, 11 September 2014

The Radxa Rock has 3 LEDs on board.

LED GPIO ref. GPIO number
Green GPIO0_B4 172
Blue GPIO0_B6 174
Red GPIO0_B7 175

All are programmable using either LEDs class devices or GPIOs.

LEDs as class devices

On the latest kernel images (Ubuntu 14.04 server/desktop), the 3 LEDs are configured as LED class devices.

You can control them via /sys/class/leds/

Read the documentation for more information: https://www.kernel.org/doc/Documentation/leds/leds-class.txt

The default status of the three on board leds are:

  • Red: On when there is power
  • Green: Flash twice per second after the kernel booting, it's called heartbeat.
  • Blue: Flash when the uSD card is reading/writing.

You can change the behaviour of each LED by using the echo command on their trigger property.

   root@radxa:~ # echo none > /sys/class/leds/red/trigger
   root@radxa:~ # echo default-on > /sys/class/leds/red/trigger
   root@radxa:~ # echo timer > /sys/class/leds/red/trigger
   root@radxa:~ # echo heartbeat > /sys/class/leds/red/trigger

You can use cat on the trigger property to list all the available values.

   root@radxa:~ # cat /sys/class/leds/red/trigger
   none test_ac-online test_battery-charging-or-full test_battery-charging test_battery-full test_battery-charging-blink-full-solid mmc0 mmc1 timer [heartbeat] backlight gpio default-on sleep rfkill0

Here is the list of current triggers:

  • none
  • test_ac-online
  • test_battery-charging-or-full
  • test_battery-charging
  • test_battery-full
  • test_battery-charging-blink-full-solid
  • mmc0
  • mmc1
  • timer
  • heartbeat
  • backlight
  • gpio
  • default-on
  • sleep
  • rfkill0

LEDs as GPIOs

On the previous kernel images, the LEDs can be controlled as GPIOs.

Below is program in different languages to flash the green led on RR.

C

#include <stdio.h>

int main()
{
  FILE *fp = fopen("/sys/class/gpio/export", "w");
  if( !fp )
  {
    printf("error open export file");
    return 1;
  }
  fprintf(fp, "%d", 172);
  fclose(fp);

  fp = fopen("/sys/class/gpio/gpio175/direction", "w");

  if( !fp )
  {
    printf("error open export file");
    return 1;
  }
  fprintf(fp, "%s", "out");
  fclose(fp);

  fp = fopen("/sys/class/gpio/gpio175/value", "w");

  if( !fp )
  {
    printf("error open export file");
    return 1;
  }
  fprintf(fp, "%d", 1);
 
}

Python

import time

def initpin(pinnum, mode):
  '''
  pinnum: pin number, eg. 172, 175 etc.
  mode: pin mode, valid values: in or out
  '''

  with open('/sys/class/gpio/export', 'w') as f:
    f.write(str(pinnum))

  with open('/sys/class/gpio/gpio' + str(pinnum) + '/direction', 'w') as f:
    f.write(str(mode))

def setpin(pinnum, value):
 
  with open('/sys/class/gpio/gpio' + str(pinnum) + '/value', 'w') as f:
    f.write(str(value))

if __name__ == '__main__':
  initpin(172, 'out')
  while True:
    setpin(172, 0)
    time.sleep(1)
    setpin(172, 1)
    time.sleep(1)

Shell

#!/bin/sh

# enable the gpio 172 -> green led
echo 172 > /sys/class/gpio/export

# set the direction to output
echo "out" > /sys/class/gpio/gpio172/direction
while true;
do
echo 0 > /sys/class/gpio/gpio172/value #led on
sleep 1
echo 1 > /sys/class/gpio/gpio172/value #led off
sleep 1
done