start	end	text
0	2700	Hi, everybody. If you're standing up, get out.
2960	8120	Or sit down, because we have my favorite train guy who only talks about trains,
8120	11580	and that's all we invite him for, because we like trains, too.
12180	17440	Please sit down and enjoy the wonderful world of hacking model trains.
23670	29590	All right, thanks. I'm Eric Reuter. I'm a fan of radios and trains,
29590	34810	and last year I did a talk on wireless protocols for real trains,
36510	42290	and at the risk of getting pigeon-holed, I'm going to talk about model trains this year.
45010	46050	Gee.
48370	52150	So, model trains have been around as long as real trains,
52150	56630	and for the last hundred years or so, they've been mostly powered by electricity.
56630	64410	And for most of that history, trains are powered by track,
64410	69810	electricity being applied to the track, usually DC, picked up through wheels and applied to a motor,
69810	74070	so the train speed is proportional to the voltage.
74390	78490	But about 25 years ago, the industry shifted considerably
78490	83630	and went to a system called DCC, Digital Command Control,
83630	87450	that allows the power and control signals to be separate,
87450	90810	although applied still through a track circuit.
91070	97590	DCC works like this. It's a differential, essentially polarity-switching signal
97590	104930	that goes to the two rails, and the symbol is encoded using the period of a square wave
104930	108050	that's nominally a 50% duty cycle.
108050	114490	So to encode a one, you have 55 microseconds one way,
114490	116890	and then the other way to get a full cycle.
117030	120630	And then with a zero, you have to have at least 90 microseconds,
120630	125390	but you can stretch a zero out so that you get an average voltage that's higher or lower
125390	128510	that will allow you to actually operate a DC engine on that track,
128510	131930	but the harmonics tend to frighten motors.
132730	137770	To separate the two signals, you rectify the track power,
137770	142630	and get DC to power whatever you're trying to power, motors, microcontrollers, whatever,
142630	147970	and then you run the signal through an optocoupler of some sort to get the data stream.
149510	152310	A DCC packet looks like this.
152430	155750	There are three bytes. There's a preamble for synchronization,
155750	159770	three bytes, two of which are information, and the third is a checksum,
159770	163270	separated by zero start bits.
165350	168470	The packets, there are several different types of packets.
168810	174590	The first two here are used for actual moving equipment, engines and things of that nature.
175250	178330	One is speed and direction, which is self-explanatory.
178530	183570	A function packet is used to control lights and sound effects and that sort of thing.
183750	186690	And then there's this other class of packet called an accessory packet
186690	190250	that's generally used to control trackside equipment.
190250	195430	One of the principal uses of this is to control the position of a switch or a turnout.
195730	199450	So you can do that from a handheld controller, throttle controller,
199450	204490	and then all of this equipment is configured through DCC also, so there are packets for that.
204730	208550	So a typical wired setup, traditional setup, looks like this.
208550	214570	You have at least one handheld throttle, which looks something like this,
214570	218570	and it's either wired or wireless,
218570	221650	but it connects to some kind of proprietary throttle bus.
221710	225810	That goes into a command station, which aggregates all the commands from the throttles
225810	228950	and creates a DCC bitstream, which is essentially a circular buffer
228950	233650	that just rotates through the commands for all the different engines and accessories.
234470	237370	That goes to a booster, which is basically an H-bridge
237370	241550	that does the polarity switching for the track, and then you can also take that bus
241550	245510	and run it to an accessory decoder to get both power and data.
246470	250850	So for smaller scales, like HO, which is a very common scale,
250850	254810	N-scale, this is the most practical way to operate a model railroad
254810	257810	because you need to supply the power
259150	261790	through some external means.
262270	266210	The scale that I model is G-scale, which is about three times
266210	269370	in scale the size of HO.
270670	275370	In G-scale, it's practical to actually put lithium-ion batteries
275370	279210	inside of an engine, because an engine is this big, and run
279210	283450	the trains without any track power. And this is desirable because
283450	287030	many of us, myself included, operate these trains outdoors where
287030	292210	keeping track clean for conductivity is a challenge.
293010	295590	But when you lose the track power, you also lose
295590	299010	the data. So generally, these
299010	303530	systems are controlled by wireless connections that are directly from
303750	307430	a handheld controller to the locomotive.
309150	311470	And to give you a sense of the scale,
311470	314290	I debated which movie to use, but this is
315790	318810	a test of a G-scale locomotive pulling
319810	323070	a case of beer. And you can see that
323070	327590	it really didn't flinch. But you can see the size of a beer
327590	331190	can, and some of them are seltzers, but it's the weight that matters.
334360	335660	Alright, so...
335660	341820	There are several competing wireless systems
341820	345520	and this has never really been standardized the way that DCC
345520	350060	was. There have been attempts at it, but it didn't go very far.
350060	353540	The one I use is called Airwire, that's made by CVP.
354280	357680	And this is the handheld controller here.
358020	360640	It's pretty straightforward. There's a rotary
361400	364720	encoder in the center, and then you press that to change direction.
364840	368520	So what you see on the screen is the number of the engine, 3841,
368520	372780	the speed, and then the arrow indicates direction.
373440	376920	And then the yellow button on the left, right by my thumb,
376920	380240	is the accessory button. So you can hit accessory and then a number
380240	384580	and throw a switch, or turn the signal on and off, or whatever you want to do.
385360	388700	And this connects to a decoder that's in
388700	392620	an engine. And this particular system
392620	396780	operates in the 900 MHz ISM band, which is what attracted me
396780	400660	to it as a ham. I have privileges in that band and I thought it
400660	405440	might allow for some interesting reverse engineering, hacking kind of stuff.
405440	407760	Make my own components and that sort of thing.
408180	412660	So I wanted to figure out how the signal is actually encoded
412660	416780	and sent to the engines. So the first step was
416980	420900	a non-destructive look
420900	424520	at it in GQRX or some software to
424520	428120	display SDR. It's pretty clear this is a 2FSK
428760	432940	signal. But what surprised me was that it's continuous.
434600	436780	What I expected was that if I made some
436780	440240	change, some control change, that it would send that change
440660	445120	and then it would sort of be quiet until the next thing happened.
445120	449120	But this is actually a continuous signal. So I dumped some
449120	453160	IQ samples and opened it up in Spectrum. And this is what it looks
453160	457100	like. And this packet might look familiar
457100	461560	from 5 minutes ago when I explained the DCC packet.
461560	465340	So this handheld throttle is actually encoding a DCC
465340	469080	bitstream and modulating it as an
469080	473480	FSK signal, which seems like a kind of brute force
473480	477520	way to do this. But that's what's going on here. So I want to
477520	481040	figure out how that's being encoded, what's going on, so
481040	485480	the next step is to open it up. And pretty straightforward, ignoring the grey wires there
485480	489300	which I'll explain in a second. So it's a microcontroller and then this
489300	493220	Anirin R9A wireless modem.
493520	497760	And the R9A is based on the TICC1101
498400	501000	which is a very common modem chip
501940	504680	packaged with an antenna and some filtering and
504680	508640	PNs matching and that sort of thing. And looking at the
508640	513100	pinout, it's essentially a lot of do not connect
513100	517020	or no connection and then power and ground and then
517020	520960	an SPI interface and then some GPIO that you can
520960	523360	configure through the SPI interface.
524880	528820	So to do analysis, I soldered some wires onto the
528820	532120	four SPI lines and also
532750	536760	eventually one of the GPIO lines and then ran them out the battery
536760	540660	connector and terminated them with DuPont connectors
540660	544820	so I could do some analysis just using a
545760	549300	logic analyzer. In this case, the Solei
549300	552960	Logic 8 device and then
552960	556720	the associated Logic software. This is the startup sequence when you
556720	560860	first power up the device, the throttle, and zooming in on this
560860	564320	you can see each of these spikes is a byte
564320	568360	and the software decodes all of that and essentially
568360	572800	there's nothing going from the modem to the microcontroller
572800	576500	it's all the microcontroller telling the modem what to do
576500	580720	you can export this to a CSV and then look at the contents
580720	583720	and this is essentially registers and their
584460	587820	contents to configure the modems. This allows you to configure
588640	592060	modulation, frequency, whether you're transmitting or receiving
592640	594760	transmit power and that kind of thing.
596360	599760	You can go through the datasheet and figure out what all these registers are
599760	602960	and the one that I found interesting was
604520	607280	this register 08, hex 08
607280	612000	which if you set this bit, it puts the modem into asynchronous mode
612000	616140	so the great thing with 11.01, the reason it's used
616140	619240	in so many different devices is it does all this cool packetization
620940	624020	and error correction and stuff, but if you put it in asynchronous
624020	627920	mode, it essentially bypasses all of that and one of the GPIO
627920	631360	lines directly modulates the FSK output
632000	634920	so the connection is just the microcontroller
636560	639900	SPI to the modem, which configures the modem
639900	644160	and then just a bit stream that directly modulates the FSK
644160	647680	output. The same setup is present
647680	650600	in the receiver, this is what would go inside of a locomotive
651680	656100	and there's also an ANN module there, this one has an antenna but it's the same
657340	659840	line and so it's really just a mirror
659840	663980	image of the transmitter, they're both in asynchronous mode so it creates
664140	667980	a virtual wire carrying a logic level DCC signal between
667980	671800	the two. So now that
671800	675880	I know this, I can create my own
677160	680160	transmitters, receivers, whatever I want to do. I'm pretty
680160	683880	happy with the off-the-shelf throttle and as far as a motion
683880	687160	decoder that you put in an engine, they're
687920	691900	pretty robust and you don't want your engines running away, they're very
691900	696120	expensive and heavy. But what I was really interested in primarily was
696120	700080	the accessory decoder because the accessory decoders from the manufacturer are very
700080	704100	expensive and with six or eight dollars
704100	708380	worth of hardware, you can put together
708380	711940	an accessory decoder that will control as many accessories
711940	715600	as you want or as you have GPIO lines for.
716040	720260	So as an example, I put together a very simple one just using a
721260	724360	very old Arduino Nano or Micro
724360	728360	and a 1101 module that you can get on eBay.
728360	732960	It's probably a clone. I changed the antenna for a more appropriate antenna.
733340	736020	And putting these together,
736700	739420	you can create either a transmitter or a receiver
740100	744300	and there are plenty of DCC libraries available for the Arduino
744920	747720	ecosystem because people have been building their own wired
748340	752380	DCC components for years. So the only missing piece is to
752380	756480	do the modem configuration. So I wrote a library that takes these
756480	760680	four inputs and allows you to dynamically configure the modem
760680	764500	to do either transmit or receive, transmit power
764500	768680	if appropriate, the RF channel, the manufacturer
768680	772640	of the throttle has defined 16 channels, and then
773900	776380	the slave select pin. So you can put as many modems
776380	780420	as you want also on this SPI connection and operate them
780420	784180	simultaneously provided you talk to them individually.
784980	787800	So the library is set up like this. You just set up the four
788740	792520	parameters, instantiate the modem. You could do many modems
792520	795700	if you wanted with different enable pins. And then you can dynamically
796240	799460	start it. There are other things you can do, change channel
800300	805990	and that sort of thing. This is a little
808010	809810	demo contraption that I put together
809810	812950	just to show a sample accessory decoder.
813630	817530	And it looks like this. I have it here, but you wouldn't be able to see it because it's quite small.
817530	821730	So I just put it up on the screen. Essentially the components that I showed you
821730	825710	and then I put four servos on it and eight open collector
825710	830010	outputs. And these are controlled by accessory numbers
830010	832930	one through eight. You could code them to be whatever you want.
834570	837790	And I was going to try to demo this live, but I just made a video
837790	842290	instead because it will be easier to see from where you're sitting.
842530	845250	Essentially I'm going to power this up and then
845790	849890	it will read from the EEPROM the last position of the
849890	853830	servos or the last binary position of those outputs. Here I'm just
853830	857750	hitting accessory one and then the one and three
857750	861870	buttons control the accessory number one.
862130	864670	I'll go through a couple others here.
868230	870090	Excluding the battery, this is
870090	873750	probably $10 or $12 worth of parts.
875250	878190	To do that with the manufacturer's equipment
878190	881450	it would cost you $250 for four channels.
883470	886410	For people in this very specific corner
886410	890210	of this very specific hobby, it provides some options for
890210	894310	creating low cost accessory decoders.
894310	898150	And of course you can also transmit by reversing the
898150	902270	process and generating a DCC bit stream and there are libraries
902270	906130	to do that as well. This device which I have hooked up here
908350	910470	is a monitor and
910470	914550	this is essentially using the library and it's cycling through
916110	918390	I asked somebody to take a picture so that may be why
919370	921590	it's just cycling through the 16 channels
922870	925430	with some defined dwell time.
926450	929750	I was going to do a real time demo of this but it doesn't seem to be working
929750	933710	but this is five different throttles set to different frequencies
933710	937150	showing the engine number
937850	941730	direction and speed. And we did this
941730	945550	at a club meeting with actually five different independent
945550	949690	throttles. And all it's doing is looping through this
949690	953350	very simple loop on the Arduino
954010	957810	and the DCC process has callback that sends
957810	962050	limited serial data to the host and then there's a
962050	965910	Python program running on the host to display it. But essentially it just
965910	969690	goes through, waits until the dwell time is over and then switches to the next channel
970630	975210	and moves on. I'm going to see if I can
975210	976490	get it to work.
979820	980760	Doesn't seem to be
992040	993400	working for some reason but
993820	995440	there's a lot of RF going on in here.
1000140	1002180	So that's all I have.
1002200	1003960	Thanks for your attention.
1005780	1009960	Thank you. I have these gadgets
1009960	1013740	here if you want to see them I'll be around so I'd be happy to show you.
1013740	1018790	No.
1024510	1026690	It may be. I've never seen any
1029230	1033350	FCC information or anything on any of the equipment.
1033870	1035950	No, no.
1035970	1038350	That's a good question.
1040390	1045170	There are 16 frequencies but the carrier frequencies are fixed.
1046330	1048470	You can change it on the throttle.
1048470	1052570	One of the drawbacks to this type of system is it's a one-to-one
1053490	1056770	well you can have one throttle and multiple locomotives
1056770	1060350	but you can't control one locomotive with multiple throttles because they would
1060350	1064270	just step on each other. Some of the other competing systems are
1064270	1067490	mesh networks to overcome that issue.
1069390	1071850	Alright, I think I'm out of time so I'm going to
1071850	1073910	get off the stage but thanks very much.
