The Raspberry Pi is a family of inexpensive credit card size single board computers that have many applications in embedded electronics. This page describes the use of the Raspberry Pi's GPIO pins under JMRI. Since the Raspberry Pi runs Linux natively, other connections are also possible using either a USB connection or via the Raspberry Pi's built in serial ports.
See here for information on how to install JMRI on a Raspberry Pi under the Raspian operating system. This must be done before using Raspberry Pi GPIO pins with JMRI objects.
Theoretically, any Raspberry Pi supported by Pi4J is supported by JMRI.
JMRI support has been tested with the Models B, B+, 2B, and 3. There's also a JMRI install help page for the Pi.
Underlying support for the Raspberry Pi's GPIO connections is provided using the Pi4J library for Java.
Version 1.0 of the Pi4J Library, used with JMRI version 4.5.4 and earlier,
require that applications using GPIO pins be run as root (or using
sudo
).
Starting with version 4.5.5, JMRI uses version 1.1 of the Pi4J Library. Version 1.1 of the Pi4J library, when used in conjunction with Raspbian Jessie (and later releases) allow the user to access the GPIO pins without running as root. For compatability reasons, and to allow possible use of PWM outputs, JMRI has choosen not to enable this mode by default.
In order to enable use of the GPIO pins by a non-root user, the user must set
the WIRINGPI_GPIOMEM
environment variable as follows:
export WIRINGPI_GPIOMEM=1
This environment varialbe must be set prior to executing JMRI
.For more information, please see the relavent portions of the pi4j web page.
It has been brought to our attention that the linux kernel used in Raspbian Stretch and Pi4j version 1.1 have a slight incompatability. This incompatability is caused by Pi4J's interface with the hardware is doesn't recognize the CPU reported by the kernel. This section describes how to determine if you are experiencing this issue and how to correct the problem on your Raspberry Pi.
If the incompatability is an issue, JMRI will crash when attempting to create a Raspberry Pi connection and the following error message will appear in the console log:
Unable to determine hardware version. I see: Hardware : BCM2835 , - expecting BCM2708 or BCM2709. If this is a genuine Raspberry Pi then please report this to projects@drogon.net. If this is not a Raspberry Pi then you are on your own as wiringPi is designed to support the Raspberry Pi ONLY.
To correct for this issue, there are two steps you need to complete. First, you need to install a recent version of the wiringPi library, whic Pi4J uses to talk to the Raspberry Pi's hardware. You can do this by running the following command in a terminal:
sudo apt-get install wiringpi
Second, we need to configure Pi4j to use the library you just installed instead of the one that is included with Pi4j. To tell JMRI to use Pi4j in this mode, we are going need to run the following command in a terminal as the user who starts the JMRI application(s):
echo "default_options=\"-Dpi4j.linking=dynamic\"" > ~/.jmri/jmri.conf
After completing these steps, JMRI will be able to configure and use Raspberry Pi hardware normally.
JMRI currently supports inputs (Sensors) and outputs (Turnouts) via the Raspberry Pi's GPIO pins.
JMRI currently uses the default Pi4J pin numbering. The Pin numbers may differ on each model Pi. Generally speaking, Broadcom GPIO pins 0 to 7 may be referenced by those pin numbers in JMRI. This is not guaranteed to be the case. Higher pin numbers are available, but may not correspond to the Broadcom pin numberings. Please refer to the Pi4J website for model specific pin numbering information.
JMRI installation on Pi/Raspbian.
The Pi4J website provides model specific Java I/O information.