RDS
Posts: 718
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Model Trains - DCC

Mon Jan 04, 2016 10:01 am

Is it possible to use a Pi to read the digital signal that passes along the power line on a DCC (Digital Command Control) Model Train layout.

User avatar
RogerW
Posts: 285
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: Model Trains - DCC

Mon Jan 04, 2016 10:24 am

It looks possible to me but might take some research. It also depends on what you want to do with the data. This link might be useful
http://www.opendcc.de/index_e.html
They supply a decoder circuit and also a sniffer which I think allows you to monitor the DCC signals.

User avatar
buja
Posts: 498
Joined: Wed Dec 31, 2014 8:21 am
Location: Netherlands

Re: Model Trains - DCC

Mon Jan 04, 2016 11:45 am

The Gertbot card (not the Gertboard!) has DCC support: http://www.gertbot.com/

drgeoff
Posts: 9805
Joined: Wed Jan 25, 2012 6:39 pm

Re: Model Trains - DCC

Mon Jan 04, 2016 12:07 pm

buja wrote:The Gertbot card (not the Gertboard!) has DCC support: http://www.gertbot.com/
The web page you link to says:
"Trains
- The board can generate DCC signals, a protocol used to control model trains. With four independent channels and 2.5A per channel you can control an awful lot if tracks, trains, points and signals. A demonstration GUI controlling three trains, four points and two signals is available. Again complete with source code."

Nothing about reading DCC signals as sought by the OP.

User avatar
buja
Posts: 498
Joined: Wed Dec 31, 2014 8:21 am
Location: Netherlands

Re: Model Trains - DCC

Mon Jan 04, 2016 12:42 pm

I am not into model trains and DCC, I just happen to know the Gertbot has DCC support. Maybe it's not complete, but I am sure the topic starter can read the website and the manuals for himself and decide if this is interesting for him.

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Model Trains - DCC

Mon Jan 04, 2016 2:50 pm

Reading the Wikipedia entry on DCC tells me that it's a pulse system which reverses the polarity of the DC signal.
You will only need to read one polarity to be able to detect these signals so you could probably manage this with just one diode and a pair of resistors (to form a voltage divider).

I would be inclined to add an optoisolator, to ensure the Pi's safety but it should be fairly simple to do.
Doug.
Building Management Systems Engineer.

RDS
Posts: 718
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Re: Model Trains - DCC

Tue Jan 05, 2016 9:55 am

Thank you to all of you for the links etc that you have provided. This opens up a whole new range of possibilities.

User avatar
ld50
Posts: 2
Joined: Mon Dec 31, 2018 1:33 pm
Location: London, England

Re: Model Trains - DCC

Mon Dec 31, 2018 1:55 pm

Sorry, almost 3 years late into this thread (but maybe this can help someone) - I was researching much the same

I found this on GitHub https://github.com/bicknell/rpi-dcc-decoder - seems to be November 2018 so way after this thread but looks most interesting.

As @BMS Doug suggests, it has a circuit for an opto-isolator.

I'm going to give this a go tomorrow (hangover permitting) and see what I can come up with (sudden thought, do I have any opto-isolators!)

Ultimate aim is a static decoder for turnouts etc, based on a Pi-Zero and a couple of stepper motors.

Salut,

Lance

darkbibble
Posts: 602
Joined: Mon Mar 09, 2015 5:20 pm
Location: corby, england

Re: Model Trains - DCC

Thu Jan 03, 2019 12:17 pm

the best pi interface to DCC train sets is the sprog3 controller/programmer
Q; How many Windows users does it take to fix a Linux problem??
A; Whats a Linux problem

User avatar
thagrol
Posts: 1840
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Model Trains - DCC

Thu Jan 03, 2019 1:05 pm

darkbibble wrote:
Thu Jan 03, 2019 12:17 pm
the best pi interface to DCC train sets is the sprog3 controller/programmer
Isn't that a controller not a decoder? And, frankly, the gertbot (https://www.gertbot.com/) has a better hardware spec: four independent 2.5amp channels expandable to sixteen with additional boards. More if you have multiple serial ports available.

You might have trouble find one these days though and the software probably isn't up to the same standard as the SPROG range. But hey, you can roll your own.
This space unintentionally left blank.

User avatar
ld50
Posts: 2
Joined: Mon Dec 31, 2018 1:33 pm
Location: London, England

Re: Model Trains - DCC

Thu Jan 03, 2019 2:52 pm

Yeah, I thought OP was asking for something that reads the DCC signals.
Is it possible to use a Pi to read the digital signal that passes along the power line on a DCC (Digital Command Control) Model Train layout.
Sadly no opto-couplers in my stash (well, really my late father's stash - and he was a lot better than me on electronics), so expecting in a couple of days - breadboard at the ready.

Brummbar
Posts: 1
Joined: Mon Aug 26, 2019 9:12 am

Re: Model Trains - DCC

Mon Aug 26, 2019 9:23 am

I would like to use a Raspberry Pi as a DCC Packet Sniffer (Packet Analyzer). I am new to Raspberry Pi's and would very much appreciate any and all help offered.

I have built an Arduino DCC signal shield before; so, I am familiar with the DCC-to-5v, 6N137 Opto-Coupler circuit; although, not interfacing it to a Raspberry Pi.

This would be a very useful tool for me and others I believe.

Thanks,

Brummbar

User avatar
thagrol
Posts: 1840
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Model Trains - DCC

Mon Aug 26, 2019 11:14 am

Brummbar wrote:
Mon Aug 26, 2019 9:23 am
I would like to use a Raspberry Pi as a DCC Packet Sniffer (Packet Analyzer). I am new to Raspberry Pi's and would very much appreciate any and all help offered.

I have built an Arduino DCC signal shield before; so, I am familiar with the DCC-to-5v, 6N137 Opto-Coupler circuit; although, not interfacing it to a Raspberry Pi.

This would be a very useful tool for me and others I believe.

Thanks,

Brummbar
The gpio on all Pi are 3.3v not 5v and will be damaged if fed 5v so you may need a different optocoupler.

The next problem is that unlike an arduino, a pi is not a hard realtime system. There's a lot of background processes running that may cause problems with the timing and interrupt handling needed for decoding.

I've considerd doing something similar but haven't got beyond that stage. What I was going to do was use a cheap chinese clone of an arduino nano to handle the actul decoding and pass the decoded packets to the pi via a serial connection.
This space unintentionally left blank.

drgeoff
Posts: 9805
Joined: Wed Jan 25, 2012 6:39 pm

Re: Model Trains - DCC

Mon Aug 26, 2019 2:27 pm

If the RPi will be used only for sniffing then only an optocoupler output will be connected to a GPIO. That side of the existing optocoupler should work fine if used with 3.3 volts from the RPi GPIO header. (Either opto pin 4 to 3.3 volts and pin 3 to GPIO and resistor to RPi ground or Pin 3 to RPi ground and pin 4 to GPIO and resistor to RPi 3.3 volts.)

Fraoch
Posts: 136
Joined: Thu Mar 07, 2013 11:53 pm
Location: Cambridge, Ontario, Canada

Re: Model Trains - DCC

Mon Aug 26, 2019 3:38 pm

Somewhat on topic - I see you can run JMRI on Pis since at least the 2:

http://jmri.org/install/Raspbian.shtml

What people on this thread are looking for, of course, is to use the RPi as a decoder/packet sniffer. JMRI relies on a DCC command station to do all the talking and uses the RPi as a general-purpose computer.

There may be a way to connect to a command station using the GPIO pins, but the information seems very generic:

http://jmri.org/help/en/html/hardware/pi/index.shtml

It would be very interesting to use a Zero or Zero W as a decoder or a command station!

I got out of trains a few years ago but I would have loved the convergence.
Pencoed-made Model 1B, Samsung memory
2B 1.1
3B+
4B 2GB

User avatar
thagrol
Posts: 1840
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Model Trains - DCC

Mon Aug 26, 2019 6:58 pm

Fraoch wrote:
Mon Aug 26, 2019 3:38 pm
It would be very interesting to use a Zero or Zero W as a decoder or a command station!
There's a couple of ways I can think of to use a Pi as a command station:
  • I believe the makers of the SPROG II do a version in HAT format: https://www.sprog-dcc.co.uk/pisprog.shtml I've not used one, just include it for information.
  • If you can get hold of a gertbot board (https://www.gertbot.com/) can do DCC command. Up to 16 seperate channels of it if you cascade four boards. Those boards also do analogue motor and stepper motor control. I've used these boards successfully with both DC and DCC model railways.
  • MERG (https://www.merg.org.uk/) may do something but most of their kits and info is members only so I don't know.
OK that's three ways :)

In essence "all" you need to do is generate the bit stream then send it through an H bridge to the track (not forgetting that the track needs an AC signal). In practise there's much more to it than that.

I still have concerns about the non-realtime nature of linux causing problems. Dropped bits may confuse decoders but they should recover if the packet is resent. Entirely dropped packeets could result in no power to your tracks and all your decoders being reset to their power on state. Gert got around this on the gertbot by offloading all the realtime stuff to a microcontroller on the board. I've no idea what the sprog does.

SPROG apparently supports DecoderPro/JMRI. I've no idea whether the gertbot does I only used Gert's demo software with it.
This space unintentionally left blank.

Return to “Beginners”