1 00:00:00,000 --> 00:00:00,780 Hi, everybody. 2 00:00:00,780 --> 00:00:02,700 If you're standing up, get out. 3 00:00:02,960 --> 00: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. 4 00:00:12,180 --> 00:00:17,440 Please sit down and enjoy the wonderful world of hacking model trains. 5 00:00:23,670 --> 00:00:24,830 All right, thanks. 6 00:00:24,830 --> 00:00:26,170 I'm Eric Reuter. 7 00:00:27,210 --> 00: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. 8 00:00:45,010 --> 00:00:46,050 Gee. 9 00:00:48,370 --> 00: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. 10 00:00:56,630 --> 00: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. 11 00:01:14,390 --> 00: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. 12 00:01:31,070 --> 00:01:33,210 DCC works like this. 13 00:01:33,230 --> 00: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. 14 00:01:48,050 --> 00:01:56,890 So to encode a one, you have 55 microseconds one way, and then the other way to get a full cycle. 15 00:01:57,030 --> 00: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. 16 00:02:12,730 --> 00: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. 17 00:02:29,510 --> 00:02:32,310 A DCC packet looks like this. 18 00:02:32,430 --> 00:02:33,650 There are three bytes. 19 00:02:33,650 --> 00: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. 20 00:02:45,350 --> 00:02:48,470 The packets, there are several different types of packets. 21 00:02:48,810 --> 00:02:54,590 The first two here are used for actual moving equipment, engines and things of that nature. 22 00:02:55,250 --> 00:02:58,330 One is speed and direction, which is self-explanatory. 23 00:02:58,530 --> 00:03:03,570 A function packet is used to control lights and sound effects and that sort of thing. 24 00:03:03,750 --> 00:03:10,250 And then there's this other class of packet called an accessory packet that's generally used to control trackside equipment. 25 00:03:10,250 --> 00:03:15,430 One of the principal uses of this is to control the position of a switch or a turnout. 26 00:03:15,730 --> 00: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. 27 00:03:24,730 --> 00:03:28,550 So a typical wired setup, traditional setup, looks like this. 28 00:03:28,550 --> 00: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. 29 00:03:41,710 --> 00: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. 30 00:03:54,470 --> 00: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. 31 00:04:06,470 --> 00: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. 32 00:04:22,270 --> 00:04:29,370 The scale that I model is G-scale, which is about three times in scale the size of HO. 33 00:04:30,670 --> 00: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. 34 00:04:42,330 --> 00: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. 35 00:04:53,010 --> 00:04:56,730 But when you lose the track power, you also lose the data. 36 00:04:56,750 --> 00:05:07,430 So generally, these systems are controlled by wireless connections that are directly from a handheld controller to the locomotive. 37 00:05:09,150 --> 00: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. 38 00:05:21,950 --> 00:05:25,070 And you can see that it really didn't flinch. 39 00:05:25,810 --> 00: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. 40 00:05:34,360 --> 00:05:35,660 Alright, so... 41 00:05:35,660 --> 00:05:46,520 There are several competing wireless systems and this has never really been standardized the way that DCC was. 42 00:05:46,880 --> 00:05:50,060 There have been attempts at it, but it didn't go very far. 43 00:05:50,060 --> 00:05:53,540 The one I use is called Airwire, that's made by CVP. 44 00:05:54,280 --> 00:05:57,680 And this is the handheld controller here. 45 00:05:58,020 --> 00:05:59,920 It's pretty straightforward. 46 00:05:59,920 --> 00:06:04,720 There's a rotary encoder in the center, and then you press that to change direction. 47 00:06:04,840 --> 00: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. 48 00:06:13,440 --> 00:06:18,440 And then the yellow button on the left, right by my thumb, is the accessory button. 49 00:06:18,440 --> 00: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. 50 00:06:25,360 --> 00:06:29,680 And this connects to a decoder that's in an engine. 51 00:06:30,120 --> 00:06:37,840 And this particular system operates in the 900 MHz ISM band, which is what attracted me to it as a ham. 52 00:06:37,840 --> 00:06:45,440 I have privileges in that band and I thought it might allow for some interesting reverse engineering, hacking kind of stuff. 53 00:06:45,440 --> 00:06:47,760 Make my own components and that sort of thing. 54 00:06:48,180 --> 00:06:55,080 So I wanted to figure out how the signal is actually encoded and sent to the engines. 55 00:06:55,320 --> 00:07:06,120 So the first step was a non-destructive look at it in GQRX or some software to display SDR. 56 00:07:06,120 --> 00:07:09,720 It's pretty clear this is a 2FSK signal. 57 00:07:10,180 --> 00:07:12,940 But what surprised me was that it's continuous. 58 00:07:14,600 --> 00: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. 59 00:07:25,120 --> 00:07:27,860 But this is actually a continuous signal. 60 00:07:27,960 --> 00:07:31,800 So I dumped some IQ samples and opened it up in Spectrum. 61 00:07:31,860 --> 00:07:33,760 And this is what it looks like. 62 00:07:33,760 --> 00:07:41,560 And this packet might look familiar from 5 minutes ago when I explained the DCC packet. 63 00:07:41,560 --> 00: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. 64 00:07:54,860 --> 00:07:56,880 But that's what's going on here. 65 00:07:57,040 --> 00: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. 66 00:08:03,260 --> 00:08:06,740 And pretty straightforward, ignoring the grey wires there which I'll explain in a second. 67 00:08:07,680 --> 00:08:13,220 So it's a microcontroller and then this Anirin R9A wireless modem. 68 00:08:13,520 --> 00: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. 69 00:08:27,440 --> 00: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. 70 00:08:44,880 --> 00: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. 71 00:09:07,380 --> 00:09:14,920 In this case, the Solei Logic 8 device and then the associated Logic software. 72 00:09:15,020 --> 00: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. 73 00:09:46,780 --> 00:09:54,760 This allows you to configure modulation, frequency, whether you're transmitting or receiving transmit power and that kind of thing. 74 00:09:56,360 --> 00: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, 75 00:10:22,920 --> 00: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. 76 00:10:45,480 --> 00: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. 77 00:11:11,180 --> 00:11:19,560 So now that I know this, I can create my own transmitters, receivers, whatever I want to do. 78 00:11:19,560 --> 00: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. 79 00:11:33,440 --> 00: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. 80 00:11:56,040 --> 00: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. 81 00:12:08,360 --> 00:12:09,720 It's probably a clone. 82 00:12:10,000 --> 00:12:12,960 I changed the antenna for a more appropriate antenna. 83 00:12:13,340 --> 00: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. 84 00:12:30,740 --> 00:12:34,160 So the only missing piece is to do the modem configuration. 85 00:12:34,160 --> 00: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. 86 00:12:55,400 --> 00: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. 87 00:13:04,980 --> 00:13:06,820 So the library is set up like this. 88 00:13:06,820 --> 00:13:11,360 You just set up the four parameters, instantiate the modem. 89 00:13:11,520 --> 00:13:14,540 You could do many modems if you wanted with different enable pins. 90 00:13:14,540 --> 00:13:16,960 And then you can dynamically start it. 91 00:13:16,960 --> 00:13:21,800 There are other things you can do, change channel and that sort of thing. 92 00:13:24,750 --> 00:13:32,950 This is a little demo contraption that I put together just to show a sample accessory decoder. 93 00:13:33,630 --> 00:13:34,810 And it looks like this. 94 00:13:34,810 --> 00:13:37,530 I have it here, but you wouldn't be able to see it because it's quite small. 95 00:13:37,530 --> 00:13:38,910 So I just put it up on the screen. 96 00:13:39,410 --> 00:13:46,690 Essentially the components that I showed you and then I put four servos on it and eight open collector outputs. 97 00:13:46,790 --> 00:13:50,890 And these are controlled by accessory numbers one through eight. 98 00:13:50,890 --> 00:13:52,930 You could code them to be whatever you want. 99 00:13:54,570 --> 00: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. 100 00:14:02,530 --> 00: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. 101 00:14:13,330 --> 00:14:21,870 Here I'm just hitting accessory one and then the one and three buttons control the accessory number one. 102 00:14:22,130 --> 00:14:24,670 I'll go through a couple others here. 103 00:14:28,230 --> 00:14:33,750 Excluding the battery, this is probably $10 or $12 worth of parts. 104 00:14:35,250 --> 00:14:41,450 To do that with the manufacturer's equipment it would cost you $250 for four channels. 105 00:14:43,470 --> 00: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. 106 00:14:54,310 --> 00: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. 107 00:15:03,990 --> 00: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. 108 00:15:26,450 --> 00: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. 109 00:15:40,430 --> 00:15:46,910 And we did this at a club meeting with actually five different independent throttles. 110 00:15:47,130 --> 00: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. 111 00:16:04,910 --> 00: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. 112 00:16:12,390 --> 00:16:16,490 I'm going to see if I can get it to work. 113 00:16:19,820 --> 00:16:20,760 Doesn't seem to be 114 00:16:32,040 --> 00:16:35,440 working for some reason but there's a lot of RF going on in here. 115 00:16:40,140 --> 00:16:42,180 So that's all I have. 116 00:16:42,200 --> 00:16:43,960 Thanks for your attention. 117 00:16:45,780 --> 00:16:46,700 Thank you. 118 00:16:48,920 --> 00: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. 119 00:16:53,740 --> 00:16:54,880 No 120 00:16:58,070 --> 00:16:58,790 . 121 00:17:04,510 --> 00:17:05,750 It may be. 122 00:17:05,750 --> 00:17:13,350 I've never seen any FCC information or anything on any of the equipment. 123 00:17:13,870 --> 00:17:15,950 No, no. 124 00:17:15,970 --> 00:17:18,350 That's a good question. 125 00:17:20,390 --> 00:17:25,170 There are 16 frequencies but the carrier frequencies are fixed. 126 00:17:26,330 --> 00:17:28,470 You can change it on the throttle. 127 00:17:28,470 --> 00: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. 128 00:17:41,910 --> 00:17:47,490 Some of the other competing systems are mesh networks to overcome that issue. 129 00:17:49,390 --> 00:17:53,910 Alright, I think I'm out of time so I'm going to get off the stage but thanks very much.