Sorry to hijack an old thread, but you seem to be plenty knowledgeable on a simple question I'm having trouble understanding. Question 1, can it be used on a mega 2560? I'm assuming yes, but if not its not a big deal anyway. My main question is, is it possible to control the Arduino through buttons, potentiometers and a keypad, not the serial line? It appears that the computer is required for this to work, but I would like to be able to control the train using physical throttles and buttons. My main goal is to have a simple controller made using an Arduino that can operate like a normal dc controller. If possible, controlling multiple trains would be nice, even if I have to use multiple Arduinos.
I never tried, but I think it should be possible.
If you want to connect your Buttons and potentiometers to the same arduino where DCC++ is unning to create the dcc signal, you have to deal with the internals of DCC++, and replace the serial receive interface with your software.
I think it's more easy to have dcc++ running at a separate UNO or NANO and use the Mega to manage your buttons and potentiometers and have it create the according serial commands. The Mega then controls DCC++ instead of a PC.
You can connect the serial output of the mega directly to the TX/RX lines of the DCC++ UNO, but have to disconnect the USB line because it uses the same interface. But once you have uploaded DCC++ to the UNO/NANO you should not need the USB line anymore.
Thanks for the quick answer. So, is the purpose of the pc when using dcc++ just to send serial commands to the arduino? Does it carry out any processing or just sends a simple command? I'm just trying to get an idea of how hard it'd be to use just the mega. I think, like you said, an uno and a mega would be easiest. It should be possible to control multiple trains this way since itll retain the functionality of normal dcc++ right?
I'm still getting to grips with the forum tools lol, I dont think it actually replied to your post, just posted in the thread.
I never used the PC-part of DCC++, I always sent the commands by myself. But I think, the pc cannot do something different.
Yes. If I remember correctly, DCC++ can manage up to 12 locomotives by default. DCC++ holds a register map for each loco with the actual data. So it can repeat the dcc packets for the locos accordingly.
You can have a look into the serialcommands.cpp file of the DCCpp_Uno directory. In this file all commands are documented in detail, and I think this is what has to be changed, if you do not want to use the serial commands, but will use your buttons and potentiometers directly instead.
I see, I'll have to mess around with this a bit, but I think it will work fine, although it may be way easier to just, as you said, use serial between two arduinos. It'd make it much simpler to understand and use. Here's my thinking so far as to what each arduino will do and have for code. The mega or whichever will be connected to the motor shield will simply run stock dcc++ code. Another board, uno/nano or whatever is cheap and easy will be linked via serial. It will run my own code to send serial commands to the mega using buttons for switches, potentiometers/rotary encoders for throttle, keypad for entering addresses, etc. And a lcd display for monitoring purposes. See any problems with this idea? Still way cheaper than most premade dcc setups, and much more customizable.
Found a clear answer as to the function of the pc. It is correct that it simply sends serial commands, which the Arduino processes and outputs a signal. So the Arduino can run on its own, without the computer, I just need to make the simple code to take input from buttons and potentiometers.
"In addition to using the DCC++ interface to automate, for example, simultaneous control of 3 trains in a complex pattern, you can create simpler automations directly within the Arduino DCC++ base station. This video shows one such routine in which the base station randomly picks 1 of 7 trains to leave its siding, complete an out-and-back across the layout, and then return to its siding, at which point another train is selected. All of this is fully controlled by the Arduino - the DCC++ interface is not used, nor is there even a computer connected to the layout."
Hi
I just thought I would write a post script to all this. I have created a traffic management system for controlling four trains simultaneously but felt , at the time trying to unravel a computer based control system for the bits I wanted was way above my skill level.
I have to say up front that my system is electronics heavy and uses a third party throttle control. I bought a MINIDCC controller board and built it into a cabinet as per instructions. Having established that it worked I disconnected the pots and connected the 4 controller inputs to four mega PWM outputs.(using an RC integrator and isolating chip to protect the mega.) I then connected the pots to 4 analog inputs on the mega. At this point I wrote a program to read the pots and output the results to the controller. I had achieved transparent control of the MINIDCC through the arduino mega. this ment that I could ignore the pot inputs to the mega and put in my own instructions to output some other speed or stop the train through the PWM outputs.
What a lot of work just to do what the MINIDCC does very well anyway!
However the purpose of this was to let the trains respond to track signaling, but first
the arduino mega had to know where each of the four trains was. This is where the electronic engineering came in. Originally I had magnetic relays set next to each other in the track with corresponding magnets glued to the bottom of the trains : the opening and closing being sent back to the mega to identify which train was passing over them. This became quite difficult due to parallel magnetic circuits. Another difficulty was around the tracks I glued in bits of vero board to short the wheels of the trains to the track. This worked and it was the primary reason for isolating the megas PWM outputs from the MINIDCC input. Remember you have a 30 volt peak to peak waveform on the rails. However the trains didn't like it ,even though displacement was only about a millimeter. I was looking through a components catalog and found the Vishay TCRT1000 optical sensor which fits neatly between the tracks. I shim down the train axel boxes to get them within 4mm of the sensor (remember everything that moves has to be clear of the rails and everything you put in the track has to be on level or below the rail surface.) Replacing the magnetic sensors and the track edge shorting strips with these I am able to tell where each train is and which train it is just by counting the number of white strips I glued to the axel boxes.
I thought I might eventually make a video but am no hand at that.
This is not a pageant it is traffic management whilst overriding speed or points setting using the additional LED/key pad assembly.
The MINIDCC controller meant that I didn't have to get involved with trying to write NMRA coding.
I forgot to mention the track light signals these in effect indicate block status. (stops trains running into the back of each other.)