UART Serial and power on same line

Hi all,

I am working on building an automated model train layout and having trouble with a few things.

Here's what I'm trying to accomplish and how I'm imagining it to work:

The base station/controller (an Arduino Mega) sends power and data through the rails to the train. On board the train is an ATtiny85 programmed to listen for its specific address and any commands that follow it regarding speed, direction and lighting. There doesn't need to be any two-way communication because any info about the trains can be gathered from sensors in the tracks.

I have read that there are ways to encode data into a carrier wave and blah blah blah, but it doesn't make any sense to me and requires extra complexity on the receiving end. Since I am working in N scale (the tiny one), simplicity and small size are key.

In the model railroad industry, there is this system called DCC (Digital Command Control - Wikipedia) that encodes the signal into the polarity of the power going to the tracks. This allows the receiving end to require only a bridge rectifier, capacitor, resistor, and maybe a diode. However, I can't seem to find any info on how the transmission side is actually done, and that's where I'm running into issues.

My first thought is to use an H-bridge and plug the serial data pin into the direction control, but an H-bridge requires 2 inputs inverse to each other in order to flip direction. Are there any ways around this or any other ways of flipping polarity using only one input pin?

The amount of sites and information about DCC is overwhelming.
The output is indeed a H-bridge output. The serial data pin is on one driver output and the inverted serial data is on the other driver output.

Ok, that seems simple enough. But how would I get the inverted serial output? Could that be done with a NOT gate? Also, would an L298 chip be able to switch directions fast enough to run serial data at > 9600 baud?

Yes, with a NOT gate, or with a transistor and two resistors, or in the Arduino sketch, or perhaps the Arduino hardware inside the microcontroller, or perhaps some H-bridge drivers have an option for that.

I think the L298 should be fast enough. The fall and rise times are about 250ns.

There's also this little guy, supplies up to 1.8 amps and only takes 1 input for phase (I think, the datasheet is not terribly helpful on this one). Do you think this would do the trick or would it be better to stick with a NOT gate and an L293 or L298?

The datasheet is indeed not very clear. I think it can do the trick. Perhaps you should use a simple NOT gate, so any driver chip can be used.

The L293 and L298 are stone-age driver chips. We are now in the mosfet era.

Here are a number of modern mosfets driver modules : Pololu - Brushed DC Motor Drivers

Pololu has a breakout for that chip, and judging by the pinouts labelled on it, it does just require one input for direction. That will be helpful for inside the train too, now I can figure out a use for the extra pin on the ATtiny! Thanks for all the help!

AJ