{"id":16220291,"url":"https://github.com/mattjlewis/pigpioj","last_synced_at":"2025-10-04T23:05:18.409Z","repository":{"id":43149743,"uuid":"50837629","full_name":"mattjlewis/pigpioj","owner":"mattjlewis","description":"Java JNI wrapper around the pigpio C library","archived":false,"fork":false,"pushed_at":"2022-03-16T09:21:59.000Z","size":949,"stargazers_count":22,"open_issues_count":3,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-17T06:35:40.505Z","etag":null,"topics":["hacktoberfest","java","pigpio","pigpiod","raspberry-pi"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mattjlewis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-01T12:22:59.000Z","updated_at":"2024-07-19T02:51:46.000Z","dependencies_parsed_at":"2022-09-06T18:50:32.848Z","dependency_job_id":null,"html_url":"https://github.com/mattjlewis/pigpioj","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattjlewis%2Fpigpioj","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattjlewis%2Fpigpioj/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattjlewis%2Fpigpioj/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattjlewis%2Fpigpioj/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattjlewis","download_url":"https://codeload.github.com/mattjlewis/pigpioj/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244416895,"owners_count":20449358,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","java","pigpio","pigpiod","raspberry-pi"],"created_at":"2024-10-10T11:58:19.970Z","updated_at":"2025-10-04T23:05:18.348Z","avatar_url":"https://github.com/mattjlewis.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# About\n\npigpioj is a Java wrapper around the excellent Raspberry Pi C library [pigpio](http://abyz.me.uk/rpi/pigpio/).\nNote that the primary driver for developing pigpioj was to provide an optimised hardware interface\nlibrary for the platform and device independent library [diozero](http://www.diozero.com).\n\nMake sure pigpio is installed on your Raspberry Pi:\n\n```shell\nsudo apt update \u0026\u0026 sudo apt -y install pigpio pigpiod pigpio-tools\n```\n\npigpioj has two modes of operation:\n\n1. JNI\n1. Remote sockets\n\n## JNI\n\nThe JNI mode requires a small system library to be loaded at runtime that allows Java to invoke the\n[pigpio C interface](http://abyz.me.uk/rpi/pigpio/cif.html). This library is packaged in the pigpioj\nJAR file and is loaded automatically when [uk.pigpioj.PigpioJ.getImplementation()](https://github.com/mattjlewis/pigpioj/blob/3e274d46892d58e4be38d454c031d50a4e31ef81/pigpioj-java/src/main/java/uk/pigpioj/PigpioJ.java#L9)\nis invoked.\n\npigpioj provides native libraries that are compiled for ARMv6, ARMv7 and AArch64 CPU architectures\nwhich are bundled within the pigpioj JAR file itself. At startup, pigpioj will detect the CPU\narchitecture and dynamically load the appropriate JNI library. It will first look for libpigpioj.so\non the Java library path, if not found it will extract the library from within the JAR file itself\nvia a temporary file that is automatically deleted once loaded.\n\nThe optimisations within pigpio (using `/dev/mem`) unfortunately requires root access.\nBecause of this all pigpioj applications that use the default JNI mode must be run as root.\nIn addition, the pigpio shared library must be installed on the Raspberry Pi; it can be installed by\nrunning:\n\n```shell\nsudo apt update \u0026\u0026 sudo apt -y install libpigpio1 libpigpiod-if2-1\n```\n\nIn addition, the pigpiod daemon process must not be running:\n\n```shell\nsudo systemctl stop pigpiod.service\n```\n\nThe pigpiod daemon process can be disabled from automatically starting on a reboot:\n\n```shell\nsudo systemctl disable pigpiod.service\n```\n\n### Running on Ubuntu\n\nAt the time of writing, the Ubuntu 64-bit operating system for Raspberry Pi didn't include the\npigpio packages, hence must be built and installed from source code.\nClone the [pigpio GitHub repository](https://github.com/joan2937/pigpio), build and install it.\n\n```shell\nsudo apt update \u0026\u0026 sudo apt -y install git make gcc\ngit clone https://github.com/joan2937/pigpio.git --depth=1\ncd pigpio\nmake\nsudo make install\n```\n\n### PWM / PCM / I2S / pigpio Conflicts\n\nAs per this [pigpio issue](https://github.com/joan2937/pigpio/issues/87), by default pigpio uses the\nPi's PCM hardware to time DMA transfers. pigpio can be configured to use the PWM hardware instead of\nthe PCM hardware by calling `gpioCfgClock` before `gpioInitialise`. To enable this in pigpioj, the\nfollowing variables must be set, either via command line or as environment variables:\n\n* PIGPIO_CLOCK_CFG_MICROS\n* PIGPIO_CLOCK_CFG_PERIPHERAL\n\n### Building the Native Library\n\nIf you need to compile the JNI library yourself you can do so either using a physical Raspberry Pi,\nor via the pigpioj Docker based cross compiler.\n\n#### Building via Docker\n\nClone pigpioj, build the Docker image and initiate the docker build process:\n\n```shell\ngit clone git@github.com:mattjlewis/pigpioj.git\ncd pigpioj/pigpioj-native/docker\ndocker build -t diozero/pigpioj-cc .\ncd ..\n./docker_build.sh\n```\n\nOnce successful, this will result in the following folder structure:\n\n```\nlib\n├── linux-aarch64\n│   └── libpigpioj.so\n├── linux-armv6\n│   └── libpigpioj.so\n└── linux-armv7\n    └── libpigpioj.so\n```\n\n#### Building on a Raspberry Pi\n\nMake sure that the pigpio development tools are installed:\n\n```shell\nsudo apt update \u0026\u0026 sudo apt -y install libpigpiod-if-dev\n```\n\nUnfortunately `pigpio.h` is not included in any of the Raspberry Pi OS packages, first of all run\nthis command in the Pi user's home directory (the Makefile assumes the header files are in\n`/home/pi/pigpio`):\n\n```shell\nsudo apt update \u0026\u0026 sudo apt -y install git make gcc\ngit clone https://github.com/joan2937/pigpio.git --depth=1\ncd pigpio\nmake\n```\n\nCopy the pigpioj-native source files to the Raspberry Pi and compile with `make`.\n\n```shell\ngit clone git@github.com:mattjlewis/pigpioj.git\ncd pigpioj/pigpioj-native/src/main/native\nmake\n```\n\nThis will produce a libpigpioj.so shared object library that needs to be made available on the\nJava library path at runtime.\n\n## Sockets\n\nBy default pigpioj uses JNI mode; to switch to the remote socket mode you must set the `PIGPIOD_HOST`\nvariable, either via environment property or Java command line property. Examples:\n\nCommand line:\n\n```shell\njava -DPIGPIOD_HOST=«your-pigpiod-host» -cp pigpioj-2.5.11.jar:«your-app.jar» «your-main-class»\n```\n\nEnvironment variable:\n\n```shell\nexport PIGPIOD_HOST=\u003cyour-pigpiod-host»\njava -cp pigpioj-2.5.11.jar:«your-app.jar» «your-main-class»\n```\n\nThe pigpiod daemon must be running on the Raspberry Pi for this to work.\n\n```shell\nsudo apt update \u0026\u0026 sudo apt -y install pigpio pigpio-tools pigpiod\nsudo systemctl enable pigpiod.service\nsudo systemctl start pigpiod.service\n```\n\nIf pigpiod is configured to listen on a non-default port (the default is 8888) you will need to\nset the `PIGPIOD_PORT` property.\n\nOne key benefit of sockets mode is to enable remote communication - this means that you can use the\nexact same APIs to run applications on another machine, including a any laptop or desktop that can\nrun Java.\n\nFor security reasons, the pigpiod daemon process can be limited to allow only local connections.\nCheck the `ExecStart` parameter in `/etc/systemd/system/pigpiod.service.d/public.conf`. If it has the `-l`\noption then it will only allow connections from the local machine, e.g.:\n\n```\nExecStart=/usr/bin/pigpiod -l\n```\n\nTo change this behaviour, simply remove the `-l` parameter from this file and restart the process:\n\n```shell\nsudo systemctl restart pigpiod.service\n```\n\nIf the file doesn't exist, run the `raspi-config` application and choose \"3 Interface Options\",\n\"P8 Remote GPIO\" and select \"Yes\". This will make the appropriate changes and create that file if\nit didn't already exist.\n\n## Example Application\n\n```java\nimport uk.pigpioj.*;\n\npublic class PigpioTest {\n\tpublic static void main(String[] args) throws InterruptedException {\n\t\tint gpio = 16;\n\t\ttry (PigpioInterface pigpio_impl = PigpioJ.getImplementation()) {\n\t\t\tpigpio_impl.setMode(gpio, PigpioConstants.MODE_PI_OUTPUT);\n\t\t\tpigpio_impl.write(gpio, true);\n\t\t\tThread.sleep(1000);\n\t\t\tpigpio_impl.write(gpio, false);\n\t\t\tThread.sleep(1000);\n\t\t}\n\t}\n}\n```\n\nThis library is used as a provider for the Raspberry Pi by the platform agnostic diozero Java\nlibrary [diozero](http://www.diozero.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattjlewis%2Fpigpioj","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattjlewis%2Fpigpioj","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattjlewis%2Fpigpioj/lists"}