Our application - an introduction

Now that we've covered how to generate the SDK for our platform and how to integrate package in our Yocto image, we will, through an example, develop an application with the general purpose input output (GPIO) pins of the Raspberry Pi and then create a recipe to integrate our application with the final image.

The idea is to develop an application that, through the GPIO pins, lights an LED and monitors a push button.

Here is the schematic diagram, realized with Fritzing (http://fritzing.org/home/):

Our application - an introduction

Thus, we can, from the Linux user space, light the LED or monitor the push button through GPIO 4 of the Raspberry Pi (pin 7 of the main connector).

We can test the following C application:

static int parse_opts(int argc, char *argv[])
int long_index = 0;
int opt;
static struct option option[]
{"Ied", required_argument, NULL, '1'
{"help", no_argument, NULL, 'h'
{"button", no_argument, NULL, 'b'
{"version", no_argument, NULL, 'v'
{0, 0, 0, 0
while ((opt = getopt_long(argc, argv, "Izbhv", option, &1ong_index)) >= 0)
switch(opt)
case 'h':
display_he1p(argv[0]);
exit(EXIT_SUCCESS);
case 'v':
fprintf(stderr, "
%s - %s

", project, VERSION);
exit(EXIT_SUCCESS);
case '1':
printf("Led Mode
");
printf("Set gpio%d to %d
",GPIO_PIN,atoi(optarg));
Set gpio4 to out mode
set_out(GPIO_PIN,atoi(optarg));
break;
case 'b':
printf("Button Mode
");
Set gpio4 to in mode
set_in(GPIO_PIN);
wait_bp_state();
break;
default:
fprintf(stderr,"[ERROR] %s: Bad option. -h for he1p
", argv[0]);
exit(EXIT_FAILURE);
return 0;

You can download it from the code bundle for this book.

We can try compiling our application with our SDK with the following command and send it to the Raspberry Pi:

$ source /opt/poky/1.7.1/environment-setup-armv6-vfp poky-linux- gnueabi
$ ${CC} gpio_example.c -o gpio_example
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.108.54