2024-07-10 10:42:29 +02:00
|
|
|
# LEDs and basic GPIO example application
|
|
|
|
|
|
|
|
## Description
|
|
|
|
|
2024-07-12 18:11:03 +02:00
|
|
|
The application `leds_shell` is a basic example, which allows easy, interactive
|
|
|
|
control of internal board LEDs, and basic GPIO for externally connected simple
|
2024-07-12 22:30:04 +02:00
|
|
|
devices (for e.g. additional LEDs, relay, motors - via dedicated drivers, etc.)
|
|
|
|
via the shell.
|
2024-07-10 10:42:29 +02:00
|
|
|
|
|
|
|
In particular, this example shows:
|
|
|
|
- on/off and toggle internal board LEDs.
|
|
|
|
- initialize GPIO port in output mode.
|
|
|
|
- set GPIO port state to HIGH or LOW.
|
|
|
|
|
|
|
|
## Shell command
|
|
|
|
|
|
|
|
The following commands are available:
|
|
|
|
|
2024-07-12 22:30:04 +02:00
|
|
|
- `led`: allows switching on/off or toggle internal board LEDs.
|
|
|
|
- `gpio`: allows initialization of GPIO port and set state to HIGH/LOW.
|
2024-07-10 10:42:29 +02:00
|
|
|
- `help`: default RIOT command, which shows available commands.
|
|
|
|
|
2024-07-12 22:30:04 +02:00
|
|
|
## Usage on `BOARD=native`
|
2024-07-10 10:42:29 +02:00
|
|
|
|
2024-07-12 22:30:04 +02:00
|
|
|
- Build and run `leds_shell` example application on the `native` target,
|
2024-07-10 10:42:29 +02:00
|
|
|
as Linux application:
|
|
|
|
|
|
|
|
```
|
2024-07-12 22:30:04 +02:00
|
|
|
$ make all term
|
2024-07-10 10:42:29 +02:00
|
|
|
[...]
|
|
|
|
RIOT native interrupts/signals initialized.
|
|
|
|
RIOT native board initialized.
|
|
|
|
RIOT native hardware initialization complete.
|
|
|
|
|
2024-07-12 18:11:03 +02:00
|
|
|
main(): This is RIOT! (Version: 2021.07-devel-10893-gb2e97-example-leds_shell)
|
2024-07-12 22:30:04 +02:00
|
|
|
This board has 2 LEDs
|
2024-07-10 10:42:29 +02:00
|
|
|
>
|
|
|
|
```
|
|
|
|
|
|
|
|
- List the available commands:
|
|
|
|
```
|
|
|
|
> help
|
|
|
|
help
|
|
|
|
Command Description
|
|
|
|
---------------------------------------
|
2024-07-12 22:30:04 +02:00
|
|
|
gpio GPIO pin initialization and set port state HIGH/LOW
|
|
|
|
led Switch on/off or toggle on-board LEDs
|
2024-07-10 10:42:29 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
- Enable internal LED0 and LED1 (the `native` target has two virtual LEDs):
|
|
|
|
|
|
|
|
```
|
2024-07-12 22:30:04 +02:00
|
|
|
> led 0 on
|
|
|
|
led 0 on
|
2024-07-10 10:42:29 +02:00
|
|
|
LED_RED_ON
|
|
|
|
|
2024-07-12 22:30:04 +02:00
|
|
|
> led 1 on
|
|
|
|
led 1 on
|
2024-07-10 10:42:29 +02:00
|
|
|
LED_GREEN_ON
|
|
|
|
```
|
2024-07-12 22:30:04 +02:00
|
|
|
## Usage on actual hardware - `BOARD=stm32f469i-disco`
|
2024-07-10 10:42:29 +02:00
|
|
|
|
2024-07-12 18:11:03 +02:00
|
|
|
- Build and flash `leds_shell` example application on sample board, for example
|
2024-07-10 10:42:29 +02:00
|
|
|
`stm32f469i-disco` target, which has 4 internal LEDs:
|
|
|
|
|
|
|
|
```
|
2024-07-12 22:30:04 +02:00
|
|
|
$ make all BOARD=stm32f469i-disco flash term
|
2024-07-10 10:42:29 +02:00
|
|
|
[...]
|
2024-07-12 18:11:03 +02:00
|
|
|
main(): This is RIOT! (Version: 2021.07-devel-10894-g2ad22b9-example-leds_shell)
|
2024-07-12 22:30:04 +02:00
|
|
|
This board has 4 LEDs
|
2024-07-10 10:42:29 +02:00
|
|
|
> help
|
|
|
|
help
|
|
|
|
Command Description
|
|
|
|
---------------------------------------
|
2024-07-12 22:30:04 +02:00
|
|
|
gpio GPIO pin initialization and set port state HIGH/LOW
|
|
|
|
led Switch on/off or toggle on-board LEDs
|
2024-07-10 10:42:29 +02:00
|
|
|
```
|
|
|
|
|
2024-07-12 22:30:04 +02:00
|
|
|
- Switch on/off internal LEDs using `led` command and appropriate LED id.
|
|
|
|
- Initialize GPIO port using `gpio init`.
|
|
|
|
- Change state of GPIO port using `gpio set` and `gpio clear`.
|