Thursday, July 24, 2014

Let's Get Current

OK - I know I shouldn't have, but I just had to. The new Raspberry Pi is out - the Model B+. So I ordered one a few days back and it arrived today. It won't go astray as I plan to have two units on my own layout - one will drive wireless control of the layout and the other will be for programming locos at the workbench.

The Model B+ is the higher-spec variant of the Raspberry Pi. It replaced the original Model B in July 2014. Compared to the Model B it has:

  1. More GPIO. The GPIO header has grown to 40 pins, while retaining the same pinout for the first 26 pins as the Model B.
  2. More USB. There are now 4 USB 2.0 ports, compared to 2 on the Model B, and better hotplug and overcurrent behaviour.
  3. Micro SD. The old friction-fit SD card socket has been replaced with a much nicer push-push micro SD version.
  4. Lower power consumption. By replacing linear regulators with switching ones we’ve reduced power consumption by between 0.5W and 1W.
  5. Better audio. The audio circuit incorporates a dedicated low-noise power supply.
  6. Neater form factor. They’ve aligned the USB connectors with the board edge, moved composite video onto the 3.5mm jack, and added four squarely-placed mounting holes.
Anyway so it arrived and as soon as I had pushed some food into my face after work, I pulled the package out and plugged in all of the cables on my table and inserted a MicroSD card I already had imaged with my Raspian "June 2014" and JMRI "3.8".

As expected it all just worked fine. So the next trick and test I wanted to see was to not use the powered USB hub. So I pulled the hub out and inserted the Wireless Adapter into the R-Pi itself.

Power was switched on and it all fired up and again I was able to drive a train. Happy happy, joy joy.

So this now leads me to the next test I must do once I can get some time at the club - that is to hook the setup into the N Scale Exhibition layout and test how far away I can get and it still work. Also to see how many can drive at the same time too.

Maybe it will all be a ripper and the new Pi has enough power to drive the adapter and hence cost and size of the setup will be lower for connecting to the layout. Now I can't wait till next club day for me!

Sunday, July 20, 2014

It's's Alive!!

My lounge room now echos to the sounds of my HO scale Burlington Northern EMD SD9. And it also looks funny that whilst this loco is moving in one direction there is an N scale Canadian National EMD SD40-2 passing in the opposite direction.

Yes - it is all alive!

I have finally nutted out, with help of course, how to get the Raspberry Pi to run in Facelesss mode and fire up the latest JMRI software which is version 3.8 and to act as an Access Point. This will now allow us at the club to start planning our implementation on our N scale exhibition layout and also our HO club room layout.

So continuing on from my last post, we start at step 22. This is where we had the JMRI running in normal mode and were able to control locos. But it still required manual intervention to start up the JMRI.

22. Once finished, exit the app on the smartphone / tablet and turnoff the device’s wifi connection if required.

Close down the WiThrottle Server by going to WiThrottle on the menu bar of the WiThrottle window and click on Stop Server.

Close down JMRI by going to File on the menu bar of the DecoderPro window and click Quit.
Exit/Logout the desktop GUI of your Raspberry Pi.
Close down the Pi if required:

sudo shutdown –h now

If you don’t intend to have the R-Pi Access Point permanently connected to the Internet (probably only required temporarily for software updates), disconnect the Ethernet cable from the R-Pi.

Bundle up your R-Pi, USB powered hub, and power sources. Position them as you wish on your layout.

Remember this order of start-up:

Turn on your DCC system/s interfaces/systems first
Turn on powered hub
Turn on computer monitor (if required)
Turn on the R-Pi

23. Now it is time to turn our attention to getting our R-Pi to run in Faceless mode. This way we do not need a keyboard, monitor or mouse to run it as our Access Point and WiThrottle. So in this configuration it will be great for our exhibition layouts.

To begin with you will first need to set WiThrottle to autostart when JMRI starts up. So startup DecoderPro as before.

Now under ‘Edit’ on the menu bar, select ‘Preferences’
Select Start Up
Under the ‘Actions’ tab, click the Add Action button and set Start WiThrottle Server on the drop down list to automatically start at Start up.
Click Save
When asked, restart the application for the changes to take effect.

Once done, close down DecoderPro. So from now on, whenever you start up the DecoderPro, the WiThrottle will also start up.

24. Next we need to make DecoderPro itself start up by itself whenever the R-Pi is turned on. First part is to create a profile for this. So turn your R-Pi on and log into it.

The older versions of JMRI used a slightly different method to setup what is called Faceless mode. Under version 3.8 we get to play with the new “profile” files a tad. Now first up we need to setup a profile for use with our Faceless mode.

Now under Edit on the menu bar, select Preferences, then select Config Files.
Click on New and give your new profile a name. I used MyFacelessMode as my name.
Now the Status of your new profile should show as “Active profile on restart”.
So hit Save and restart the JMRI. It should restart and be sitting at the Connections page of Preferences.
So add the details into this profile, the same as before:

So I selected NCE as the System Manufacturer.
Next I selected NCE USB as the System Connection.
Next select /dev/ttyUSB0 in the Serial port dropdown menu under the Settings section.
My USB version I set to V6.x.x as that is what I have.
My system I selected as PowerCAB.

Also select Start Up, then the ‘Actions’ tab, then click the Add Action button and set Start WiThrottle Server on the drop down list to automatically start at Start up.

Now if you want a fixed port number for you WiThrottle, then in the WiThrottle section look at the Network option. Tick the box and give it a 5 digit number (make it below 65000 or there abouts).

Click Save and restart JMRI when asked to.

At this point you could test a train to make sure you have it right or just trust you are following the instructions correctly.

25. Now shutdown the JMRI for the next step where we make the configuration file for the autostart. At a command prompt on you R-Pi, make a new file:

sudo cp /home/pi/.jmri/ /home/pi/.jmri/

Now let’s edit this new file and make it autostart:

sudo nano /home/pi/.jmri/

Now change the line:

<entry key="autoStart">false</entry>

To now be:

<entry key="autoStart">true</entry>

Now save and exit the file.

26. Finally we will edit the R-Pi’s start up file to start JMRI at boot time. So at the command prompt we will edit the startup file:

sudo nano /etc/rc.local

Add the following line so it is the second last line. Copy it exactly, as if you haven’t already guessed, Linux, of which Raspbian is a version, is case sensitive when you type. So a capital letter is different in a command than a lower case letter and so on. And the ampersand at the end of the line means something too.

sudo –u pi /home/pi/JMRI/JmriFaceless &

The last line of course will therefore be “exit 0”.
Now save and exit the file.

You can now reboot your R-Pi and JMRI should now start up as will the WiThrottle. I’ll now be able to connect this one to the club exhibition layout so we can use our tablets and phones to drive our trains at our next show.

27. If at any time you wish to cancel the JMRI Faceless mode then:

Power off the R-Pi (pull out the power lead)
Connect up the computer screen and keyboard
Reconnect the power
Login to the R-Pi and at the command prompt type:

killall java

You can then comment out the execution of JmriFaceless from the startup script if you are intending to work on JMRI, etc. So at the prompt:

                sudo nano /etc/rc.local

Now just put a hash in front the second last line. It should then look like:

sudo -u pi /home/pi/JMRI/JmriFaceless &

Save the file and exit.

So you are now up and running with a Raspberry Pi for remote controlling of you locos. For shutting down I plan on just pulling the power plug. It can't damage the components at all, but in the long term it might corrupt the SD card. So you can always make a backup copy onto another SD card and carry a spare. You can reburn the failed one when you get near your desktop computer. Of course you need to take a copy first - that you do with something like the "Win32DiskImager" which is free on the internet.

Wednesday, July 16, 2014

Consistency has been Achieved

OK, so I have been buggering around with my Raspberry Pi over the last few weeks. I have now been able to time after time follow these here destructions and get a working JMRI out of it and control my trains on track connected to my NCE PowerCAB.

There is only one more step alluding me, and that is how to get the R-Pi to autostart JMRI and thereby allowing me to run "faceless".

But these instructions so far as I have gotten, may be of help to those out there wanting to put the latest version of JMRI 3.8 onto their Raspberry Pi. (the hardware is as per my previous post):

1. Purchase your bits and pieces. Here are the parts I purchased to use for myself and this project:

2. Next I pulled down a small piece of software to format the SD Card I will use with this Raspberry Pi. The software is called “SD Formatter 4.0 for SD/SDHC/SDXC” and is available from:

So I followed the relevant instructions as per their website and formatted my SD Card.

3. Obtain the latest Operating System for the Raspberry Pi. You can get it from:

For my current build, the download I used was “NOOBS version 1.3.9”. This will get me the “Raspbian Debian Wheezy” Operating System that was release on 20 June 2014.

4. Follow the instructions to get the NOOBS copied to your SD Card and the to install the Operating System on your Pi:

5. Make a few minor configuration changes like:

            Password for your Pi
Locale:  select “en_AU.UTF-8”  and deselect the default “en_GB.UTF-8
Timezone: I selected “Australia”, then “Brisbane”
Keyboard Layout
Name you want to give your Pi

6. Reboot the Pi and login to it. The default user is “pi” with a password of “raspberry

7. I ensured I had my Ethernet cable plugged into the Pi and connected up to my hub/switch and router to my home internet feed. This way my Pi got an IP address and was able to connect to the internet to get all the software needed to continue with this build.

8. Check that the system is all up to date with its software. So issue the following command at the prompt. The prompt is that blue coloured dollar sign “$” on your screen. So here is the command:

                sudo apt-get update

9. Now to install the remote control software so you can get into your Raspberry Pi from your desktop computer, because as we know that has the most comfortable chair in the house and a nice big screen. But if you want, you really don’t need the remote software. So if you do, here we go. We want to install “TightVNCServer”. So type in the following command at the prompt:

sudo apt-get install tightvncserver

Once it has completed its install, you can start it up (note, there is a space before the colon):

vncserver :1

You will be asked to give it a password. Please note it only accepts a maximum of 8 characters. If asked for a read only password say no to it.

10. Install a VNC Client on your desktop PC. There are many, but I used the one from RealVNC at:

11. You can now connect remotely to your Raspberry Pi (let’s start shortening the name to R-Pi shall we) and be comfortable. As an example, my R-Pi when connected to my Ethernet at home, grabbed an IP Address of . Hence to connect via VNC to it from my desktop PC, I just fired up the RealVNC software and put this IP Address in for the remote connection I was going to (ie the R-Pi) as well as adding in a colon and a one at the end ie -

To find out your IP Address, at the prompt on you R-Pi, just type in:


This is part of what gets spat out. The important bits we want are the four numbers after the “inet:addr” in the section of “eth0”:

eth0    Link encap:Ethernet  HWaddr b8:27:eb:30:de:32 
                       inet addr:  Bcast:  Mask:
          RX packets:804 errors:0 dropped:0 overruns:0 frame:0
          TX packets:943 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:42747 (41.7 KiB)  TX bytes:220723 (215.5 KiB)

The following 2 steps would seem out of order, but it has a reason – it saves typing because you can do the second step much easier this way – trust me.

12. One problem I had with the TightVNC was that copy/paste between my Raspberry Pi and Desktop PC did not work. So I found a solution here:

So you pull down and install “autocutsel”:

sudo apt-get install autocutsel

Then you need to open this file /home/pi/.vnc/xstartup and edit it. So at the command prompt type this:

nano /home/pi/.vnc/xstartup

By the way, nano is a small editor that is in your Pi by default.

The edit is to insert this line   autocutsel -fork   into the existing file and thereby give a file that looks like the following:

xrdb $HOME/.Xresources
xsetroot -solid grey
autocutsel -fork
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
# Fix to make GNOME work

So save the file and with a reboot of your Pi, the copy and paste will now work with your VNC.

13. We now need to make sure the TightVNC starts up automatically each time the Pi starts up. I tried a number of recommended ways, but ended up following the “Adding Tightvnc to the startup“ section of this one which worked fine for me:

So here we go – go to the command prompt (that little blue dollar sign) and we will make a new file to autostart the TightVNC. So start typing:

cd /etc/init.d
                sudo nano tightvncserver

Add all these lines into this file we have just created and opened up:

# Provides:          tightvncserver
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start/stop tightvncserver
# More details see:
### Customize this entry
# Set the USER variable to the name of the user to start tightvncserver under
export USER='pi'
### End customization required
eval cd ~$USER
case "$1" in
    su $USER -c '/usr/bin/tightvncserver :1'
    echo "Starting TightVNC server for $USER "
    pkill Xtightvnc
    echo "Tightvncserver stopped"
    echo "Usage: /etc/init.d/tightvncserver {start|stop}"
    exit 1
exit 0

Now to set the file up to run. Type the following at the command prompt:

sudo chown root:root /etc/init.d/tightvncserver
sudo chmod 755 /etc/init.d/tightvncserver
sudo update-rc.d tightvncserver defaults

Reboot the Pi and voila, the TightVNC has now started.

14. Let us now install and configure the software to turn our Raspberry Pi into a wireless Access Point. Depending on the Wireless Dongle you have purchased, these steps may change. But for the one I have used (the Nano 150 from Jaycar), the best method was to follow one I found on the internet. This instruction set suits all dongles that have the Realtek 8188CUS chipset in them:

So here are the key strokes to follow at the command prompt:

tar -zxvf v1.1.tar.gz
cd RTL8188-hostapd-1.1/hostapd
sudo make

After a while, you should be given control back to the terminal. So then do these instructions:

sudo make install

So now we have the “hostapd” program installed – this is part of our Wireless Access Point. Now we need this program to also autostart every time we boot up the Raspberry Pi. So type this at the command prompt:

sudo ln -s /etc/init.d/hostapd /etc/rc2.d/S02hostapd
sudo update-rc.d hostapd enable

This is the output that will come too your screen – don’t worry about the two warnings:

update-rc.d: using dependency based boot sequencing
insserv: warning: current start runlevel(s) (2) of script `hostapd' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (empty) of script `hostapd' overrides LSB defaults (0 1 6).

This should ensure that the “hostapd” application starts after a reboot.

15. Now we will install “dnsmasq” to use as the DHCP Server:

sudo apt-get install dnsmasq

16. Now you have to configure the “/etc/network/interfaces” file. So let’s edit:

sudo nano /etc/network/interfaces

Comment out the line “allow-hotplug wlan0” ie put a “#” in front of the line so it looks like:

# allow-hotplug wlan0

Add the following lines to setup the IP addressing. Now this can be all sorts of addresses, I’ll give an example here:

#Setup the device with an static IP
iface wlan0 inet static
# Static IP Address
# Network mask

Comment out the line with “wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf”
Comment out the “iface default inet dhcp” line
Save the file and exit the editor.

17. Now to edit the /etc/hostapd/hostapd.conf file:

sudo nano /etc/hostapd/hostapd.conf

Edit it replace it with the following lines. You just need to pick your own passphrase and ssid:

# Basic configuration

# WPA and WPA2 configuration
# passphrase has to be 8-63 characters in length

# Hardware configuration

18. Next we edit the file to configure the DNS mask. So edit:

sudo nano /etc/dnsmasq.conf

Now add the following two lines to the very bottom of the file:


18. So now that the Raspberry Pi is acting as a proper Access Point for us, it is time to turn our thoughts to installing the JMRI. So let’s start typing on the little blue dollar sign of our Pi.

First let’s check that the Pi is up to date:

sudo apt-get update

Download JMRI 3.8, which is the most current at the time of writing this article:

sudo tar -zxvf JMRI.3.8-r26527.tgz

19. Now to start JMRI and configure it. Now connect your DCC system interface (in my case an NCE USB adapter and my PowerCAB) to the USB Hub before starting up JMRI. Fire up a desktop environment:

cd /home/pi

Open File Manager and go to the directory  /home/pi/JMRI

Start JMRI by clicking on the DecoderPro (not DecoderPro3) start up file. This will take a while for the first time it starts.
When asked, use “Execute” and don’t use “Execute in a Terminal”.

Once the JMRI has started, change some preferences. These are found under Edit then Preferences in the menu bar of JMRI.

Once this Preferences window is displayed, enter the Connection information of your DCC system you wish JMRI to connect to, making sure you have connected your DCC system’s USB interface first to the USB hub. So I selected NCE PowerCAB.

Next select /dev/ttyUSB0 in the Serial port dropdown menu.
Save your settings and restart JMRI when asked to.

20. Once JMRI appears to be responding, activate the JMRI ‘WiThrottle’ (wifi) server. Do this by going to the menu bar and selecting Tools, then Throttle, then Start WiThrottle Server.

If this worked it should advise the static IP Address of the Pi (e.g. with a random port number (e.g. 49876) in a new window. Eg

21. To test connectivity, grab your smartphone or tablet and connect to the WiFi that your Raspberry Pi has been set to advertise. In this document we used MyWFiName and we used a password of MYSPECIALPASSWORD.

Let’s assume you have already gone and installed the Engine Driver app on your Android or WiThrottle app on your iPhone. If JMRI is working correctly, you should see the IP address and port of the JMRI ‘WiThrottle’ server on your app. So connect to it.

If this worked, the JMRI ‘WiThrottle ’server’ window on the Raspberry Pi should list the relevant smartphone / tablet device name (configured in the app) connecting to JMRI.

If connected to a layout, try acquiring a train and running the engine remotely.


By the way - I see there is a new Raspberry Pi available. It is called a Model B+. Same processor and memory, but a smaller form factor and a few other changes like now it uses a MicroSD card and has 4 USB ports and more GPIO pins.