WEBVTT

00:00.000 --> 00:00.780
Hi, everybody.

00:00.780 --> 00:02.700
If you're standing up, get out.

00:02.960 --> 00:11.580
Or sit down, because we have my favorite train guy who only talks about trains, and that's all we invite him for, because we like trains, too.

00:12.180 --> 00:17.440
Please sit down and enjoy the wonderful world of hacking model trains.

00:23.670 --> 00:24.830
All right, thanks.

00:24.830 --> 00:26.170
I'm Eric Reuter.

00:27.210 --> 00:42.290
I'm a fan of radios and trains, and last year I did a talk on wireless protocols for real trains, and at the risk of getting pigeon-holed, I'm going to talk about model trains this year.

00:45.010 --> 00:46.050
Gee.

00:48.370 --> 00:56.630
So, model trains have been around as long as real trains, and for the last hundred years or so, they've been mostly powered by electricity.

00:56.630 --> 01:14.070
And for most of that history, trains are powered by track, electricity being applied to the track, usually DC, picked up through wheels and applied to a motor, so the train speed is proportional to the voltage.

01:14.390 --> 01:30.810
But about 25 years ago, the industry shifted considerably and went to a system called DCC, Digital Command Control, that allows the power and control signals to be separate, although applied still through a track circuit.

01:31.070 --> 01:33.210
DCC works like this.

01:33.230 --> 01:48.050
It's a differential, essentially polarity-switching signal that goes to the two rails, and the symbol is encoded using the period of a square wave that's nominally a 50% duty cycle.

01:48.050 --> 01:56.890
So to encode a one, you have 55 microseconds one way, and then the other way to get a full cycle.

01:57.030 --> 02:11.930
And then with a zero, you have to have at least 90 microseconds, but you can stretch a zero out so that you get an average voltage that's higher or lower that will allow you to actually operate a DC engine on that track, but the harmonics tend to frighten motors.

02:12.730 --> 02:27.970
To separate the two signals, you rectify the track power, and get DC to power whatever you're trying to power, motors, microcontrollers, whatever, and then you run the signal through an optocoupler of some sort to get the data stream.

02:29.510 --> 02:32.310
A DCC packet looks like this.

02:32.430 --> 02:33.650
There are three bytes.

02:33.650 --> 02:43.270
There's a preamble for synchronization, three bytes, two of which are information, and the third is a checksum, separated by zero start bits.

02:45.350 --> 02:48.470
The packets, there are several different types of packets.

02:48.810 --> 02:54.590
The first two here are used for actual moving equipment, engines and things of that nature.

02:55.250 --> 02:58.330
One is speed and direction, which is self-explanatory.

02:58.530 --> 03:03.570
A function packet is used to control lights and sound effects and that sort of thing.

03:03.750 --> 03:10.250
And then there's this other class of packet called an accessory packet that's generally used to control trackside equipment.

03:10.250 --> 03:15.430
One of the principal uses of this is to control the position of a switch or a turnout.

03:15.730 --> 03:24.490
So you can do that from a handheld controller, throttle controller, and then all of this equipment is configured through DCC also, so there are packets for that.

03:24.730 --> 03:28.550
So a typical wired setup, traditional setup, looks like this.

03:28.550 --> 03:41.650
You have at least one handheld throttle, which looks something like this, and it's either wired or wireless, but it connects to some kind of proprietary throttle bus.

03:41.710 --> 03:53.650
That goes into a command station, which aggregates all the commands from the throttles and creates a DCC bitstream, which is essentially a circular buffer that just rotates through the commands for all the different engines and accessories.

03:54.470 --> 04:05.510
That goes to a booster, which is basically an H-bridge that does the polarity switching for the track, and then you can also take that bus and run it to an accessory decoder to get both power and data.

04:06.470 --> 04:21.790
So for smaller scales, like HO, which is a very common scale, N-scale, this is the most practical way to operate a model railroad because you need to supply the power through some external means.

04:22.270 --> 04:29.370
The scale that I model is G-scale, which is about three times in scale the size of HO.

04:30.670 --> 04:42.330
In G-scale, it's practical to actually put lithium-ion batteries inside of an engine, because an engine is this big, and run the trains without any track power.

04:42.330 --> 04:52.210
And this is desirable because many of us, myself included, operate these trains outdoors where keeping track clean for conductivity is a challenge.

04:53.010 --> 04:56.730
But when you lose the track power, you also lose the data.

04:56.750 --> 05:07.430
So generally, these systems are controlled by wireless connections that are directly from a handheld controller to the locomotive.

05:09.150 --> 05:20.930
And to give you a sense of the scale, I debated which movie to use, but this is a test of a G-scale locomotive pulling a case of beer.

05:21.950 --> 05:25.070
And you can see that it really didn't flinch.

05:25.810 --> 05:31.190
But you can see the size of a beer can, and some of them are seltzers, but it's the weight that matters.

05:34.360 --> 05:35.660
Alright, so...

05:35.660 --> 05:46.520
There are several competing wireless systems and this has never really been standardized the way that DCC was.

05:46.880 --> 05:50.060
There have been attempts at it, but it didn't go very far.

05:50.060 --> 05:53.540
The one I use is called Airwire, that's made by CVP.

05:54.280 --> 05:57.680
And this is the handheld controller here.

05:58.020 --> 05:59.920
It's pretty straightforward.

05:59.920 --> 06:04.720
There's a rotary encoder in the center, and then you press that to change direction.

06:04.840 --> 06:12.780
So what you see on the screen is the number of the engine, 3841, the speed, and then the arrow indicates direction.

06:13.440 --> 06:18.440
And then the yellow button on the left, right by my thumb, is the accessory button.

06:18.440 --> 06:24.580
So you can hit accessory and then a number and throw a switch, or turn the signal on and off, or whatever you want to do.

06:25.360 --> 06:29.680
And this connects to a decoder that's in an engine.

06:30.120 --> 06:37.840
And this particular system operates in the 900 MHz ISM band, which is what attracted me to it as a ham.

06:37.840 --> 06:45.440
I have privileges in that band and I thought it might allow for some interesting reverse engineering, hacking kind of stuff.

06:45.440 --> 06:47.760
Make my own components and that sort of thing.

06:48.180 --> 06:55.080
So I wanted to figure out how the signal is actually encoded and sent to the engines.

06:55.320 --> 07:06.120
So the first step was a non-destructive look at it in GQRX or some software to display SDR.

07:06.120 --> 07:09.720
It's pretty clear this is a 2FSK signal.

07:10.180 --> 07:12.940
But what surprised me was that it's continuous.

07:14.600 --> 07:25.120
What I expected was that if I made some change, some control change, that it would send that change and then it would sort of be quiet until the next thing happened.

07:25.120 --> 07:27.860
But this is actually a continuous signal.

07:27.960 --> 07:31.800
So I dumped some IQ samples and opened it up in Spectrum.

07:31.860 --> 07:33.760
And this is what it looks like.

07:33.760 --> 07:41.560
And this packet might look familiar from 5 minutes ago when I explained the DCC packet.

07:41.560 --> 07:54.860
So this handheld throttle is actually encoding a DCC bitstream and modulating it as an FSK signal, which seems like a kind of brute force way to do this.

07:54.860 --> 07:56.880
But that's what's going on here.

07:57.040 --> 08:03.160
So I want to figure out how that's being encoded, what's going on, so the next step is to open it up.

08:03.260 --> 08:06.740
And pretty straightforward, ignoring the grey wires there which I'll explain in a second.

08:07.680 --> 08:13.220
So it's a microcontroller and then this Anirin R9A wireless modem.

08:13.520 --> 08:26.620
And the R9A is based on the TICC1101 which is a very common modem chip packaged with an antenna and some filtering and PNs matching and that sort of thing.

08:27.440 --> 08:43.360
And looking at the pinout, it's essentially a lot of do not connect or no connection and then power and ground and then an SPI interface and then some GPIO that you can configure through the SPI interface.

08:44.880 --> 09:07.120
So to do analysis, I soldered some wires onto the four SPI lines and also eventually one of the GPIO lines and then ran them out the battery connector and terminated them with DuPont connectors so I could do some analysis just using a logic analyzer.

09:07.380 --> 09:14.920
In this case, the Solei Logic 8 device and then the associated Logic software.

09:15.020 --> 09:46.780
This is the startup sequence when you first power up the device, the throttle, and zooming in on this you can see each of these spikes is a byte and the software decodes all of that and essentially there's nothing going from the modem to the microcontroller it's all the microcontroller telling the modem what to do you can export this to a CSV and then look at the contents and this is essentially registers and their contents to configure the modems.

09:46.780 --> 09:54.760
This allows you to configure modulation, frequency, whether you're transmitting or receiving transmit power and that kind of thing.

09:56.360 --> 10:22.920
You can go through the datasheet and figure out what all these registers are and the one that I found interesting was this register 08, hex 08 which if you set this bit, it puts the modem into asynchronous mode so the great thing with 11.01, the reason it's used in so many different devices is it does all this cool packetization and error correction and stuff,

10:22.920 --> 10:45.180
but if you put it in asynchronous mode, it essentially bypasses all of that and one of the GPIO lines directly modulates the FSK output so the connection is just the microcontroller SPI to the modem, which configures the modem and then just a bit stream that directly modulates the FSK output.

10:45.480 --> 11:08.820
The same setup is present in the receiver, this is what would go inside of a locomotive and there's also an ANN module there, this one has an antenna but it's the same line and so it's really just a mirror image of the transmitter, they're both in asynchronous mode so it creates a virtual wire carrying a logic level DCC signal between the two.

11:11.180 --> 11:19.560
So now that I know this, I can create my own transmitters, receivers, whatever I want to do.

11:19.560 --> 11:33.140
I'm pretty happy with the off-the-shelf throttle and as far as a motion decoder that you put in an engine, they're pretty robust and you don't want your engines running away, they're very expensive and heavy.

11:33.440 --> 11:55.600
But what I was really interested in primarily was the accessory decoder because the accessory decoders from the manufacturer are very expensive and with six or eight dollars worth of hardware, you can put together an accessory decoder that will control as many accessories as you want or as you have GPIO lines for.

11:56.040 --> 12:08.360
So as an example, I put together a very simple one just using a very old Arduino Nano or Micro and a 1101 module that you can get on eBay.

12:08.360 --> 12:09.720
It's probably a clone.

12:10.000 --> 12:12.960
I changed the antenna for a more appropriate antenna.

12:13.340 --> 12:30.740
And putting these together, you can create either a transmitter or a receiver and there are plenty of DCC libraries available for the Arduino ecosystem because people have been building their own wired DCC components for years.

12:30.740 --> 12:34.160
So the only missing piece is to do the modem configuration.

12:34.160 --> 12:55.400
So I wrote a library that takes these four inputs and allows you to dynamically configure the modem to do either transmit or receive, transmit power if appropriate, the RF channel, the manufacturer of the throttle has defined 16 channels, and then the slave select pin.

12:55.400 --> 13:04.180
So you can put as many modems as you want also on this SPI connection and operate them simultaneously provided you talk to them individually.

13:04.980 --> 13:06.820
So the library is set up like this.

13:06.820 --> 13:11.360
You just set up the four parameters, instantiate the modem.

13:11.520 --> 13:14.540
You could do many modems if you wanted with different enable pins.

13:14.540 --> 13:16.960
And then you can dynamically start it.

13:16.960 --> 13:21.800
There are other things you can do, change channel and that sort of thing.

13:24.750 --> 13:32.950
This is a little demo contraption that I put together just to show a sample accessory decoder.

13:33.630 --> 13:34.810
And it looks like this.

13:34.810 --> 13:37.530
I have it here, but you wouldn't be able to see it because it's quite small.

13:37.530 --> 13:38.910
So I just put it up on the screen.

13:39.410 --> 13:46.690
Essentially the components that I showed you and then I put four servos on it and eight open collector outputs.

13:46.790 --> 13:50.890
And these are controlled by accessory numbers one through eight.

13:50.890 --> 13:52.930
You could code them to be whatever you want.

13:54.570 --> 14:02.290
And I was going to try to demo this live, but I just made a video instead because it will be easier to see from where you're sitting.

14:02.530 --> 14:13.330
Essentially I'm going to power this up and then it will read from the EEPROM the last position of the servos or the last binary position of those outputs.

14:13.330 --> 14:21.870
Here I'm just hitting accessory one and then the one and three buttons control the accessory number one.

14:22.130 --> 14:24.670
I'll go through a couple others here.

14:28.230 --> 14:33.750
Excluding the battery, this is probably $10 or $12 worth of parts.

14:35.250 --> 14:41.450
To do that with the manufacturer's equipment it would cost you $250 for four channels.

14:43.470 --> 14:54.310
For people in this very specific corner of this very specific hobby, it provides some options for creating low cost accessory decoders.

14:54.310 --> 15:03.770
And of course you can also transmit by reversing the process and generating a DCC bit stream and there are libraries to do that as well.

15:03.990 --> 15:25.430
This device which I have hooked up here is a monitor and this is essentially using the library and it's cycling through I asked somebody to take a picture so that may be why it's just cycling through the 16 channels with some defined dwell time.

15:26.450 --> 15:39.910
I was going to do a real time demo of this but it doesn't seem to be working but this is five different throttles set to different frequencies showing the engine number direction and speed.

15:40.430 --> 15:46.910
And we did this at a club meeting with actually five different independent throttles.

15:47.130 --> 16:04.910
And all it's doing is looping through this very simple loop on the Arduino and the DCC process has callback that sends limited serial data to the host and then there's a Python program running on the host to display it.

16:04.910 --> 16:11.870
But essentially it just goes through, waits until the dwell time is over and then switches to the next channel and moves on.

16:12.390 --> 16:16.490
I'm going to see if I can get it to work.

16:19.820 --> 16:20.760
Doesn't seem to be

16:32.040 --> 16:35.440
working for some reason but there's a lot of RF going on in here.

16:40.140 --> 16:42.180
So that's all I have.

16:42.200 --> 16:43.960
Thanks for your attention.

16:45.780 --> 16:46.700
Thank you.

16:48.920 --> 16:53.740
I have these gadgets here if you want to see them I'll be around so I'd be happy to show you.

16:53.740 --> 16:54.880
No

16:58.070 --> 16:58.790
.

17:04.510 --> 17:05.750
It may be.

17:05.750 --> 17:13.350
I've never seen any FCC information or anything on any of the equipment.

17:13.870 --> 17:15.950
No, no.

17:15.970 --> 17:18.350
That's a good question.

17:20.390 --> 17:25.170
There are 16 frequencies but the carrier frequencies are fixed.

17:26.330 --> 17:28.470
You can change it on the throttle.

17:28.470 --> 17:41.830
One of the drawbacks to this type of system is it's a one-to-one well you can have one throttle and multiple locomotives but you can't control one locomotive with multiple throttles because they would just step on each other.

17:41.910 --> 17:47.490
Some of the other competing systems are mesh networks to overcome that issue.

17:49.390 --> 17:53.910
Alright, I think I'm out of time so I'm going to get off the stage but thanks very much.

