[00:00.000 --> 00:02.700] Hi, everybody. If you're standing up, get out. [00:02.960 --> 00:08.120] Or sit down, because we have my favorite train guy who only talks about trains, [00:08.120 --> 00:11.580] 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:29.590] All right, thanks. I'm Eric Reuter. I'm a fan of radios and trains, [00:29.590 --> 00:34.810] and last year I did a talk on wireless protocols for real trains, [00:36.510 --> 00:42.290] 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:52.150] So, model trains have been around as long as real trains, [00:52.150 --> 00:56.630] and for the last hundred years or so, they've been mostly powered by electricity. [00:56.630 --> 01:04.410] And for most of that history, trains are powered by track, [01:04.410 --> 01:09.810] electricity being applied to the track, usually DC, picked up through wheels and applied to a motor, [01:09.810 --> 01:14.070] so the train speed is proportional to the voltage. [01:14.390 --> 01:18.490] But about 25 years ago, the industry shifted considerably [01:18.490 --> 01:23.630] and went to a system called DCC, Digital Command Control, [01:23.630 --> 01:27.450] that allows the power and control signals to be separate, [01:27.450 --> 01:30.810] although applied still through a track circuit. [01:31.070 --> 01:37.590] DCC works like this. It's a differential, essentially polarity-switching signal [01:37.590 --> 01:44.930] that goes to the two rails, and the symbol is encoded using the period of a square wave [01:44.930 --> 01:48.050] that's nominally a 50% duty cycle. [01:48.050 --> 01:54.490] So to encode a one, you have 55 microseconds one way, [01:54.490 --> 01:56.890] and then the other way to get a full cycle. [01:57.030 --> 02:00.630] And then with a zero, you have to have at least 90 microseconds, [02:00.630 --> 02:05.390] but you can stretch a zero out so that you get an average voltage that's higher or lower [02:05.390 --> 02:08.510] that will allow you to actually operate a DC engine on that track, [02:08.510 --> 02:11.930] but the harmonics tend to frighten motors. [02:12.730 --> 02:17.770] To separate the two signals, you rectify the track power, [02:17.770 --> 02:22.630] and get DC to power whatever you're trying to power, motors, microcontrollers, whatever, [02:22.630 --> 02:27.970] 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:35.750] There are three bytes. There's a preamble for synchronization, [02:35.750 --> 02:39.770] three bytes, two of which are information, and the third is a checksum, [02:39.770 --> 02:43.270] 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:06.690] And then there's this other class of packet called an accessory packet [03:06.690 --> 03:10.250] 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:19.450] So you can do that from a handheld controller, throttle controller, [03:19.450 --> 03:24.490] 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:34.570] You have at least one handheld throttle, which looks something like this, [03:34.570 --> 03:38.570] and it's either wired or wireless, [03:38.570 --> 03:41.650] but it connects to some kind of proprietary throttle bus. [03:41.710 --> 03:45.810] That goes into a command station, which aggregates all the commands from the throttles [03:45.810 --> 03:48.950] and creates a DCC bitstream, which is essentially a circular buffer [03:48.950 --> 03:53.650] that just rotates through the commands for all the different engines and accessories. [03:54.470 --> 03:57.370] That goes to a booster, which is basically an H-bridge [03:57.370 --> 04:01.550] that does the polarity switching for the track, and then you can also take that bus [04:01.550 --> 04:05.510] and run it to an accessory decoder to get both power and data. [04:06.470 --> 04:10.850] So for smaller scales, like HO, which is a very common scale, [04:10.850 --> 04:14.810] N-scale, this is the most practical way to operate a model railroad [04:14.810 --> 04:17.810] because you need to supply the power [04:19.150 --> 04:21.790] through some external means. [04:22.270 --> 04:26.210] The scale that I model is G-scale, which is about three times [04:26.210 --> 04:29.370] in scale the size of HO. [04:30.670 --> 04:35.370] In G-scale, it's practical to actually put lithium-ion batteries [04:35.370 --> 04:39.210] inside of an engine, because an engine is this big, and run [04:39.210 --> 04:43.450] the trains without any track power. And this is desirable because [04:43.450 --> 04:47.030] many of us, myself included, operate these trains outdoors where [04:47.030 --> 04:52.210] keeping track clean for conductivity is a challenge. [04:53.010 --> 04:55.590] But when you lose the track power, you also lose [04:55.590 --> 04:59.010] the data. So generally, these [04:59.010 --> 05:03.530] systems are controlled by wireless connections that are directly from [05:03.750 --> 05:07.430] a handheld controller to the locomotive. [05:09.150 --> 05:11.470] And to give you a sense of the scale, [05:11.470 --> 05:14.290] I debated which movie to use, but this is [05:15.790 --> 05:18.810] a test of a G-scale locomotive pulling [05:19.810 --> 05:23.070] a case of beer. And you can see that [05:23.070 --> 05:27.590] it really didn't flinch. But you can see the size of a beer [05:27.590 --> 05:31.190] 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:41.820] There are several competing wireless systems [05:41.820 --> 05:45.520] and this has never really been standardized the way that DCC [05:45.520 --> 05:50.060] was. 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 --> 06:00.640] It's pretty straightforward. There's a rotary [06:01.400 --> 06:04.720] encoder in the center, and then you press that to change direction. [06:04.840 --> 06:08.520] So what you see on the screen is the number of the engine, 3841, [06:08.520 --> 06:12.780] the speed, and then the arrow indicates direction. [06:13.440 --> 06:16.920] And then the yellow button on the left, right by my thumb, [06:16.920 --> 06:20.240] is the accessory button. So you can hit accessory and then a number [06:20.240 --> 06:24.580] and throw a switch, or turn the signal on and off, or whatever you want to do. [06:25.360 --> 06:28.700] And this connects to a decoder that's in [06:28.700 --> 06:32.620] an engine. And this particular system [06:32.620 --> 06:36.780] operates in the 900 MHz ISM band, which is what attracted me [06:36.780 --> 06:40.660] to it as a ham. I have privileges in that band and I thought it [06:40.660 --> 06:45.440] 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:52.660] So I wanted to figure out how the signal is actually encoded [06:52.660 --> 06:56.780] and sent to the engines. So the first step was [06:56.980 --> 07:00.900] a non-destructive look [07:00.900 --> 07:04.520] at it in GQRX or some software to [07:04.520 --> 07:08.120] display SDR. It's pretty clear this is a 2FSK [07:08.760 --> 07:12.940] signal. But what surprised me was that it's continuous. [07:14.600 --> 07:16.780] What I expected was that if I made some [07:16.780 --> 07:20.240] change, some control change, that it would send that change [07:20.660 --> 07:25.120] and then it would sort of be quiet until the next thing happened. [07:25.120 --> 07:29.120] But this is actually a continuous signal. So I dumped some [07:29.120 --> 07:33.160] IQ samples and opened it up in Spectrum. And this is what it looks [07:33.160 --> 07:37.100] like. And this packet might look familiar [07:37.100 --> 07:41.560] from 5 minutes ago when I explained the DCC packet. [07:41.560 --> 07:45.340] So this handheld throttle is actually encoding a DCC [07:45.340 --> 07:49.080] bitstream and modulating it as an [07:49.080 --> 07:53.480] FSK signal, which seems like a kind of brute force [07:53.480 --> 07:57.520] way to do this. But that's what's going on here. So I want to [07:57.520 --> 08:01.040] figure out how that's being encoded, what's going on, so [08:01.040 --> 08:05.480] the next step is to open it up. And pretty straightforward, ignoring the grey wires there [08:05.480 --> 08:09.300] which I'll explain in a second. So it's a microcontroller and then this [08:09.300 --> 08:13.220] Anirin R9A wireless modem. [08:13.520 --> 08:17.760] And the R9A is based on the TICC1101 [08:18.400 --> 08:21.000] which is a very common modem chip [08:21.940 --> 08:24.680] packaged with an antenna and some filtering and [08:24.680 --> 08:28.640] PNs matching and that sort of thing. And looking at the [08:28.640 --> 08:33.100] pinout, it's essentially a lot of do not connect [08:33.100 --> 08:37.020] or no connection and then power and ground and then [08:37.020 --> 08:40.960] an SPI interface and then some GPIO that you can [08:40.960 --> 08:43.360] configure through the SPI interface. [08:44.880 --> 08:48.820] So to do analysis, I soldered some wires onto the [08:48.820 --> 08:52.120] four SPI lines and also [08:52.750 --> 08:56.760] eventually one of the GPIO lines and then ran them out the battery [08:56.760 --> 09:00.660] connector and terminated them with DuPont connectors [09:00.660 --> 09:04.820] so I could do some analysis just using a [09:05.760 --> 09:09.300] logic analyzer. In this case, the Solei [09:09.300 --> 09:12.960] Logic 8 device and then [09:12.960 --> 09:16.720] the associated Logic software. This is the startup sequence when you [09:16.720 --> 09:20.860] first power up the device, the throttle, and zooming in on this [09:20.860 --> 09:24.320] you can see each of these spikes is a byte [09:24.320 --> 09:28.360] and the software decodes all of that and essentially [09:28.360 --> 09:32.800] there's nothing going from the modem to the microcontroller [09:32.800 --> 09:36.500] it's all the microcontroller telling the modem what to do [09:36.500 --> 09:40.720] you can export this to a CSV and then look at the contents [09:40.720 --> 09:43.720] and this is essentially registers and their [09:44.460 --> 09:47.820] contents to configure the modems. This allows you to configure [09:48.640 --> 09:52.060] modulation, frequency, whether you're transmitting or receiving [09:52.640 --> 09:54.760] transmit power and that kind of thing. [09:56.360 --> 09:59.760] You can go through the datasheet and figure out what all these registers are [09:59.760 --> 10:02.960] and the one that I found interesting was [10:04.520 --> 10:07.280] this register 08, hex 08 [10:07.280 --> 10:12.000] which if you set this bit, it puts the modem into asynchronous mode [10:12.000 --> 10:16.140] so the great thing with 11.01, the reason it's used [10:16.140 --> 10:19.240] in so many different devices is it does all this cool packetization [10:20.940 --> 10:24.020] and error correction and stuff, but if you put it in asynchronous [10:24.020 --> 10:27.920] mode, it essentially bypasses all of that and one of the GPIO [10:27.920 --> 10:31.360] lines directly modulates the FSK output [10:32.000 --> 10:34.920] so the connection is just the microcontroller [10:36.560 --> 10:39.900] SPI to the modem, which configures the modem [10:39.900 --> 10:44.160] and then just a bit stream that directly modulates the FSK [10:44.160 --> 10:47.680] output. The same setup is present [10:47.680 --> 10:50.600] in the receiver, this is what would go inside of a locomotive [10:51.680 --> 10:56.100] and there's also an ANN module there, this one has an antenna but it's the same [10:57.340 --> 10:59.840] line and so it's really just a mirror [10:59.840 --> 11:03.980] image of the transmitter, they're both in asynchronous mode so it creates [11:04.140 --> 11:07.980] a virtual wire carrying a logic level DCC signal between [11:07.980 --> 11:11.800] the two. So now that [11:11.800 --> 11:15.880] I know this, I can create my own [11:17.160 --> 11:20.160] transmitters, receivers, whatever I want to do. I'm pretty [11:20.160 --> 11:23.880] happy with the off-the-shelf throttle and as far as a motion [11:23.880 --> 11:27.160] decoder that you put in an engine, they're [11:27.920 --> 11:31.900] pretty robust and you don't want your engines running away, they're very [11:31.900 --> 11:36.120] expensive and heavy. But what I was really interested in primarily was [11:36.120 --> 11:40.080] the accessory decoder because the accessory decoders from the manufacturer are very [11:40.080 --> 11:44.100] expensive and with six or eight dollars [11:44.100 --> 11:48.380] worth of hardware, you can put together [11:48.380 --> 11:51.940] an accessory decoder that will control as many accessories [11:51.940 --> 11:55.600] as you want or as you have GPIO lines for. [11:56.040 --> 12:00.260] So as an example, I put together a very simple one just using a [12:01.260 --> 12:04.360] very old Arduino Nano or Micro [12:04.360 --> 12:08.360] and a 1101 module that you can get on eBay. [12:08.360 --> 12:12.960] It's probably a clone. I changed the antenna for a more appropriate antenna. [12:13.340 --> 12:16.020] And putting these together, [12:16.700 --> 12:19.420] you can create either a transmitter or a receiver [12:20.100 --> 12:24.300] and there are plenty of DCC libraries available for the Arduino [12:24.920 --> 12:27.720] ecosystem because people have been building their own wired [12:28.340 --> 12:32.380] DCC components for years. So the only missing piece is to [12:32.380 --> 12:36.480] do the modem configuration. So I wrote a library that takes these [12:36.480 --> 12:40.680] four inputs and allows you to dynamically configure the modem [12:40.680 --> 12:44.500] to do either transmit or receive, transmit power [12:44.500 --> 12:48.680] if appropriate, the RF channel, the manufacturer [12:48.680 --> 12:52.640] of the throttle has defined 16 channels, and then [12:53.900 --> 12:56.380] the slave select pin. So you can put as many modems [12:56.380 --> 13:00.420] as you want also on this SPI connection and operate them [13:00.420 --> 13:04.180] simultaneously provided you talk to them individually. [13:04.980 --> 13:07.800] So the library is set up like this. You just set up the four [13:08.740 --> 13:12.520] parameters, instantiate the modem. You could do many modems [13:12.520 --> 13:15.700] if you wanted with different enable pins. And then you can dynamically [13:16.240 --> 13:19.460] start it. There are other things you can do, change channel [13:20.300 --> 13:25.990] and that sort of thing. This is a little [13:28.010 --> 13:29.810] demo contraption that I put together [13:29.810 --> 13:32.950] just to show a sample accessory decoder. [13:33.630 --> 13:37.530] And it looks like this. I have it here, but you wouldn't be able to see it because it's quite small. [13:37.530 --> 13:41.730] So I just put it up on the screen. Essentially the components that I showed you [13:41.730 --> 13:45.710] and then I put four servos on it and eight open collector [13:45.710 --> 13:50.010] outputs. And these are controlled by accessory numbers [13:50.010 --> 13:52.930] one through eight. You could code them to be whatever you want. [13:54.570 --> 13:57.790] And I was going to try to demo this live, but I just made a video [13:57.790 --> 14:02.290] instead because it will be easier to see from where you're sitting. [14:02.530 --> 14:05.250] Essentially I'm going to power this up and then [14:05.790 --> 14:09.890] it will read from the EEPROM the last position of the [14:09.890 --> 14:13.830] servos or the last binary position of those outputs. Here I'm just [14:13.830 --> 14:17.750] hitting accessory one and then the one and three [14:17.750 --> 14:21.870] buttons control the accessory number one. [14:22.130 --> 14:24.670] I'll go through a couple others here. [14:28.230 --> 14:30.090] Excluding the battery, this is [14:30.090 --> 14:33.750] probably $10 or $12 worth of parts. [14:35.250 --> 14:38.190] To do that with the manufacturer's equipment [14:38.190 --> 14:41.450] it would cost you $250 for four channels. [14:43.470 --> 14:46.410] For people in this very specific corner [14:46.410 --> 14:50.210] of this very specific hobby, it provides some options for [14:50.210 --> 14:54.310] creating low cost accessory decoders. [14:54.310 --> 14:58.150] And of course you can also transmit by reversing the [14:58.150 --> 15:02.270] process and generating a DCC bit stream and there are libraries [15:02.270 --> 15:06.130] to do that as well. This device which I have hooked up here [15:08.350 --> 15:10.470] is a monitor and [15:10.470 --> 15:14.550] this is essentially using the library and it's cycling through [15:16.110 --> 15:18.390] I asked somebody to take a picture so that may be why [15:19.370 --> 15:21.590] it's just cycling through the 16 channels [15:22.870 --> 15:25.430] with some defined dwell time. [15:26.450 --> 15:29.750] I was going to do a real time demo of this but it doesn't seem to be working [15:29.750 --> 15:33.710] but this is five different throttles set to different frequencies [15:33.710 --> 15:37.150] showing the engine number [15:37.850 --> 15:41.730] direction and speed. And we did this [15:41.730 --> 15:45.550] at a club meeting with actually five different independent [15:45.550 --> 15:49.690] throttles. And all it's doing is looping through this [15:49.690 --> 15:53.350] very simple loop on the Arduino [15:54.010 --> 15:57.810] and the DCC process has callback that sends [15:57.810 --> 16:02.050] limited serial data to the host and then there's a [16:02.050 --> 16:05.910] Python program running on the host to display it. But essentially it just [16:05.910 --> 16:09.690] goes through, waits until the dwell time is over and then switches to the next channel [16:10.630 --> 16:15.210] and moves on. I'm going to see if I can [16:15.210 --> 16:16.490] get it to work. [16:19.820 --> 16:20.760] Doesn't seem to be [16:32.040 --> 16:33.400] working for some reason but [16:33.820 --> 16:35.440] 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:49.960] Thank you. I have these gadgets [16:49.960 --> 16:53.740] here if you want to see them I'll be around so I'd be happy to show you. [16:53.740 --> 16:58.790] No. [17:04.510 --> 17:06.690] It may be. I've never seen any [17:09.230 --> 17:13.350] 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:32.570] One of the drawbacks to this type of system is it's a one-to-one [17:33.490 --> 17:36.770] well you can have one throttle and multiple locomotives [17:36.770 --> 17:40.350] but you can't control one locomotive with multiple throttles because they would [17:40.350 --> 17:44.270] just step on each other. Some of the other competing systems are [17:44.270 --> 17:47.490] mesh networks to overcome that issue. [17:49.390 --> 17:51.850] Alright, I think I'm out of time so I'm going to [17:51.850 --> 17:53.910] get off the stage but thanks very much.