-1

I have a BeagleBone Black with Debian installed. I successfully ssh'd into it with MobaXterm and wrote the following code (have written/compiled/run this in both nano and gedit):

 #include <iostream>
 #include <stdio.h>
 #include <unistd.h>
 using namespace std;

 int main(){
 cout << "LED Flash Start" << endl;
 FILE *LEDHandle = NULL;
 const char *LEDBrightness="/sys/class/leds/beaglebone:green:usr0/brightness";

 for(int i=0; i<10; i++){ 
    if((LEDHandle = fopen(LEDBrightness, "r+")) != NULL){
        fwrite("1", sizeof(char), 1, LEDHandle);
        fclose(LEDHandle);
    }
    usleep(1000000);

    if((LEDHandle = fopen(LEDBrightness, "r+")) != NULL){
        fwrite("0", sizeof(char), 1, LEDHandle);
        fclose(LEDHandle);
    }
    usleep(1000000);
  }
  cout << "LED Flash End" << endl;
 }

basically I followed the steps shown here: http://elinux.org/Beagleboard:C/C%2B%2B_Programming

The code compiles and runs. In the terminal it displays the expected output however on the BeagleBone Black the USR0 led never changes from its usual heartbeat pattern. Does anyone know why this could be?

Thanks in advance.

Indi008
  • 41
  • 5
  • No error checking whatsoever, you get what you deserve, I'm afraid. – Ulrich Eckhardt Dec 01 '15 at 05:25
  • If you think there's something I haven't tried then why don't you suggest it otherwise keep mean comments to yourself. I don't know what you mean by error checking? – Indi008 Dec 01 '15 at 19:48
  • Function calls can and do fail. Read the documentation to find out how they signal failures. Check for these signals and at least alert the user. – Ulrich Eckhardt Dec 02 '15 at 22:19

1 Answers1

1

First check if it all works from command line

# cd beaglebone:green:usr0
# more trigger
  none ...... mmc0 mmc1 timer oneshot [heartbeat] backlight gpio cpu0 default-on transient
# echo none > trigger

you will see that the led stops blinking. Now try this

# echo 1 > brightness

The first LED should go on

# echo 0 > brightness

The first LED should go off.

# echo heartbeat > trigger

Setting it Back to heartbeat.

If all of this works then may be your are doing something wrong. Do a proper error checking then it would be easier for you to debug it.

S.I.J
  • 979
  • 1
  • 10
  • 22
  • Thanks for the reply :). After entering the first command you have given (cd beaglebone:green:usr0) it gives the error "No such file or directory". – Indi008 Dec 01 '15 at 19:48
  • I get the same problems using putty. – Indi008 Dec 01 '15 at 19:58
  • Okay nevermind,it works if I put "/sys/class/leds" in front of the commands. – Indi008 Dec 01 '15 at 20:03
  • So I don't think it's the code itself since I know others have used it successfully with Debian. It's not a hardware issue with the leds or a comms issue because they can be controlled from the command line. It's not the editor or a putty/MobaXterm issue because they give the same result. It's possible that I put my file in the wrong place but in the instructions it doesn't say to put it anywhere specific and when using nano root is the default saving place. It can't be the compiler/toolchain since it compiles & outputs the comments fine and I don't get errors. I don't know what else to try. – Indi008 Dec 01 '15 at 21:12
  • I don't know why it doesn't work but it doesn't matter. I'm just going to use Python instead of C++. Seems to be more commonly used with the BBB and I found a better tutorial which I managed to step through successfully. Thank you for the help anyway. – Indi008 Dec 02 '15 at 00:05