Have you ever need see data on your digital model railroad? Or do you only want see the packets of DCC? Now, it is possible with low price or for free!
During the making DCC command station (DCC command station for model trains controled via Android (iOS) application), I wanted see the DCC packets and signals.
At first I was using the logic analyzer from SALEAE, but it was really annoying, parsing the all DCC packets. I decided make own analyzer for the DCC commands with AVR microcontroller Atmega328. I used board from Arduino Nano, but it was programmed in AVR Studio.
The program is very simple. It is only parsing the all DCC data from rails and writting this data into console. You can see parsed address, type of DCC command, speed of train, direction of train, etc…
Data in console looks like here:
+-----+-----------------------------------------------------------------------+-------------+------+ | # | DCC PACKET | PACKET TYPE | ADDR | +-----+-----------------------------------------------------------------------+-------------+------+ | 0 | 1111111111 11111111 0 00000000 0 11111111 1 | IDLE | 0 | |.....|.......................................................................|.............|......| | 1 | 1111111111 11111111 0 00000000 0 11111111 1 | IDLE | 0 | |.....|.......................................................................|.............|......| | 2 | 1111111111 00000011 0 00111111 0 10100111 0 10011011 1 | TRAIN | 3 | | | Direction: 1, Speed: 39 | | | |.....|.......................................................................|.............|......| | 3 | 1111111111 00000011 0 10000000 0 10000011 1 | TRAIN_FUNC | 3 | | | F0=0, F1=0, F2=0, F3=0, F4=0, | | | |.....|.......................................................................|.............|......| | 4 | ERROR: DCC signal corrupted. | | | |.....|.......................................................................|.............|......| | 5 | 11111111111 10000001 0 11111010 0 01111011 1 | ACCESSORY | 1 | | | Switch: 2, State: 1 | | | |.....|.......................................................................|.............|......|
The DCC data are writting into console on PC (fig. 1). But my friend is going to make program with graphical interface.
Fig. 1: DCC packets in console PUTTY.
Now, the program can parse these commands:
- IDLE – not active packet, it is for making voltage in rails
- RESET – reset all DCC devices
- TRAIN – control train
- TRAIN_FUNC – train functions (lights, sounds, etc.)
- ACCESSORY – control accessories (lights, turnouts, etc.)
- ACCESSOR_EX – extended accessory packet
- PROGRAM – programming
How can you make it?
It is very simple. You need only Arduino Nano and write the HEX file (download on the end of this article) into it. You will need ISP, ASP or similar programmer.
Then, you make device on schematic (Figure 2). Put the DCC signal to DCC-IN. Connector OUT is used for connection to Arduino (1 – VCC (3V3), 2 – Signal to PB3, 3 – GND)
Figure 2: Schematic, how to connect DCC signal to Arduino PB3 pin.
At the end, we can put all into nice box. (like on the gallery on the ond of article)
After you make the hardware , you can connect device via micro USB from Arduino to USB at computer. You will see new virtual serial port COM on your computer. You can check it on your Device manager (right click to Computer icon -> Properties -> on the left top corner Device manager). Now you should see window like on the picture 3. You will need a number of COM port. You can find out it, when you unplug and plug board into USB port.
Fig. 3: Device manager window.
The next step is launch terminal (some the console application). I am using PUTTY (http://www.putty.org/). After you launch the Putty, then you should set right COM port number and baud speed, which is 115 200. You can see the right settings of Putty on the picture 4. Then you click on Open. After that, you should see window like on the picture 2. It should resize the window for better display a table.
Fig. 4: Settings of Putty.
Use
You can change display of IDLE packets on the window by press button “i” on your keyboard.
Video
Gallery
Download
HEX file for the DCC sniffer
You can download the source code on GitHub: https://github.com/zavovi/DCCSniffer
Instead of a HEX file, can you provide an Aurduino sketch file? (.ino)? Did your friend ever finish a GUI version? Thank you!
Hi Fred,
I am sorry, I haven’t got the *.ino file, because I made it in AVR Studio, not in Arduino IDE. I used only Arduino board.
The GUI version isn’t done now. My friend haven’t got a time for it now.
Hello,
would you mind sharing the source code?
Hello,
I am sorry for the late reply. Why do you need the source code? I don’t want share source code for now. I would prepare it for sharing on github for example. But it takes long time…
I shared the source code on GitHub. Link is in the article.
Hi again, Can you explain your circuit? Is the resistor 22k? The Arduino can only handle 5V on a digital pin, but the track can have 12V or more. So it looks like you are applying 12V directly to a digital pin through a current limiting resistor which should destroy the pin. Also, since the DCC signal is a square wave, you decided not to have any filtering at the output of the bridge rectifier? It still would be noisy DC to power the Nano. I hope you do put the code on github to it can be there forever. Then you can never lose it 😉
Hello Fred,
I am sorry about my schematic. I updated the schematic for better in the article. And I put the code to GitHub too, I hope, that it will help to you.
Please, if you share the code or device, share my web address too. And you can make some changes in code and make pull request on GitHub too.
Thank you and good luck with my code 🙂
Did the old schematic work? Which one did you use for the pictures? I see only one resistor in the pictures.
We have experimented as well with an oscilloscope to look at the effect of different resistors and capacitors. In another design, we got rid of R2, made R3 much smaller, added filter capacitors. Your new circuit should work ok for getting the pulses, though we needed extra speed to detect the accuracy of the signal in addition to the 1’s and 0s.
There is only one real correction left, what is the bridge rectifier for? It’s not connected to anything and would need a regulator if you were going to use it to power the Nano and the 6N137. Since you have to be connected to a USB to read the serial output, you can probably just get rid of the diode bridge and the capacitor and show that Vcc should connect to the 5V pin on the Nano. Then everything is powered by the 5V from the USB cable.
Thans again for your efforts and sharing with everyone!
The old schematic was working, but not for all command stations. I discovered, that the new schematic is better for me and I changed my design in the box for the new schematic. But the old one used really only one resistor and it worked (I found this solution on some another website).
And about the bridge rectifier, you are right, it is not necessary in this case. I have this schematic used on my model railway layout and I am using the power from DCC in some cases. I have lot of this small boards and I used it for this sniffer too – it was simplier. I will edit the schematic again later.