Switching a GPIO to and LED via the device tree

71 views
Skip to first unread message

Mark A. Yoder

unread,
Aug 26, 2020, 6:23:12 PM8/26/20
to BeagleBoard
Beagler's:
  I just wrote up some notes on how to edit the device tree to change a GPIO into an LED.


It's are rather involved process that requires understanding some deeper magic.

Let me know what you think.

--Mark

Mark Lazarewicz

unread,
Aug 26, 2020, 9:59:23 PM8/26/20
to beagl...@googlegroups.com, Mark A. Yoder

Well presented I like your approach at documentation I bet that comes from teaching 

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/61317cde-fb07-4c98-bc56-c968e58e7a10n%40googlegroups.com.

Mark A. Yoder

unread,
Aug 27, 2020, 9:06:05 AM8/27/20
to BeagleBoard

Yup, years for facing blank stares has taught me a few things.

This particular example touched on so many different things it could be a nice final exam.

--Mark

Renaud Waldura

unread,
Aug 27, 2020, 11:30:59 AM8/27/20
to beagl...@googlegroups.com
Good stuff, thank you Mark!

How are the triggers defined? They're more or less self explanatory, I'm just curious how it works.


Mark A. Yoder

unread,
Aug 27, 2020, 12:10:59 PM8/27/20
to BeagleBoard
Ren:
  Good question.  I poked around the kernel source a bit hoping to create an example for my students.  
But it was more complicated than what I wanted for my students.

--Mark

jonnymo

unread,
Aug 27, 2020, 12:11:56 PM8/27/20
to Beagle Board
Very cool Mark.

A couple of notes:
1.  It might be a good idea to put a note in there for the folks to back up their currently booted dts/dtb files before editing them.
 
2. Under "Finding which device tree to edit" I believe there is a typo:
     Note: If you want to edit the source using cloud9 us the following trick ...
   Should be:
     Note: If you want to edit the source using cloud9 use the following trick ...

3. When you run make, would it be best to just run it against the file that was edited rather than the whole folder?
     Maybe the build script is smart enough to figure this out.

4.  Under "Adding our LED" there is the following without explaining the why.  Was this intentional?
    "How did I know to use gpio1 and 18?"

This is a nice series.  Thanks for sharing.

Cheers,

Jon

Mark A. Yoder

unread,
Aug 27, 2020, 12:32:02 PM8/27/20
to BeagleBoard
Jon:
  Thanks for the suggestions.  I'll address each in line..

--Mark

On Thursday, August 27, 2020 at 12:11:56 PM UTC-4 jonn...@gmail.com wrote:
Very cool Mark.

A couple of notes:
1.  It might be a good idea to put a note in there for the folks to back up their currently booted dts/dtb files before editing them.
 Good idea, but this is a git repo, so I added the following: https://elinux.org/EBC_Exercise_17_Switching_a_GPIO_to_an_LED#Recovering_from_a_miss-edit
2. Under "Finding which device tree to edit" I believe there is a typo:
     Note: If you want to edit the source using cloud9 us the following trick ...
   Should be:
     Note: If you want to edit the source using cloud9 use the following trick ...
Fixed.  Thanks.
3. When you run make, would it be best to just run it against the file that was edited rather than the whole folder?
     Maybe the build script is smart enough to figure this out.
You can do the individual file, but it more typing.  I guess I'm lazy.  And it still installs everything.
4.  Under "Adding our LED" there is the following without explaining the why.  Was this intentional?
    "How did I know to use gpio1 and 18?"
That was intentional to get my students to think a bit.  Should I include the answer for the broader audience

Jim F

unread,
Aug 27, 2020, 2:17:24 PM8/27/20
to beagl...@googlegroups.com
Hi Mark,

Nice tutorial. Wish I'd had that quite some time ago, I had to pull all those pieces together myself.

From having read a bunch of posts here, I have a few suggestions for your consideration.

1. User needs to be in the gpio group. This isn't mentioned.
2. People often ignore parts of instructions. If your prompt included the current directory name, it would be slightly more obvious where each command is run.
3. It would be AMAZING if tutorials such as these included a description of what version of code this was developed/tested on. You could either mention the RCN release number or the kernel build, but it would be so great if this were a standard thing to mention. Consider how much things have changed with device trees over the past five (?) years. There's tons of now-wrong notes on how to do things. (I know you mention a kernel in the compilation section, I guess it would be nice to spell this out up top, i.e. "This tutorial is applicable to Beaglebone release xxx").
4. Not sure this comment is welcome, but a top level Tutorials page containing all the EBC## tutorials would be cool. I found the others by clicking on your ECE497 link, but that isn't exactly obvious (to me). Those look like some great materials that I hadn't come across before, for some reason.

Best,

Jim

--

Ren W

unread,
Aug 27, 2020, 3:29:53 PM8/27/20
to BeagleBoard
> tutorials such as these included a description of what version of code this was developed/tested on.

This ^^^^^
As a beginner, it's been quite frustrating to have to wade through all the tutorials referring to a cape manager that no longer exists.
Not only have I learnt how things work today, I've also had to learn how they used to work — which I could have done without.

Mark A. Yoder

unread,
Aug 28, 2020, 5:32:55 PM8/28/20
to BeagleBoard
Jim:
  Thanks for the feedback.  I like your suggestions.  Responses below:

On Thursday, August 27, 2020 at 2:17:24 PM UTC-4 jimf...@gmail.com wrote:
Hi Mark,

Nice tutorial. Wish I'd had that quite some time ago, I had to pull all those pieces together myself.

From having read a bunch of posts here, I have a few suggestions for your consideration.

1. User needs to be in the gpio group. This isn't mentioned.
The debian image has user debian in the gpio group by default.  Though there are other use cases, I want to keep this focused on my students.
They are fighting too many alligators for me to add the group alligator.
2. People often ignore parts of instructions. If your prompt included the current directory name, it would be slightly more obvious where each command is run.
Good suggestion.  To keep the clutter down I just converted all paths to absolute.  Does that work? 
3. It would be AMAZING if tutorials such as these included a description of what version of code this was developed/tested on. You could either mention the RCN release number or the kernel build, but it would be so great if this were a standard thing to mention. Consider how much things have changed with device trees over the past five (?) years. There's tons of now-wrong notes on how to do things. (I know you mention a kernel in the compilation section, I guess it would be nice to spell this out up top, i.e. "This tutorial is applicable to Beaglebone release xxx").
Great idea.  Wiki pages age so quickly.   I've added a footnote that displays the output of uname and cat /etc/dogtag.  What do you think? 
4. Not sure this comment is welcome, but a top level Tutorials page containing all the EBC## tutorials would be cool. I found the others by clicking on your ECE497 link, but that isn't exactly obvious (to me). Those look like some great materials that I hadn't come across before, for some reason.
Another good idea, but...  I'm sticking with using the Category to collect all my pages.  I hope my titles are descriptive enough that I can remember what's in them. 

Thanks again for the feedback.

--Mark

Jim F

unread,
Aug 29, 2020, 2:27:49 AM8/29/20
to beagl...@googlegroups.com
Mark,

I wish more tutorials looked like this. I should have started with congratulations on a great job. Thanks for considering my suggestions. 

Best, 
Jim 

TJF

unread,
Aug 29, 2020, 12:46:15 PM8/29/20
to BeagleBoard
The output lines in a GPIO subsystem are limited to a maximum current of 6 mA. The users/students should know that they need a low power/current LED for your circuit.

The value of the current limiting resistor depends on the threshold voltage of the LED, which depends on the LED color. 220Ω is OK for a blue LED, but too small for ie. an orange LED with 1V65 threshold / 6mA. This may damage the LED, or - most likely - the output line in the GPIO subsystem (= the BB CPU).

Regards
Reply all
Reply to author
Forward
0 new messages