-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetuart.c
More file actions
37 lines (30 loc) · 913 Bytes
/
setuart.c
File metadata and controls
37 lines (30 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <mraa/uart.h>
#include <mraa/gpio.h>
int main()
{
// Initialize the MRAA library
mraa_init();
// Initialize UART on port 0
mraa_uart_context uart = mraa_uart_init(0);
// Initialize GPIO pin D03
mraa_gpio_context gpio = mraa_gpio_init(3); // Assuming D03 corresponds to GPIO pin 3
if (gpio == NULL) {
fprintf(stderr, "Failed to initialize GPIO pin D03\n");
return 1;
}
// Set the direction of the GPIO pin to output
if (mraa_gpio_dir(gpio, MRAA_GPIO_OUT) != MRAA_SUCCESS) {
fprintf(stderr, "Failed to set GPIO pin D03 direction\n");
return 1;
}
// Set the GPIO pin to low
if (mraa_gpio_write(gpio, 0) != MRAA_SUCCESS) {
fprintf(stderr, "Failed to write low to GPIO pin D03\n");
return 1;
}
// Clean up
mraa_gpio_close(gpio);
mraa_uart_stop(uart);
mraa_deinit();
return 0;
}