BeagleBone on board LED Blink in C
Given most of us have extra time on our hands right now, I decided to fire up the Beaglebone Black. I intend to post a series of tutorials on using embedded linux and C. I am no means and expert on this topic. I read books, experiment and try new things. I think the perspective you’ll see when I post these tutorials is one from someone learning from nothing. Given that, I hope it is useful and a practical way to learn and understand.
To get started, lets simply flash the onboard LED a number of times. There are a number of tutorials online to do this but its a great way to get familiar with the Beaglebone. One of the books I highly recommend is Derek Molloy “Exploring Beaglebone: Tools and Techniques with Embedded Linux.” It covers in great detail all the capabilities of the Beaglebone and embedded electronics.
There are 4 onboard LEDs that are mapped in the system as user0-3
. These can be found by browsing the directory to cd /sys/class/leds
. We can then cd
into a specific LED and we’ll notice several files within the respective folder. cat
or view each file and you’ll see there is a rather simply structure. The primary ones of interest are the ones below.
brightness
is either 0 or 1 for on or offtrigger
is the particular function of the LED
By writing a 0 or 1 to the brightness
file, we can change the status of the LED. This is how all the GPIO pins work as well. There is a respective file system associated with all the interfaces. Accessing and editing these files can be done as the individual user prefers. This includes python, C/C++, perl, bash and so on. My preference is to work and learn more about C. I enjoy not downloading an establish library with defined functions to handle the programming. It is a great educational tool to challenge yourself and really understand embedded electronics,linux and the language of interest. Eventually, you can grow into developing your own libraries for future use. That will be the emphasis of more of the complex tutorials.
I’ve hosted on github this simple script as ‘makeLED’. You’ll find the file and function to flash the onboard user LED. It simply writes to the files we’ve discussed in the respective directory.
There is also a folder called ‘gpioLED’. It is a very similar code to the ‘userLED’ expect controlling a gpio pin. I encourage you to review these and give them a try. Take your time, read the code and make sense of what is taking place. I’ll spend more time on my next posts which pertain to interfacing some i2c devices I had laying around.