CMRI RS485 Turnout Control

In this demonstration we will be using the same single servo control code of the arduino and the same turnout table on JMRI as we did in my previous blog for JMRI - CMRI control of turnouts. The difference with this blog is we will be using a USB to RS485 converter on the computer and an arduino RS485  TTL MODUS to do a two wire communication between the PC and the Arduino.

The main advantages of this setup is we can run two wires around the layout as a serial communication bus connected to you PC with the JMRI running. Then we can tap off this bus line with a number of Arduinos controlling accessories on your layout with out having to run USB cables. It also allows you to run more than one arduino with the CMRI library.

I have demonstrated this in a previous blog running two Arduinos each turning on an LED from the JMRI program. The only difference with this blog we will be changing the Arduino code to now run a servo for a turnout and using the JMRI turnout table. This was written up as some people asked how this can be done.

First upload the code blow to your Arduino

#include <CMRI.h>
#include <Auto485.h>
#include <Servo.h>

#define CMRI_ADDR 1
#define DE_PIN 2 

int turnout1 = 0;

Auto485 bus(DE_PIN); // Arduino pin 2 -> MAX485 DE and RE pins
CMRI cmri(CMRI_ADDR, 24, 48, bus); // defaults to a SMINI with address 0. SMINI = 24 inputs, 48 outputs
Servo turnOut1;

void setup() {

void loop() {
    turnout1 = (cmri.get_bit(0));
    if (turnout1 == 1){
    } else {

Now connect up your RS845 and TTL module to your computer and Arduino as shown in the picture above. Remember if we are using different power supplies to run the Arduino and the Servos then we need to connect the ground cable together so we have a common ground across all power supplies. Also is you are running an extension USB cables and have problem with communicating to the USB/RS485 then this may be the extension cable you are using. I also found problems when trying to power the Arduino from a USB plug power supply. I found the problems with poor communication was eliminated when using a dedicated 12V power supply into the Arduino power jack. This may be due to the low current and voltage from the USB plug and also any noise on the power lines.

for JMRI we will be changing the connection to use the RS485. First open PanelPro then click on Edit >preferences to bring up the connection window. Create a new connection tab with the settings shown below. The main difference with my setup to your will be the serial COM port and the name if you want to name yours differently. If you still have the Arduino > CMRI connection setup in a different tab you will need to either delete this connection or disable it so you do not get any errors when starting PanelPro.


Now we will have to setup a NODE. So create a node and set the address to 1. Each Arduino you attach to the serial bus line will have a different address within the arduino code #define CMRI_ADDR 1. This will be the NODE address in JMRI.


Now save all this and restart JMRI PanelPro. It should now startup with out any errors and with your new COM connection.

We will now setup a turnout on the tables. Click on Tools > Tables > Turnouts to open the turnout table. Create a new turnout with the address 1001. We use 100 as we have a NODE address of 1. If we was on NODE 2 then the address will start with 200. The last number is the bit address from the arduino code plus 1. Seeing as we are using bit 0 then this will be 1 in JMRI, therefore 1001. Hope this made some sense.


If you now ensure all your power supplies are switched on you should now be able to control the servo on the Arduino running on your new serial bus line.



Cookie Policy

About Us

Privacy Policy

This site was created and designed by S Brackstone