I had some time to work with the RIoTBoard again last week, and decided to build a little app to try blinking the LEDs.


As I mentioned in previous blog posts, the fact that RIoTBoard runs Android is one of the reasons I'm interested in it. So to be clear, this is all on Android, not on Linux as many others are choosing to do.


For app development you need Android Developer Tools, and Sagar does a great job describing how to get all of that set up in his blog posts, starting with Part 1: Build an Android app on RIoTBoard .


As I write Android apps for my work, I already had all of that set up, saving me a lot of effort - yay!


So I wrote a little app with two checkboxes to control the 2 pre-defined LEDs: D45 and D46.

This is what it looks like when it is running on the RIoTBoard on my TV:


(Note: RIoTBoard is in "landscape mode" for apps)


There is one little trick to keep in mind when you go to connect to the RIoTBoard for the first time. To be able to connect to it from ADT you need to enable Debugging mode first. And this can be tricky, as "Developer Options" doesn't show up unless you perform a little bit of magic first: you need to tap "build number" 7 times (in "About Tablet"). This is an Android thing, not just RIoTBoard.



So once that's done and the board is connected to ADT, it's easy to run the app and see the debug information.

At this point you can pretty much write and run regular Android apps, but seeing as we have all those IO pins, the fun part is to have an app that can take advantage of those.


The app runs well, but sadly the LEDs do exactly nothing!


This is the error I'm getting, and I'm pretty sure it's related to permissions in Android, as it's generally not a good idea to allow an app to go writing to system files all willy nilly.

08-27 01:48:01.603: E/Exception(3243): File write failed: java.io.FileNotFoundException: /sys/class/leds/sys_led/brightness: open failed: EACCES (Permission denied)


Note the little "Permission denied" bit at the end.


Does anyone know how this can be done? I mean without hacking the whole system? Given that the IO pins are part of the RIoTBoard the way it's shipped, I would expect the supplied Android image to handle the IO pins through app code somehow.


The key code in my app is this:


      try {

          FileOutputStream ioFile = new FileOutputStream(new File(pin_file));

          OutputStreamWriter outputStreamWriter = new OutputStreamWriter(ioFile);




      catch (IOException e) {

          Log.e("Exception", "File write failed: " + e.toString());



"pin_file" is either "/sys/class/leds/user_led/brightness" (LED D45) or "/sys/class/leds/sys_led/brightness" (LED D46).

"high" is a boolean variable.

Has anyone tried using an Android app to access the IO pins yet? tusharp maybe?


edit: ps, to connect the RIoTBoard for ADT, plug the usb cable into the port closest to ethernet port