Ramin Sangesari
Published © GPL3+

Introduction to NanoPi NEO Air

Meet the smallest single-board computer and access to GPIO pin.

BeginnerProtip1 hour7,422
Introduction to NanoPi NEO Air

Things used in this project

Hardware components

FriendlyARM NanoPi NEO Air
×1
LED (generic)
LED (generic)
×1

Story

Read more

Schematics

Wiring LED

Code

led.c

C/C++
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "libfahw.h"

#define STATUS_CHANGE_TIMES		20

int main(int argc, char **argv)
{
	int i;
	int intValue = 0;
	int pin = GPIO_PIN(7);  //LED connected to Pin number 7
            
	if (boardInit() < 0)
	{
		printf("Fail to init board\n");
        return -1;
	}
            
	if (exportGPIOPin(pin) != 0)
	{
		printf("exportGPIOPin(%d) failed\n", pin);
	}
            
    if(setGPIODirection(pin, GPIO_OUT) == -1)
    {
        printf("setGPIODirection(%d) failed\r\n",pin);
	}
            
	for(i = 0; i < STATUS_CHANGE_TIMES; i++)
	{
		intValue ^= 1;		//0 xor 1 = 1, 1 xor 1 = 0
		if(setGPIOValue(pin, intValue) > 0)
		{
			printf("%d - GPIO_PIN(%d) value is %d\r\n",i+1, pin, intValue);
		}
		else
		{
			printf("setGPIOValue(%d) failed\r\n", pin);
		}
		usleep(500000);
	}
           
	unexportGPIOPin(pin);
	return 0;
}

Credits

Ramin Sangesari

Ramin Sangesari

24 projects • 316 followers
Programmer and IoT Developer

Comments