Compiling with wiringPi

Recently I bought from xDev Magazine a copy of a PDF document entitled “Program Raspberry Pi 2B and Raspberry Pi 3B Electronics with Xojo”. This document describes how to write a Xojo program, how to copy a GPIO module into the IDE, how to build the program, and how to copy the resulting files to the Raspberry Pi 3B. Once there it further describes how to give the executable permission to run.

The above procedure works fine for programs not involving any wiring of the Raspberry. To accommodate such programs, the document tells how to install on the Raspberry a system by name of wiringPi. When building this system you are receiving the following message:

“Note: To compile programs with wiringPi, you need to add:
-lwiringPi
to your compile line(s).”

Unfortunately, however, the above-mentioned document does not tell you how to carry out this instruction. The compiling presumably takes place in Xojo, while the wiringPi is located on the Raspberry.

My question thus is: How do I include the wiringPi code in my executable file?

Any help with this problem will be greatly appreciated.

Strange

Hello Strange,

WiringPi is a library that is to be installed on the Raspberry Pi that contains the instructions used by Xojo. Instructions to install this library are in Chapter 5 in the section called “Install Wiring Pi”. Another option is to use the instructions directly from the creator of the library at: WiringPi Download and Install. I find that his ‘Plan B’ instructions for installing WiringPi always work.

Happy to help,

Eugene

Sorry, I don’t believe I directly answered your question.

The wiringPi library is not installed within the executable, and will need to be installed separately.

Hi Eugene,

Thanks for your response. - However, I believe you haven’t answered my
question, which was: How do I include wiringPi in the executable. Having
compiled, e.g., Example5-2 on Xojo, and having moved the built files to
the Raspberry, and then permitted the executable to run, nothing happens
when I double-click the excutable (and answer Yes to run it). - And no
wonder, it seems to me, since at no point have I made wiringPi to
compile with my Xojo file.

PS. As I mentioned in my original mail, wiringPi has been installed, -
and it has provided the instruction:

“Note: To compile programs with wiringPi, you need to add:
-lwiringPi
to your compile line(s).”

So my question remains: How do I get wiringPi to get included in the
executable? - Perhaps it should be moved to the same folder as the
executable?

Hoping that you can clarify this point to me,

Strange

Hello Strange,

Could I ask for you to try to run the program in a different way? If the Example 5-2 folder has been copied to the Raspberry Pi desktop (with the subfolder Example5-2 Libs and Example5-2 executable), then right-mouse-click the Example5-2 folder and select ‘Open in Terminal’. In the terminal type the following command to run the program:

sudo ./Example5-2

This should run the program.

To double-check that the Raspberry Pi ‘sees’ the wiringPi library, type the following command:

dpkg --get-selections | grep wiringpi

If the library is accessible with Raspberry Pi, then the response from the command should show up with a red coloured wiringpi .

Could you let me know what messages were shown? Thanks!

Hello Eugene,

Hurrah, the sudo order made the program run! That is, the display with the buttons showed up, - but there was no action when clicking the buttons. This may be due to a wiring error, since I have not been able to figure out how to connect the green wire in the photo. - I shall therefore try another wiring example, and I shall be sure to report back.

Thanks very much for the help so far!

Best regards, Strange

This is great news.

The green wire in the photo is connected to pin #4 (GPIO #4, See page 24, with figure #10). GPIO Pin #4 is equal to pin #7.

Pin numbers are a bit confusing, and I wish whoever named them, would have made them all the same. Oh well, that’s how it works :slight_smile:

Hi again Eugene,

Sorry to bother you so much! - By now I succeeded in producing a pipe character on my Danish keyboard. However, your dpkg instruction produced the response “install”. I then carefully repeated your instructions from the PDF document, and finally got the message “Already up-to-date” in response to ‘git pull origin’, - but still the response to the dpkg instruction was “install”. And the same thing happens when I copy the wiringPi directory to Desktop.

Hoping that you will be able to sort this out,

Strange

Hi Strange,

The instructions for installing wiringPi with Plan A worked a few times for me and then stopped working. There is a Plan B to install the wiringPi library that has worked every time for me. Could I ask you to give Plan B a try, as I am getting the same message as you are.

We are getting close!

Hi Eugene,

Having installed wiringPi according to Plan B, I get (among others) these messages following ./build:

“Device tree enabled”

“> ie. export WIRINGPI_GPIOMEM=1”

The gpis -v instruction answers correct. The dpkg instruction, however, still responds “install”. - Executing “sudo ./Example5-2” results in the display of the desired layout with the two buttons, but clicking these buttons has no effect on the LED, which is turned on all the time.

Does it matter where the wiringPi folder is located? At present it still sits in the Downloads folder.

Are we getting closer? Hopefully!

Strange

Hello Strange,

Yes, it sounds like we are getting closer. The part that seems odd is that the LED is on. The default should be that the LED is turned off. One of the wires should be to ground, which is connected to the resistor and the LED, while the other wire should be going to GPIO #4 (Pin #7).

With with LED connected to GPIO 4 (Pin #7), could you type the following commands in a terminal on the Pi? These commands should turn the LED on and off through the GPIO.

This turns power on to pin 7

gpio 7 1 

This turns power off of pin 7

gpio 7 0 

If the gpio -v command is working, then it sounds like the GPIO is installed correctly, and it should give you a version (my version is gpio version: 2.32).

Hello Eugene,

With the LED connected to pin #7, the Led does not light in response to either gpio 7 1 or gpio 7 0. And when the LED is connected to pin #4 (as it appears to be in your illustration), it is lighted all the time.

My version of gpio also is 2.32.

Hello Eugene,

I now discover that in response to “gpio 7 1”, the system responds with “Unknown command: 7”. How shouldI enter that instruction?

It seems like the wiringpi library is either corrupt or did not compile correctly. Wiring Pi should be uninstalled and then reinstalled. Do you know how to uninstall it?

I know how to delete files/folders with rm -r. Do I need to know more?

Having deleted wiringPi and reinstalling according to Plan B, I now get the response “uninstall” when entering the dpkg instruction, - which is good, I suppose?

The instruction “gpio 7 0” still returns “Unknown command: 7”.

Hi Strange,

When the following command is typed:

dpkg --get-selections | grep wiringpi

If wiringpi is configured and installed correctly, the Raspberry Pi should return wiring pi install

I would suggest using the purge command (removes program files and configuration files) instead of the remove command (only removes program files). This will help with a fresh install. Here are the steps I am suggesting to reinstall:

sudo apt-get purge wiringpi //deletes program files and configuration files sudo apt-get autoremove //removes old programs sudo apt-get update //updates available program package list sudo apt-get upgrade //updates programs, this may take a while sudo rpi-update //updates Pi-firmware sudo reboot //reboots the Pi Install wiring Pi according to steps in Plan B dpkg --get-selections | grep wiringpi //should return wiring pi <lots of space> install

If this doesn’t work, then the Jessie OS may need to be reinstalled. Sorry that this hasn’t been easy

The dpkg instruction did not produce the desired output, so the entire installation was done all over again. And now the dpkg instruction does produce “install”.

The Plan A installation of wiringPi ends with:

Raspberry Pi Details.
Type: Pi 3, Revision: 02, Memory: 1024MB, Make: Sony
* Device tree is enabled.
* This Raspberry Pi supports user-level GPIO access.
-> See the man-page for more details
-> ie. export WIRINGPI_GPIOMEM=1

Path to wiringPi library: /home/pi/wiringPi/wiringPi, containing a number of .h and .c files.

Response to “gpis 7 0”: Unknown command: 7.

LED is still on all the time.

And now, when I want to try out Example5-2 after a reboot, the machine asks for user and password, and will not accept “pi” and “raspberry”. I have been in this situation once before, but have forgotten how to get around it!

  • It just seems impossible to get the system to work!

Strange

Having reinstalled the system (this time avoiding the ‘password trap), I turned to installing wiringPi. Following Plan A, the instruction “sudo apt-get git-core” gave the response “git-core is already the newest version.” The next instruction, “ cd wiringPi”, however, resulted in “No such file or directory.”

Moving on to Plan B and clicking “snapshot” for the top listing resulted in a notice at the bottom left saying: “wiringPi-b0a60c3(5).tar.gz Finished”, and a window with the wiringPi… as its name, an entry labelled “Location:”, and two sections with the wiringPi… file listed in both. However, owing to my ignorance I don’t know which button to press in order to effectuate the download. (On previous attempts the file just seemed to appear in its right place). Examining the File Manager, no trace of the file appears.

It is had to understand how seemingly identical procedures can lead to such diverging results!

Hi Strange,

Were you able to open a terminal and go to the folder where the wiringPi-b0a60c3(5).tar.gz file (from Plan B) is located and then run the following commands?

tar xfz wiringPi-b0a60c3(5).tar.gz cd wiringPi-b0a60c3(5) ./build

These steps download the zipped file (tar.gz), and create a new directory called wiringPi-b0a60c3(5) which contains the unzipped files. Typing cd wiringPi-b0a60c3(5) moves the terminal to this directory. The ./build command compiles the code to make the wiringpi program.

Once the wiringpi program is built (compiled), then it is able to run on your Raspberry Pi to control the electricity going into/out the GPIO pins.