Trains.com

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

JMRI on Raspberry Pi to Arduino Mega with DCC++ l298p and PCA9685 Servo Turnout Control

5292 views
8 replies
1 rating 2 rating 3 rating 4 rating 5 rating
  • Member since
    January 2020
  • 8 posts
JMRI on Raspberry Pi to Arduino Mega with DCC++ l298p and PCA9685 Servo Turnout Control
Posted by Spankyty on Tuesday, January 21, 2020 8:58 AM

I'm planning an N scale 4x8 layout and have some questions:

 

I am confused on why people are using an Arduino for each track signal when you can just use one mega for everything. Is there a reason? Look at the picture I have linked for what I want to do.

 

With JMRI can I just control one mega with dcc++, the pca9685 for servo turnout control, and then use the rest of the outputs on the mega for manual servo turnout control with toggle switches?

 

Wiring Layout

Sorry I'm such a noob. :p

  • Member since
    December 2015
  • From: Shenandoah Valley
  • 9,094 posts
Posted by BigDaddy on Tuesday, January 21, 2020 4:55 PM

I can Welcome you to the forum, but Mel is our Arduino guy

I can do pictures too.

Henry

COB Potomac & Northern

Shenandoah Valley

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Tuesday, January 21, 2020 5:15 PM

Welcome

Thanks Henry
 
I’m not the go to guy for either JRMI control or DCC turnout servo control.  DCC control for anything other than running my trains isn’t my thing.  I like to be the engineer and manually operate my layout not a computer.
 
Randy might be.
 
I’m in favor of using servos controlled by a UNO or MEGA but using a computer program to operate the turnouts is not my thing.
 
 
 
Mel
 
 
 
My Model Railroad   
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.
 
  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Tuesday, January 21, 2020 6:44 PM

 Some people like central control, some like distributed control. I am of the latter bent, Mel is of the former.

 Sure, you have lots of IO pins on a Mega, so you cna drive a lot of things from a single unit. But in my mind, running tons of cables from one side to the other of a 20 foot wide layout is just too darn much wire snaking all over the place, even if you do use 50 pair phone cable.

 I've built my own controllers to drive servos for turnouts. I use the ATMega328 chip, same as in the Uno or Nano. Between driving 2 servers, provising LED position indicators, local control buttons, and controls for dispatcher control, I'm using most of the pins to run 2 turnouts. These will be distributed around my layout.

I want to have interior lighting in my sctructures, with some animation (random lights turning on and off, a flickering representation of a TV in some homes, etc. For this I plan to put an ATTiny85 in each structure. Instead of a centralized Arduino Mega with dizens of wires fanning out to all my buildings. With the small 8 pin chip in each building, all I need to do is provide power to the building - same as I would if I had just plain lights in each one (and some will). That wire can be a bus running around, not a fan of wires all over the place.

Common block sensing devices like the Digitraxl BDL-168 detect as many at 16 blocks. From a central location. So that's 16 heavy bus lines running from that central point. I prefer current sense coil types, first because they don;t cause a voltage drop, and second because they can be located near the bus they are detecting, only the low power signal needs to come back to the rest of the circuit. I am designing my own here as well, where each unit will support the typical number of blocks needed at a crossover or passing siding, typically 6 to 8. So even the low current signal wires won't be long.

 And same with railroad signals. Instead of one massuve board with dizens of wires to all the signal heads ont he layout, a smaller chip with just enough pins can drive each signal head plus have an input from the preceeding block and an output to signal the next block, and be completely standalone. 

                                           --Randy


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    July 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Wednesday, January 22, 2020 5:12 AM

of course, multiple Arduino Megas can be used as JMRI nodes to minimize wire lengths, as well as a combination of Megas and Unos.

Uno only has 18 (13 digital + 5 analog) I/O pins.  3 needed for RS-485 communication with a PC using an adaper.

greg - Philadelphia & Reading / Reading

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Wednesday, January 22, 2020 9:36 AM

 I suspect in some cases there are people experimenting with this on a smaller layout where a single Mega has enough IO for everything they want to do. WHich isn't a bad thing - sure easier to start with something simple and once you have it working, then try to build a big layout with the same automation.

 As for RS485 - the guys at MRCS (cpNode) manage to do it with just the serial in and serial out. They have some sort of self enable mechanism using a 555 time, but frankly I can;t understand how it can possibly work - it detects the attempt to send, and then enables the transmitter with the 555. Everythign in me says the additional logic delay enabling the 555 means it will miss the first bit or two, depending on the speed used. The schematic is freely posted on their site, so you can take a look and see what I mean. Perhaps it jsut because the CMRI protocol is actually just robust enough to handle that condition. Which I have to say puts it at least several steps ahead of the NCE cab bus. Perhaps you read the Arduini group on groups.io, there is a current thread of someone trying to tap in to the LCD on the cab to see if a proper response is received. Would it have killed them to put even a simple CRC check byte on each packet?

                            --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    July 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Wednesday, January 22, 2020 11:29 AM

rrinker
people experimenting with this on a smaller layout where a single Mega has enough IO for everything they want to do. WHich isn't a bad thing - sure easier to start with something simple and once you have it working

when developing code for an application requiring the serial interface (i.e. JMRI RS-485), it make sense to develop that code on a mega which has 4  Serial interface.   This allow you to use the Serial monitor for debugging while simultaneously exercising JMRI code (yes, 2 rs-485 interfaces to the PC).

this require using Serial 1 for the Arduino Serial monitor and Serial 2 for JMRI.   Once code is stable, an Uno can use the same code, albeit with less I/O, but must be built with JMRI using Serial 1 (handled with #ifdefs).

 

greg - Philadelphia & Reading / Reading

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Wednesday, January 22, 2020 12:37 PM

 Yes and no - the RS485 adapters work fine with SoftwareSerial - that's how I did my initial test with a Nano connected to my computer. Basically liek this except that one one side, it was a USB to 485 adapter plugged in to my computer running JMRI

https://arduinoinfo.mywikis.net/wiki/SoftwareSerialRS485Example

The Arduino serial port was thus free to enable editing and uploading the sketch, or had I need to, set up some serial feedback. It was a trivial example that defined one CMRI input and one output, so that manual operation in JMRI would turn an LED on or off, and the input was read by JMRI. I made a simple logic element that turned ont he LED if the input was low and turned it off if the input was high.

FOr really simple debugging - I incorporate a heartbeat LED in my projects so I know the code is executing, but the number of flashes and/or the flash rate cold easily be changed beind some #ifdef directives to indicate which way a branch takes you, or if the code is even getting to a point you expect. 

 There are others that have multiple UARTS, but then you end up getting into the 32 bit cores, and they may or may not have other features you might need. ANd most of those are available only as surface mount, so if you end up rolling your own like I do, you end up having to solder surface mount.

                                 --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    January 2020
  • 8 posts
Posted by Spankyty on Saturday, January 25, 2020 9:01 AM

I see, thank you guys for the welcome and also thank you, I understand a lot better now. I have decided to just use an arduino mega for my dpdt toggle switches/lighting/servos for my turnouts and have an arduino uno for the dcc++.

My next problem is that I have minitrix turnouts. It seems that there is no hole in the throwbar. Do I just drill a hole very carefully or is that not a good idea. I'd put the servos on the side but the throwbar is too short. Did I mess up and not get good track? I also have a 9157 fleischmann three way turnout. There also is no hole in the throwbar. (also not long enough) I have taken the springs out of these.

I also have a couple polarize frogs in my train yard. Do I connect the 3rd frog lead to my autoreverser? Sorry again, I'm a slow learner.

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Users Online

There are no community member online

Search the Community

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
Model Railroader Newsletter See all
Sign up for our FREE e-newsletter and get model railroad news in your inbox!