Files
2026-06-17 14:00:51 +02:00

172 lines
8.0 KiB
Plaintext

<!DOCTYPE html>
<html lang="en">
<head>
<meta name="generator" content="HTML Tidy for HTML5 for Apple macOS version 5.8.0">
<title>JMRI Hardware Setup Support - Raspberry Pi GPIO</title>
<meta name="author" content="Paul Bender">
<meta name="keywords" content="Raspberry Pi GPIO Configuration Information for JMRI">
<!--#include virtual="/help/en/parts/Style.shtml" -->
</head>
<body>
<!--#include virtual="/help/en/parts/Header.shtml" -->
<div id="mBody">
<!--#include virtual="../SidebarUp.shtml" -->
<div id="mainContent">
<h1>Hardware Setup Support: Raspberry Pi via GPIO</h1>
<p>The <a href="https://www.raspberrypi.org/" target="_blank">Raspberry Pi</a> 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
<a href="../USBtoSerial.shtml">USB connection</a> or via the Raspberry Pi's built in serial
ports.</p>
<img src="images/Pi2ModB1GB_-comp.jpg" alt=
"Raspberry Pi2 model B (courtesy www.raspberrypi.org" width="528" height="300" class=
"floatRight" title="Pi2 model B (&copy; www.raspberrypi.org)"> <a id="hardware"></a>
<p class="noted">See <a href="https://www.jmri.org/install/Raspbian.shtml">here for information</a>
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.</p>
<h2>Supported Hardware</h2>
<p>Theoretically, any Raspberry Pi supported by <a href="https://pi4j.com/" target=
"_blank">Pi4J</a> is supported by JMRI.<br>
JMRI support has been tested with the Models B, B+, 2B, and 3. There's also a <a href=
"https://www.jmri.org/install/Raspbian.shtml">JMRI install help page for the Pi</a>.</p>
<h2 id="connecting">Connecting</h2>
<p>Underlying support for the Raspberry Pi's GPIO connections is provided using the <a href=
"https://pi4j.com/">Pi4J library for Java</a>.</p>
<p><strong>Version 1.0 of the Pi4J Library, used with JMRI version 4.5.4 and earlier,
<em>require that applications using GPIO pins be run as root (or using
<code>sudo</code></em></strong>).</p>
<p><strong>Starting with version 4.5.5, JMRI uses version 1.1 of the Pi4J Library. Version
1.1 of the Pi4J library, <em>when used in conjunction with Raspbian Jessie (and later
releases)</em> 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.</strong>
</p>
<p><strong><em>In order to enable use of the GPIO pins by a non-root user, the user must set
the <code>WIRINGPI_GPIOMEM</code> environment variable as follows:</em></strong>
</p>
<p><code>export WIRINGPI_GPIOMEM=1</code>
</p>
<p><strong>This environment varialbe must be set prior to executing JMRI</strong>
</p>
.
<p>For more information, please see the relavent portions of <a href=
"http://www.savagehomeautomation.com/projects/pi4j-now-supports-non-privileged-access-no-more-rootsudo.html"
target="_blank">the pi4j web page</a>.</p>
<h3>Pi4j 1.1 and Raspbian Stretch</h3>
<p>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.</p>
<h4>Determining if the incompatability is a problem</h4>
<p>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:</p>
<pre style="font-family: monospace;">
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.
</pre>
<h4>How to correct for this issue</h4>
<p>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:</p>
<p><code>sudo apt-get install wiringpi</code>
</p>
<p>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):</p>
<p><code>echo "default_options=\"-Dpi4j.linking=dynamic\"" &gt; ~/.jmri/jmri.conf</code>
</p>
<p>After completing these steps, JMRI will be able to configure and use Raspberry Pi hardware
normally.</p>
<h3>Wiring</h3>
<p>JMRI currently supports inputs (Sensors) and outputs (Turnouts) via the Raspberry Pi's
GPIO pins.</p>
<h4>Input/Output pin addressing</h4>
<p>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 <a href=
"https://pi4j.com/">Pi4J website</a> for model specific pin numbering information.</p>
<h3>Settings</h3>
<ol>
<li>Make sure you have the latest version of JMRI installed, then go to the Preferences
panel of a JMRI-based program. This opens automatically the first time a program is run, or
you can select it from the "Edit" menu</li>
<li>Select "Raspberry Pi Foundation" from the System Manufacturer selection box.</li>
<li>Select "Raspberry Pi GPIO" from the System Connection selection box. <!--
<li> The "Connection Prefix" is used to help JMRI communicate
separately with multiple "connections" to layout hardware. Each
"connection" must have a unique identifier, which is specified as
the "Connection Prefix". By default, the first Pi connection is
given a prefix of "P", and additional Pi networks are given
prefixes like "P1", "P2", ... Most users should be able to use the
default "Connection Prefix" value provided by the JMRI tools.
<li>When a JMRI tool is configured for more than one connection,
each connection gets a menu item on the main JMRI tool window. To
help users differentiate between their different connections, each
connection has a "Connection Name", which is used as the name of
the associated menu item on the main JMRI tool window. Users may
change the "Connection Name" for any connection to suit their needs.
--></li>
<li>Click "Save". You'll be asked if it's OK for the program to quit, click "Yes".</li>
<li>Restart the program. You should be up and running.</li>
</ol>
<h2 id="documentation">Documentation</h2>
<h3>JMRI Help</h3>
<p><a href="https://www.jmri.org/install/Raspbian.shtml">JMRI installation on Pi/Raspbian</a>.</p>
<h3>Third Party info</h3>
<p>The <a href="https://pi4j.com/" target="_blank">Pi4J website</a> provides model specific
Java I/O information.</p>
<!--#include virtual="/help/en/parts/Footer.shtml" -->
</div>
<!-- closes #mainContent-->
</div>
<!-- closes #mBody-->
<script src="/js/help.js"></script>
</body>
</html>