mnishiguchi
Can I add an LED to /sys/class/leds and control it using nerves_leds?
I am learning IoT using Nerves and Raspberry Pi. I saw various ways to let LEDs blink, such as:
- blinking LEDs connected to GPIO pions using elixir-circuits/circuits_gpio
- blinking on-board LEDs using nerves-project/nerves_leds
Is it viable to register to /sys/class/leds an LED that is connected to GPIO, and blink it using nerves-project/nerves_leds?
I have limited knowledge of C and Linux, but I did my best to find some related info:
Marked As Solved
fhunleth
Hi @mnishiguchi,
Both nerves_leds and circuits_gpio can control LEDs. It looks like you found the Linux documentation on how the two libraries are implemented. To summarize, the difference is that circuits_gpio is lower level and controls (or monitors) whether a microprocessor’s I/O pin is on or off. nerves_leds provides a higher level interface to an I/O pin with the assumption that the pin controls an LED or something similar. nerves_leds lets you tell the Linux kernel to do things like blink the LED, tie the LED to CPU activity, etc.
To use nerves_leds the Linux kernel needs to be told about the pin that controls the LED. That’s done through a device tree configuration file. Sometimes it is possible to adapt someone else’s device tree file to your needs, but the files can be intimidating. I’d recommend using circuits_gpio to control your own LEDs and any LEDs that aren’t already under /sys/class/leds.
The Elixir Circuits quickstart has a guide on controlling an LED. The other place to look is at the hello_leds and hello_gpio projects in the Nerves examples.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









