Accessing GPio using jetson nano with qt creator

I have written a code for accessing gpio in jetson nano , written in terminal, how should it run in qt for jetson nano , the code is enclosed hereby:

// Handles input and output

#include <iostream>

// For delay function

#include <chrono>

// Handles threads of program execution

#include <thread>

// Signal handling

#include <signal.h>

#include <JetsonGPIO.h>

// Pin Definitions

int led_pin = 7;

// Flag to determine when user wants to end program

bool done = false ;

// Function called by Interrupt

void signalHandler ( int s){

done = true ;

}

int main() {

// When CTRL+C pressed, signalHandler will be called

// to interrupt the programs execution

signal (SIGINT, signalHandler);

// Pin Definitions

GPIO::setmode(GPIO::BOARD);

// LED pin gets set to high initially

GPIO::setup(led_pin, GPIO::OUT, GPIO::HIGH);

std::cout << "Press CTRL+C to stop the LED" << std::endl;

int curr_value = GPIO::HIGH;

// Blink LED every 0.5 seconds

while (!done) {

std::this_thread::sleep_for(std::chrono::milliseconds(500));

curr_value = GPIO::HIGH;

GPIO::output(led_pin, curr_value);

std::cout << "LED is ON" << std::endl;

std::this_thread::sleep_for(std::chrono::milliseconds(500));

curr_value = GPIO::LOW;

GPIO::output(led_pin, curr_value);

std::cout << "LED is OFF" << std::endl;

}

GPIO::cleanup();

return 0;

}

hello walihullah,

I don’t have experience with QT creator.
but, please refer to below thread to resolve the issue, Jetson.GPIO not working on Python inside the container.

Hi @walihullah ,

We have controlled by using system commands with qt creator. Our gpio numbers were 508,509 and 510. You should enter your gpio numbers.

system("echo 508 > /sys/class/gpio/export");
system("echo out > /sys/class/gpio/gpio508/direction");
system("echo 509 > /sys/class/gpio/export");
system("echo out > /sys/class/gpio/gpio509/direction");
system("echo 510 > /sys/class/gpio/export");
system("echo out > /sys/class/gpio/gpio510/direction");

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.