Introducing DCC++ ---a complete open-source DCC station and interface

Gregg Aug 25, 2015

  1. Scott Eric Catalano

    Scott Eric Catalano TrainBoard Member

    205
    57
    6
  2. Gregg

    Gregg TrainBoard Member

    237
    307
    18
    This looks like a straight DC power supply with selectable voltage output. Should work fine for powering the Pololu but make sure to disable any power coupling back to the Arduino, which can't handle such high voltage. The Arduino should be separately powered through a USB cable or standalone supply.
     
  3. Gregg

    Gregg TrainBoard Member

    237
    307
    18

    Pinpres,

    I finally had a chance to check out the magnetic devices you suggested and they look quite good for a number of reasons. First, I have fond memories of measuring the Hall Effect in physics lab way back in college (even if we did manage to obliterate a sensor by turning on the electromagnet without securing the poles, which promptly came together in a split second completely crushing our first sensor, but fortunately not anyone's hand!). Second, these sensors only have 3 connections instead of the 4 required for the QRD1114 IR sensors, which simplifies the wiring. Third, if these are sufficiently sensitive and current flow sufficiently high when activated, it might be possible to use the Arduino's internal pull-up resistors to anchor an open pin to +5V, instead of requiring an external pull-up resistor, which greatly simplifies the connections.

    In exploring the technical docs, I was further intrigued by some of the models that offered "latching" whereby the sensor would turn on when it senses a magnetic field, but would not turn off until it senses a second magnetic field in the opposite direction. Using this type of sensor with 2 pair of reverse-polarity magnetic disks at either end of a train could yield a very robust block-detection mechanism. Consider a 6-car train with 4 magnets lined up as follows:

    |--N--S--|--------|--------|--------|--------|--S--N-->​

    and a magnetic latch set to turn on when it senses a South Pole and to turn off when it senses a North Pole.

    When the train above crosses this sensor, it will first sense the North Pole and therefore do nothing, since the sensor is already off. However, once the South Pole magnet crosses the sensor, it will turn on, signaling that a train has been detected. If the train continues moving forward, the sensor will remain on even after the South pole magnet is no longer in range, which is good since the train is in fact still over the sensor. When the last car crosses the sensor, the sensor first sees another South Pole, which has no effect since the sensor is already on, but then sees a North Pole magnet which turns the sensor off just as the train itself has cleared the sensor.

    Also, if instead the train stops and reverses after the first car has crossed the sensor but before the last car has, the sensor still operates as intended -- it remains on when it senses the South Pole and turns off when it senses the North Pole, at which point the train has in fact cleared the sensor.

    What's nice about this potential set-up is that it greatly simplifies the logic required by any sensing program. In DCC++ the system must keep track of when an IR sensor is activated, de-activated, and then activated again to indicate the final car has cleared. Using 4 magnets and a latching magnetic sensor yield a much simpler situation where if the sensor is on, there is a train somewhere over the sensor. And it it's off, there is no train over the sensor. I know this is ideally what an IR sensor should be able to do, but the gaps between the cars and different levels of reflectivity make it hard to achieve robust signal. I may order a few of these magnetic latching sensors just to give this a try on a test track.

    -Gregg
     
    KC Smith and papahnash like this.
  4. Scott Eric Catalano

    Scott Eric Catalano TrainBoard Member

    205
    57
    6
    Hello Gregg,

    My motor shield arrived today and I am going to start assembling everything tonight and I will report back on my progress. I may have some questions so be prepared. - Scott
     
  5. Scott Eric Catalano

    Scott Eric Catalano TrainBoard Member

    205
    57
    6
    Ok...I've soldered all my components onto the motor shield.....now I am ready to cut the trace to pin 10 and remap it to to pin 11.....now do I just solder a jumper wire on the underneath of the motor shield? I want to make sure I do this right with out messing up the board. Thanks in advance!
     
  6. esfeld

    esfeld TrainBoard Member

    402
    368
    13
    Gregg
    I have the whole thing assembled and it gives power to my test track and initiates sound, so I think I'm good. I am patiently awaiting your Java code .... in the interim can you post a simple code snip-it for selecting a loco address, direction control and throttle from which I might be able to get an engine to run. Again, loving this project.
     
  7. Scott Eric Catalano

    Scott Eric Catalano TrainBoard Member

    205
    57
    6
    Hello esfeld,

    If you look in the commands.h files you will find serial commands to make the engines go.....are you modelling N Scale or HO Scale? What motor shields are you using? I have to remap my shield to make it work....so right now you are one step ahead of me in getting something to work. I model HO Scale so I needed to use a high grade of motor shield.
     
  8. esfeld

    esfeld TrainBoard Member

    402
    368
    13
     
    papahnash likes this.
  9. esfeld

    esfeld TrainBoard Member

    402
    368
    13
    Scott, Thanks for the reply .... I studied "serial commands.h" and although I see his explanation I was looking for a simple set of commands to type in to the serial window to initiate action without analyzing and writing my own (lazy, I know) ....... I am in n scale (used to be HO many many years ago) I am using a motor shield from Micro Computer and instead of monkeying with the trace I simply bent the "Vin" pin back so that when the shield is plugged into the UNO there is no connection. I'm not sure what you are looking to solder as shown in the videos you should be using jumpers unless your motor shield does not have pin inputs ... seems odd if it is an UNO compatible sheild ( you can buy input blocks to solder to the shield and then use jumpers .... makes it easier).
     
    papahnash likes this.
  10. Scott Eric Catalano

    Scott Eric Catalano TrainBoard Member

    205
    57
    6
    I'm using the Pololu motor shield which the default pin mappings are different than an Arduino Motor shield....so I have to cut the trace...which I am just about ready to do....and then solder a jumper wire to make it match the pin 11....I'll post an update soon.....I've read the serialcommands.h file as well and I will be making my own GUI controls soon if Gregg hasn't had a chance to post his Java interface.....I program mostly in Perl and Perl/Tk...cross platform Linux and Windows
     
    papahnash likes this.
  11. Scott Eric Catalano

    Scott Eric Catalano TrainBoard Member

    205
    57
    6
    Ok....my first try failed...I am getting no power to my tracks...either program or main track...followed Greggs instructions for the remapping of the Pololu motor shield....I am getting power to my motor shield board by the blue status light....the motor status lights do not light up....used the power on command via the serial monitor and nothing....used the <c> command to get track amps.....nothing....So I am at a loss at this point....any help or suggestions would be greatly appreciated. Thanks!
     
    papahnash likes this.
  12. esfeld

    esfeld TrainBoard Member

    402
    368
    13
    I looked at the Pololu shield and from what I see I think you could bend the "Vin" pin the way I did and not mess with the trace but I do see that some pin remapping is necessary. I taught C and C++ at the graduate level a long time ago but am using Java and Python now pretty much. Just was looking to save some time ... guess I'll have to code my own GUI if Gregg doesn't post soon. At one point I had the same (no power) problem ... found that the motor shield was pressing up against the UBS socket and shorting out. You did cut the trace (bend pin) to disconnect the "Vin" from the Arduino board ...... as well as when you remapped pin 10 ....
     
    Last edited: Oct 30, 2015
    papahnash likes this.
  13. Gregg

    Gregg TrainBoard Member

    237
    307
    18
    Hi all,

    I will try to post the Java GUI this weekend on the GitHub site. In the interim, please do try out the <t> command to see if you can get the train moving. For example, <t 3 6210 50 1> would use DCC++ register 3 to set the throttle of cab 6210 to speed step 50 in the forward direction. Remember you'll also need to send a <1> command to enable track power. I generally always start with <s> to make sure I'm communicated correctly with the Arduino. If that command does not return a bunch of status data, check your baud rates.

    -Gregg
     
    papahnash likes this.
  14. Scott Eric Catalano

    Scott Eric Catalano TrainBoard Member

    205
    57
    6
    Ok...so I tried the Pololu Arduino motor shield library and hooked it up to a regular DC test track and put a DC train on the track and using the demo code provided by Pololu it worked.....moved back and forth on Motor 1....now Motor 2 did not work as I cut the trace and mapped it to pin 11 which should work under regular DC once I recode the default Pololu motor shield code from pin 10 to pin 11 this should work.
     
    papahnash likes this.
  15. Scott Eric Catalano

    Scott Eric Catalano TrainBoard Member

    205
    57
    6
    Here is update #1:
    1.) I have success in the following areas: I hooked Pin 10 to pin 4 instead of pin 7 and both my motors A and B have green status lights and when command <1> was issued track power turned on and the sound locomotive turned on.
    2.) I issued command <t 1 1108 1 1> and the locomotive moved forward as expected....however when command <t1 1108 1 0> was issued the locomotive did nothing. I am assuming this is because my motor shield pin mappings aren't correct? Pins 7 & 8 aren't switching directions

    Also issuing other commands like turning on a head light and bell etc did not work either.
     
    papahnash likes this.
  16. esfeld

    esfeld TrainBoard Member

    402
    368
    13
    Glad to see your progress, when I send <s> it gives me: <p1><iDCC++ BASE STATION ....... so I know I am communicating.
    When I send: " <1> <t 3 01 50 1>" for a loco with two digit address of 01 ... I get " <p1><T3 50 1> and I get sound from the engine but no motion! Measuring track voltage on AC volts I get only 5v not the 12v I should get. Not sure if it is the shield or not.
     
    papahnash likes this.
  17. Scott Eric Catalano

    Scott Eric Catalano TrainBoard Member

    205
    57
    6
    Looks like 5v is the Arduino power...the 12v should be the motor shield power....when I issue the <c> command it responds with <a0> when it should read back the amps etc. I get motion....I just can't change direction. Looks like Gregg will have to comment on our questions here. I know I am getting closer to getting it to work 100% I might have to change some parameters in the Arduino sketch...again I will wait for Greggs comments as different motor shields have different mappings etc
     
    papahnash likes this.
  18. Gregg

    Gregg TrainBoard Member

    237
    307
    18
    Hi Scott,

    I took another look at the Pololu specs and it seems there is an additional control line that is not present on the Arduino version of the motor shield. This line is called D2 on the Pololu and it enables and disables the entire board. The default is that it maps to pin 4 on the Arduino itself. This line must be driven high to enable the board - it's pulled low by default. The best way to do this is probably to add a few lines of code to the sketch that sets pin 4 to be an output and then sets it high with a digitalWrite command. However, above you mention that you mapped pin 10 to pin 4. This will likely cause problems since as pin 10 toggles from high to low the power on the board outputs will also toggle. I think the loco may have responded to the direction command because it is picking up what may look like a DC signal? Not quite sure, but you'll have to keep pin 4 separate from the other pins in any case.

    Also, speed step 1 is sometimes lower than the minimum threshold for a loco to move. May want to start with a speed of 10 or 15 for testing. Lets us know how it goes.

    -Gregg
     
  19. Gregg

    Gregg TrainBoard Member

    237
    307
    18
    The communication does seem to be correct but the voltage is definitely too low. Do you have a separate supply connected to the motor shield inputs? Note that for n scale you may need 15v. I found the trains would not really run at 12v unless I set the speed step close to the max.
     
  20. Scott Eric Catalano

    Scott Eric Catalano TrainBoard Member

    205
    57
    6
    Hello Gregg,

    This is where I will need some direction.....which file do I need to add lines of code too? What I did was trial and error....I just used jumpers from pin 10 to pin 4 as pin 10 to pin 7 did not work and pin 8 to pin 5 did not work.....however since the board is off by default this makes sense? Where should I add the code too? And does the Arduino use pin 4 for anything else on the motor shield or DCC++ base station? Thanks Gregg
     

Share This Page