Download and Install

WiringPi is now maintained under GIT for ease of change tracking, however there is a Plan B if you’re unable to use GIT for whatever reasons (usually your firewall will be blocking you, so do check that first!)

If you do not have GIT installed, then under any of the Debian releases (e.g. Raspbian), you can install it with:

sudo apt-get install git-core

If you get any errors here, make sure your Pi is up to date with the latest versions of Raspbian:

sudo apt-get update
sudo apt-get upgrade

To obtain WiringPi using GIT:

git clone git://git.drogon.net/wiringPi

If you have already used the clone operation for the first time, then

cd wiringPi
git pull origin

Will fetch an updated version then you can re-run the build script below.

To build/install there is a new simplified script:

cd wiringPi
./build

The new build script will compile and install it all for you – it does use the sudo command at one point, so you may wish to inspect the script before running it.


Plan B

Click on this URL: (it should open in a new page)

https://git.drogon.net/?p=wiringPi;a=summary

Then look for the link marked snapshot at the right-hand side. You want to click on the top one.

This will download a tar.gz file with a name like wiringPi-98bcb20.tar.gz. Note that the numbers and letters after wiringPi (98bcb20 in this case) will probably be different – they’re a unique identifier for each release.

You then need to do this to install:

tar xfz wiringPi-98bcb20.tar.gz
cd wiringPi-98bcb20
./build

Remmeber the actual filename will be different – you will have to check the name and adjust accordingly.


Test wiringPi’s installation

run the gpio command to check the installation:

gpio -v
gpio readall

That should give you some confidence that it’s working OK.

WiringPi is released under the GNU Lesser Public License version 3.

Comments

Download and Install — 320 Comments

  1. Hi..
    The PWM-Test (test2) with a LED between Pin12 and Pin3 (GND) produces weird noises on the sound output jack. Can I solve this somehow ?

    • No, sorry!

      The Pi only has 2 PWM output pins and they’re normally used for the audio output on the 3.5mm jack socket. If you re-program the GPIO pin for PWM, it then uses one of the 2 PWM channels that goes to the audio output – so when you use it to drive an LED or motor, etc. it will make some sort of noise on the audio…

      -Gordon

  2. Thank you for your work done with this project. I can now run test2 successfully from command line only. I have a rough idea how to write and compile programs with text editors. (I’ve used Geany as my editor.)

    I am teaching my 13 year old daughter with Geany on the Raspi to write basic C++ programs. (I never used Linux for C/C++ before yesterday.) How do I include these libraries into g++ so that I can use Geany to write and test the code? It will be great if we can “do stuff” via GPIO as well. I don’t want to drag out the Arduino as well.

    Regards

    • I really don’t know much about Geany and its environment. All my work is done using a text editor like Vi (or vim), and Makefiles…
      I’ll have a look at it if I have some time though.
      -Gordon

      • Thank you for both replies to my questions. I still have a lot to learn, at least I can write with Geany, its just the compiling bit that’s a bummer. I think my question is more general in any case. Basically, how to get extra libraries and headers into C++ with linux. So far I did not had much luck figuring it out.
        Regards and thank you once a again for helping me make my own LED pattern go blink blink blink!

        • What you can do is simply copy the source-code in-line with your own program. Just add it all on at the top of the program. It’s not elegant, but it should work!

          I’ve not had time to look at Geany yet though.

          -Gordon

    • Hello Jaques
      Like you I use Geany to program, compile and debug C programs and also I had the same problem with wiring library. Here is my solution.
      Go to ‘Build’ menu and then ‘Set Build Commands’. In the second option, ‘Build’, you have to write the following:

      gcc -o “%e” -l/usr/local/include “%f” -L/usr/local/lib -lwiringPi

      I assume that you have followed the standar installation instructions.

      Hope this helps.

      Regards.

  3. Hello Gordon,

    I have just downloaded and perused your WiringPi code.

    Looks very interesting. Thanks for making it available as it shows many useful specifics for using the Raspberry Pi’s GPIO.

    One thing that I noticed was that in the definition of the pinMode function in wiringPi.c the static flag pwmRunning seems only to be defined and initialised to FALSE and tested and never set to anything else. Should it possibly be set to TRUE somewhere, maybe at the end of the if (!pwmRunning) block? Or have I missed the point?

    Regards

    Ralph

    • Looks like you’ve not missed the point, but I’ve missed a line! There should be a pwmRunning = TRUE in that block. However it’s not really doing any harm, just a minor optimisation and I’ll sort it out then next time I do an update!

      Thanks!

      -Gordon

  4. Could this code be used on my Raspberri Pi? I know it runs on an Arduino to control leds on a reef tank. Thanks

    byte MoonPhase()
    {
    int m,d,y;
    int yy,mm;
    long K1,K2,K3,J,V;
    byte PWMvalue;
    m = month();
    d = day();
    y = year();
    yy = y-((12-m)/10);
    mm = m+9;
    if (mm>=12) mm -= 12;
    K1 = 365.25*(yy+4712);
    K2 = 30.6*mm+.5;
    K3 = int(int((yy/100)+49)*.75)-38;
    J = K1+K2+d+59-K3;
    V = (J-2451550.1)/0.29530588853;
    V -= int(V/100)*100;
    V = abs(V-50);
    PWMvalue = 4*abs(50-V); // 5.12=100% 4=~80%
    //pinMode(lowATOPin,OUTPUT);
    return (PWMvalue*100)/255;
    }

    It returns 0-100.
    You can comment the kast line and return PWMvalue for 0-255.

    • Essentially yes.

      You may have to tweak a few things though – e.g. there might not be a “byte” type (and even on the arduino, you probably want to #include <stdint.h> and use uint8_t instead of ‘byte’…)
      The PWM value is 0 to 1023, so might need a little scaling.
      ints on the Pi are signed 32-bit values, as are longs, so do check ranges and so on.

      Not sure where you’re getting the day(), month() and year() functions from either, but I’ll assume you have something else to provide them… If not, and you’re not sure how to do this stuff under unix then lookup the manual page for the ctime() function.

      -Gordon

  5. I tried to cc the code and got this error.
    It also did not like the stdint.h

    lunar.c:1:1: error: unknown type name ‘unit8_t’
    lunar.c: In function ‘MoonPhase’:
    lunar.c:7:1: error: unknown type name ‘unit8_t’
    lunar.c:16:6: error: expected expression before ‘int’
    lunar.c:19:6: error: expected expression before ‘int’

  6. Gordon – have recently downloaded this update with added serial commands. I’m very new to all this and wondered if you could help? I’ve written some midi code for the Arduino (which all works fine)based on the Arduino midi example:

    void setup() {
    // Set MIDI baud rate:
    Serial.begin(31250);
    }

    void loop() {
    // play notes from F#-0 (0x1E) to F#-5 (0x5A):
    for (int note = 0x1E; note < 0x5A; note ++) {
    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, note, 0x45);
    delay(100);
    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
    noteOn(0x90, note, 0x00);
    delay(100);
    }
    }

    // plays a MIDI note. Doesn't check to see that
    // cmd is greater than 127, or that data values are less than 127:
    void noteOn(int cmd, int pitch, int velocity) {
    Serial.write(cmd);
    Serial.write(pitch);
    Serial.write(velocity);
    }

    I've tried to adapt this using your serial library but I just can't work it out – if you, or someone else who reads this, wouldn't mind could you adapt the above code so it will run on raspberry pi – once I have that I think I can work on it from there.

    Thanks for your help

    • ok. A very quick translation:

      Serial.begin (baud) becomes fd = serialOpen (“/dev/ttyAMA0”, 31250) ;

      However sadly this will fail as that’s not a recognised baud rate in the Linux world.

      So if you can change the baud rates then it’ll work, otherwise I don’t know where to start, but a quick google suggests this may help you: http://joost.damad.be/2009/05/how-to-set-serial-port-at-midi-speed-in.html

      in your noteOn() function:

      Serial.write (val) becomes serialPutchar (fd, val) ;

      And that’s it at it’s simplest. the ‘fd’ value (and int) is the file descriptor (everything is a file in unix land). You just need to make that avalable to any code that wants to use the serial port. (maybe a global for you). The /dev/ttyAMA0 is the on-board serial port (3.3v, remember). However it could be a USB serial port – e.g. /dev/ttyUSB0 for example…

      -Gordon

      • Hello Gordon,

        “However it could be a USB serial port โ€“ e.g. /dev/ttyUSB0 for exampleโ€ฆ”

        With device “/dev/ttyAMA0″ and a MAX3232 it works nice. Your second suggestion sending serial data to USB sounds interesting. Anyway, i do not have a /dev/ttyUSB0” in my /dev/ folder. May you explain how to do this ?

        thanks wally

        • You’ll only see a /dev/ttyUSB0 if you plug in a USB serial device.
          The Pi’s on-board serial port is /dev/ttyAMA0.

          In Linux all serial ports work more or less the same – they just have different names – /dev/ttyAMA0 for the on-board on one a Pi, /dev/ttyS0 for the on-board one on a typical PC, /dev/ttyUSB0 for usb serial devices (ftdi), and /dev/ttyACM0 for some other modem devices (sometimes 3G modems)

          -Gordon

  7. I seem to be stuck already. Am I ok doing this in lx terminal or should i be elsewhere, the files are in the examples folder

    pi@raspberrypi:/tmp/wiringPi/examples$ sudo ./test1
    sudo: ./test1: command not found
    pi@raspberrypi:/tmp/wiringPi/examples$ sudo ./test2
    sudo: ./test2: command not found

    thanks

    JG

    • lxterm is fine.
      did you do the sequence of:
      cd wiringPi/wiringPi
      make
      sudo make install
      cd ../ gpio
      make
      sudo make install
      — and finally:
      cd ../examples
      make <--- did you type make? sudo ./test1 I'm wondering if you missed out the 'make' command in the examples directory. However, unless you connect up some LEDs to the Pi, you're not going to see very much happening - they are really intended to be used as examples to base your own GPIO programs on. -Gordon

    • Ah, guesed you missed the final ‘make’ them. Do look at the programs though and if you want more examples, there are a few more on my website – e.g. lookup the TuxX program and the ladders game …

      -Gordon

  8. Have just tried to install following your guidelines but ran into a problem:
    pi@raspberrypi /tmp $ tar xfz wiringPi.tgz
    pi@raspberrypi /tmp $ cd wiringPi/wiringPi
    pi@raspberrypi /tmp/wiringPi/wiringPi $ make
    [CC] wiringPi.c
    [CC] serial.c
    [CC] wiringShift.c
    [CC] lcd.c
    [CC] piHiPri.c
    [CC] piThread.c
    [AR] wiringPi.o serial.o wiringShift.o lcd.o piHiPri.o piThread.o
    make: avr-ar: Command not found
    make: *** [libwiringPi.a] Error 127
    pi@raspberrypi /tmp/wiringPi/wiringPi $

    Got round the problem by using a Makefile from a download yesterday. The fix was:

    $(TARGET): $(OBJ)
    @echo [AR] $(OBJ)
    @ar rcs $(TARGET) $(OBJ)
    @size $(TARGET)

    • Aargh )-:
      bother.
      That’s what I get for working on some ATmega and Pi projects at the same time. I’ve put the wrong thing in the wrong makefile – (and it happens I have the arduino IDE installed on my Pi’s so I never noticed it).
      Thanks for that. I’ll fix it right away.

      -Gordon

  9. Hi Gordon and thank you for your library. Is it possible to stop the program after I started it?

    • Type Control-C in the terminal window you started the program in.
      (That’s the usual unix/linux way!)
      -Gordon

  10. I just wanted to let you know that I have prepared and inserted this into the Arch Linux ARM repos.

    • Thanks!

      What I’m aiming to do is to move it all to GIT, but that requires learning GIT first – I just need to sit down for an afternoon with no interruptions and get on with it..

      -Gordon

  11. Hi Gordon

    I’ve downloaded and run the install for wiringPi and this completed all ok. Trouble is I can’t seem to compile my own test app, what I did is this:
    #include
    #include
    #include
    #include
    int main()
    {
    if(wiringPiSetup() == -1)
    exit(1);
    else
    printf(“wiringPi library ok!”);

    return(0);
    }

    and what i get is “undefined reference to ‘wiringPiSetup’ and a failed compilation.

    What do i need to do to get this to compile? BTW: this is both using the gcc command line and geany, both give the same error!

    Help!! Thanks in advance! Dan

    • Try:

      cc -o test test.c -lwiringPi

      to compile it (assuming your file is called test.c!)

      then

      sudo ./test

      to run it.

      I’m not sure about using geany – I don’t use it myself, but I might have to start to have a look soon to work out how to make it use additional libraries.

      -Gordon

  12. Many thanks Gordon, much much appreciated! I’ll be sure to let you know how I get on and if I manage to get it to compile under Geany.

    Thanks again ๐Ÿ™‚

    Dan

  13. Dear Gordon,
    Thanks for great stuff!
    I use the pi as small server and ‘case fan speed contoller’. Your library is really easy to use for beginner like me.

    The fan doesn’t accept high frequency pwm wave form (up to 30KHz). so I changed ‘wiringPi.c’ as follows.
    in function ‘pinModeGpio’
    *(pwm + PWM0_RANGE) = 600/ ; // new
    *(pwm + PWM0_DATA) = ;
    *(pwm + PWM_CONTROL) = PWM0_ENABLE | PWM1_ENABLE | PWM0_MS_MODE | PWM1_MS_MODE;
    Regards

    • Yes – you’re putting the PWM into the other mode (which is possibly more sensible than the default which is balanced out, but who knows) – it’s something I’ll be doing for the next release, providing the ability to change the frequency and mode.

      Cheers,

      -Gordon

  14. Hi. Great site, great posts. Due to simplicity of the rpi(Raspberry Pi) I am a recent convert and devotee of the Raspberry Pi and I have a bunch of things to do with it. Can i do the following:
    1. Connect 4 rpi and run them in parallel, like multi-threading. I would like them to run one application and give me feed back on different screens. and How can I achieve this.
    2. Connect LCD screens to the rpi’s.
    3. Use regular DC batteries to power them?
    It would be great to hear from you.
    Thanks

    • You’ve just sent me an email which I’ll answer shortly, but briefly:

      1 – In theory yes. There are various setups and libraries to do this – e.g. The Beowolf project and so on, or just by writing your own communication mechanisms.

      2 – The on-board LCD display port doesn’t have any drivers yet, so right now we’re limited to the HDMI or composite video output

      3 – You can power a Pi from batteries, but you’ll need a 5V regulator and be aware that the Pi is going to comsume some 3 watts, so regulat AA’s won’t last long, you’ll need something bigger.

      -Gordon

  15. Thanks for this excellent library. Despite being Linux noob and not having done C programming since high school (at which time it was at the hello-world level), I managed to adapt it to servo-motor control. Just increase the period to 12000 (0x2EE0 – giving 50hz), use MS mode as koma did for his fan speed control, and modify the pwm_write routines to allow higher values than 1023 (400 to 1400 would be a suitable range for most servos – I decided to allow up to 4095 to allow for experimenting). Oh, and do not supply power to your servo-motor from the Raspi, even if said servo is small; it *will* lead to crashes.

    Which brings me to the point of this post: I don’t think you should recommend building the library in the /tmp folder, or if you do, warn people to copy it elsewhere before starting to modify the source. The reason? Guess what folder is amongst those “cleaned up” as a matter of housekeeping routine when the Raspi starts ๐Ÿ˜€


    Best regards, Kรกri.

    • Glad your able to use it and modify it – but you’re probably right about /tmp, however you did learn something new ๐Ÿ˜‰

      -Gordon

    • I do use version control – it’s something I put together for myself some 20 years ago based on rcs and really not fit for public consumption… However I’m getting to grips with GIT and will be hosting it on my own servers shortly with gitweb as the front-end (same front-end as the Linux kernel uses)

      -Gordon

  16. Hey Mr. Gordon,

    Thanks for the additional libraries to wiringPi again, its so exciting to check site for new additional functions, this Serial library will be so helpful to me

    Then, when i tried to install again it gives error for /gpio section as :
    gpio.c : In function main
    gpio.c:555:5 warning: implicit declaration of function ‘wiringPiSetupPiFaceForGpioProg’
    gpio.c: error: ‘WPI_MODE_PIFACE’ undeclared (first use in this function)

    etc. So as a result i could not build the library

    I wonder if i am the only one suffering from the problem, which parts/codes should i remove to sucecsfully build it?

    Thanks in advance a lot,
    Cheers

    • Hi,

      How did you download and install it?

      If you try this:

      git clone git://git.drogon.net/wiringPi

      then:

      cd wiringPi/wiringPi
      make
      sudo make install
      cd ../ gpio
      make
      sudo make install

      then that should make everything cleanly.

      Let me know how you get on with that.

      -Gordon

  17. i simply follow instructions on the article above, so i use wget to download and then other steps…

    It gives error for piFace code actually, i don’t know wheter i am downloading properly or something to do with my own RPi.

    Then when i use git clone commands, it says
    bash:git: command not found

    error.
    Could i please also learn how to use git command from LXTerminal so?

    Thank you.

    • OK. If you’re running Debian (Squeeze/Wheezy/Raspbian), then

      sudo apt-get install git-core

      will fetch and install GIT for you. It may be that the old release files are somewhat incomplete though – probably my fault when moving the project into GIT, so I’ve just pushed the current version to the old downloads site, so try again, either way and let me know how you get on.

      -Gordon

  18. Why is nothing in the /wiringPi/examples/ directory executable? Are these complete programs that need to be recompiled?

    I thought I was pretty computer savvy but the Rpi code out there is making me feel like an idiot. And there is some bad info on the web, which only makes things worse.

    Please, someone out there tell me, from start to finish, what do I need to do to blink an LED on GPIO 21.

    I have installed the example programs

  19. adding Git (whatever that is) to my Pi ate up 13.8 MB of space.

    I’m trying to SAVE space on the SD card… but I dont pretend to understand all of this anyway.

    What was wrong with apt-get or aptitude? Can i remove Git now that I’ve installed wiringPi?

    Thank you

    • It’s a good question – and one reason is that while I’ve been using Debian for 18 years, I’m relatively new to actually building packages for it, so it’s on the cards, but not yet.
      Also, the GIT way will work on other Linux releases too – e.g. Arch which seems to have a small, but growing community, so GIT makes it an easy way to distribute for everyone.

      However, yes, you can remote git –

      sudo apt-get purge git-core
      sudo apt-get clean

      However, you’ll need it again, should you need to upgrade wiringPi.

      -Gordon

  20. Well you rock, Sir.
    You have a great body of work here. Very helpful. I’ve spent a lot of time wandering the pages here.

    Thank you!

  21. Hi,

    Im trying to connect a DS18B20 to my pi, and have successfully done so. But I have a problem with timings. I use your lib in the code. Do u know how to make the program faster? I have to have precise timings about 6us. Is there a way to isolate the .c program?

    When running in terminal mode I get the fastest pwm high/low within a 336us period and that is to long, want to short it to at lest 15us.

    I would like that this sensor worked within the latest debian distro, or is this impossible? Do I have to run the program under other “faster” linux?

    • If you pull the latest wiringPi via GIT then the delayMicroseconds() code uses a hardware timer when asking to delay under 100uS, then you can bit-bang the interface.

      However, there is a kernel module for 1-wire – I’ve not used it myself yet, but it’s there… However, even with the new delayMicroseconds() code, I’d be concerned about latency due to Linux getting in the way. Run as root, call wiringPiSetup() first, then piHiPri (50) ;

      Good luck!

      -Gordon

  22. Nice work, Gordon!

    I took the liberty to change your gpio.c code to make “write” accept any number of pins and values setting them all in one call. E.g.

    gpio write 0 1 1 1 2 0 3 0

    turns on pins 0 and 1, and turns of pins 2 and 3.

    This is my patch:
    ============================

    — gpio.orig.c 2012-09-09 17:50:03.791177105 +0200
    +++ gpio.mla.c 2012-09-09 17:56:42.654686200 +0200
    @@ -607,25 +607,26 @@

    static void doWrite (int argc, char *argv [])
    {
    – int pin, val ;
    + int ix;

    – if (argc != 4)
    + if (argc < 4 || argc % 2)
    {
    – fprintf (stderr, "Usage: %s write pin value\n", argv [0]) ;
    + fprintf (stderr, "Usage: %s write pin value [ pin value … ]\n", argv [0]) ;
    exit (1) ;
    }

    – pin = atoi (argv [2]) ;
    + for (ix = 2; ix < argc; ix += 2) {
    + int pin, val;

    – if ((wpMode == WPI_MODE_PINS) && ((pin = NUM_PINS)))
    – return ;
    + pin = atoi(argv[ix]);

    – val = atoi (argv [3]) ;
    + if ((wpMode == WPI_MODE_PINS) && ((pin = NUM_PINS)))
    + return ;

    – /**/ if (val == 0)
    – digitalWrite (pin, LOW) ;
    – else
    – digitalWrite (pin, HIGH) ;
    + val = atoi(argv[ix + 1]);
    +
    + digitalWrite (pin, val ? HIGH : LOW) ;
    + }
    }
    ==================================

    Naturally, you do with it what you please!

    Cheers!

    fischelbyxa

  23. Hello Gordon,

    for using wiringPi with gambas i need shared library.
    May you show us, how to modify the build-script and/or Makefile
    so it creates a shared library additionally ?

    wally

  24. Hello Gordon,

    maybe this is interesting for winringPi shared lib build.
    i uses it and it works.

    http://www.raspberrypi.org/phpBB3/viewtopic.php?f=34&t=6182&hilit=gambas3

    by g4eml ยป Sat Aug 11, 2012 9:57 pm

    Unfortunately Gambas3’s external function definition won’t work with a .a library. It needs a shared object .so library instead.

    Not expecting it to work I ran the command

    ‘ gcc -shared -o libwiringPi.so *.o ‘

    in the wiringPi source directory. To my surprise it produced a .so file with no errors displayed.

    The file produced is here:- http://www.filedropper.com/libwiringpi

    When this was used in a this Gambas test project http://www.filedropper.com/gpiotest it worked as expected.

    • Have sent you an email – but for anyone else reading, I’m testing a new Makefile which generates both a static and shared library for wiringPi and it’s ancilliary functions.

      -Gordon

  25. Hello Gordon,

    thanks for getting this nice library on the Pi!
    I have just connected an older 2×20 Seiko LCD (L2432)andit essentially works.
    But when I run the lcd example it works a while and then suddenly writes random character into the display. Currently no idea what goes wrong. Could this be a timing issue?

    -Florian

    • It could be timing. How old if your wiringPi? But check the file lcd.c in the wiringPi directory – look for delayMicroseconds () – if both calls are 50 then it’s new, but if not then make both numbers 50 – if they already are 50 then try to increase it to 75 to see if it helps.

      -Gordon

      • Hurra – Yes it was timing. I had to increase the delays in the strobe function to 50 and 150. Then it worked. B.t.w. the display is a 2×24. Had to change the validation in lcd.c.
        thanks a lot for your tip!

        • OK. I’ll look into i again. Odd though – the data sheets for those chips all specify the timings in the nano seconds range!

          And it seems that the differnet displays have differnet ways to address len x hight.

          More to investigate…

          -Gordon

  26. Hello Gordon,
    I’m little confused yesterday,, i compiled some little test program in your Demo direktori of WiringPi. I got Raspberry PI device. I just wondering, why it is okey if i compile the test.c file with command cc -o test test1.c -lwiringPi? but got error if i compile the source with command “gcc test1.c -o test1”? any answer about my problem?? Thanks
    -Naito

    • With the latest wiringPi release, you compile the examples separately. e.g.

      make test2

      However… the difference between cc and gcc … Or is it simply because you omitted the -lwiringPi from the 2nd one? Can you post the output?

      -Gordon

  27. My 512MB board has the Revision “000f”, but gpio won’t recognize that it’s a hex number and interpret it as 0, not 15.

  28. Excuse me, I tried the git command in my Pi, but got time out problem while connecting to git.drogon.net. I download the file listed, but it is not the newest one and cannot find the SPI function… Thank you!

    • Error message are always useful here. Try to ping git.drogon.net and see if https://git.drogon.net/ works too. However I’d try the git commands again – just in-case there was some internet routing issues along the way.

      cd
      git clone git://git.drogon.net/wiringPi
      cd wiringPi
      ./build

      -Gordon

      • Dear Gordan:

        Thank you very much. I ping the git.drogon.net and all the data lost. But I can visit the https://git.drogon.net. In this case, how can I install the software? I am afraid it is the firewall in my institute block the link. May I do the manual clone? Thank you very much.

  29. Hi Gordon,
    I’ve a problem with the last version of wiringPi and gpio.
    When I try to execute a simple command like “gpio write 0 1” I have an error :

    “gpio: error while loading shared libraries: libwiringPi.so.1: cannot open shared object file: No such file or directory”

    but in my /usr/local/lib/ I have those files :

    # ls -l
    total 36
    lrwxrwxrwx 1 root root 33 Oct 27 23:26 libwiringPi.so -> /usr/local/lib/libwiringPi.so.1.0
    lrwxrwxrwx 1 root root 33 Oct 27 23:26 libwiringPi.so.1 -> /usr/local/lib/libwiringPi.so.1.0
    -rwxr-xr-x 1 root root 32951 Oct 27 23:26 libwiringPi.so.1.0

    Any idea ?

    (sorry for my english, I’m french ^^”)

    • Sorry, it’s me again ! xD

      I’ve found a very simple solution

      echo “/usr/local/lib/” >> /etc/ld.so.conf/d/gpio.conf
      ldconfig

      That’s all, for information I’m running ArchLinuw on my Raspberry Pi and apparently, Arch by default don’t seek on /usr/local/lib for shard object…

      that’s weird

      • Ah, Arch Linux. I do all my devleopment on Debian (Raspbian) and it has /usr/local/lib in /etc/ld.so.conf.d/libc.conf by default.

        I’ll need to investigate some way round that one (although putting it in /usr/lib might be the way round it!)

        Thanks,

        -Gordon

        • I haven’t try but it should work if you put the lib in /usr/lib, that’s where I’ve all the .so files

          Or, I think you can modify your makefile to add /usr/local/lib in ld.so.conf during the install process, so it will works with any GNU/Linux distros, even with the oddest one ๐Ÿ˜€

          • You’re using Arch, I guess?
            I’ll have a look … moving from a static library to dynamic has caused more issues that any other change to wiringPi )-:

            -Gordon

        • Hi,Gordon
          I have the same issue in tinycore(for pi) 4.7.7

          google it find this page, have not test it yet ……

  30. Thanks very much for this library. I especially like the sys mode for those of us with a nervous disposition (thus reluctant to run everything via sudo!). Via swig I managed to get lua bindings for wiringPi but I had to make a couple of small alterations to wiringpi.i. I also thought that for the sys mode it would be useful to be able to know what direction the pins were set in so wrote that into the code for wiringPi.c. wpiToGpio (is that the right name?) also looked useful but wasn’t available so I fixed that. Let me know if any of these would be useful to you (I have a git repository of my changes). Via lua, I managed to control the pins from within a TeX document, but I’ll be amazed if anyone finds that useful!

    • Well I use LaTeX for some of my own documentation, but controlling GPIO via TeX – that’s “special” ๐Ÿ˜‰

      Drop me an email with your changes and I’ll have a look and see what’ swhat.

      -Gordon

  31. So I got the wiringpi installed and everything works perfectly from the console. But when I use the gpio command in a shell script and start it with update-rc.d, it looks like the command is not executed.
    Any idea ?
    What I know:
    * script is really running
    * no other program is using gpio
    * when I run the script manually it always works
    * the same script written in python also does not work when started automatically

    my greatest wish right now:

    #!/bin/sh
    gpio -g mode 7 out
    gpio -g write 7 0 #set port 7 to 0V

    • Maybe double-check that it really is working by using the gpio -v command which will dump some text on the console (if you have a console going!)

      But also make sure you’re looking at the right pin – pin 7 (-g) is one of the SPI pins. If the SPI driver is loaded, it might be pulling that pin high.

      -Gordon

      • Thanks for the fast answer ๐Ÿ™‚
        When calling the script from the console output.txt contains some infos about the wiringpi.
        After reboot the file is created but contains nothing.
        Using the SPI port or using another port does not matter.
        Any new ideas?
        new script:
        #!/bin/sh
        gpio -v > /srv/scripts/output.txt
        gpio -g mode 17 out
        gpio -g write 17 0

        • How is the LED wired up?

          If you go: GPIO -> Resistor -> LED -> 3.3v then the LED will light when you write 0. Try writing 1 to see if it goes off…

          Normally, I’d wire an LED like: GPIO -> Resistor -> LED -> 0v

          (Resistor and LED are interchangable)

          -Gordon

          • Everything works fine from the commandline, but when I start the script on bootup via update-rc.d the port is floating and the file mentioned in the post before contains nothing.

            Sorry if I myself unclear.

          • I can’t think why it might not be starting – I’d go through the scripts again, making sure the paths are set right, etc. I can’t think any other reasons right now, sorry..

            -Gordon

  32. Hey all.
    I’m still trying to get (understand, grasp, comprehend) what I need to do to get the RPi to read data from the ADXL34 3-axis accelerometer. I would be happy if i could call some command line function to get a reading or await interrupts or something.

    I’m not smart enough to figure out the few examples I’ve found.

    Does someone have a COMPLETE, idiot’s guide to making this happen?

    I have no idea if I should use SPI or I2C and there appear to be no wiring schematics in any but one example.

    So please, anyone… the world needs a COMPLETE solution for stupid people like me.

    0. What am I to expect? is this a command line program or just a library example?? Is this a logging function or will I see something on my screen when I tap the module?
    1. Wiring diagram – seriously – Its not even funny, how many “examples” are out there where the schematic was thought of as unnecessary.
    2. What do I need installed for the way its wired?
    3. What do I do if something doesn’t work?
    4. Perhaps EXPLAIN a little about why each of the previous steps was performed. Not everyone knows linux that well.
    Thank you very much

    • You can use Either I2C or SPI with this device. Personally, I’d use SPI, but if you’re more familairwith I2C, then use that.

      In either mode, you essentially send the device a read or write command, then specify the internal register to read/write, then you write the data, or read the value of that register. These are all 8-bit commands, so you exchange 2 bytes each cycle.

      Then you need to work out the register details, and so on…

      It’s not a device I’ve used myself – If you want more replies then you might be better off posting this on one of the Raspberry Pi forums though – or even looking through the Arduino ones too – as Sparkfun make a breakout board for this device, so there will probably be plenty of people using it there…

      -Gordon

  33. I’ve really been able to follow your examples on the led. I am a complete noob to this .. so I got this nokia display for $10 and I found
    code to drive it.. from the pi .. but the display back light I want to turn on and off .. I can permanently power it off the 3.3 line .. so I thought that I could
    1) my gpio is version 1.4 installed a day ago
    2) from what I could see I need a switching transistor .. I am using a 2N3906
    3) gpio -g mode 18 pwm
    at this point the screen goes blank..
    my question
    1) why the switching transistor.. why can’t I just turn on and off the leds like I did in your experiment? using gpio17 ?
    2) I found a document
    or the 22N3906 …
    R1 = Supply Voltage / ( Maximum Current Required / Minimum HFE * 1.3 )
    R1 = 3.3 / (.1 / 100 * 1.3)
    2538 so a 2k ohm resistor ?
    http://www.rason.org/Projects/transwit/transwit.htm
    would that make a difference ??
    any guidance would be appreciated ..

    • the important thing is to find out what the voltage and current rating the back-light needs. If it’s a simple LED or 2, then you might be able to drive it directly from the Pi (via a suitable resistor).

      The switching transistor might be needed to drive the backlight at a higher voltage and/or current than the Pi can provide – without knowing the characteristics of the display, I don’t know if it’s needed or not.

      I’d also start by not using PWM. So try:

      gpio mode 1 out
      gpio write 1 0
      gpio write 1 1

      and see what happens.

      -Gordon

  34. Hello Gordon,

    I have problem with install your wiringPi library.
    when i execute instruction ./build i receive message:

    WiringPi library
    ./build: line 29: make: command not found
    sudo: make: command not found

    Can You explain me what i do wrong?

    PS I USE RASPBMC distribution and g++ compiler.

    Best regards
    Andrew

    • It looks like the ‘make’ command isn’t installed with raspbmc. It’s a distribuition I’m not that familair with, but if it’s based on Raspbian (which I think it is), then try this:

      sudo apt-get insall make

      then re-run the build script.

      -Gordon

      • I ran into the same problem on Raspbmc. This worked:

        sudo apt-get update
        sudo apt-get install make
        sudo apt-get install gcc

        Then ./build

  35. Hi Grodon,
    Trying to use wiringPi from Eclipse. I immediately ran into problems linking to it. So I studied your make file for the examples. There is a section there:
    ==========================================================
    #DEBUG = -g -O0
    DEBUG = -O3
    CC = gcc
    INCLUDE = -I/usr/local/include
    CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe

    LDFLAGS = -L/usr/local/lib
    LIBS = -lwiringPi
    ===========================================
    What I do not understand is the library reference “LIBS = -lwiringPi”. Where does compiler find this wiringPi library?
    It is definitely not in /usr/local/lib where you install the shared shared library. Even the shared library name is not the same there (libwiringPi but not wiringPi as in the LIBS declaration).
    So where does the compiler find this mysterious “wiringPi” to link to?
    Best regards
    TJ

    • -lwiringPi causes the C compiler to look for libwiringPi. where is .a for a static library or .so for the dynamic ones…

      So there should be /usr/local/lib/libwiringPi.so as well as some symbolic links to it to represent the versions of that library.


      gordon @ pi0: ls -l /usr/local/lib
      total 48
      lrwxrwxrwx 1 root staff 33 Oct 21 18:53 libwiringPi.so -> /usr/local/lib/libwiringPi.so.1.0
      lrwxrwxrwx 1 root staff 33 Oct 21 18:53 libwiringPi.so.1 -> /usr/local/lib/libwiringPi.so.1.0
      -rwxr-xr-x 1 root staff 33532 Oct 21 18:53 libwiringPi.so.1.0

      I’m now wondering what distro you are using? I know that Debian includes /usr/local/lib in the library search paths by default, but so others?

      -Gordon

  36. Aha I was not aware that all libraries in Linux are pre-pended with “lib” (wonder why). As I’m doing cross compiling from Windows Eclipse I copied the /usr/local/lib/libwiringPi.so.1.0 to the lib-path of the Cygwin crosscompiler for RPi and simply renamed it to libwiringPi.so. And acadabra the app linked successfully.
    So to fully understand this, why are you installing the libwiringPi.so with a version number appended and then creatig links to that?

    • The lib prefix is a bit of history that goes back over 30 years (I don’t know why) as for the version numbers – to be honest I did it that way because it seems that’s how everyone else does it – this is the first time I’ve actualyl built a dynamic library for Linux…

      Hiny, tips, suggestions for improvement are welcome ๐Ÿ˜‰

      -Gordon

  37. Hi Gordon,

    I get the following when I run gpio:

    Unable to determine board revision from 0

    (uname -a = Linux custard 3.2.27+ #250 PREEMPT Thu Oct 18 19:03:02 BST 2012 armv6l GNU/Linux) This is a 512MB Made in China RPi deliver a few weeks ago.

    Nick

    • Make sure you’ve got the latest version of wiringPi from GIT.

      cd
      it clone git://git.drogon.net/wiringPi
      cd wiringPi
      ./build

      It sounds like your SoC hasn’t bee properly programmed though – check the output of

      cat /proc/cpuinfo

      but later versions of wiringPi cater for this (by assuming Rev 2)

      -Gordon

  38. Bug discovered in wiringPi/wiringPi.c:

    529: (void)*(pwm + PWM_CONTROL) ;
    530: while ((*(pwm + PWM_CONTROL) & 0x80) != 0) // Wait for clock to be !BUSY

    Obvious writing mistake. Code don’t match the goal described by comment.
    Should be corrected to “clk + PWMCLK_CNTL”?

    • You’re probably right and I’ve gone over the whole of the PWM code – again. Personally, I think the Pi’s PWM hardware is just a bit of a waste of time and have reverted to my software PWM for everything now.

      -Gordon

  39. Thank you very much for the explanation. I’m new to linux so sorry in advance for the basic questions. I managed to get the examples to run on my RPi. I have two questions to ask:
    1) how can i write my own C++ program and make them compile with your library? is there a special program I need?
    2) I’m working on a robotic project, how can i make a specific program run automatically when the raspberry pi is connected to the power?
    Thanks

    • c++ is fine – just #include <wiringPih> as usual and us ethe functions as you would in a C program.

      To run a program at boot time – look into /etc/rc.local – you can add it in there. (Raspbian – Arch may be different)

      -Gordon

  40. Hi Gordon,

    I followed the install instructions above and everything seemed to work fine. I wanted to use wiringPi to geht those easy commands for switching the GPIO outputs. But when I use e.g.:
    gpio mode 1 out
    gpio write 1 1
    the attached light won’t switch on (and no error message is shown). When I use

    echo โ€œ1โ€ณ > /sys/class/gpio/export
    echo โ€œoutโ€ > /sys/class/gpio/gpio1/direction
    echo โ€œ1โ€ณ > /sys/class/gpio/gpio1/value

    The light is perfectly switching on (and off if “0”).

    What did I do wrong?

    Many thanks in advance and best regards

    • The issue is confusing the wiringPi numbering scheme with the native chip GPIO numbering scheme.

      So using the /sys/class/gpio interface – you’ve exported pin 1 – this is BCM_GPIO 1 – Which on a Rev 1 board is one of the I2C pins. (On a Rev 2 board, it’s not brought out to the edge connector).

      So to use the gpio command with that numbering scheme, use the -g flag.

      gpio -g mode 1 out
      gpio -g write 1 1

      and so on.

      -Gordon

  41. I was not having any luck compiling the okLed example.

    Typing make okLed in the wiringPi directory results in

    make: *** No rule to make target `okLed’. Stop.

    cd’ing into examples/ and typing make okLed results in:

    [link]
    /usr/local/lib/libwiringPi.a(piThread.o): In function `piThreadCreate’:
    piThread.c:(.text+0x18): undefined reference to `pthread_create’
    collect2: ld returned 1 exit status
    make: *** [okLed] Error 1

    Any idea what I am doing wrong?

    • You’re doing OK – I goofed when I re-introduced the static libraries. Change the Makefile and add in -lpthread to the LIBS line. I’ll be releasing the fix soon.

      -Gordon

      • Since I just D/L’d your wiringPi. And all installed OK.
        I then went to the gpio/examples dirctory and entered:
        make okLed . It return to the prompt. No errors.
        But typin okLed returns “command not found”. What am I
        doing wrong?

        • You need to explicitly specify the path to run programs in the current directory (it’s a security measure) Also, this program needs root permissions to run, so:

          sudo ./okLed

          then watch the OK (or Act) LED on your Pi.

          -Gordon

  42. Hi Gordon,

    Thanks for your efforts in creating/supporting the wiringPi library, much appreciated!

    I’ve done a fresh Raspbian (2012-12-16) install on my 256MB model B. Followed the instructions, cloned the git repository. Some of the examples won’t build though (cd examples; make $EXAMPLE):

    [CC] tone.c
    tone.c: In function โ€˜mainโ€™:
    tone.c:17:8: warning: unused variable โ€˜bufโ€™ [-Wunused-variable]
    tone.c:16:10: warning: unused variable โ€˜jโ€™ [-Wunused-variable]
    [link]
    /usr/local/lib/libwiringPi.a(piThread.o): In function `piThreadCreate’:
    piThread.c:(.text+0x18): undefined reference to `pthread_create’
    collect2: ld returned 1 exit status
    make: *** [tone] Error 1

    I get the same linker error for “servo” and “okLed”. It seems that the pthreads library is missing from the linker invocation. I’ve made the following modification to the Makefile to fix:

    pi@raspberrypi ~/github/wiringPi/examples $ git diff -p Makefile
    diff –git a/examples/Makefile b/examples/Makefile
    index 738d36c..f219c9e 100644
    — a/examples/Makefile
    +++ b/examples/Makefile
    @@ -95,15 +95,15 @@ serialRead: serialRead.o

    okLed: okLed.o
    @echo [link]
    – @$(CC) -o $@ okLed.o $(LDFLAGS) $(LDLIBS)
    + @$(CC) -o $@ okLed.o $(LDFLAGS) $(LDLIBS) -lpthread

    tone: tone.o
    @echo [link]
    – @$(CC) -o $@ tone.o $(LDFLAGS) $(LDLIBS)
    + @$(CC) -o $@ tone.o $(LDFLAGS) $(LDLIBS) -lpthread

    servo: servo.o
    @echo [link]
    – @$(CC) -o $@ servo.o $(LDFLAGS) $(LDLIBS)
    + @$(CC) -o $@ servo.o $(LDFLAGS) $(LDLIBS) -lpthread

    .c.o:

  43. Oops – missed the same fix for wfi in the Makefile… Partial patch:

    wfi: wfi.o
    @echo [link]
    – @$(CC) -o $@ wfi.o $(LDFLAGS) $(LDLIBS)
    + @$(CC) -o $@ wfi.o $(LDFLAGS) $(LDLIBS) -lpthread

    • Hi,

      thanks for that. I goofed when I re-introduced the static libraries again. I have a fix for it, but not pushed it out to the GIT site yet. Will get there soon!

      Cheers,

      -Gordon

  44. Trying the build on OS X 10.7.5.. getting this:

    wiringPi Build script – please wait…

    WiringPi library
    [Compile] wiringPi.c
    wiringPi.c:350:47: error: invalid suffix “b100” on integer constant

    Really not used to C.. any thoughts?

    • Sorry, I left out important error messages. The ‘invalid suffix’ goes on for a while, and then I get:

      wiringPi.c: In function โ€˜wiringPiSetupโ€™:
      wiringPi.c:1114: warning: cast from pointer to integer of different size
      wiringPi.c:1115: warning: cast from pointer to integer of different size
      ..
      ..

      which goes on for a while. And then:

      make: *** [wiringPi.o] Error 1
      [Install]
      install: libwiringPi.a: No such file or directory
      make: *** [install] Error 71

      So I guess I’m just missing this file.. but where is it?

      • It’s probably a side-effect of the binary constands not being recognised earlier.

        Can you build it directly on a Raspberry Pi?

        -Gordon

    • It’s designed to be built on a Raspberry Pi. The 0b number prefix is relatively new extension to C, and might not be in the compiler you’re using on the Mac.

      -Gordon

      • Ah. I suspected that it needed to be built on the Pi, but that was failing for me because I didn’t have the necessary tools installed. I’m very fresh on Arch Linux and I just learned about pacman.

        Thanks for the tip. Getting some build errors but I’m much further along.

        • I do all my stuff under Raspbian – because I’ve been using Debian for 18+ years now, and it seems to be what everyone else is using on the Pi right now too.

          Not sure what packages you might need under Arch to build it though – basic compiler & build tools I imagine, make, gcc, etc.

          -Gordon

        • Success!

          I had scp’d to the Pi the repo I cloned on my mac. That wasn’t working, so I installed git on the Pi, cloned WiringPi locally, and it built fine.

          Onward..

  45. Hi Gordon,

    Does this error message tell you/us why git clone isn’t working for me? I don’t know if it is just me or if others are having the same problem.

    thanks,
    b

    pi@raspberrypi ~ $ git clone git://git.drogon.net/wiringPi
    Cloning into ‘wiringPi’…
    fatal: unable to connect to git.drogon.net:
    git.drogon.net[0: 195.10.226.169]: errno=Connection timed out
    git.drogon.net[1: 2a00:ce0:2:feed:beef:cafe:0:3]: errno=Address family not supported by protocol

    • I’m supecting that maybe your local site is blocking GIT for some reason. The server is running (check with https://git.drogon.net/ ) and I’ve just done some test GIT fetches from it.

      There was an issue a few days ago with IPv6, but that should be sorted – and it looks like your site can’t do IPv6 anyway – which is what’s leading me to think it might be an issue at your end – maybe a firewall?

      You can use the web link above to ge a tar.gz image of wiringPi (click on wiringPi in the main screen, then click on the ‘snapshot’ link at the right).

      -Gordon

    • OK. Another reply – as it actually looks like it might have been *my* firewall this time. (oops!)

      Give it another go and let me know how you get on.

      Thanks,

      -Gordon

      • Hi –
        I’m having the same issue here. I can wget the package, but not git clone it – same error as the original poster. I know it is not our local firewall as I can control it :)…
        Thanks

        • Wondering now if it’s to do with IPv6… You could try this:

          git clone git://195.10.226.169/wiringPi

          The wget package is old and will give you build issues with I2C (which I see from your other replies here)

          -Gordon

  46. Hi Gordon,

    Something you might want to add to your instructions is to tell users that if they have trouble installing git to run the following command first. I am new to Linux and it took me a while to solve that problem.

    sudo aptitude update

  47. This is a heads up to some of the people having the no control of GPIO2 problem.

    I just installed the newest archlinuxarm – and had the GPIO2 stuck low. I don’t remember if wiringpi was already installed – I think so. Arch’s pacman still has an older package. Anyway, removed the distro version and did a new build.

    /usr/local/lib/ is not searched for libwiringPi.so.1.0

    moved to /usr/lib/ and built the symlinks. Works fine.

  48. I’ve been trying all day and have had trouble cloning from your git server:

    root@mypi:/opt/wiringPi# git clone git://git.drogon.net/wiringPi
    Cloning into ‘wiringPi’…
    fatal: unable to connect to git.drogon.net:
    git.drogon.net[0: 195.10.226.169]: errno=Connection timed out
    git.drogon.net[1: 2a00:ce0:2:feed:beef:cafe:0:3]: errno=Address family not supported by protocol

    root@mypi:/opt/wiringPi#

    [ha ha I have a dead beef cafe]

    Am I doing something wrong or is your server somehow unavailable?

    • There were some issues a few days ago (mostly to do with ipv6 and firewalling), but I’m pretty sure they’re OK, and I can see people using the site OK now. Can you access https://git.drogon.net/ instead? Just do some basic network tests, ping, ping6, etc.

      The same physical server runs this website, so the server itself is fine – just some issues with GIT maybe…

      -Gordon

      • Aha problem fixed – firewall blocked TCP port 9418, which is needed by git protocol – the list is at . I unblocked 9418 and it worked.

        Sorry, after submitting this issue, I see somebody else had a similar problem 4 messages up. I thought I checked for that before submitting a comment. Maybe my fix is helpful to them too…

        [sent from my pi using IceWeasel browser…]

  49. Gordon,
    I am newish to linux and c, although I have programmed in other languages and windows for years. I want to transmit using an Ebay RF Wireless Transmitter and Receiver Link Kit Module 433Mhz for Remote Control on the Raspberry Pi and receive on an Arduino. I installed wiringPi using the instructions at the top of this page: https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/ I can make test1 ok, however I want to compile the send.cpp program from this site: https://github.com/r10r/rcswitch-pi I copied send.cpp, RCSwitch.cpp and RCSwitch.h to /home/pi/wiringPi/wiringPi/examples (where test1.c is) and tried to compile using this command: g++ send.cpp -o send But I get these errors: send.cpp:(.text+0x58): undefined reference to `wiringPiSetup’
    send.cpp:(.text+0x9c): undefined reference to `RCSwitch::RCSwitch()’
    send.cpp:(.text+0xac): undefined reference to `RCSwitch::enableTransmit(int)’

    I thought that I needed to compile RCSwitch first so I tried: g++ RCSwitch.cpp -o RCSwitch But got cant find ‘main’, which is understandable becuase it does not exist in RCSwitch.cpp

    I think my knowledge of c and making of c programs is letting me down – Can you help, please?
    Sorry if this is a bit basic, Chris.

    • You need to include the wiringPi library, so:

      g++ -o send send.cpp -lwiringPi

      However you also need to compile the library at the same time, so:

      g++ -o send send.cpp RCSwitch.cpp -lwiringPi

      Check the Makefile there too – that should have worked OK.

      -Gordon

  50. Gordon – thanks that worked a treat, but now I am having problems at run-time.
    I decided to go back to basics and just try to flash a LED.

    When I use the GPIO commands I can make my LED flash on then off

    gpio mode 4 out
    gpio write 4 1
    gpio write 4 0

    Then I wrote a small test program in c to do the same:

    #include
    #include
    #include
    #include

    int main (void)
    {
    int pin;
    int n;

    printf (“Raspberry Pi wiringPi test1b program\n”) ;

    if (wiringPiSetupSys() == -1)
    exit (1) ;

    pin = 4;
    for( n=0; n<5; n++)
    {
    pinMode (pin, OUTPUT) ;
    digitalWrite (pin, HIGH);
    delay(1000);
    digitalWrite (pin, LOW);
    delay(1000);
    }

    printf ("Finished\n") ;
    return 0 ;
    }

    The "make test1b" (in the examples folder), resulted in:
    gcc -O3 -Wall -I/usr/local/include -Winline -pipe -L/usr/local/lib test1b.c -lwiringPi -o test1b

    When I ran it:

    ./test1b
    Raspberry Pi wiringPi test1b program
    Finished

    The LED did not flash – what am I doing wrong?

    • the issue is that the gpio command uses naive wiringPi pin numbers by default, and your using wiringPiSetupSys() in the code.

      So if you change the wiringPiSetupSys() into wiringPiSetup() then it will work, but you’ll need to run the progam with sudo.

      If you want to do it without sudo, then:

      gpio export 23 out

      and use the wiringPiSetupSys() in the program, and change pin 4 to pin 23.

      However pinMode() does’t work in ‘Sys’ mode – it will only ever work if you use sudo. (And you only need to do it once, not in the loop)

      -Gordon

  51. Thanks for your speedy response.

    I have recoded as suggested:

    if (wiringPiSetup() == -1)
    exit (1) ;

    pin = 23; // == GPIO 4;
    pinMode (pin, OUTPUT) ;
    for( n=0; n<5; n++)
    {
    digitalWrite (pin, HIGH);
    delay(1000);
    digitalWrite (pin, LOW);
    delay(1000);
    }

    I did the:
    gpio export 23 out
    But now my Pi just crashes when I run:
    sudo ./test1b

    I get no error message – it just hangs, all the lights go out on the Pi except one red led, the same one that remains lit when you do a shutdown.

    • it’s pin number confision.

      bcm_gpio Pin 23 is wiringPi pin 4.

      wiringPiSetup() – my own wiringPi pin numbers.

      wiringPiSetupSys() – bcm_gpio pin numbers.

      Stick to one system or the other.

      So here, change the 23 into 4.

      you don’t need the gpio export command in wiringPi() mode either.

      And, as you’ve seen, poking the wrong pins can crash the pi!

      -Gordon

  52. Unable to build…any thoughts?

    pi@raspberrypi ~/wiringPi $ ./build
    wiringPi Build script – please wait…

    WiringPi library
    ./build: line 28: cd: wiringPi: No such file or directory
    make: *** No targets specified and no makefile found. Stop.
    make: *** No rule to make target `install’. Stop.

    GPIO Utility
    ./build: line 33: cd: ../gpio: No such file or directory
    make: *** No targets specified and no makefile found. Stop.
    make: *** No rule to make target `install’. Stop.

    Examples
    ./build: line 38: cd: ../examples: No such file or directory
    make: *** No targets specified and no makefile found. Stop.

    All Done.
    pi@raspberr

    • It really sounds like the installation is incomplete. Do you have the gpio, wiringPi and examples directories?

      try this:

      cd
      rm -rf wiringPi
      git clone git://git.drogon.net/wiringPi
      cd wiringPi
      ./build

      -Gordon

  53. here is a print of the wiringPi directory….

    pi@raspberrypi ~ $ sudo dir /home/pi/wiringPi
    build COPYING.LESSER examples gpio People

    pi@raspberrypi ~ $ sudo dir /home/pi/wiringPi/examples
    COPYING.LESSER gertboard.png nes.c pwm.c servo.c test2.c
    delayTest.c lcd.c okLed.c README.TXT speed.c tone.c
    gertboard.c
    Makefile piface.c serialRead.c test1.c wfi.c
    pi@raspberrypi ~ $ sudo dir /home/pi/wiringPi/gpio
    COPYING.LESSER gpio gpio.1 gpio.c gpio.o Makefile test.sh

    • Well it looks fine, but please stop using sudo for everything. That’s probably where it’s all gone wrong – the files will have been installed with root premissions rather than that of the ‘pi’ users (or whaterver user you are doing).

      So… Best to start again..

      cd
      sudo rm -r wiringPi

      …. then don’t use sudo, but:

      git clone git://git.drogon.net/wiringPi
      cd wiringPi
      ./build

      not a sudo in sight.

      -Gordon

  54. Thanks for the help…but still no luck….


    pi@raspberrypi ~ $ cd
    pi@raspberrypi ~ $ sudo rm -r wiringPi
    pi@raspberrypi ~ $ git clone git://git.drogon.net/wiringPi
    Cloning into 'wiringPi'...
    remote: Counting objects: 204, done.
    remote: Compressing objects: 100% (204/204), done.
    remote: Total 204 (delta 122), reused 0 (delta 0)
    Receiving objects: 100% (204/204), 79.75 KiB, done.
    Resolving deltas: 100% (122/122), done.
    pi@raspberrypi ~ $ cd wiringPi
    pi@raspberrypi ~/wiringPi $ ./build
    wiringPi Build script - please wait...

    WiringPi library
    [Compile] wiringPi.c
    [Compile] wiringPiFace.c
    [Compile] wiringSerial.c
    [Compile] wiringShift.c
    [Compile] gertboard.c
    [Compile] piNes.c
    [Compile] lcd.c
    [Compile] piHiPri.c
    [Compile] piThread.c
    [Compile] wiringPiSPI.c
    [Compile] softPwm.c
    [Compile] softServo.c
    [Compile] softTone.c
    [Link (Static)]
    [Link (Dynamic)]
    [Install]

    GPIO Utility
    [Compile] gpio.c
    [Link]
    [Install]

    Examples

    wiringPi Examples
    =================

    There are now too many examples to compile them all in a sensible time,
    and you probably don't want to compile or run them all anyway, so they
    have been separated out.

    To compile an individual example, just type

    make exampleName

    Where exampleName is one of:

    test1 test2 speed lcd wfi piface gertboard nes pwm tone servo
    delayTest serialRead okLed

    All Done.
    pi@raspberrypi ~/wiringPi $ make test1
    make: *** No rule to make target `test1'. Stop.
    pi@raspberrypi ~/wiringPi $ make speed
    make: *** No rule to make target `speed'. Stop.
    pi@raspberrypi ~/wiringPi $ make lcd
    make: *** No rule to make target `lcd'. Stop.
    pi@raspberrypi ~/wiringPi $

  55. Hi,
    I am facing a problem interfacing GPIO with the Hello_pi samples.
    My objective is to seek videos from a switch connected to GPIO. I am using Hello video.c program (in directory /opt/vc/src/hello_pi) I have figured out how to seek videos but I am not able to get GPIO input in the hello video program. The problem lies in compiling the program which is by “make”command and running the hello_video.bin
    I browsed through the messages above. But I did not see a mention on it.
    So, could you please tell me if it’s possible by adding wiringPi.h?
    Thanks,

    • IF you have installed wiringPi, then it should not be hard. You add

      #include <wiringPi.h>

      into your program, initialise and use wiringPi as per the examples programs, just remember to include

      -lwiringPi

      when linking the program

      -Gordon

      • I did the exact same thing.
        I tried it earlier with bcm2835.h too but it gives same problem. May be i’m doing something wrong. Just correct me if I am wrong.
        1. I copied and saved test1.c program to /home/pi
        2. On terminal screen I wrote “gcc test1.c -lwiringPi”
        It shows
        “usr/bin/ld: cannot find lwiringPi
        collect2:ld returned 1 exit status ”

        also when I compile hello video program in which I use digitalRead and pinMode to take input ;
        by “make -lwiringPi”
        It gives warning as
        “implicit declaration of function ‘pinMode’ ‘digitalRead’ and also error with ‘wiringPi setup’

        • Are you sure you typied it correctly? There is a hyphen (or a minus sign) in-front of the lwiringPi, so:

          cc -o test1 test1.c -lwiringPi

          For hello_video, you will probably have to edit the Makefile to include the -lwiringPi. Look in the Makefile:

          Change:

          LDFLAGS+=-lilclient

          into

          LDFLAGS+=-lilclient -lwiringPi

          If you still get undefined references then it means that you have probably not installed wiringPi correctly.

          -Gordon

          • WOWOWOW!!
            THanks so much. the edit in makefile was the culprit!
            This means a lot to me. I had been banging my head all this weekend. if you would been around I would have given a treat to you !
            ๐Ÿ˜€
            Sir, you Rock!

  56. Gordon,
    I follow the instruction according the link below.
    Keep getting error: cp: cannot stat `gpio’: No such file or directory
    I can’t find any file in /usr/local/bin/ as mention in post above.
    I do not work under sudo as mention in post above.
    Any suggestion ??
    Ruud.

    Link:
    https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/

    //Part of screendump:
    collect2: ld returned 1 exit status
    make: *** [gpio] Error 1
    [Install]
    cp: cannot stat `gpio’: No such file or directory
    make: *** [install] Error 1

    Examples

    • I can’t tell what’s going on without more clues, however if there were references to some smbus/i2c earlier on the build run, then you managed to fetch a version of wiringPi that was live for about 10 miuntes before I added another check into it – re-fetch it and try it again.

      look at the start of the gpio.c program to check – if the version is 1.7 then it’s the newest and there is something else wrong, if it’s anything other than 1.7 then fetch the new version…

      -Gordon

      • Hi,

        I just ran into the same error. The test for existence of /usr/include/linux/i2c-dev.h does not work correctly. On my Raspbian with libi2c-dev not installed the file exists, because it is provided by linux-libc-dev. After I installed it, compilation worked fine.

        With libi2c-dev installed:
        root@pi:~# dpkg -S /usr/include/linux/i2c-dev.h
        diversion by libi2c-dev from: /usr/include/linux/i2c-dev.h
        diversion by libi2c-dev to: /usr/include/linux/i2c-dev.h.kernel
        linux-libc-dev:armhf, libi2c-dev: /usr/include/linux/i2c-dev.h

        And without:
        root@pi:~# dpkg -S /usr/include/linux/i2c-dev.h
        linux-libc-dev:armhf: /usr/include/linux/i2c-dev.h

        I’m not sure how to fix it, because checking if the package is installed would only work on debian-based systems.

        Armin

        • Yes, thanks. I’ll work another way as I’ve had a couple of issues with that now. One way might even be to take out the I2C code for now.

          -Gordon

        • Think I can fix it by grepping for the right functions in the overlaid version of i2c-dev.h.

          Still can’t auto-install the package, but at least I can provide a pointer!

          -Grodon

          • I’m confused. I’m having this issue too. I have /usr/include/linux/i2c-dev.h but I’m getting:

            usr/lib/gcc/arm-linux… ‘i2c_smbus_write_byte’
            ‘i2c_smbus_read_byte’
            _write_byte_date’ …

            collect2: ld returned 1 exit status
            make: *** [gpio] Error 1
            [Install]
            cp: cannot stat `gpioโ€™: No such file or directory
            make: *** [install] Error 1

          • What issue too?

            Sorry – this isn’t really a forum so the comments don’t thread well, so I’m a little confused about what you’re getting.

            Firstly, have you got the latest version of wiringPi (Not the one from the project-downloads site, but the one via GIT). If you did not use GIT to download it, then you will not have the latest wiringPi and the compile will fail unless you install the i2c-dev package – and note that you will have a /usr/include/linux/i2c-dev.h, but not the right one!

            So – sudo apt-get install libi2c-dev

            will fix that for you – unless you’re on Arch in which case you won’t get the I2C stuff at all as they don’t provide it yet.

            -Gordon

      • Problem solved.
        Start from scratch new .img on sd-card.
        Follow the instruction.
        Get a error and message to install I2C lib.
        After that ./build runs oke.
        Thanks

        • Thanks Gordon,
          I’m very new to using the Raspberry pi. How do I go about installing this libi2c-dev without the internet connected to my raspberry pi?
          Thanks

          • How did you get wiringPi into the Pi without Internet?

            You really need an Internet connection – you need to update & upgrade the existing software on the Pi from the initial SD card image. The nyou can fetch the i2c stuff and the latest wiringPi, etc.

            -Gordon

          • I downloaded the wiringPi folder onto a usb stick and copied it into my home directory… i compiled the makefile for wiringPi ok but not the makefile for the gpio…. hmmm

          • If you can still use a usb stick to do the transfer then:

            Fetch the latest wiringPi – use git if possible.
            Fetch this file: http://unicorn.drogon.net/i2c-dev.h
            copy the i2c-dev.h file to /usr/include/linux/i2c-dev.h

            make wiringPi:
            cd wiringPi
            ./build

            Do not try to use the inidvidual makefiles.

            -Gordon

  57. I had wiringPi working on Raspbmc, but I had to create a new version of Raspbmc and now I cannot get wiringPi to work again.
    It installed fine.

    pi@raspbmc:~/wiringPi$ ./build
    wiringPi Build script – please wait…

    WiringPi library
    [UnInstall]
    [Compile] wiringPi.c
    [Compile] wiringPiFace.c
    [Compile] wiringSerial.c
    [Compile] wiringShift.c
    [Compile] gertboard.c
    [Compile] piNes.c
    [Compile] lcd.c
    [Compile] piHiPri.c
    [Compile] piThread.c
    [Compile] wiringPiSPI.c
    [Compile] wiringPiI2C.c
    [Compile] softPwm.c
    [Compile] softServo.c
    [Compile] softTone.c
    [Link (Dynamic)]
    [Install]

    GPIO Utility
    [Compile] gpio.c
    [Link]
    [Install]

    Examples

    wiringPi Examples
    =================

    There are now too many examples to compile them all in a sensible time,
    and you probably don’t want to compile or run them all anyway, so they
    have been separated out.

    To compile an individual example, just type

    make exampleName

    Where exampleName is one of:

    test1 test2 speed lcd wfi isr piface gertboard nes pwm tone servo
    delayTest serialRead serialTest okLed

    All Done.

    But when I run my script to initialise the necessary pins to drive my binary clock I get an error message.

    Here is my script

    #! /bin/bash

    sudo ntpdate 0.uk.pool.ntp.org
    pins=(“2 3 4 14 15 17 18 27 22 23”)
    #initialise the pins for output and set all pins to 0
    for x in $pins
    do
    gpio -g mode $x out
    gpio -g write $x 0
    done
    gpio -g mode 24 in

    And here are the error messages

    pi@raspbmc:~/scripts$ ./settime.sh
    17 Jan 12:57:28 ntpdate[1163]: the NTP socket is in use, exiting
    gpio: Unable to initialise GPIO mode.
    gpio: Unable to initialise GPIO mode.
    gpio: Unable to initialise GPIO mode.
    gpio: Unable to initialise GPIO mode.
    gpio: Unable to initialise GPIO mode.
    gpio: Unable to initialise GPIO mode.
    gpio: Unable to initialise GPIO mode.
    gpio: Unable to initialise GPIO mode.
    gpio: Unable to initialise GPIO mode.
    gpio: Unable to initialise GPIO mode.
    gpio: Unable to initialise GPIO mode.
    gpio: Unable to initialise GPIO mode.
    gpio: Unable to initialise GPIO mode.
    gpio: Unable to initialise GPIO mode.
    gpio: Unable to initialise GPIO mode.
    gpio: Unable to initialise GPIO mode.
    gpio: Unable to initialise GPIO mode.
    gpio: Unable to initialise GPIO mode.
    gpio: Unable to initialise GPIO mode.
    gpio: Unable to initialise GPIO mode.
    gpio: Unable to initialise GPIO mode.

    I have tried running the script with sudo but I get the same errors. Any ideas?

    thanks

    • Struggling to work out why not, however can you do this: Add this line to your script:

      export WIRINGPI_DEBUG=1

      at the top, before the gpio lines and run it – email me the output if you want as it’s a bit verbose for here…

      -Gordon

      Ps. ntpdate can’t be run once ntp has started, it used to be common to run ntpdate befoew ntp, but if ntp is started with the right flags, it’s not needed anymore…

  58. Great guide Gordon.

    Followed all of the above and seems to work fine.

    However before building it gave me this message: The wiringPi I2C helper libraries will not be built.

    Is this OK or has it errored in some way?

    Thanks,

    Simon

    • Perfectly normal and in some-ways I’m glad you got that message ๐Ÿ˜‰

      I’ve had a bit of a struggle to make sure other peoples system can build wiringPi – when they don’t have the i2c development libraries installed – essentially, I’ve put together some “helpers” for I2C similar to what I did for SPI, but it seems the I2C systems are widly different on different distributions. My I2C code is still somewhat experimental though, but if you are running Raspbian, then:

      sudo apt-get install libi2c-dev

      then re-doing the ./build ought to build and install them OK.

      -Gordon

  59. Problems compiling…
    The library compiles up OK, but when I try to use it to compile gpio or any of the examples, I get a set of error messages of the type
    libwiringPi.so: undefined reference ‘i2c_smbus_read_byte’
    … and then again for several other i2c functions.
    I’ve done an ‘apt-get update’ but no luck. The package was downloaded via wget (as git gives me errors connecting) and is the Jan 15 version. I’ve also installed the libi2c-dev as you mention above, but this has not helped either. The error message sounds like another library needs to be linked?
    Thanks,
    Steve

    • … and solved.
      I noticed the problem was that the functions were set as inline in linux/i2c-dev.h — seems that make had helpfully decided not to recreate wiringPiI2C.o after I installed the libi2c-dev and so the old .o still held them as external references. Removed all .o files and ran build again, and all was fine.
      Thanks for making this available!
      -Steve

  60. Can’t build my C-project in Code::Block with wiringPi:

    ————– Build: Debug in LS020 —————

    Compiling: main.c
    Compiling: ../../wiringPi/wiringPi/wiringPi.c
    /home/pi/wiringPi/wiringPi/wiringPi.c: In function โ€˜delayโ€™:
    /home/pi/wiringPi/wiringPi/wiringPi.c:1054:19: error: storage size of โ€˜sleeperโ€™ isnโ€™t known
    /home/pi/wiringPi/wiringPi/wiringPi.c:1054:28: error: storage size of โ€˜dummyโ€™ isnโ€™t known
    /home/pi/wiringPi/wiringPi/wiringPi.c:1059:3: warning: implicit declaration of function โ€˜nanosleepโ€™ [-Wimplicit-function-declaration]
    /home/pi/wiringPi/wiringPi/wiringPi.c:1054:28: warning: unused variable โ€˜dummyโ€™ [-Wunused-variable]
    /home/pi/wiringPi/wiringPi/wiringPi.c:1054:19: warning: unused variable โ€˜sleeperโ€™ [-Wunused-variable]
    /home/pi/wiringPi/wiringPi/wiringPi.c: In function โ€˜delayMicrosecondsSysโ€™:
    /home/pi/wiringPi/wiringPi/wiringPi.c:1083:19: error: storage size of โ€˜sleeperโ€™ isnโ€™t known
    /home/pi/wiringPi/wiringPi/wiringPi.c:1083:28: error: storage size of โ€˜dummyโ€™ isnโ€™t known
    /home/pi/wiringPi/wiringPi/wiringPi.c:1083:28: warning: unused variable โ€˜dummyโ€™ [-Wunused-variable]
    /home/pi/wiringPi/wiringPi/wiringPi.c:1083:19: warning: unused variable โ€˜sleeperโ€™ [-Wunused-variable]
    /home/pi/wiringPi/wiringPi/wiringPi.c: In function โ€˜delayMicrosecondsHardโ€™:
    /home/pi/wiringPi/wiringPi/wiringPi.c:1108:3: warning: implicit declaration of function โ€˜timeraddโ€™ [-Wimplicit-function-declaration]
    /home/pi/wiringPi/wiringPi/wiringPi.c:1110:3: warning: implicit declaration of function โ€˜timercmpโ€™ [-Wimplicit-function-declaration]
    /home/pi/wiringPi/wiringPi/wiringPi.c:1110:34: error: expected expression before โ€˜<โ€™ token
    /home/pi/wiringPi/wiringPi/wiringPi.c: In function โ€˜delayMicrosecondsWPiโ€™:
    /home/pi/wiringPi/wiringPi/wiringPi.c:1117:19: error: storage size of โ€˜sleeperโ€™ isnโ€™t known
    /home/pi/wiringPi/wiringPi/wiringPi.c:1117:19: warning: unused variable โ€˜sleeperโ€™ [-Wunused-variable]
    Process terminated with status 1 (0 minutes, 4 seconds)
    6 errors, 8 warnings

    • I’ve no idea what Code::Blocks is, but it looks like it’s trying to build wiringPi rather than use wiringPi’s own build system.

      Why are you not building wiringPi as a library and linking with the library? That’s the way I’ve designed it to work.

      Those error messages indicate that a header file is missing, or has not been included. Probably time.h or sys/time.h.

      -Gordon

        • Sorry. I’ve no idea. It’s not something I’ve ever used.

          Normally I’d suggest building the library standalone, and installing it, then working out how to include the header file in your program (if a simple #include <wiringPi.h> doesn’t work, then work out how to make code::blocks include the library at program link time. you need to get it to include -lwiringPi

          -Gordon

          • Connected to linker file libwiringPi.so.1.0.
            Project builded, but displays:
            wiringPi:
            Must be root to call wiringPiSetup().
            (Did you forget sudo?)

  61. Thanks for the effort first of all. I am a bit stuck. I want to connect to a wii nunchuck. With the following :

    i2cdetect -y 1
    i2cput -y 1 0x52 0x40
    i2cput -y 1 0x52 0x00
    i2cdump -y -r 0-5 1 0x52 c

    I get values.

    With you utilities, I tried:


    // is this correct, from you document I think it should be 1???
    // but then where do you give the device address?
    wiringPiI2CSetup(0x52);
    fd = open(“/dev/i2c-1”, O_RDWR)
    wiringPiI2CWrite(fd, 0x40);
    wiringPiI2CWrite(fd, 0x00);

    Then in a for loop
    byte = wiringPiI2CWrite(fd);

    But it doesn’t seem to work. Could you, or some other knowledgeable being, please help me out. I noticed there were no example using your i2c functions.

    Thanks,

    • I don’t know how the Wii nunchucks worok, however:

      If the device is 0x52, then you just need to do:

      fd = wiringPiI2CSetup (0x52) ;

      then to write 0x40 to the device:

      wiringPiI2CWrite (fd, 0x40) ;

      This is a simple write one byte down the bus command. If you’re writing to a device register, then use:

      wiringPiI2CWriteByte8 (fd, 0x40, value) ;

      I think the mistake you might be making is calling open() rather than use the return value from wiringPiI2CSetup()

      -Gordon

      • Thanks for the tip. that solved the first issue. But for some reason I don’t think the next two are equal.

        i2cdump -y -r 0-5 1 0ร—52 c

        for (int i = 0; i < 6; i++) {
        array[1] = wiringPiI2CRead(fd);
        }

        Is the read with or without an ACK.

        This is what I need. Is you code able to handle reads with/without the ACK bit set?
        for(i=0;i<5;i++) //5 values with ACK
        {
        data[i]= read_Ack();
        }
        data[5]= read_Nak(); // the last one without

        Thanks,

        • Some I2C devices can simply supply data in response to read requsts, some need you to read a particular register. You’ll need to study the device to see how.

          My routines are nothing more than easy to use wrappers round the standard Linux libraries, so AIUI, they all handle ACK, START, etc. stuff just returning the data to you.

          So if you need to read a register, then use wiringPiI2CReadReg8 (or readReg16), but if the device just sends bytes, then a simple wiringPiI2CRead will work. I have a touchscreen that does the latter – it sends 5 bytes at a time, so I do 5 back to back wiringPiI2CRead () calls and it works just fine.

          It’s also possible that I don’t know what I’m doing, but that works for the limited number of devices I have used so-far.

          i2cdump reads registers sequentially. To emulate that, use

          for (i = 0 ; i < 6 ; ++i) array [i] = wiringPiI2CReadReg8 (fd, i) ; to read registers 0-5 inclusive. -Gordon

  62. Hi Gordon,
    From all reports wiringPi is an excellent piece of work allowing us novices to get projects off the ground (mine is home automation which I plan to use the Pi as a web server).
    I am having trouble installing wiringPi, I am sure that I am doing something stupid so I have included the output from Pi, I dont need i2c, just gpio interfaces to C.
    Output:-
    pi@raspberrypi ~ $ cd /tmp
    pi@raspberrypi /tmp $ wget http://project-downloads.drogon.net/files/wiringPi.tgz –2013-02-07 08:56:44– http://project-downloads.drogon.net/files/wiringPi.tgz
    Resolving project-downloads.drogon.net (project-downloads.drogon.net)… 195.10.22 6.169, 2a00:ce0:2:feed:beef:cafe:0:4
    Connecting to project-downloads.drogon.net (project-downloads.drogon.net)|195.10.2 26.169|:80… connected.
    HTTP request sent, awaiting response… 200 OK
    Length: 335974 (328K) [application/x-gzip]
    Saving to: `wiringPi.tgz’

    100%[========================================>] 335,974 104K/s in 3.2s

    2013-02-07 08:56:48 (104 KB/s) – `wiringPi.tgz’ saved [335974/335974]

    pi@raspberrypi /tmp $ dir
    wiringPi.tgz
    pi@raspberrypi /tmp $ tar xfz wiringPi.tgz
    pi@raspberrypi /tmp $ dir
    wiringPi wiringPi.tgz
    pi@raspberrypi /tmp $ cd wiringPi/wiringPi
    pi@raspberrypi /tmp/wiringPi/wiringPi $ make
    [Compile] wiringPi.c
    [Compile] wiringPiFace.c
    [Compile] wiringSerial.c
    [Compile] wiringShift.c
    [Compile] gertboard.c
    [Compile] piNes.c
    [Compile] lcd.c
    [Compile] piHiPri.c
    [Compile] piThread.c
    [Compile] wiringPiSPI.c
    [Compile] wiringPiI2C.c
    wiringPiI2C.c: In function รขwiringPiI2CReadรข:
    wiringPiI2C.c:43:3: warning: implicit declaration of function รขi2c_smbus_read_byteรข [-Wimplicit-function-declaration]
    wiringPiI2C.c: In function รขwiringPiI2CReadReg8รข:
    wiringPiI2C.c:55:3: warning: implicit declaration of function รขi2c_smbus_read_byte_dataรข [-Wimplicit-function-declaration]
    wiringPiI2C.c: In function รขwiringPiI2CReadReg16รข:
    wiringPiI2C.c:60:3: warning: implicit declaration of function รขi2c_smbus_read_word_dataรข [-Wimplicit-function-declaration]
    wiringPiI2C.c: In function รขwiringPiI2CWriteรข:
    wiringPiI2C.c:72:3: warning: implicit declaration of function รขi2c_smbus_write_byteรข [-Wimplicit-function-declaration]
    wiringPiI2C.c: In function รขwiringPiI2CWriteReg8รข:
    wiringPiI2C.c:84:3: warning: implicit declaration of function รขi2c_smbus_write_byte_dataรข [-Wimplicit-function-declaration]
    wiringPiI2C.c: In function รขwiringPiI2CWriteReg16รข:
    wiringPiI2C.c:89:3: warning: implicit declaration of function รขi2c_smbus_write_word_dataรข [-Wimplicit-function-declaration]
    [Compile] softPwm.c
    [Compile] softServo.c
    [Compile] softTone.c
    [Link (Dynamic)]
    pi@raspberrypi /tmp/wiringPi/wiringPi $ sudo make install
    [Install]
    pi@raspberrypi /tmp/wiringPi/wiringPi $ cd ../gpio
    pi@raspberrypi /tmp/wiringPi/gpio $ make
    [Compile] gpio.c
    [Link]
    /usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libwiringPi.so: undefined reference to `i2c_smbus_write_byte’
    /usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libwiringPi.so: undefined reference to `i2c_smbus_read_byte’
    /usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libwiringPi.so: undefined reference to `i2c_smbus_write_byte_data’
    /usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libwiringPi.so: undefined reference to `i2c_smbus_write_word_data’
    /usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libwiringPi.so: undefined reference to `i2c_smbus_read_word_data’
    /usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libwiringPi.so: undefined reference to `i2c_smbus_read_byte_data’
    collect2: ld returned 1 exit status
    make: *** [gpio] Error 1
    pi@raspberrypi /tmp/wiringPi/gpio $ sudo make install
    [Install]
    cp: cannot stat `gpio’: No such file or directory
    make: *** [install] Error 1
    pi@raspberrypi /tmp/wiringPi/gpio $

    sorry for long winded output
    Hoping you can help!
    cheers,
    Peter

    • Is there any reason you can’t use GIT?

      the tgz version there is a little older than the GIT hosted version and doesn’t build on systems that don’t have the I2C helpers.

      If you have git then:

      cd
      # rm -rf wiringPi # in-case you have an old one
      git clone git://git.drogon.net/wiringPi
      cd wiringPi
      ./build

      Test with:

      gpio -v

      If you really can’t use GIT, then get the GIT version by going here:

      https://git.drogon.net/?p=wiringPi;a=summary

      and clicking on the snapshot link at the top-right.

      -Gordon

      • Hi Gordon,
        Looks like my router doesn’t like git:// so i downloaded as suggested put it in /tmp then:
        pi@raspberrypi /tmp $ ls
        wiringPi-56c77b5.tar.gz
        pi@raspberrypi /tmp $ ./build
        -bash: ./build: No such file or directory
        what an I doing?
        or should I follow the previos route?
        thanks,
        Peter

      • Hi Gordon,
        Thanks a lot I am getting there!
        Thanks to your help test1 works!
        Thanks,
        peter

  63. Gordon,

    Just a note to say the WiringPi i2c module works fine on Arch Linux, with a minor hack! All the necessary kernel modules are present in Arch, it’s just the Arch i2c-dev.h header that’s incompatible.

    Steps needed are:
    1) Update Arch.
    # pacman -Syu
    # uname -r
    3.6.11-6-ARCH+

    2) Install api-headers and i2c-tools.
    # pacman -Sy linux-api-headers i2c-tools

    3) Hack: get the Debian i2c-dev.h header file (http://unicorn.drogon.net/i2c-dev.h) or extract from the Raspbian distro.

    3) Install the Debian header in place of the Arch one.
    # mv /usr/include/linux/i2c-dev.h /usr/include/linux/i2c-dev.h.saved
    # cp /i2c-dev.h /usr/include/linux/i2c-dev.h

    4) Build WiringPi.
    # cd ~/wiringPi
    # ./build

    The i2c module should then build and install just fine.

    5) Remove and reload the i2c kernel modules, using a lower baud rate.
    # rmmod i2c_bcm2708 i2c_dev
    # gpio load i2c 10

    The lower baud rate (10Kbps) was needed to get my i2c ADC working. Maybe other devices would accept a higher rate (trail & error).

    The WiringPi i2c functions then work well on Arch. In my case, I also needed to read block data from the ADC, which I could do with the ‘i2c_smbus_read_i2c_block_data()’ native function.

    I prefer Arch, so it’s nice to know the wiringPi i2c module works with the above tweak!

    Many thanks,

    Dave

  64. i’m having difficulties compiling this with cross-compile toochain, is it even possible ? Cos I’m developing on my main linux machine not on raspberry.

      • “cd wiringPi/wiringPi”
        “vi Makefile”
        (change CC = gcc to CC ?= gcc, save, quit)

        In your main project:
        “CC=arm-none-linux-gnueabi-gcc make -C /wiringPi static”
        Now you can x-comp against /wiringPi/libwiringPi.a

        • Intended to write:
          โ€œCC=arm-none-linux-gnueabi-gcc make -C wiringPi_path/wiringPi staticโ€
          and
          wiringPi_path/wiringPi/libwiringPi.a

          • Forgot to mentioned that ar and ranlib are need to be changed to arm-none-linux-gnueabi-ar and arm-none-linux-gnueabi-ranlib in the Makefile

  65. I had the same problems as Peter Davis. I had trouble connecting to the git.drogon.net site, maybe a firewall problem, so I used the ‘wget’ method and followed your instructions. I got warnings in compiling wiringPi and couldn’t link gpio.

    You do not mention running ‘build’ in the above install instructions but, after looking through ‘build’, I loaded the I2C development libraries and, so far, the problems have gone away.

    Thanks for sharing you work, I am looking forward to using your tools and having fun.

    John Windle

    • The other method will get you an older version of wiringPi. To get the latest, then use the GIT site via http…

      Access the GIT site using https://git.drogon.net/

      Navigate to the project – e.g. wiringPi, then look on the right-hand side where you will see a link marked “snapshot”. Download this and unpack it – it will create a filename like wiringPi-123456789abvdef.tar.gz and extract into a directory like wiringPi-1234567879abcdef.

      -Gordon

  66. Do the Download and Install instructions require the V2 board. I have the V1 board but both the new and old methods fail.

    • It should download on either board OK – or do you mean compile/build? (in which case it should still do that OK on either board).

      Let me know what sort of error messages you’re getting

      -Gordon

      • first To obtain WiringPi using GIT:
        git clone git://git.drogon.net/wiringPi

        my results
        Cloning into ‘wiringPi’…
        fatal: unable to connect to git.drogon.net:
        git.drogon.net[0: 195.10.226.169]: errno=Connection refused
        git.drogon.net[1: 2a00:ce0:2:feed:beef:cafe:0:3]: errno=Address family not supported by protocol
        Phil

  67. Could you add this to the library; because there are some compatibility issues around the booleans.

    typedef bool boolean;

    • C doesn’t have a native bool type. Only C++

      So as I write in C, if I did that then it would make it incompable with C.

      However I’ll double check to make sure the I’m not using bool/boolean anywhere that might conflict with c++

      -Gordon

  68. help please i m french
    use rabmc (which don’t suport apt-get upgrade)
    have this error
    The wiringPi I2C helper libraries will not be built.

    WiringPi library
    sudo: make: command not found
    ./build: line 65: make: command not found

    Make Failed…
    Please check the messages and fix any problems. If you’re still stuck,
    then please email all the output and as many details as you can to

    • You are using a distribution designed for media viewing, not realyl aimed at program devleopment. Raspbian would be a much better distribution to pick for that.

      If you can’t use apt-get then nothing more will work for you, but if you can, then what you need to do is

      sudo apt-get install make
      sudo apt-get install gcc

      then re-do the ./build in the top of the wiringPi directory.

      -Gordon

  69. Hi Gordon, today install the wirinpPi library from your page, but i have a problem, my porpouse is use this device for i2c sensors, but in my configuration from “gpio readall” my pin 1 and 0 just i think is 5v and 3,3 volts, the state for this pines is low state, how can i solve or enable this pines, please need your help.

    • If you want to use the wiringPi I2C helpers, then you need to make sure that it’s compiled with the I2C headers – under raspbian, sudo apt-get install libi2c-dev then ./build.

      The gpio readall will always show the state of the pins – it’s probably not a good idea to rely on anything you read from them. (And it looks like at boot time on the latest foundation kernel they’re set to outputs, and set low) Once you load the i2c module (either at boot time, or using the gpio load i2c command), then the pins will be set correctly and gpio readall ought to report:


      | 8 | 0 | 3 | SDA | ALT0 | High |
      | 9 | 1 | 5 | SCL | ALT0 | High |

      -Gordon

      • My SDA and SCL are in High state but my sensor aren’t recognizeg… maybe is the sensor, i think is because the 5volts pin are in low state but i put a Led to ground today and still working, the led flash and have current and voltage… I’ll keep you informed, Thanks for the prompt reply Gordon, my sensor is a Lego Mindstorms 1.0 Gyro Sensor. Saludos from Mexico sorry for my english

        • I don’t kow mch about it, but it looks like it might be a 5v device…
          Did you load the I2C module? Make sure that’s loaded first and that i2dcdetect can see the sensor. You won’t be able to do anything at all until you’ve done that.

          -Gordon

  70. Hi Gordon

    I tried to cdownload and build wiringPi, but I ve got this error… can you advice please?

    root@raspbian:~/wiringPi# ./build
    wiringPi Build script
    =====================

    The wiringPi I2C helper libraries will not be built.

    WiringPi library
    ./build: line 64: sudo: command not found
    [Compile] wiringPi.c
    [Compile] wiringPiFace.c
    [Compile] wiringSerial.c
    [Compile] wiringShift.c
    [Compile] gertboard.c
    [Compile] piNes.c
    [Compile] lcd.c
    [Compile] piHiPri.c
    [Compile] piThread.c
    [Compile] wiringPiSPI.c
    [Compile] softPwm.c
    [Compile] softServo.c
    [Compile] softTone.c
    [Link (Dynamic)]
    ./build: line 67: sudo: command not found

    Make Failed…
    Please check the messages and fix any problems. If you’re still stuck,
    then please email all the output and as many details as you can to

    Thanks in advance

    • What distribution are you using?

      I recommend Raspbian.

      And it’s probably best to not build it as root. That’s why it uses sudo.

      -Gordon

  71. Hello Gordon

    I am tring to install WiringPi by using your “Plan B”, but after typing: ./build I have a message (bash: /build: Permission denied). How can I resolve this problem?
    I downloaded SD image of Rasbian (Rasbian Pi SDCard image (4GB SanDisk) as used in our workshops) from here http://pi.cs.man.ac.uk/download/. I am sorry, I am new in it.

    • I’ve jsut gone through some tests and can’t see any issues when I run it. I’m really surprised that you can’t ./build though. That does surprise me. It suggests that something has gone wrong in the extract process – maybe you’ve gotten some corruption, etc. Turn off all overclocking and try again…

      I also have to say; I would NOT use the kernel, etc. on the man.ac.uk site. The standard Raspbian kernel supports SPI and has done so for the past 6 months or so. Once you have wiringPi installed, then you can simply use the gpio command to load the SPI modules..

      However back to wiringPi – I’ve just run this:

      gordon @ pi0: wget -OwiringPi.tgz ‘https://git.drogon.net/?p=wiringPi;a=snapshot;h=98bcb20d9391ebde24f9eb1244f0d238fb1a1dab;sf=tgz’
      –2013-03-06 08:52:26– https://git.drogon.net/?p=wiringPi;a=snapshot;h=98bcb20d9391ebde24f9eb1244f0d238fb1a1dab;sf=tgz
      Resolving git.drogon.net (git.drogon.net)… 2a00:ce0:2:feed:beef:cafe:0:3, 195.10.226.169
      Connecting to git.drogon.net (git.drogon.net)|2a00:ce0:2:feed:beef:cafe:0:3|:443… connected.
      HTTP request sent, awaiting response… 200 OK
      Length: unspecified [application/x-gzip]
      Saving to: `wiringPi.tgz’

      [ <=> ] 56,722 –.-K/s in 0.06s

      2013-03-06 08:52:31 (860 KB/s) – `wiringPi.tgz’ saved [56722]

      gordon @ pi0: file wiringPi.tgz
      wiringPi.tgz: gzip compressed data, from Unix
      gordon @ pi0: tar xfz wiringPi.tgz
      gordon @ pi0: cd wiringPi-98bcb20/
      gordon @ pi0: ls -l build
      -rwxr-xr-x 1 gordon gordon 1462 Feb 7 21:53 build

      So that looks OK to me – and a subsequent ./build worked fine.

      So double-check the download means – for that, I used my browser on my desktops ability to copy a link (hover over the “snapshot” link, right-click in firefox, select “copy link”, then in a terminal ssh’d into a Pi, I copied it to the command-line, added in the wget command, enclosed the url in quotes too – and off it went. You could use your browser to get the file, then copy it over to the Pi by whatever means though.

      But really – why is git failing? I’m really surprised at the number of places that seem to be blocking it though. I’ll look at providing ‘dumb’ http/https access to it though (so you can git clone https:// …)

      -Gordon

  72. Hi Gordon, I’m new to Raspberry Pi. Ive done a lot of programming in the past using C++ and Clipper but for past 20 years, concentrated on running my business so my programming skills are a little rusty. I want to write a program to read a couple of temperature probes and control a couple of relays for my oil fired boiler and it looks like your wiringPi library might be very useful especially as you say its c++ compatible. I’m just wondering if there is any functions to read a DS18B20 sensor? Also, can you advise the best way to write a C++ program for use on the Pi? by that I mean what software would you use to write it eg code:blocks etc?
    Keep up the good work and thanks you for making it available.

    Steve.

    • Hi,

      That’s a 1-wire sensor – something no experience of on the Pi, so you might have to start looking on the forums, etc…. But yes, wiringPi can be used from c++ – it’s just a set of functions at the end of the day (rather than a set of clases)

      I do my Pi devleopment using the vi editor and Makefiles. (and it’s mostly in C too, not C++) I don’t know anything about the IDEs, etc.

      -Gordon

  73. excellent work on wiringPi, is there a full syntax and examples of the gpio command line commands especially spi

    thanks

  74. Hi Gordon
    I am running the large display, it powers up with 2×20 rows of 4×8 white squares
    The example program lcd.c “hangs” at lcdInit(4, 20, etc…)
    gpio readall returns data for pins 0-31 and the 4 input switches work correctly with digitalRead(n).
    wiringPiSetup() returns 0
    had to add a “\r” after the “\n\r” to see any further printf comments
    Any help would be much appreciated, Paul

    • there is nothing in lcdInit() that would cause a hang. I’d start to put more traces in your program to see what’s happening.

      -Gordon

  75. Thanks Gordon, you were right.
    Problem is that lcdPuts() does not write to (change) the display from the white squares.
    PSU = 1A (5v) 4x input buttons work OK
    Any pointers would be appreciated

      • I appreciate that thanks
        In the mean time I checked my soldering but that was my first commercial job (while building ZX80’s) and it near flow-line,
        So I bought another display (not arrived)
        Tried another PI with a new flashed SD same result. My money is on the LCD itself.
        Its for a “coin operated” project to release to the Pi community. I will send you my first sample.
        You can drive things with coins and later bank notes !

        • Sorry – I’ve lost the thread here – the wordpress comment system isn’t really a forum, so I don’t get to see the threads this is relating to. I am planning a forums system for the new site though..

          -Gordon

  76. Hello Gordon,
    can I install wiringPi on another debian based system to programm and compile at this ??

    • I often edit & compile for syntax check on my Debian desktop (x86) before copying over to a Pi to do the testing, so you should be able to do that, but it won’t run (although some of it will if you’re careful – e.g. the serial code, timings, etc.). If your other system has similar GPIO them it might be adaptable, but who knows!

      I don’t do any corss compiling though, but I know others have with varying degrees of success.

      -Gordon

  77. the build script fail every time with this message, make and gcc is installed

    /home/pi/wiringPi# ./build
    wiringPi Build script
    =====================

    The wiringPi I2C helper libraries will not be built.

    WiringPi library
    [UnInstall]
    [Compile] wiringPi.c
    make: gcc: Command not found
    make: *** [wiringPi.o] Error 127

    Make Failed…
    Please check the messages and fix any problems. If you’re still stuck,
    then please email all the output and as many details as you can to
    projects@drogon.net

    • wiringPi is designed to be used when developing programs. your chosen Linux distribution does not support program development, and I’m really sorry to say this, but “gcc: command not found” is a really obvious error that you should have been able to recognise, and I fear that you’ll have more problems later on when you try to build your own programs.

      Install Raspbian and all will work.

      alternatively some of the media-centric distributions can be “fixed” with a command like

      sudo apt-get install gcc

      -Gordon

  78. Hi Gordon
    Having trouble with the large LCD (READ YOUR PI) , it powers up with 2ร—20 rows of 4ร—8 white squares but I cant write to it using GIT WiringPi test program lcd.c
    Has anyone else used this device that you know of, who’s code (c) I can have a look at and try.
    It may be the display so I have ordered a second one
    Thank you
    Paul

  79. Gordon,
    I try to install the wiringPi in both ways.

    But allways I still get the message:

    pi@pi-nas ~ $ cd wiringPi-98bcb20
    pi@pi-nas ~/wiringPi-98bcb20 $ ./build
    wiringPi Build script
    =====================

    The wiringPi I2C helper libraries will not be built.

    WiringPi library
    [UnInstall]
    [Compile] wiringPi.c
    Assembler messages:
    Fatal error: can’t create wiringPi.o: Permission denied
    make: *** [wiringPi.o] Fehler 2

    Make Failed…
    Please check the messages and fix any problems. If you’re still stuck,
    then please email all the output and as many details as you can to
    projects@drogon.net

    What can I do?

    • You need to learn a bit more about Linux and the command-line and what error messages mean. In this case, the error is clear: “Permission denied”, but what you need to work out is why.

      My guess is that you have used sudo to download the image or unpack the tar file. Don’t.

      -Gordon

        • In-general you should use sudo as little as possible.
          So to fix your situation:
          cd
          sudo chown -R pi.pi wiringPi

          If you used sudo to download and/or unpack, then the files & directories would be ownded by root and not the pi user.

          -Gordon

  80. Gordon,
    I still have a nother problem with my pi.
    Could you help me?
    The remote function will not work.
    Ever i get this message and I think that is the problem that i didnt get on the pi via webif.

    pi@pi-nas ~/raspberry-remote $ sudo ./daemon &
    [1] 3216
    pi@pi-nas ~/raspberry-remote $ ERROR on binding: Address already in use
    ^C
    [1]+ Exit 1 sudo ./daemon

  81. Hello Gordon,
    I still have an nother problem and hope you can help me.
    I couldnt get on the pi via webif (remote)
    I will a start daemon and get this message:

    pi@pi-nas ~/raspberry-remote $ sudo ./daemon &
    [1] 3200
    pi@pi-nas ~/raspberry-remote $ ERROR on binding: Address already in use
    ^C
    [1]+ Exit 1 sudo ./daemon

    Did you see a chance to help me?

  82. Hi Gordon

    Firstly thank you for making WiringPi available, you’ve no idea how much stress you’ve saved this final-year computer science student!

    I’m using the the wiringPiISR function to generate an interrupt on the rising edge of pulses from an opto-isolator, and I’m increasingly running into the following error message when I try to run the program:

    “gpio: error while loading shared libraries: libwiringpPi.so.1: cannot open shared object file: Error 24”

    Do you have any advice as to how I might solve this problem? I can provide code if necessary.
    Apologies for what may be a very simple question, but I’m new to the world of Pi!

    Best regards,
    Craig.

    [Raspberry Pi Model B running Raspbian (wheezy), programming in C]

    • I’m guessing that wiringPi hasn’t been installed correctly, or something has changed since you installed it (but struggling to think what)

      so I’d try a full re-install:

      cd
      rm -rf wiringPi
      git clone git://git.drogon.net/wiringPi
      cd wiringPi
      ./build

      and see how you get on.

      Programs using the ISR code calls that gpio program directly to do the proper port setups – the only other thing that I can think of is that your LD_LIBRARY_PATH environment variable is set to something (it’s not normally set)

      -Gordon

      • Hi Gordon

        I’ve spoken to my tutor in the mean time and it appears I was simply calling the function in the wrong way! I’d put the call to wiringPiISR inside a while (1) loop (the program records output from an ‘electricity meter’ thus needs to be effectively always-on), whereas actually it needed to be called just once outside of the loop. Rookie error!

        Thanks for the prompt response, and keep up the great work.

        Regards,
        Craig.

  83. Hi Gordo. I’m from Ecuadorian.
    I need a help.
    I need to create a code. The Data arriving by lxterminal want them saved in a document .txt.
    I am working with minicom library.

    Help me please

  84. Hi Gordon,
    first of all…GREAT JOB!!

    your wiring library is only for version 1 or it works for all versions of raspberry pi?
    A,B, versions 1 and 2?
    I think that in version 2 they have altered some tinhgs, and added one more conector p5 with more gpio pins?!

    thanks in advance

    regards
    tux

    • wiringPi works perfectly well with the revision 2 board – however to make sure your code is portable then you need to stick to the wiringPi pin numbers rather than use the native bcm gpio pin numbers. See the pins page here for the numbers:

      http://wiringpi.com/pins/

      -Gordon

    • the i2c helpers will help you to write the code you need to access that sensor, but it’s not one I have myself, so I’ve not written any code for it myself.

      -Gordon

  85. I guess ic2.h and ic2-dev.h should handle it, sorry for the disturbance ๐Ÿ™‚

    /Mats

  86. Hi Gordon,

    i tried to install the wiringPi library, but no Joice ๐Ÿ™
    well..i have extracted the tarball and instaled i2c libraries and afther that ./build(to use the dynamic linker/loader).

    i have in /usr/lib/ symbolic links to /usr/local/lib/libwiringPi
    edited file /etc/ld.so.conf and i inserted /usr/local/lib and tried too with /usr/lib.

    ldconfig afther…

    and tried to compile and link an example you have there.

    root@raspberrypi:~/wiringPi-98bcb20/examples# gcc test1.c -o test1
    /tmp/ccYwagZs.o: In function `main’:
    test1.c:(.text+0x14): undefined reference to `wiringPiSetup’
    test1.c:(.text+0x154): undefined reference to `delay’
    test1.c:(.text+0x16c): undefined reference to `delay’
    test1.c:(.text+0x178): undefined reference to `pinMode’
    test1.c:(.text+0x180): undefined reference to `digitalWrite’
    test1.c:(.text+0x184): undefined reference to `digitalRead’
    collect2: ld returned 1 exit status

    where is the problem? in #include ?? or in the wiringPi shared library in /usr7local/lib ?

    Sorry for the trouble, and thanks in advance

    regards
    tuxd3v

    • I’m sure it’ll work – if you write the code for it. It won’t use the existing wiringPi LCD code.

      However it looks like it uses SPI only – not I2C. It also looks like it needs an extra GPIO pin or 2 to connect the reset and D/C pins to (I think the latter one is data/command)

      -Gordon

  87. If we use the Linux terminal, it is because it is great and because we want info on the command we launch.

    —deleted—

  88. In the past I was able to compile code that uses the LCD panel with:
    gcc lcdip.c -I/usr/local/include -L/usr/local/lib -o IPOnLCD -lwiringPi

    After pulling a new version of Raspian and wiring Pi that line will throw “undefined reference” errors on compile for all of the lcd functions. To get it to compile I have to explicitly include the lcd object file like so:
    gcc lcdip.c /home/pi/wiringPi/devLib/lcd.o -o IPonLCD -lwiringPi

    The code that is giving me errors is:

    #include
    #include
    #include
    const int EN = 20; // EN on GPIO20
    const int RS = 18; // RS on GPIO9
    const int D0 = 17; // D4 on GPIO8
    const int D1 = 19; // D5 on GPIO19
    const int D2 = 5; // D6 on GPIO5
    const int D3 = 4; // D7 on GPIO4

    int main(int argc, char* argv[]){
    if (wiringPiSetup() < 0)
    exit(-1);

    int lcdFD;
    if ((lcdFD = lcdInit(2, 16, 4, RS, EN, D0, D1, D2, D3, D0, D1, D2, D3)) 1){
    lcdPosition(lcdFD, 0,0);
    lcdPrintf(lcdFD, argv[1]);
    }
    if (argc > 2){
    lcdPosition(lcdFD, 0,1);
    lcdPrintf(lcdFD, argv[2]);
    }
    }

    Can you give me an idea of why defining the include and library directories is no longer enough?

      • Thank you
        gcc lcdip.c -o IPonLCD -lwiringPiDev -lwiringPi

        works perfectly. I don’t even need to specify the include and library directories any longer.

        • Great! Do check the new example program too – examples/lcd.c – it has a new function that lets you user-define characters now.

          -Gordon

  89. Looks like the lcdInit line got mangled, let me try again:

    int lcdFD;
    if ((lcdFD = lcdInit
    (2, 16, 4, RS, EN,
    D0, D1, D2, D3,
    D0, D1, D2, D3)) 1){
    lcdPosition(lcdFD, 0,0);
    lcdPrintf(lcdFD, argv[1]);
    }

  90. Ahh…. It’s stripping everything between greater and less than symbols for being HTML. The includes are gone as well.
    #include stdlib.h
    #include wiringPi.h
    #include lcd.h

    and

    int lcdFD;
    if ((lcdFD = lcdInit
    (2, 16, 4, RS, EN,
    D0, D1, D2, D3,
    D0, D1, D2, D3)) lt 0)
    exit (-1);

    if (argc > 1){
    lcdPosition(lcdFD, 0,0);
    lcdPrintf(lcdFD, argv[1]);
    }

  91. This may look like a simple problem but I’m stuck.
    When I use ./build I get this…

    ./build: line 52: sudo command not found
    [Compile] wiringPi.c
    make: gcc: Command not found
    make: *** [wiringPi.o] Error 127

    Make Failed…

  92. I would like to use the wiringpi library with piCore (a version of Tiny Core written for the Raspberry Pi). piCore, like Tiny Core, does not use the debian based apt-get package manager. Instead it uses a system called tce and wiringpi is not in the repository yet. I would like to add it to the repository but I am a novice and can’t even get wiringpi to compile in piCore. Well, actually, I did a few weeks ago but something has changed. Let me explain what I have tried. I started off trying this:

    $ git clone git://git.drogon.net/wiringPi
    $ cd wiringPi
    $ ./build

    But I get the following error attempting to build:

    “-sh: ./build: not found”

    So I try this:

    $ sudo ./build

    and get this error:

    “sudo: unable to execute ./build: No such file or directory”

    I’ve also tried this:

    $ sudo -s
    $ ./build

    And get this error:

    “/bin/sh: ./build: not found”

    I’ve even tried using:

    $ sudo -i

    which restarts the system but I still get the same errors as before.

    A few weeks ago I was able to install wiringpi by using git as follows:

    $ git clone git://git.drogon.net/wiringPi
    $ cd wiringPi/wiringPi
    $ sudo make install

    When I try this now I get a compile error regarding mcp3422.c using the function ‘myAnalogRead’ and the variable ‘b3’ but it seems to compile. I used to just copy the libwiringPi.so.1.0 file to the examples directory and compile my code from there. This seems to no longer work and I see that the file libwiringPi.so.2.0 is used in place of the earlier version. I realize now that I should have been installing this library as follows:

    $ cd wiringPi/wiringPi
    $ make
    $ sudo make install
    $ cd ../ gpio
    $ make
    $ sudo make install
    $ cd ../examples
    $ make blink
    $sudo ./blink

    But I get this error:

    “gpio.c:39:23: fatal error: gertboard.h: no such file or directory
    compilation terminated.
    make: *** [gpio.o] Error 1”

    I would like to understand what I am doing wrong so that I can create a tcz file for others to use. Any help will be appreciated. Thanks.

    • the build script needs /bin/bash – Do you have a /bin/bash in your system? That’s probably where the no such file of directory error is coming from.

      Do try to use the build script – it will make sure all the headers are in-place.

      The error about ‘b3’ in not an error – it’s a warning and it’s fine.

      If you want to make it all manually, then hte sequence is:

      cd wiringPi
      make
      sudo make install

      cd ../devLib
      make
      sudo make install

      cd ../gpio
      make
      sudo make install

      then you can make the examples.

      -Gordon

      • I used bash and everything works just fine now. Thank you so much for your help and thank you for this library. WiringPi is now available through the tce package management system in piCore.

  93. Hi,
    I had one problem. i m using opencv and raspberry pi, i use Cmake to compile my code. i have cmake list file which has library link to opencv.
    I want to include your header files in my project , can you help me out how should i add them??

    • I have one project myself that uses cmake and uses wiringPi – it just #include <wiringPi.h> as usual and in the CMakeLists.txt file it also has:

      if(${RASPBERRYPI})
      set(rtb_LINK_LIBRARIES wiringPi ${rtb_LINK_LIBRARIES})
      add_definitions(-DRASPBERRY_PI)
      endif(${RASPBERRYPI})

      Seems to work..

      -Gordon

      • ๐Ÿ™ sadly still getting errors , i dint understand this code u told me , actually i need to add the wiringpi folder in set_include_directories command and set_libraries i am confused over it . can you share your whole cmakelist file please

  94. Great job! Really love the tool and library.
    Is there any specific reason why /dev/mem is open without the O_CLOEXEC flag?
    I noticed descriptors piling up so I looked around a bit. Didn`t see any reason for it to mess things up but thought I might`ve missed something.

    • The trouble with learning C 32 years ago on an old Unix system … is that sometiems you miss these new fangled features! So I’ve done some reading & added it in. Shouldn’t really be an issue though. Hopefully done the right thing by defining _GNU_SOURCE in the Makefile and setting the flag in wiringPi.c … Will do a push shortly.

      Cheers,

      -Gordon

  95. Is it possible to alter the default behaviour of a pin after boot from in to out?

  96. Hi,
    could i know why in this version the Physical PIN n.6 was not represented as GND PIN?

    20 | 31 | 6 | GPIO11 | IN | Low

    the 6th physical pin in rev.b is GND [2 is VCC 4 is VCC and 6 is GND]

    this is ->gpio version: 2.13

    in the older -> gpio version: 2.08

    the 6th PIN is

    | 6 | | | 0v | |

    thanks

  97. Hi,

    I’m having trouble with the git version. I’m getting

    Cloning into ‘wiringPi’…
    fatal: unable to connect to git.drogon.net:
    git.drogon.net[0: 195.10.226.169]: errno=Connection timed out
    git.drogon.net[1: 2a00:ce0:2:feed:beef:cafe:0:3]: errno=Address family not supported by protocol

    on the output…

    Thanks

    • Not observed any issues with the server or my end of the network – can ping do some basic tests like ping git.drogon.net and so on?

      Some universities/workplaces block GIT though…

      -Gordon

      • Hi,

        I’m not behind a proxy at all, just a fresh install of Raspbian. Cannot even ping the address above.

        Thanks for your continued support
        Glen

        • Hi Gordon

          I’m sorted. Was the firewall on the Viginmedia router that was blocking the git calls. Just need to understand how to set it up to allow calls through – over to virginmedia site …

          thanks

  98. hi, what am I doing wrong?
    git-core is installed, update/grade is done

    pi@raspberrypi ~ $ git clone git://git.drogon.net/wiringPi
    Cloning into ‘wiringPi’…
    fatal: unable to connect to git.drogon.net:
    git.drogon.net[0: 195.10.226.169]: errno=Die Wartezeit f?r die Verbindung ist abgelaufen
    git.drogon.net[1: 2a00:ce0:2:feed:beef:cafe:0:3]: errno=Die Adressfamilie wird von der Protokollfamilie nicht unterst?tzt

  99. Hello ,

    I wanted to read a motor encoder’s output using a GPIo pin.. I referred to isr.c to get the count of falling edges.. but I want to calculate number of pulses in a second.. How can I use interrupt to get the same ?
    I tried the following code..

    static volatile int globalCounter=0 ;

    void myInterrupt (void) { ++globalCounter ; }
    int main (void)
    {
    int gotOne, pin ;
    int myCounter=0;
    int lastCounter=0;

    wiringPiSetup () ;

    if (wiringPiISR (5, INT_EDGE_FALLING, &myInterrupt) < 0)
    {
    fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
    return 1 ;
    }

    for (;;)
    {
    fflush (stdout) ;

    while (myCounter == globalCounter)
    delay (1000) ;

    printf (" Done. counter: %6d: %6d\n",
    globalCounter, myCounter – lastCounter) ;
    lastCounter = myCounter ;
    myCounter = globalCounter ;
    }

    Its not giving me expected output..
    Please see to it.

    Thanks

  100. Hi Gordon,

    I think the work you are doing is great and has helped many people. I got wiringPi running on my Pi without a problem, but recently I got interested in using gcc so I could develop software for the Pi on an Ubuntu machine in eclipse. While building a simple helloWorld I get an error:

    18:12:34 **** Incremental Build of configuration Debug for project HelloRpiWorld ****
    make all
    Building target: HelloRpiWorld
    Invoking: Cross G++ Linker
    arm-linux-gnueabihf-g++ -L/usr/local/lib -o “HelloRpiWorld” ./HelloRpiWorld.o -lwiringPi
    /usr/local/lib/libwiringPi.so: file not recognized: File format not recognized
    collect2: error: ld returned 1 exit status
    make: *** [HelloRpiWorld] Error 1

    I realise that this question is out of the scope of you project, but I was wondering if there’s any chance you have seen this problem before and would be able to solve the error.

    Kind regards.

    • For people with the same problem, the problem can be solved if you install the static library instead of the normal ./build.
      cd to wiringPi/wiringPi
      sudo make static
      sudo make install-static

      • Oh never mind, after cleaning and rebuilding the project, the same error occured for the static .a file ๐Ÿ™ Could not read symbols: File format not recognized

  101. When trying to clone wiringPi I always have this error:
    $ git clone git://git.drogon.net/wiringPi
    Cloning into wiringPi…
    fatal: read error: Connection reset by peer

    It’s not the same error that other people had (git port blocked by firewall). It looks like the connection is made then reset.

    Any ideas?

    Thanks

    P.S.: If you have nothing against Github, you should think sharing your repo there, it’s really simple and work really well.

    • I’m sorry that the place you’re using is blocking your Internet access, but it’s something that I have no control over.

      I have no plans to move to github.

      Please use the “Plan-B” instructions on the download page.

      -Gordon

      • Thanks for your fast answer!

        I had already use Plan-B but is less than ideal in certain scenarios.

        Unfortunately I don’t think the problem with the git access is on my side. As I said, a “Connection reset by peer” mean that the connection was made but that the server decided to close the connecting abruptly (for different reasons).

        Also I checked 2 things:
        1. I tried to clone another git repo through the git protocol. It works.
        2. I checked the TCP packet exchange and everything seem to be correct except that your server, at one moment, decided to send a “RST” for a unknown reason (to me, at least). The exchange looks like this:
        192.168.1.10 -> 195.10.226.169 59174 -> 9418 [SYN]
        195.10.226.169 -> 192.168.1.10 9418 -> 59174 [ACK, SYN]
        192.168.1.10 -> 195.10.226.169 59174 -> 9418 [ACK]
        192.168.1.10 -> 195.10.226.169 59174 -> 9418 [ACK, PUSH]
        195.10.226.169 -> 192.168.1.10 9418 -> 59174 [ACK]
        195.10.226.169 -> 192.168.1.10 9418 -> 59174 [ACK, RST]

  102. Anyone had any luck getting wiringPi working on Arch Linux?
    when trying wiringPi/build it fails on the linking gpio part. “undefined reference to pinModeaAlt” and other errors.
    My c program using wiringPi which works fine on debian doesn’t work on Arch. WiringPiISR: “unable to open /sys/class/gpio/gpio17/value”
    “gpio readall” etc works ok.

    • Undefined reference usually means you’re not linking the library in. make sure you try:

      -L/usr/loccal/lib -lwiringPi

      on the gcc compile line.

      -gordon

  103. Hi Gordon,
    had the same Problem here, but plan B works.
    No other complains, many thanks for your work.

    Olaf

  104. Hi,

    I am sorry I don’t understand. When I use below comand “gpio readall”
    my GPIO are sometimes low and sometimes High even if I don’t touch anything. Why ? I don’t understand !! please help me

    • In input mode, the GPIO lines “float”, so are subject to stray electrical noise, so when you read them, sometimes they’re high and sometimes low.

      This is to be expected.

      -Gordon

  105. I’m tring to build blink sample with ubuntu using the official toolchain. But a wild error appear:

    “/home/nick/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-gnueabihf/bin/ld: skipping incompatible /usr/local/lib/libwiringPi.so when searching for -lwiringPi
    /home/nick/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lwiringPi
    collect2: error: ld returned 1 exit status
    make: *** [Led] Errore 1”

    Why?

    • I compile everything directly on my Pi’s. You’re cross compiling.

      But the issue is fairly obvious – look at the error message: “cannot find -lwiringPi” this means that it can not find the wiringPi library. So you need to make sure that wiringPi is (cross) compiled and installed on whatever machine you’re doing the cross compiling on.

      -Gordon

        • You need to cross compile wiringPi – the 32/64 bit underlying OS is irrelevant. It needs to be compiled with the ARM compiler. I do all my compiling on the Pi – it was designed so that it can support native compilition, so I can’t really help with cross compiling.

          -Gordon

  106. #include
    #include

    // LED Pin – wiringPi pin 0 is BCM_GPIO 17.

    #define LED 0

    int main (void)
    {
    printf (“Raspberry Pi – Gertboard Blink\n”) ;

    wiringPiSetup () ;

    pinMode (LED, OUTPUT) ;

    for (;;)
    {
    digitalWrite (LED, 1) ; // On
    delay (500) ; // mS
    digitalWrite (LED, 0) ; // Off
    delay (500) ;
    }
    return 0 ;
    }

    this program shows error
    please help me

    pi@raspberrypi ~ $ vi blink.c
    pi@raspberrypi ~ $ cc -o blink blink.c -lwiringpi
    blink.c:6:12: warning: missing whitespace after the macro name [enabled by default]
    blink.c: In function โ€˜mainโ€™:
    blink.c:10:1: error: stray โ€˜\302โ€™ in program
    blink.c:10:1: error: stray โ€˜\240โ€™ in program
    blink.c:12:1: error: stray โ€˜\302โ€™ in program
    blink.c:12:1: error: stray โ€˜\240โ€™ in program
    blink.c:14:1: error: stray โ€˜\302โ€™ in program
    blink.c:14:1: error: stray โ€˜\240โ€™ in program
    blink.c:14:1: error: stray โ€˜\302โ€™ in program
    blink.c:14:1: error: stray โ€˜\240โ€™ in program
    blink.c:14:1: error: stray โ€˜\302โ€™ in program
    blink.c:14:1: error: stray โ€˜\240โ€™ in program
    blink.c:14:1: error: stray โ€˜\302โ€™ in program
    blink.c:14:1: error: stray โ€˜\240โ€™ in program
    blink.c:14:1: error: stray โ€˜\302โ€™ in program
    blink.c:14:1: error: stray โ€˜\240โ€™ in program
    blink.c:16:1: error: stray โ€˜\302โ€™ in program
    blink.c:16:1: error: stray โ€˜\240โ€™ in program
    blink.c:17:1: error: stray โ€˜\302โ€™ in program
    blink.c:17:1: error: stray โ€˜\240โ€™ in program
    blink.c:18:1: error: stray โ€˜\302โ€™ in program
    blink.c:18:1: error: stray โ€˜\240โ€™ in program
    blink.c:18:1: error: stray โ€˜\302โ€™ in program
    blink.c:18:1: error: stray โ€˜\240โ€™ in program
    blink.c:18:1: error: stray โ€˜\302โ€™ in program
    blink.c:18:1: error: stray โ€˜\240โ€™ in program
    blink.c:18:1: error: stray โ€˜\302โ€™ in program
    blink.c:18:1: error: stray โ€˜\240โ€™ in program
    blink.c:18:1: error: stray โ€˜\302โ€™ in program
    blink.c:18:1: error: stray โ€˜\240โ€™ in program
    blink.c:18:1: error: stray โ€˜\302โ€™ in program
    blink.c:18:1: error: stray โ€˜\240โ€™ in program
    blink.c:18:1: error: stray โ€˜\302โ€™ in program
    blink.c:18:1: error: stray โ€˜\240โ€™ in program
    blink.c:18:1: error: stray โ€˜\302โ€™ in program
    blink.c:18:1: error: stray โ€˜\240โ€™ in program
    blink.c:18:1: error: stray โ€˜\302โ€™ in program
    blink.c:18:1: error: stray โ€˜\240โ€™ in program
    blink.c:18:1: error: stray โ€˜\302โ€™ in program
    blink.c:18:1: error: stray โ€˜\240โ€™ in program
    blink.c:18:1: error: stray โ€˜\302โ€™ in program
    blink.c:18:1: error: stray โ€˜\240โ€™ in program
    blink.c:19:1: error: stray โ€˜\302โ€™ in program
    blink.c:19:1: error: stray โ€˜\240โ€™ in program
    blink.c:19:1: error: stray โ€˜\302โ€™ in program
    blink.c:19:1: error: stray โ€˜\240โ€™ in program
    blink.c:19:1: error: stray โ€˜\302โ€™ in program
    blink.c:19:1: error: stray โ€˜\240โ€™ in program
    blink.c:19:1: error: stray โ€˜\302โ€™ in program
    blink.c:19:1: error: stray โ€˜\240โ€™ in program
    blink.c:19:1: error: stray โ€˜\302โ€™ in program
    blink.c:19:1: error: stray โ€˜\240โ€™ in program
    blink.c:19:1: error: stray โ€˜\302โ€™ in program
    blink.c:19:1: error: stray โ€˜\240โ€™ in program
    blink.c:19:1: error: stray โ€˜\302โ€™ in program
    blink.c:19:1: error: stray โ€˜\240โ€™ in program
    blink.c:19:1: error: stray โ€˜\302โ€™ in program
    blink.c:19:1: error: stray โ€˜\240โ€™ in program
    blink.c:19:1: error: stray โ€˜\302โ€™ in program
    blink.c:19:1: error: stray โ€˜\240โ€™ in program
    blink.c:19:1: error: stray โ€˜\302โ€™ in program
    blink.c:19:1: error: stray โ€˜\240โ€™ in program
    blink.c:19:1: error: stray โ€˜\302โ€™ in program
    blink.c:19:1: error: stray โ€˜\240โ€™ in program
    blink.c:19:1: error: stray โ€˜\302โ€™ in program
    blink.c:19:1: error: stray โ€˜\240โ€™ in program
    blink.c:19:1: error: stray โ€˜\302โ€™ in program
    blink.c:19:1: error: stray โ€˜\240โ€™ in program
    blink.c:19:1: error: stray โ€˜\302โ€™ in program
    blink.c:19:1: error: stray โ€˜\240โ€™ in program
    blink.c:19:1: error: stray โ€˜\302โ€™ in program
    blink.c:19:1: error: stray โ€˜\240โ€™ in program
    blink.c:19:1: error: stray โ€˜\302โ€™ in program
    blink.c:19:1: error: stray โ€˜\240โ€™ in program
    blink.c:19:1: error: stray โ€˜\302โ€™ in program
    blink.c:19:1: error: stray โ€˜\240โ€™ in program
    blink.c:20:1: error: stray โ€˜\302โ€™ in program
    blink.c:20:1: error: stray โ€˜\240โ€™ in program
    blink.c:20:1: error: stray โ€˜\302โ€™ in program
    blink.c:20:1: error: stray โ€˜\240โ€™ in program
    blink.c:20:1: error: stray โ€˜\302โ€™ in program
    blink.c:20:1: error: stray โ€˜\240โ€™ in program
    blink.c:20:1: error: stray โ€˜\302โ€™ in program
    blink.c:20:1: error: stray โ€˜\240โ€™ in program
    blink.c:20:1: error: stray โ€˜\302โ€™ in program
    blink.c:20:1: error: stray โ€˜\240โ€™ in program
    blink.c:20:1: error: stray โ€˜\302โ€™ in program
    blink.c:20:1: error: stray โ€˜\240โ€™ in program
    blink.c:20:1: error: stray โ€˜\302โ€™ in program
    blink.c:20:1: error: stray โ€˜\240โ€™ in program
    blink.c:20:1: error: stray โ€˜\302โ€™ in program
    blink.c:20:1: error: stray โ€˜\240โ€™ in program
    blink.c:20:1: error: stray โ€˜\302โ€™ in program
    blink.c:20:1: error: stray โ€˜\240โ€™ in program
    blink.c:20:1: error: stray โ€˜\302โ€™ in program
    blink.c:20:1: error: stray โ€˜\240โ€™ in program
    blink.c:20:1: error: stray โ€˜\302โ€™ in program
    blink.c:20:1: error: stray โ€˜\240โ€™ in program
    blink.c:21:1: error: stray โ€˜\302โ€™ in program
    blink.c:21:1: error: stray โ€˜\240โ€™ in program
    blink.c:21:1: error: stray โ€˜\302โ€™ in program
    blink.c:21:1: error: stray โ€˜\240โ€™ in program
    blink.c:21:1: error: stray โ€˜\302โ€™ in program
    blink.c:21:1: error: stray โ€˜\240โ€™ in program
    blink.c:22:1: error: stray โ€˜\302โ€™ in program
    blink.c:22:1: error: stray โ€˜\240โ€™ in program
    blink.c:23:1: error: stray โ€˜\302โ€™ in program
    blink.c:23:1: error: stray โ€˜\240โ€™ in program

    • How did you get the source for that program? Are you using the blink.c one in the examples directory? If not then use it – don’t copy & paste from elsewhere.

      -Gordon

  107. Hello Gordon,

    I installed wiring and it all works well, I have set it up with siriproxy and I have made siriproxy to start from boot automatically. My issue is that siriproxy responds to all the commands well except for wiringpi i.e. it doesnโ€™t switch on the led according to my command on gpio.

    Can you please help?

    Thanks

    • I don’t use apple products, so I’ve no idea what/how siriproxy works. But make sure it can find your program – maybe specify the full path – e.g. /home/pi/myprog etc.

      -Gordon

  108. Hi Gordon,

    In which mode works SPI in wiringpi? Mode 0,1,2 or 3 (CPOL and CPHA)? Is it possible to change this mode?

    Michael