Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. My gpio does not change with my code but changes occured with this code.
Forum Updated to NodeBB v4.3 + New Features

My gpio does not change with my code but changes occured with this code.

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 293 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MhM93M Offline
    MhM93M Offline
    MhM93
    wrote on last edited by
    #1

    Hi.
    I have a matrix relay with a nanopi fire (like rasperry pi). I connected this relay to my device and want to change gpio value.(my device has multi gpio pin. first I should create gpio folder with export command and then change direction folder "out" and with changing value the relay should turn on and off.)
    this is my code:

    bool GPIOClass::ChangeValue(QString IO, QString port)
    {
        QString gpio;
        QString comand;
    //    comand=" echo ";
    //    comand.append(QIO);
    //    comand.append(" > ");
    //    gpio=config->GpioFromPort(port);
    
    //    if(gpio.length()==0)
    //        return false;
    //    //IO should be 1 or 0
    
        QString src=IdenGPIOSrc(gpio);//src is /sys/class/gpio/gpio95
        src.append("/value");
    
    //    comand.append(src);
    //    qDebug()<<port<<gpio<<"with src:"
    //           <<src <<"with command:"<<comand;
    //    system(comand.toStdString().c_str());
    
        ///===========================================================
        QFile file(src);
        if ( file.open(QIODevice::WriteOnly) )
        {
            //clear the content
    //        file.resize(0);
            file.seek(0);
            file.write(QByteArray::number(IO.toInt()),1);
    
        }
    
        if(GetValue(port)==IO.toInt())
        {
            return true;
        }
        else
            return false;
    }
    

    the relay is not changed, but when I run the executable sample the relay is turn on and off:

    int main(int argc, char ** argv) 
    {
        int pin = GPIO_PIN(7); 
        int i, value, board;
        int ret = -1;
     
        if ((board = boardInit()) < 0) {
            printf("Fail to init board\n");
            return -1;
        }
        if (board == BOARD_NANOPI_T2)
            pin = GPIO_PIN(15);
     
        if (argc == 2)
            pin = GPIO_PIN(atoi(argv[1]));
        if ((ret = exportGPIOPin(pin)) == -1) {   
            printf("exportGPIOPin(%d) failed\n", pin);
        }
        if ((ret = setGPIODirection(pin, GPIO_OUT)) == -1) {
            printf("setGPIODirection(%d) failed\n", pin);
        }
        for (i = 0; i < STATUS_CHANGE_TIMES; i++) {
            if (i % 2) {
                value = GPIO_HIGH;
            } else {
                value = GPIO_LOW;
            }
            if ((ret = setGPIOValue(pin, value)) > 0) {
                printf("%d: GPIO_PIN(%d) value is %d\n", i+1, pin, value);
            } else {
                printf("setGPIOValue(%d) failed\n", pin);
            }
            sleep(1);
        }
        unexportGPIOPin(pin);
        return 0;
    }
    

    in that code also the value in that address changed like my code (i test it ) and the relay is working.
    where is my code problem?

    H.Ghassami

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved