Code Monkey home page Code Monkey logo

wiringpi's Introduction

WiringPi

WiringPi is a performant GPIO access library written in C for Raspberry Pi boards.

⚠️️ 🚧 on Pi5, PWM support is currently under development and will not work at this point. If you're interested in the progress, please check the corresponding issue.

To compile programs with wiringPi, you need to include wiringPi.h as well as link against wiringPi:

#include <wiringPi.h> // Include WiringPi library!

int main(void)
{
  // uses BCM numbering of the GPIOs and directly accesses the GPIO registers.
  wiringPiSetupGpio();

  // pin mode ..(INPUT, OUTPUT, PWM_OUTPUT, GPIO_CLOCK)
  // set pin 17 to input
  pinMode(17, INPUT);

  // pull up/down mode (PUD_OFF, PUD_UP, PUD_DOWN) => down
  pullUpDnControl(17, PUD_DOWN);

  // get state of pin 17
  int value = digitalRead(17);

  if (HIGH == value)
  {
    // your code
  }
}

To compile this code, link against wiringPi:

gcc -o myapp myapp.c -l wiringPi

Be sure to check out the examples, build them using Make:

cd examples
make <example-name | really-all>

The tool gpio can be used to set single pins as well as get the state of everything at once:

pi@wiringdemo:~ $ gpio readall
 +-----+-----+---------+------+---+---Pi 3B--+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5v      |     |     |
 |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 0 |  7 || 8  | 0 | IN   | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | IN   | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 1 | 11 || 12 | 1 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 1 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 1 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 1 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI |   IN | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO |   IN | 0 | 21 || 22 | 1 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK |   IN | 0 | 23 || 24 | 1 | IN   | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 0 | IN   | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 0 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 0 | 31 || 32 | 1 | IN   | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |   IN | 1 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 1 | 35 || 36 | 1 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 1 | 37 || 38 | 1 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 1 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi 3B--+---+------+---------+-----+-----+

Installing

You can either build it yourself or use the prebuilt binaries:

From Source

  1. create debian-package
# fetch the source
sudo apt install git
git clone https://github.com/WiringPi/WiringPi.git
cd WiringPi

# build the package
./build debian
mv debian-template/wiringpi-3.0-1.deb .

# install it
sudo apt install ./wiringpi-3.0-1.deb

Prebuilt Binaries

Grab the latest release from here.

Unzip/use the portable prebuilt verison:

# unzip the archive
tar -xfv wiringpi_3.0.tar.gz

Install the debian package:

# install a dpkg
sudo apt install ./wiringpi-3.0-1.deb

Ports

wiringPi has been wrapped for multiple languages:

Support

Please use the issue system of GitHub.

If you're not sure whether to create an issue or not, please engage in discussions!

Please do not email Gordon or @Gadgetoid.

Please don't email GC2 for reporting issues, you might contact us for anything that's not meant for the public.

History

This repository is the continuation of 'Gordon's wiringPi' which has been deprecated, a while ago.

  • The last "old wiringPi" source of Gordon's release can be found at the final_source_2.50 tag.
  • The default master branch contains code that has been written since version 2.5 to provide support for newer hardware as well as new features.

ℹ️️ Since 2024, GC2 has taken over maintenance of the project, supporting new OS versions as well as current hardware generations. We are dedicated to keeping the arguably best-performing GPIO Library for Raspberry Pi running smoothly. We strive to do our best, but please note that this is a community effort, and we cannot provide any guarantees or take responsibility for implementing specific features you may need.

Debug

WIRINGPI_DEBUG=1 ./my_wiringpi_program

WIRINGPI_DEBUG=1 gpio readall

wiringpi's People

Contributors

akvavit01 avatar clach04 avatar corfr avatar davidantliff avatar faboor avatar fanoush avatar freddyrios avatar gadgetoid avatar gordondrogon avatar ijackson avatar isaonakamura avatar kurttomlinson avatar liffiton avatar lolsborn avatar michaing avatar mstroh76 avatar mwallner avatar neuralassembly avatar pinkfreud avatar steveb avatar toca21 avatar tomwardill avatar wolfv avatar ykla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wiringpi's Issues

unregister ISR

wiringPiISR() will register a ISR. works well.

but then your program finishes execution. the program is not running anymore (ps -ef). you start a different program what is not using ISR at all.
it looks like the other program is kind of pausing execution at some point and waiting for a interrupt to occur. when you send signals on the pin used by the ISR the second program resumes.

if i set the ISR pin mode to output at the end of program one i will get process two running normal afterwards.

pinMode(Pin, OUTPUT);

edit:
i think there should be something like:
wiringPiISR(Pin, INT_EDGE_NONE)

lcdPuts and 0th custom character: null terminated string problem

It works well to print custom characters as an escaped characters: "lcdPuts(lcd, "test: \001\002\000aa");".

However, text is cut off at "null termination", so this method works only for characters 1. - 7, but not 0.

It would be nice to have a similar function with a length parameter.

piNes broken

I was building the code, and the makefile failed on the piNes module:
piNes.c:25:12: warning: extra tokens at end of #include directive [enabled by default]
piNes.c:25:10: error: empty filename in #include

Apparently the include was wrong, this fixed it for me:

-#include ""wiringPi.h""
+#include "wiringPi.h"

GPCLK0 clock generation on raspberry pi 4B

Hello,

I am using is WiringPi 2.50 from the apt repositories (latest Raspbian).
If I understand the pin numbering correctly, this should let me generate a 1MHz clock on GPIO4 / GPCLK0:

gpio mode 7 clock
gpio clock 7 1000000

However, I see GPIO4 stay at 3.3v on my scope.

Has this changed for the Pi 4 maybe?

# cat /proc/device-tree/model
Raspberry Pi 4 Model B Rev 1.2

Does one need to enable / disable something in config.txt for that clock to be usable maybe?
Here is my /boot/config.txt:

# grep /boot/config.txt -ve"^#"
disable_overscan=1
dtparam=audio=on

[pi4]
dtoverlay=vc4-fkms-v3d
max_framebuffers=2

[all]

The future of this wiringPi fork

I'm posting this an issue to state the goals for the wiringPi org with the hope that those qualified to help and those more invested in the wiringPi ecosystem might be able to help steer this project toward them.

It's important to me, despite my lack of personal investment in this project, that:

  1. This fork has some kind of future
  2. It's clearly communicated that this is an unofficial fork, but also the canonical public version of the sourcecode
  3. It's clearly communicated (perhaps in sweeping changes to the source headers) that this repository and the accompanying Discord are the canonical places to get help/support (not Gordon)

With respect to how this repository is maintained and organised, let's keep things simple and in order of priority:

  1. Tag releases to give ports a stable version to submodule/link against/etc
  2. Reduce busywork by adding continuous-integration and auto builds via GitHub actions
  3. Keep on top of bugfix PRs, new Pi versions, etc
  4. Consider new features and improvements
  5. Build & release new deb files, potentially replacing the rotting deb files - RPi-Distro/repo#214

If you have a vested interest in keeping this wiringPi fork alive, and would like to join the org as a maintainer- let us know!

Incorrect read GPIO pin

If gpio pin in "write" mode and when call digitalRead(pin) then pin switch to "read" mode.

This is not entirely correct from the point of view of organizing work with gpio as files, since if you have write permissions, reading is also allowed without switching modes. In the implemented case, when the relay modules are connected to the port, their twitching occurs when reading the status from the port

softServo.h is disable

I would like to ask why in the new version of the library softServo is no longer enabled by default?
Any problems caused?

WiringPi error/warning : sudo gpio load i2c

I'm getting an error for WiringPi by sudo gpio load i2c:

pi@raspberrypi:~ $ sudo gpio load i2c
gpio: Warning (not an error): File not present: /dev/i2c-0

I have a Raspi 2B,
gpio -v shows no errors though.

pi@raspberrypi:~ $ gpio -v
gpio version: 2.26
Copyright (c) 2012-2015 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty

Raspberry Pi Details:
Type: Model 2, Revision: 1.1, Memory: 1024MB, Maker: Sony

what's wrong or faulty?

Sunfounder PiCar control?

Looked through the python code (https://github.com/sunfounder/SunFounder_PCA9685/blob/master/PCA9685.py) they provide and i want to recreate in PHP using something like https://github.com/WiringPi/WiringPi-PHP

I would like to know if its possible to access the servos/motors on the boards via the above library? (It can access I2C and GPIO)

I am just playing with the below:

php $handle = wiringPiI2CSetup(0x40); // The PCA9685 device

$testWrite = wiringPiI2CWriteReg16($handle, 0xFC, 1); // 1 or 0 on/off?

wiringPiSPIDataRW returns EINVAL

Hello !

I'm using arch linux: 3.18.3-3-ARCH #1 PREEMPT with newest wiringpi-git packet from the AUR.
module spi_bcm2708 is loaded and devices are in /dev/spidev0.0 and /dev/spidev0.1

fd = wiringPiSPISetup (0, 500000);
if (fd == -1)
    errExit("wiringPiSPISetup");

--works without errors

uint8_t buff = 0b11110000;
ret = wiringPiSPIDataRW (0, &buff, 1);
if (ret == -1)
    errExit("wiringPiSPIDataRW");

returns -1 with [EINVAL Invalid argument]

echo 1 > /dev/spidev0.0 works fine

This code worked with older kernels, but after the jump to 3.18 it doesn't.
But i can't say it exactly because i have used the libwiringPi the last time in last year.

mfg marco

Debian package

Hi,
Is it possible to install this version of wiring pi using apt (as it was with the official package)?

PWM not working?

I tried gpio mode 1 pwm as well as gpio -g mode 18 pwm but the pin stays in digital output mode:

$ gpio exports
GPIO Pins exported:
  17: in   0  none
  18: out  0  none
  23: out  1  none

Note: I'm running 25e4ec since master seems to be broken (“gpio: Unable to initialise wiringPi mode” on any export).

gpio clock calculations are wrong

I've been trying to set a 4MHz clock with the GPIO utility, and was consistently getting not 4MHz, I finally traced down the problem:

divf = (int)((double)divr * 4096.0 / 19200000.0) ;

To get the DIVF component, the code is dividing by the base clock frequency, but it actually needs to be dividing by the target clock frequency.

To illustrate, calculated I+F values at frequencies near I boundaries, and what the frequency generated by current impl:

freq suggested current actual freq
3.84MHz (5,0) (5, 0) 3.84MHz
3.85MHz (4, 4042) (4, 810) 4.57MHz

Compute Module 4 support is wrong

I did not get my project to work when migrated to CM4 from RpiZ. So I examined the CM4 support in WiringPi and found out that CM4 is treated as CM3 and that is not correct in terms of pin numbering afaik. CM4 is more like standard RPI4 etc.

So I removed the statement model == PI_MODEL_CM4 in below code inside WiringPi.c:

 if ((model == PI_MODEL_CM) ||
      (model == PI_MODEL_CM3) ||
      (model == PI_MODEL_CM3P) ||
      (model == PI_MODEL_CM4))
    wiringPiMode = WPI_MODE_GPIO ;
  else
    wiringPiMode = WPI_MODE_PINS ;

and also moved the CM4-define to correct place in readall.c as below:

if ((model == PI_MODEL_A) || (model == PI_MODEL_B))
    abReadall (model, rev) ;
  else if ((model == PI_MODEL_BP) || (model == PI_MODEL_AP) ||
	(model == PI_MODEL_2)    ||
	(model == PI_MODEL_3AP)  ||
	(model == PI_MODEL_3B)   || (model == PI_MODEL_3BP) ||
	(model == PI_MODEL_4B)   || (model == PI_MODEL_400) ||
	(model == PI_MODEL_ZERO) || (model == PI_MODEL_ZERO_W) || (model == PI_MODEL_CM4))
    piPlusReadall (model) ;
  else if ((model == PI_MODEL_CM) || (model == PI_MODEL_CM3) || (model == PI_MODEL_CM3P))
    allReadall () ;
  else
    printf ("Oops - unable to determine board type... model: %d\n", model) ;

I compiled and got it working all the way. I could do a pull req if you agree that this is correct?

gpio readall pin numbers wrong

testing on a CM4 module with cm4 I/O board.

gpio readall gives a list of pins 1-50. this seems wrong on a 40 way connector. Also many pins are not even GPIOs.
( GND 5v etc)

driver crashes on gpio -g mode 28 in

The following lines cause a crash on the Raspberry pi 4B 8 GB

gpio -g mode 28 in
gpio -g mode 29 in

Basically, one is not allowed to touch these pins. I have fixed this by downloading and patching wiringpi.c in WiringPi But would welcome a more beautiful fix

void pinMode (int pin, int mode)                                                                                     
 {
      int    fSel, shift, alt ;
      struct wiringPiNodeStruct *node = wiringPiNodes ;
      int origPin = pin ;
      if ((pin == 28) | (pin == 29)){ 
                         return ;      
      }
# code continues

I have another library which makes calls to these pins so that's why I can't block the calls another way
ArduCAM/MIPI_Camera#82

SIGINT & ISR not working well together

when using ISRs i have trouble using ctrl-c to end a process.
it seams like execution pauses on some random points and waits for a ISR to get called.

reproduce:

start program
press ctrl-c
program is not shutting down as expected (most of the time) it kind of hangs
trigger the ISR (signals on the pin) and the program will resume for a moment and pause again
after triggering the ISR some more times the execution stops as expected

void handleTermination(int s) {
    printf("Termination: Caught signal %d\n", s);
    exit(1);
}

int main() {
    struct sigaction sigIntHandler;

    sigIntHandler.sa_handler = handleTermination;
    sigemptyset(&sigIntHandler.sa_mask);
    sigIntHandler.sa_flags = 0;

    sigaction(SIGINT, &sigIntHandler, NULL);
    sigaction(SIGTERM, &sigIntHandler, NULL);

    //setup ISRs
    if (wiringPiISR(pin_a, INT_EDGE_RISING, &micISR) < 0) {
        fprintf(stderr, "Unable to init ISR %s\n", strerror(errno));
        return 1;
    }

    if (wiringPiISR(pin_b, INT_EDGE_RISING, &touchISR) < 0) {
        fprintf(stderr, "Unable to init ISR %s\n", strerror(errno));
        return 1;
    }

   while(1) {}
}

edit: may be kind of related but i think not the same problem #28

wiringpi reaps unrelated processes when registering interrupt handler

The problem is specifically in these lines, where some child process is started but then unrelated processes are reaped with wait(NULL)

There is more context on the thread where tmds from microsoft answered such a call reaps other processes and suggested "The native library can wait for the specific child it started using waitpid (instead of wait)". There is some good context on my comment before that + a nice trace using strace earlier.

2.52 version for ubuntu on rpi4B

Hi,

I don't know if this is the correct place to ask but I would like to know about the 2.52 version of WiringPi. I saw Gordon posted on his blog that there's a new update: http://wiringpi.com/wiringpi-updated-to-2-52-for-the-raspberry-pi-4b/

Is anybody working on the update for this mirror?

I am trying to make the 2.52 update work with Ubuntu 16.04.6 running on a rpi4B (following the instructions on Gordon's blog) but it doesn't upgrade.

Any info is welcomed. Thank you in advance.

image

Unable of building package with dpkg-buildpackage

I was trying to build the package using dpkg-buildpackage and got stuck in an error.
I would like to know if this is this something that is only occurring to me and if this could be fixed.

How to reproduce:

Run: dpkg-buildpackage -uc -us -b

Logs:

make[1]: Leaving directory '/WiringPi-final_official_2.50'
 debian/rules binary
dh binary
dh: warning: Compatibility levels before 10 are deprecated (level 8 in use)
   dh_testroot
   debian/rules override_dh_prep
make[1]: Entering directory '/WiringPi-final_official_2.50'
dh_prep -Xdebian/tmp
make[1]: Leaving directory '/WiringPi-final_official_2.50'
   debian/rules override_dh_auto_install
make[1]: Entering directory '/WiringPi-final_official_2.50'
dh_install
dh_install: warning: Compatibility levels before 10 are deprecated (level 8 in use)
dh_install: warning: Cannot find (any matches for) "debian/tmp/usr/man" (tried in ., debian/tmp)

dh_install: warning: wiringpi missing files: debian/tmp/usr/man
dh_install: error: missing files, aborting
make[1]: *** [debian/rules:40: override_dh_auto_install] Error 255
make[1]: Leaving directory '/WiringPi-final_official_2.50'
make: *** [debian/rules:49: binary] Error 2
dpkg-buildpackage: error: debian/rules binary subprocess returned exit status 2

Possible solution

One solution that I've found was to replace (in file: debian/wiring.install):
this:

debian/tmp/usr/bin
debian/tmp/usr/man	usr/share
README.TXT		usr/share/doc/wiringpi
People			usr/share/doc/wiringpi

with this:

debian/tmp/usr/bin
debian/tmp/usr/share/man	usr/share
README.TXT		        usr/share/doc/wiringpi
People			        usr/share/doc/wiringpi

Enhance LCD library with I2C

The LCD library allows to connect 1602 and 2004 LCDs in 4bit or 8bit mode.

Another common possibility to control LCDs like this would be to use the I2C interface with a I2C controller between the Raspberry Pi and the LCD. This would only require 2 pins which aren't even blocked - up to 127 additional devices could be added on the same pins.

Connecting the LCD via I2C can be achieved using the I2C library (demonstrated in this example) but a more convenient way would probably be an enhancement of the LCD library or a second library called "I2C_LCD" or similar.

https://github.com/karunadheera/ - this might be a good starting point.

gpio numbering inconsistent??

I found it very confusing that gpio export always treats pin numbering as "-g", while gpio mode or write don't.

Is this intentional?

Archlinux ARM "Unable to determine board revision from /proc/cpuinfo"

I have archlinux arm installed on my raspberry pi 4, but I get the following error while trying to use wiringpi:

Oops: Unable to determine board revision from /proc/cpuinfo
 -> No "Hardware" line
 ->  You'd best google the error to find out why.

I tried both the python library and the library for haskell, but both has resulted in the error above.
Here is my /proc/cpuinfo:

processor	: 0
BogoMIPS	: 108.00
Features	: fp asimd evtstrm crc32 cpuid
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0xd08
CPU revision	: 3

processor	: 1
BogoMIPS	: 108.00
Features	: fp asimd evtstrm crc32 cpuid
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0xd08
CPU revision	: 3

processor	: 2
BogoMIPS	: 108.00
Features	: fp asimd evtstrm crc32 cpuid
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0xd08
CPU revision	: 3

processor	: 3
BogoMIPS	: 108.00
Features	: fp asimd evtstrm crc32 cpuid
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0xd08
CPU revision	: 3

No longer builds with gcc10

I am running this on Arch Linux. It no longer builds as Arch has updated to gcc10 (currently at gcc 10.2.0) and it fails with this linker error at build.

[Link (Dynamic)]
/usr/bin/ld: wpiExtensions.o:(.bss+0x408): multiple definition of `comDat'; drcNet.o:(.bss+0x400): first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:78: libwiringPi.so.2.60] Error 1

I tried a few things based on some internet googling, but cannot get it past this step.
FWIR the unaccepted hack is to add -fcommon to CFLAGS as I could not figure out the preferred way according to this page:
Gentoo Wiki
If I go into the wiringPi directory and add '-fcommon' to the CFLAGS, it will build libwiringPi.so.2.60 but when I do the same in the wiringPiD directory, I get a libcrypt error.

[Link]
/usr/bin/ld: warning: libcrypt.so.1, needed by /usr/lib/gcc/aarch64-unknown-linux-gnu/10.2.0/../../../../lib/libwiringPi.so, may conflict with libcrypt.so.2

Building examples does not work as documented

After wiringpi is built using build-script, it says:

"To compile an individual example, just type

make exampleName"

$ make servo
make: *** No rule to make target `servo'. Stop.

If i cd to examples directory, it still won't compile.

$ make servo
[CC] servo.c
[link]
/usr/local/lib/libwiringPi.a(piThread.o): In function piThreadCreate': piThread.c:(.text+0x18): undefined reference topthread_create'
collect2: ld returned 1 exit status
make: *** [servo] Error 1

Using Pi4J 1.2 Java Library with Raspberry 4 - Sharing Docker file to produce : libpi4j.so

Hi,

You want to use Pi4J 1.2 Java Library with Raspberry 4 and arm64 architecture?

You know that last version of Pi4J (1.2 as of 2020/12/05) contains the JNI library called libpi4j.so build for armhf architecture...So I would like to share this Dockerfile : https://github.com/fguiet/automationserver-v2/blob/main/libpi4j/builder/Dockerfile

Just run :

docker build -t libpi4j .
docker run -it --rm -v /tmp:/tmp libpi4j /bin/bash -c "cp -r /applications/builder/output/libpi4j.so /tmp"

You'll get the libpi4j.so in your /tmp folder...built again last version of WiringPi (Raspberry 4 ready).
All you have to do to use the Pi4J Java library is to replace lib\raspberrypi\dynamic\libpi4j.so in the Pi4J 1.2 Jar file that you can get from Maven Repository (or you can specify the location of the new compiled library via pi4j.library.path environment See : <https://v2.pi4j.com/documentation/advanced/library-path )

You can build the WiringPi on your distro by running :

cd automationserver-v2/libpi4j/builder/vendor/WiringPi/master-20201205 && chmod u+x build && ./build

Now you can use the Pi4J 1.2 Jar file in your raspberry 4 java project to control GPIO :)

Use it at your own risk :)

I just tested on GPIO 2 (PJ4J numbering scheme) on a debian 10 distro with OpenJDK 11 installed ... so far so good !

My two cent,
Fred

Build script fails with error

When I try to build wiringpi after freshly cloning it from github (git clone https://github.com/WiringPi/WiringPi), the ./build script fails on "Debian Jessie" when linking the GPIO Utility:

GPIO Utility
[Compile] gpio.c
[Link]
gpio.o: In function `main':
gpio.c:(.text.startup+0x154): undefined reference to `wiringPiSetupPiFaceForGpioProg'
gpio.c:(.text.startup+0x580): undefined reference to `gertboardSPISetup'
gpio.c:(.text.startup+0x594): undefined reference to `gertboardAnalogWrite'
gpio.c:(.text.startup+0x760): undefined reference to `gertboardSPISetup'
gpio.c:(.text.startup+0x770): undefined reference to `gertboardAnalogRead'
collect2: error: ld returned 1 exit status
Makefile:45: recipe for target 'gpio' failed
make: *** [gpio] Error 1

Commenting out the GPIO-Utility in the build script and a ./build clean && ./build compiles without error. Any suggestions to fix this issue?

Unable to export GPIO17 (pin 11) on Raspberry Pi 2

When I try to do gpio export 17 out I get

gpio: Unable to open GPIO direction interface for pin 17: No such file or directory

I tried GPIO18 and GPIO22 and there is no problem. I know for sure that 17 is functional since I can access it using the RPi.GPIO lib and my LED is blinking accordingly.

I'm using this tutorial.

SPI addressing issue with more than one MCP23S08

Hi,

I had an issue to control an MCP23S08 with wiringPi. The hardware addressing is not automatically activated in the ...S08 version: the datasheet says that HAEN (bit3) needs to be set in IOCON register for that.

In mcp23x0817.h I had to change line 82 to:
#define IOCON_INIT (IOCON_SEQOP | IOCON_HAEN)

Secondly I had to change in mcp23s08.c line 48 to:
spiData [0] = CMD_WRITE | ((devId & 3) << 1)
as MCP23S08 only support 2 address bits.

After these changes the setup worked with 4 MCP23S08. I've sent these suggestions to Gordon in 2017, but I still see the issues with the current version here.
So I'm not sure if more than one MCP23S08 are supposed to be controlled differently with wiringPi, so that the hardware addressing works properly without my changes.
Maybe someone who knows the source code in more detail can check and comment on my issue and corrections?

Thanks,
Tjareson

question: regarding pins usable for clock

The below comment in wiringPi.c suggests that only pins 4 and 21 are usable as a clock output:

// gpioToGpClkALT:
// ALT value to put a GPIO pin into GP Clock mode.
// On the Pi we can really only use BCM_GPIO_4 and BCM_GPIO_21
// for clocks 0 and 1 respectively, however I'll include the full
// list for completeness - maybe one day...

What is meant by this and is it still true for RaspberryPi4B? I have just used GPIO20 with ALT5/CPCLK0 on my RaspberryPi4 and it actually seems to output my configured clock frequency. Is there some kind of problem that I might be overlooking?

I²C or pcf8574 broken

Hi!

I tried to use my 2004-LCD screen with a PCF8574 I2C controller and WiringPi. I wrote some basic "Hello World!" C code (I'm not very good with C, but it seems alright).

Find it here: https://gist.github.com/speendo/0c168dc50e428e9edc91

The code doesn't throw any errors and the LCD backlight switches off when the code runs. I also can switch the backlight back on. However, I don't get any characters to the display.

When I first run some other sample code copied from here:
http://www.recantha.co.uk/blog/?p=4849

and run my code afterwards, my code works just fine.

Besides, gpio load i2c returns

gpio: Warning (not an error): File not present: /dev/i2c-0

Segfault on "gpio readall" with Model A, rev 2

I'm switching same SD card (with Wheezy 2014-06-20 + WiringPI) between RPI B Rev1 and RPI A Rev2. It looks like WiringPI is "working just fine" on rev1 B model. But on rev2 A model "gpio readall" will segfault after "id 20". Also "physical pin number" does not look right on last 4 entries?

root@raspberrypi2:~# gpio -v
gpio version: 2.18
Copyright (c) 2012-2014 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty

Raspberry Pi Details:
Type: Model A, Revision: 2, Memory: 256MB, Maker: Sony
root@raspberrypi2:~# gpio readall
+----------+-Rev2-+------+--------+------+-------+
| wiringPi | GPIO | Phys | Name | Mode | Value |
+----------+------+------+--------+------+-------+
| 0 | 17 | 11 | GPIO 0 | IN | Low |
| 1 | 18 | 12 | GPIO 1 | IN | High |
| 2 | 27 | 13 | GPIO 2 | IN | Low |
| 3 | 22 | 15 | GPIO 3 | IN | Low |
| 4 | 23 | 16 | GPIO 4 | IN | High |
| 5 | 24 | 18 | GPIO 5 | IN | High |
| 6 | 25 | 22 | GPIO 6 | IN | Low |
| 7 | 4 | 7 | GPIO 7 | IN | Low |
| 8 | 2 | 3 | SDA | IN | High |
| 9 | 3 | 5 | SCL | IN | High |
| 10 | 8 | 24 | CE0 | IN | High |
| 11 | 7 | 26 | CE1 | IN | Low |
| 12 | 10 | 19 | MOSI | IN | High |
| 13 | 9 | 21 | MISO | IN | Low |
| 14 | 11 | 23 | SCLK | IN | High |
| 15 | 14 | 8 | TxD | ALT0 | Low |
| 16 | 15 | 10 | RxD | ALT0 | High |
| 17 | 28 | 53 | GPIO 8 | IN | Low |
| 18 | 29 | 54 | GPIO 9 | IN | Low |
| 19 | 30 | 55 | GPIO10 | IN | Low |
| 20 | 31 | 56 | GPIO11 | IN | Low |
Segmentation fault

QT cross compile

Good morning. I've an ubuntu enviroment to do cross-compiling from ubuntu (with QT) to raspberry PI 4.
I've downloaded and compiled your library (from the raspberry with no errors) and executed again the rsync commands (from ubuntu) but when I try to compile QTCreator says:
cannot find -lwiringPi collect2: error: ld returned 1 exit status
Thanks in advice.

how to support 256000 baudrate?

as for now, the termios.h does not contain B256000
... #define B57600 0010001 #define B115200 0010002 #define B230400 0010003 #define B460800 0010004 #define B500000 0010005 ...

Using wiringPi on QT windows

Hi all,
I am very newly in this matters, I would like to be able to use the wiringPi library in Qt in Windows, is it possible?,
What have I to do in order to use the libraries on Qt. I have only done microcontroller programs, and in that cases, using the librarie in the project's folder and including it was enough, ubt in this way I dont succeed with Qt.
Thank you in advance.

Lcd.c driver incorrect start address for 4x16 displays

When a 4 row, 16 col LCD is used with the lcd.c driver the 3rd and 4th line content is shifted by 4 positions to the right.
The issue is the Row offsets are assumed to be the same for all display layouts. In case of the 4 line 16 pos displays the start address needs to change from:
static const int rowOff [4] = { 0x00, 0x40, 0x14, 0x54 } ;
to
static const int rowOff [4] = { 0x00, 0x40, 0x10, 0x50 } ;
as described in https://www.avrfreaks.net/sites/default/files/forum_attachments/OPTREX_DMC_HD44780compatible_manual.pdf on page 20

Some displays deviate from this even further and custom row offset init would be desirable.

Debian 10: wiringPiSetup: mmap (GPIO) failed: Operation not permitted

[To workaround issue #107] I hardcoded the return of piBoardId() to PI_MODEL_4B,0,0,0 seeing that the rest of the values don't seem to matter and finally got past the error:

 gpio -v
gpio version: 2.60
Copyright (c) 2012-2018 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty

Raspberry Pi Details:
  Type: Pi 4B, Revision: 00, Memory: 256MB, Maker: Sony
  * Device tree is enabled.
  *--> Raspberry Pi 4 Model B Rev 1.2
  * Root or sudo required for GPIO access.

But I still can't get it working on plain Debian 10, getting this:

wiringPiSetup: mmap (GPIO) failed: Operation not permitted

Tried to add iomem=relaxed to /boot/firmware/cmdline.txt as suggested in the Debian Wiki and running as root but it didn't make any difference.

Originally posted by @albertmonzo in #107 (comment)

Pi 400 and CM4 support

This patch was needed to support Pi400 (tested) and CM4 (untested)
See also https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md

diff --git a/debian/rules b/debian/rules
old mode 100644
new mode 100755
diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c
index c3b9d8b..59e1baf 100644
--- a/wiringPi/wiringPi.c
+++ b/wiringPi/wiringPi.c
@@ -219,7 +219,7 @@ volatile unsigned int *_wiringPiTimerIrqRaw ;
 
 static volatile unsigned int piGpioBase = 0 ;
 
-const char *piModelNames [20] =
+const char *piModelNames [21] =
 {
   "Model A",   //  0
   "Model B",   //  1
@@ -240,7 +240,8 @@ const char *piModelNames [20] =
   "CM3+",      // 16
   "Pi 4B",     // 17
   "Unknown18", // 18
-  "Unknown19", // 19
+  "Pi 400",    // 19
+  "CM4",       // 20
 } ;
 
 const char *piRevisionNames [16] =
@@ -2312,6 +2313,8 @@ int wiringPiSetup (void)
       break ;
 
     case PI_MODEL_4B:
+    case PI_MODEL_400:
+    case PI_MODEL_CM4:
       piGpioBase = GPIO_PERI_BASE_2711 ;
       piGpioPupOffset = GPPUPPDN0 ;
       break ;
diff --git a/wiringPi/wiringPi.h b/wiringPi/wiringPi.h
index ecce383..0800ad2 100644
--- a/wiringPi/wiringPi.h
+++ b/wiringPi/wiringPi.h
@@ -103,6 +103,8 @@
 #define        PI_MODEL_3AP            14
 #define        PI_MODEL_CM3P           16
 #define        PI_MODEL_4B             17
+#define        PI_MODEL_400            19
+#define        PI_MODEL_CM4            20
 
 #define        PI_VERSION_1            0
 #define        PI_VERSION_1_1          1
@@ -114,7 +116,7 @@
 #define        PI_MAKER_EMBEST         2
 #define        PI_MAKER_UNKNOWN        3
 
-extern const char *piModelNames    [20] ;
+extern const char *piModelNames    [21] ;
 extern const char *piRevisionNames [16] ;
 extern const char *piMakerNames    [16] ;
 extern const int   piMemorySize    [ 8] ;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.