Author Topic: How can i control the LEDs on cubieboard.  (Read 5983 times)

Offline sanyigz

  • Full Member
  • ***
  • Posts: 100
  • Karma: +1/-2
    • View Profile
How can i control the LEDs on cubieboard.
« on: September 14, 2013, 03:39:23 pm »
How can i switch the leds on and off? The blue flashing led is very annoying and strong at night.

skr00b74

  • Guest
Re: How can i control the LEDs on cubieboard.
« Reply #1 on: September 21, 2013, 12:38:47 pm »
I'll try to help you. Linux uses 'triggers' to change the status of the LEDS on the board. Here is a simple way to see what trigger you are using....

for the blue led you:

cat /sys/class/leds/blue:ph21:led2/trigger

your output:

[none] battery-charging-or-full battery-charging battery-full battery-charging-blink-full-solid ac-online usb-online mmc0 mmc1 timer heartbeat backlight gpio cpu0 cpu1 default-on

notice the brackets []??? That is telling me I don't want to activate the leds. Your brackets are probably around mmc0. So you watch for SD card activity.

To STOP that blinking you type (as root)

echo none > /sys/class/leds/blue:ph21:led2/trigger

now, if you cat the trigger file again you'll see your brackets have moved around [none].  And the led has stopped blinking. If you look at the folder /sys/class/leds you'll see there is a green led folder there too. It works exactly the same. Here are some more fun things you can do.

echo timer > /sys/class/leds/blue:ph21:led2/trigger

that starts the blue led blinking.  To STOP that blinking type:

echo none > /sys/class/leds/blue:ph21:led2/trigger

to turn the led on solid you can also:

echo 255 > /sys/class/leds/blue:ph21:led2/brightness

to turn it back off

echo 0 > /sys/class/leds/blue:ph21:led2/brightness

the led's cannot change brightness so even an echo 1 would turn it on. echo 0 back off.

if you reboot your probably going to be doing these steps again.
« Last Edit: September 21, 2013, 01:30:44 pm by skr00b74 »

Offline sanyigz

  • Full Member
  • ***
  • Posts: 100
  • Karma: +1/-2
    • View Profile
Re: How can i control the LEDs on cubieboard.
« Reply #2 on: September 21, 2013, 12:47:39 pm »
Meanwhile i got the "missing link", these can't be set with simple sudo, only by real root. so with sudo sh -c "echo...."
Otherwise i get permission denied.

skr00b74

  • Guest
Re: How can i control the LEDs on cubieboard.
« Reply #3 on: September 21, 2013, 12:51:52 pm »
Thanks for the 'sudo' comment. I used root for my stuff. That's what I get for 'assuming' :)

skr00b74

  • Guest
Re: How can i control the LEDs on cubieboard.
« Reply #4 on: September 21, 2013, 04:20:53 pm »
Here is a VERY simple little Python script to blink the LED's. Python is NOT a language I am used to. If anyone has suggestions or better ways to do this. Please post your comments as I would like to see them.

Code: [Select]
    #!/usr/bin/python
    # Python example to blink those little LED's on the Cubieboard2
    # Written by skr00b74 (skr00b74@gmail.com)
    # I probably could have written this in a LOT less code.
    # It is intended for learning purposes. That's it!

    #We want to run some system commands so we need to import os
    import os

    #We need to use sleep in our loop so we need to import time
    import time

    #setup some strings to kill the led triggers

    #Kill the blue led trigger
    blueled_trigger = 'echo none > /sys/class/leds/blue:ph21:led2/trigger'

    #Kill the green led trigger
    greenled_trigger = 'echo none > /sys/class/leds/green:ph20:led1/trigger'

    #setup some strings to manage the blue led

    #Turn the blue led on
    blueled_on = 'echo 1 > /sys/class/leds/blue:ph21:led2/brightness'

    #Turn the blue led off
    blueled_off = 'echo 0 > /sys/class/leds/blue:ph21:led2/brightness'

    #setup some strings to manage the green led

    #Turn the green led on
    greenled_on = 'echo 1 > /sys/class/leds/green:ph20:led1/brightness'

    #Turn the green led off
    greenled_off = 'echo 0 > /sys/class/leds/green:ph20:led1/brightness'

    #Before we get started with the loop let's make sure we don't have triggers in use

    #Set the blue trigger to none
    os.system(blueled_trigger)

    #Set the green trigger to none
    os.system(greenled_trigger)

    #Just in case lets make sure that the leds start in the off position

    #Turn off the blue led
    os.system(blueled_off)

    #Turn off the green led
    os.system(greenled_off)

    #variable to keep track of the loops

    loop_count = 0;

    #Start the loop

    while(True):
        if loop_count <= 10:
            #Turn on the blue led
            os.system(blueled_on)

            #Sleep for half a second
            time.sleep(0.5)

            #Turn off the blue led
            os.system(blueled_off)

            #Turn on the green led
            os.system(greenled_on)

            #Sleep for a half a second
            time.sleep(0.5)

            #Turn off the green led
            os.system(greenled_off)

            #Let's add 1 to each loop count
            loop_count = loop_count + 1

        else:
            #We got here due to the fact loop count exceeded our if statement

            #Turn off the blue led
            os.system(blueled_off)

            #Turn off the green led   
            os.system(greenled_off)

            #We're done so lets break out of the loop

            break

    #The end of the code