Skip to content

Commit a4e6749

Browse files
committed
examples/guides: Introduce tutorial references
1 parent 94c4749 commit a4e6749

20 files changed

Lines changed: 338 additions & 0 deletions

File tree

examples/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,14 @@ Here is a quick overview of the examples available in the RIOT:
142142
| [twr_aloha](./advanced/twr_aloha/README.md) | This example allows testing different two-way ranging algorithms between two boards supporting a dw1000 device. This makes use of the uwb-core pkg. |
143143
| [senml_saul](./advanced/senml_saul/README.md) | This example demonstrates the usage of the SAUL (Sensor Actuator Uber Layer) module with the SenML (Sensor Measurement Lists) format. |
144144
| [opendsme](./advanced/opendsme/README.md) | This example demonstrates the usage of the OpenDSME module in RIOT. |
145+
146+
## Examples for Guides
147+
148+
| Example | Description |
149+
|---------|-------------|
150+
| [creating_project](./guides/creating_project/README.md) | This example is used in the [Create Project](https://guide.riot-os.org/c_tutorials/create_project/) tutorial |
151+
| [shell](./guides/shell/README.md) | This example is used in the [Echo](https://guide.riot-os.org/c_tutorials/shell/) tutorial |
152+
| [gpio](./guides/gpio/README.md) | This example is used in the [GPIO](https://guide.riot-os.org/c_tutorials/gpio/) tutorial |
153+
| [saul](./guides/saul/README.md) | This example is used in the [SAUL](https://guide.riot-os.org/c_tutorials/saul/) tutorial |
154+
| [threads](./guides/threads/README.md) | This example is used in the [Threads](https://guide.riot-os.org/c_tutorials/threads/) tutorial |
155+
| [timers](./guides/timers/README.md) | This example is used in the [Timers](https://guide.riot-os.org/c_tutorials/timers/) tutorial |
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# name of your application
2+
APPLICATION = hello-world
3+
4+
# Change this to your board if you want to build for a different board
5+
BOARD ?= native
6+
7+
# This has to be the absolute path to the RIOT base directory:
8+
RIOTBASE ?= $(CURDIR)/RIOT
9+
10+
# Comment this out to disable code in RIOT that does safety checking
11+
# which is not needed in a production environment but helps in the
12+
# development process:
13+
DEVELHELP ?= 1
14+
15+
# Change this to 0 show compiler invocation lines by default:
16+
QUIET ?= 1
17+
18+
include $(RIOTBASE)/Makefile.include
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# RIOT Tutorial Replica
2+
3+
This example is a replica of the output of the RIOT tutorial. The tutorial is available at [RIOT Tutorial](https://guide.riot-os.org).
4+
5+
The tutorial itself is located within [doc/guides/c_tutorials](/doc/guides/c_tutorials/). Please refer to the original tutorial for more information.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <stdio.h>
2+
3+
int main(void)
4+
{
5+
puts("Hello World!");
6+
7+
return 0;
8+
}

examples/guides/gpio/Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# name of your application
2+
APPLICATION = hello-world
3+
4+
# Change this to your board if you want to build for a different board
5+
BOARD ?= feather-nrf52840-sense
6+
7+
# This has to be the absolute path to the RIOT base directory:
8+
RIOTBASE ?= $(CURDIR)/RIOT
9+
10+
# Comment this out to disable code in RIOT that does safety checking
11+
# which is not needed in a production environment but helps in the
12+
# development process:
13+
DEVELHELP ?= 1
14+
15+
# This board requires a start sleep to actually catch the printed output
16+
USEMODULE += shell
17+
18+
# Add the gpio module to the build
19+
USEMODULE += periph_gpio
20+
USEMODULE += periph_gpio_irq
21+
22+
# Enable the milliseconds timer.
23+
USEMODULE += ztimer
24+
USEMODULE += ztimer_msec
25+
26+
# Change this to 0 show compiler invocation lines by default:
27+
QUIET ?= 1
28+
29+
include $(RIOTBASE)/Makefile.include

examples/guides/gpio/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../creating_project/README.md

examples/guides/gpio/main.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "periph/gpio.h"
2+
#include "board.h"
3+
#include "ztimer.h"
4+
5+
// Define the LED0 pin and mode
6+
gpio_t led0 = GPIO_PIN(1, 9);
7+
gpio_mode_t led0_mode = GPIO_OUT;
8+
9+
// Define the LED0 pin and mode
10+
gpio_t led1 = GPIO_PIN(1, 10);
11+
gpio_mode_t led1_mode = GPIO_OUT;
12+
13+
// Define the button pin
14+
gpio_t button = GPIO_PIN(1, 2);
15+
16+
void button_callback (void *arg)
17+
{
18+
(void) arg; /* the argument is not used */
19+
if (!gpio_read(button)) {
20+
gpio_set(led1);
21+
}
22+
else {
23+
gpio_clear(led1);
24+
}
25+
}
26+
27+
int main(void) {
28+
// Initialize the LED0 pin
29+
gpio_init(led0, led0_mode);
30+
// Turn off the LED0 pin
31+
gpio_clear(led0);
32+
33+
// Initialize the LED1 pin
34+
gpio_init(led1, led1_mode);
35+
// Turn off the LED1 pin
36+
gpio_clear(led1);
37+
38+
// Initialize the button pin
39+
gpio_init_int(button, GPIO_IN_PU, GPIO_BOTH, button_callback, NULL);
40+
41+
while (1) {
42+
gpio_toggle(led0);
43+
ztimer_sleep(ZTIMER_MSEC, 500);
44+
}
45+
}

examples/guides/saul/Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# name of your application
2+
APPLICATION = hello-world
3+
4+
# Change this to your board if you want to build for a different board
5+
BOARD ?= feather-nrf52840-sense
6+
7+
# This has to be the absolute path to the RIOT base directory:
8+
RIOTBASE ?= $(CURDIR)/RIOT
9+
10+
# Comment this out to disable code in RIOT that does safety checking
11+
# which is not needed in a production environment but helps in the
12+
# development process:
13+
DEVELHELP ?= 1
14+
15+
# This board requires a start sleep to actually catch the printed output
16+
USEMODULE += shell
17+
18+
# Add the SAUL module to the application
19+
USEMODULE += saul
20+
USEMODULE += saul_default
21+
22+
# Enable the milliseconds timer.
23+
USEMODULE += ztimer
24+
USEMODULE += ztimer_msec
25+
26+
# Change this to 0 show compiler invocation lines by default:
27+
QUIET ?= 1
28+
29+
include $(RIOTBASE)/Makefile.include

examples/guides/saul/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../creating_project/README.md

examples/guides/saul/main.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <stdio.h>
2+
3+
#include "board.h"
4+
#include "ztimer.h"
5+
#include "saul_reg.h"
6+
7+
int main(void) {
8+
ztimer_sleep(ZTIMER_MSEC, 5000);
9+
puts("Welcome to SAUL magic!");
10+
11+
// Define our temperature sensor
12+
saul_reg_t *temperature_sensor = saul_reg_find_type(SAUL_SENSE_TEMP);
13+
14+
// Exit if we can't find a temperature sensor
15+
if (!temperature_sensor) {
16+
puts("No temperature sensor found");
17+
return 1;
18+
} else {
19+
// Otherwise print the name of the temperature sensor
20+
// and continue the program
21+
printf("Temperature sensor found: %s\n", temperature_sensor->name);
22+
}
23+
24+
while (1) {
25+
// Define a variable to store the temperature
26+
phydat_t temperature;
27+
28+
// Read the temperature sensor
29+
// and store the result in the temperature variable
30+
// saul_reg_read returns the dimension of the data read (1 in this case)
31+
int dimension = saul_reg_read(temperature_sensor, &temperature);
32+
33+
// If the read was successful (1 or more dimensions), print the temperature
34+
if (dimension <= 0) {
35+
puts("Error reading temperature sensor");
36+
return 1;
37+
}
38+
39+
// Dump the temperature to the console
40+
phydat_dump(&temperature, dimension);
41+
42+
// Sleep for 1 seconds
43+
ztimer_sleep(ZTIMER_MSEC, 1000);
44+
}
45+
}

0 commit comments

Comments
 (0)