Advice on programming a accessory decoder for a computer controlle train layout.

Hey everyone,

I need some advice on where to start my little project and would be greatly appreciative if you could help point me in the right direction. I realize that people have done work in this area before, but I have two issues with that.

The first is that I use a competing digital system, where as the most common information is for DCC, my system is Marklin's digital system (They do support DCC, yes, but a lot of my current decoders are Marklin's format and so I'm not keen on spending the cash to displace those for newer DCC models). The second issue is that a lot of the work has already been done, but isn't explained. I want to know how it works. And so that's the difficulty I'm facing. I'm not really sure where to look for information to learn more about how to interface with a digital system like this. I can find information on the digital protocols, but don't know where to go to learn about how to read that in to the Arduino and how to handle it. I think that's the key point for me.

I've done programming before, to some small extent. I built a train controller application for a touchpad (For a dcc system), but it used a library that I had found on the internet, so I didn't really gain knowledge in the way of interfacing with the system I was using. That work had been done for me, essentially.

I was thinking perhaps I could start by looking at some of the work people have done on the dcc side, like this, http://www.mynabay.com/arduino/2-uncategorised/14-arduino-dcc-monitor , but my issue with this is that he shows how to put it together, throws some code at you, but it's not really explained. The what/where/why. And this is what I find frustrating about some of this stuff. It's a lot of do this, but they don't explain why we're doing that. I did get the parts I'd need though, so at the least I can play with it and see if I can make sense of it. I've looked over the code some, but since it's a little advanced compared to what I know now, I don't really know how to hack it for my needs. I get parts of it, but not the important parts.

I did find one fella that did an accessory decoder for the Marklin system, but his code is written out in C and is flashed to the chip rather than using Arduino's IDE (Or rather, it's a similar microchip, but it isn't Arduino?) I'm not really sure how to translate that information. Maybe that'd be a better place to start? I don't know. GitHub - daspilker/uncoupler-decoder-firmware: Contains the source code of the firmware for an decoder for the Märklin Digital system.

I did consider another approach. Marklin's CS2 broadcast it's message over the network, over UDP. It uses CAN-Bus. I'd like to learn about this too, but I don't know if this is the right group to ask about that. The basic idea is that I could have a program listening in on a computer and then send commands to a Arduino via wireless, or something. There are other reasons I'd like to learn about this too (so I can adjust my existing program to work with Marklin's system). If anyone would have information about how to interface with a CAN-Bus over UDP using C#? I've heard one guy say it was easy, but he never gave any details.

This all might be over my head. I don't know. You guys know a lot more than I do, and so that's why I'm coming to you for advice. I have this basic knowledge, but this is getting into a few areas that are a little beyond what I've learned. I'm going at this alone too, so I don't really know where to look for information, or what the keywords are to find the information I am looking for. What I want to do seems basic in theory, but in practice it seems a little more advanced for a noob. To take in a digital signal, a packet, and interrupt it.

My end goal here is to build an accessory decoder based around the setup that was shown in the first link I posted, the dcc monitor, and to use that to switch things, whatever tickles my fancy. Lights, switches, track power, signals, whatever. My big issue is that it's DCC and I'd like it to play with Marklin's Motorola protocol.

Thanks in advance to anyone that can help. I've looked around a lot, but feel like I've exhausted what I can do/find.

Hopefully I posted this in the right section. I realized there's a programming section too that might be more along the lines of what I need help with. Sorry guys.

How about a model train protocol primer ?

My problem with using a CAN-Shield is the cost. Approaching this situation by using an Adruino has a lot to do with getting the cost of the system down, as with Marklin they seem to overcharge for their components.

I thought I could build a wireless system, using a base system that is connected to the CAN-Bus and then communicating wirelessly with a few smaller Arduinos placed around the layout. I don't know that this is the direction I want to go though. It's starting to complicate a system that I'd like to be simple.

I plan to do a similiar system with the S88 feedback, using multiple Arduinos. One would be a host and would be connected to a S88, and then the slaves would send their state to the host and the host would communicate that to the S88. That seems easy enough and I've found most the information I'd need to do that. - There is a guy around here that is doing something similiar. He's mimicking a S88 directly with an Arduino (Mine would be connected to a S88, rather than taking it's place completely). I think what he's doing is a little beyond me.

I don't want to do that with the accessory decoder though. I just want a simple system that works like any other accessory decoder. With the S88 it's different, because the goal there is to replace wires with something wireless. In this instance I essential have the infrastructure there, I just need to figure out how to make use of it.

CAN BUS Interface IC

http://www.mouser.com/ProductDetail/Texas-Instruments/SN65HVD1040DR/?qs=h%2FYsCRHtaqOO7rWtzP6eRQ%3D%3D&gclid=CMjTyIr51L0CFVBgfgodDxMArA

ATtiny85 uC

http://www.mouser.com/Search/Refine.aspx?Keyword=ATtiny85-20PU

If cost is a factor you can’t get any cheaper than using ATtiny85 uControllers (8-pin ic)/($1.32/ea qty:1, $1.20, qty:10)
An ATtiny85 has enough I/O to drive the CAN BUS Tranceiver Ic you need to communicate with CAN BUS. (you also need to learn
about termination resistors (120 ohm at each end of the bus, to prevent reflected wave)

Whether or not you can use ATtiny85s will depend largely on what else you need to do besides drive the CAN BUS ics.
It is possible to communicate using I2C with two of the pins and use the other two for the CAN BUS.

Arduino Pro-Mini’s have all the I/O an UNO does (almost) and cost $3

SN65HVD1040.pdf (906 KB)

Atmel-2586-AVR-8-bit-Microcontroller-ATtiny25-ATti-276549.pdf (448 KB)

Interesting. I worry that might get a little beyond me. I don't know though. Maybe I should pick up a CAN-Shield and play with it. Truth be told, I've only started to get some of the components I need to start playing with this stuff. I'm not so good at just reading up on things. I've got to do it first hand so I can see how things work, how changes make things break or work differently.

Part of my end goal was to build these off the Arduino Minis. I started with the Uno and recently ordered a nano. The main thing I'd be controlling is relays. I'm not against the idea of getting into the system via the CAN interface since it would allow me to do some other ideas I've been tinkering with. I gotta keep it in perspective though and start small.

I do need a primer of some sort. I understand, in theory, what they're talking about when they talk about the train protocols and how it works. It's just applying it, getting from point A to point B.

There is an ongoing long Thread about decoding DCC here.

Just out of curiosity I started to explore the process of how the DCC signal is decoded by an Arduino and, as I couldn't easily figure out the DCC-Monitor code (and they have zero documentation) I wrote a simple piece of code just to detect and display the DCC packets. You can get that code here. It's in Reply #33.

It may help to expose the process and may be adaptable to a different system.

Obviously once you have a packet you can do any amount of additional processing of the data.

...R

Hey Robin,

Thank you, I think the information you have provided will do a lot to help. I've glanced over the files you have shared, but I'm a bit too tired to put a lot of thought into it right now. You've done what I was looking for, which is to have a stripped down version of a dcc monitor, that gets to the core of what I'm trying to figure out.

You're welcome.

If you have questions I will try to help, but no guarantees.

...R

Thanks for the offer. I should be good. I don't want to bug you guys too much since it's really not your job to hold my hand. My father has done some programming before too though, and so I think between the two of us we can probably break it down.

Both of you guys have inspired me to take this idea a little further. Some of the grander ideas I had early on don't seem so daunting now. I think I'd like to try and make a self contained unit that has all the circuitry I need. Something I can hide in an enclosure and plug cables in. It all seems very doable now. Now, I just gotta find the guy that's working on the Arduino S88.

This thing is way cool. I got drunk one night and bought my uno on a whim. Best drunken decision I've made.

I don't understand the role of CAN bus or the S88? Could you provide more detail?

Also I'm not sure why there would be a need for multiple Arduinos?

...R

Automation?

There's a number of things one could do, I suppose. Some of this could be handled if I connected a regular computer into the system, but I really don't care to do that. I'm not a big fan of most the software packages out there, and neither do I want to tether it to a computer. If I'm listening in on the CAN-Bus I could execute some fun logic when triggers are hit. Even if I bypassed the S88 and fed the triggers directly into an Arduino, I'd still need it to send commands to the CAN-Bus to turn switches.

I could feasibly have a home made controller too that's setup for a dedicated purpose, like shunting. I can imagine a couple of reasons why this might be desirable. On the regular controller, when you change directions, it stops the train abruptly. If I built my own controller, I could have it slow to a stop and reverse/ramp up to the same speed. So it wouldn't be so abrupt. I could also have a button on the controller to control the telex couplers and another button to control the uncoupling track.

My layout is on the floor and extends a bit down. I hate cables on stuff like this, since they get in the way and look a bit unsightly. The use of multiple Arduino's is to help cut the clutter of wires. They'd serve different purposes too. I don't know if I could jam everything I needed into one Arduino. For the S88, I'm not overly keen on running cables all the way across my living space, so using the Arduino as a wireless bridge seems like a good idea.

Josheh-digi:
Automation?

There's a number of things one could do, I suppose. Some of this could be handled if I connected a regular computer into the system, but I really don't care to do that. I'm not a big fan of most the software packages out there, and neither do I want to tether it to a computer. If I'm listening in on the CAN-Bus I could execute some fun logic when triggers are hit. Even if I bypassed the S88 and fed the triggers directly into an Arduino, I'd still need it to send commands to the CAN-Bus to turn switches.

I could feasibly have a home made controller too that's setup for a dedicated purpose, like shunting. I can imagine a couple of reasons why this might be desirable. On the regular controller, when you change directions, it stops the train abruptly. If I built my own controller, I could have it slow to a stop and reverse/ramp up to the same speed. So it wouldn't be so abrupt. I could also have a button on the controller to control the telex couplers and another button to control the uncoupling track.

My layout is on the floor and extends a bit down. I hate cables on stuff like this, since they get in the way and look a bit unsightly. The use of multiple Arduino's is to help cut the clutter of wires. They'd serve different purposes too. I don't know if I could jam everything I needed into one Arduino. For the S88, I'm not overly keen on running cables all the way across my living space, so using the Arduino as a wireless bridge seems like a good idea.

Sorry, but I have to refer you back to my earlier question. You are assuming knowledge that I don't have.

I have a vague idea what Can Bus is - something to do with automobiles. I have no idea what S88 is.

...R

Oh, I'm sorry. I misunderstood the intention of your question.

Marklin uses a CAN-Bus to communicate between components. It has a network connect too where it'll broadcast over the network via UDP. From what I understand, CAN-Bus is mainly used in automobiles, but it has seen some use with model train systems too.

The S88 is a feedback device. So when a trigger gets tripped (Be it a switch, reed contact, or block detection, or whatever), it'll let the device it's connected to know.

The S88 is separate from the rest of the system. In the case of Marklin's CS2, it has it's own connection. I know that it'll (The CS2) broadcast over the CAN-Bus when feedback is detected via the S88, but I don't think you can connect into the CAN-Bus and mimic the S88 by sending occupied commands.

On Railuino, the S88 connection was separate from the CAN-Bus connection. There's also a few devices that allow a direct connection from an S88 into the computer, for use with train software.

I suggest that you get in touch with MERG (Model Railway Electronics Group) http://www.merg.org.uk/
They designed DCC, so know much about it. There's some stuff on their homepage and there's a forum, but I think you have to be a member to use it.

elektor has a book on the subject.
there are three busses in the system the can between controllers
the rails bus moving the locomotives and switches and the s88 for feedback
contact the local model railway i am sure they run marklin dcc

Henry_Best:
I suggest that you get in touch with MERG (Model Railway Electronics Group) http://www.merg.org.uk/
They designed DCC, .

Not true, though I'm sure they know a lot about it. For all practical purposes DCC is now in the public domain.

However the OPs problem is how to use a Marklin non-DCC system, if I understand correctly.

@Josheh-digi, you are still going a bit too fast for me. Let me try to explain how far I have got...

Marklin uses CAN-Bus to send data between some devices - what devices? Is it how the locomotives are controlled in place of DCC?

If not, what sort of information is sent over CAN-Bus? between what devices? and why do you want to interact with it?

I think I'm still completely in the dark about S88. You describe it as a feedback device. What does it feedback? Is it fitted in a locomotive? How is the feedback data transmitted?

Is there data transferred via CAN-Bus or S88 that is not available within the DCC system? if so what is it?

I'm not trying to be difficult but I need to understand the system before I can think about advice.

...R

I've actually found out most of the information I needed and am up and running in some small capacity since I first posted. I have a few prototypes running. Right now I'm just waiting for parts in the mall.

Are you familiar with digitrax and loconet? I guess Marklin's use of CAN-Bus would be similar to that. It's an internal protocol to talk between various components in much the same way. The signal that gets sent out to the track is similar to DCC.

The S88 is for stuff like block detection.

If it isn't too much trouble can you post your project details for others who wish to follow in your footsteps,
Have you seen these posts ?

http://forum.arduino.cc/index.php?action=search2

http://www.cti-electronics.com/hardware.htm
Equipment,
Parts
Schematic
Code

Josheh-digi:
Are you familiar with digitrax and loconet?

I’ve written a PC program to send Xpressnet signals to a Hornby Elite.

…R