kramann.info
© Guido Kramann

Login: Passwort:










kramann.info
© Guido Kramann

Login: Passwort:




GPIO-Test

(EN google-translate)

(PL google-translate)

Anschluss einer LED  mit 2200Ohm Vorwiderstand an PIN13 == GPIO_14 und PIN14 == GND.

Bild 0-1: Anschluss einer LED mit 2200Ohm Vorwiderstand an PIN13 == GPIO_14 und PIN14 == GND.

Anschluss einer LED mit 2200Ohm Vorwiderstand an PIN13 == GPIO_14 und PIN14 == GND.

Bild 0-2: Anschluss einer LED mit 2200Ohm Vorwiderstand an PIN13 == GPIO_14 und PIN14 == GND.

Anschlußplan zu den GPIO: https://www.jetsonhacks.com/nvidia-jetson-nano-j41-header-pinout/
  • Direkter Test, eine LED zu steuern über verfügbare vorkompilierte Steuerbefehle:
sudo su
echo 14 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio14/direction
echo 1 > /sys/class/gpio/gpio14/value
echo 0 > /sys/class/gpio/gpio14/value

Code 0-1: Direkter Test, eine LED zu steuern über verfügbare vorkompilierte Steuerbefehle

Quelle zu diesem (hier angepassten) Beispiel ist: https://maker.pro/nvidia-jetson/tutorial/how-to-use-gpio-pins-on-jetson-nano-developer-kit
Quelle des nachfolgenden Beispiels: https://github.com/valentis/jetson-nano-gpio-example
//
// Simple GPIO memory-mapped example by YoungJin Suh (http://valentis.pe.kr / valentis@chollian.net)
//                           originally from Snarky (github.com/jwatte)
// build with:
//  g++ -O1 -g -o led led.cpp -Wall -std=gnu++17
// run with:
//  sudo ./led 
//

#include <stdio.h>
#include <stdlib.h>                     // for exit()
#include <unistd.h>
#include <sys/fcntl.h>
#include <sys/mman.h>

#include "gpionano.h"

int main(int argc, char** argv)
{
    //  read physical memory (needs root)
    int fd = open("/dev/mem", O_RDWR | O_SYNC);
    if (fd < 0) {
        fprintf(stderr, "usage : $ sudo %s (with root privilege)
", argv[0]);
        exit(1);
    }

    //  map a particular physical address into our address space
    int pagesize = getpagesize();
    int pagemask = pagesize-1;

    //  This page will actually contain all the GPIO controllers, because they are co-located
    void *base = mmap(0, pagesize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (GPIO_14 & ~pagemask));
    if (base == NULL) {
        perror("mmap()");
        exit(1);
    }

    //  set up a pointer for convenient access -- this pointer is to the selected GPIO controller
    gpio_t volatile *pinLed = (gpio_t volatile *)((char *)base + (GPIO_14 & pagemask));

    // for LED : GPIO OUT 
    pinLed->CNF = 0x00FF;
    pinLed->OE = OUTPUT;
    pinLed->OUT = 0xFF;
    
    //  disable interrupts
    pinLed->INT_ENB = 0x00;

    // blank led light  
    for(uint8_t cnt = 0; cnt < 10; cnt++) {
        pinLed->OUT ^= 0xff;
        usleep(1000*1000);		// wait 1 sec
    }

    /* turn off the LED */
    pinLed->OUT = 0;

    /* unmap */
    munmap(base, pagesize);

    /* close the /dev/mem */
    close(fd);

    printf("
Good Bye!!!
");
    
    return 0;
}

Code 0-2: led.c, Quelle des Beispiels: https://github.com/valentis/jetson-nano-gpio-example (jedoch GPIO_12 durch GPIO_14 ersetzt)


#Kompilieren:
g++ -O1 -g -o led led.cpp -Wall -std=gnu++17
#Starten: Achtung das funktioniert nur als root!
su root
./led 

Code 0-3: Kompilieren und Starten des Beispiels

Weitere Links zu diesem Thema:

https://maker.pro/nvidia-jetson/tutorial/how-to-use-gpio-pins-on-jetson-nano-developer-kit
https://www.jetsonhacks.com/2019/06/07/jetson-nano-gpio/