WiringNP in QT

From wiki.ferrari.mo.it
Revision as of 19:43, 20 April 2020 by Admin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Installing WiringNP[edit]

The WiringNP in the /root folder, at least for NanoPI K1 Plus, is not good. It shows the NanoPI Neo/Neo2 GPIOs.

Reinstall it from sources:

git clone https://github.com/friendlyarm/WiringNP
cd WiringNP/
chmod 755 build
./build

then, check it via gpio command

gpio readall

Basic C test[edit]

#include <wiringPi.h>
int main(void)
{
  wiringPiSetup();
  pinMode(21, OUTPUT);
  for(;;)
  {
    digitalWrite(21, HIGH);
    delayMicroseconds(500);
    digitalWrite(21, LOW);
    delayMicroseconds(3500);
  }
}

Compile with:

gcc -Wall -o test test.c -lwiringPi -lpthread

Use in QT[edit]

Add the following line to <project>.pro:

LIBS += /usr/local/lib/libwiringPi.so

It will include the libpthread.so library automatically.

In the files, don't forget to add

#include <wiringPi.h>

and

wiringPiSetup();

before doing any other operation.

If you want to use it for PWM output, in QT it's really unstable, at least for frequencies above 50Hz.