DCC++ Hardware - Throttles

KE4NYV Jan 25, 2016

  1. Bret Kuehn

    Bret Kuehn New Member

    5
    4
    3
    Dave, sboyer2,

    It Works!!! sboyer, you were right on....and Dave you spelled it out in the program..."enter your LCD address here, find it in the I2C scanner." I had to do a little google search on how to find the address (mine is 0x3f also) but after that it started to make sense. After all, I have only started tinkering with Arduino's for a couple months now...
    Funny thing, the grand kids came over this afternoon and the first thing out of my granddaughters mouth was "did you get the remote fixed?". I had to give her the bad news at the time...they left a few hours ago but at least I can have this ready for next time they come over!

    Now my final question...at least for now. I'm sure the electronic components are sensitive to shock. Dave I really like your acrylic case but if it was dropped to the ground or knocked off a layout, would it damage any of the electronics? I'm using foam board as a mock up for the face and now I'm thinking it might be a good idea to build the whole case out of foam board to soften any potential grand child mishap and still be sturdy enough as an enclosure.

    Thoughts???

    I REALLY appreciate your guys help!!!
     
    Scott Eric Catalano likes this.
  2. SP_fan_1951

    SP_fan_1951 TrainBoard Member

    93
    85
    6
    Dave, I have got my DCC++ running on a UNO, and your pot throttle running on a NANO with a wired serial connection, and now I'm trying to get the HC-12 wireless link working. I am connecting through COM 1 RS-232 port on my PC. When I try and run the configuration utility with the SET pin grounded, the HC-12 echos back the AT command character for character instead of the expected "OK." I've tried swapping Tx & Rx, a power down and up reset with the SET pin grounded, and powering it up and then grounding the SET pin. With the set pin ungrounded, it does not appear to respond at all. With it grounded, all I get is the echo. I have tried both modules that I have and they both seem to behave the same. Any clue as to what I am doing wrong?
     
    Scott Eric Catalano likes this.
  3. David Bodnar

    David Bodnar TrainBoard Member

    264
    481
    13

    Bret - that is great news - as to shock, there is little that is really sensitive to shock other than the LCD display and your solder joints - I have never had issues with things breaking from a short drop to the floor.
    dave
     
    Scott Eric Catalano likes this.
  4. David Bodnar

    David Bodnar TrainBoard Member

    264
    481
    13
    Have you tried the HC-12 configuration utility program described here:

    http://trainelectronics.com/Arduino/HC-12-Serial_Radio/
    in the section titled Using the HC-12 Configuration Tool

    you can download it here:

    http://www.thebackshed.com/forum/uploads/robertrozee/2016-01-12_042418_HC12_config.zip

    I find it much easier to use.

    dave
     
    Scott Eric Catalano likes this.
  5. SP_fan_1951

    SP_fan_1951 TrainBoard Member

    93
    85
    6
    I got it figured out - I had to build a RS-232 to TTL level shifter. :barefoot:Once I had TTL levels everything started working fine.(y)
     
    Scott Eric Catalano likes this.
  6. sboyer2

    sboyer2 TrainBoard Member

    35
    41
    6
    Hi Dave

    i built you encoder version of the throttle and it keeps freezing, it'll work for a while (not more than 5 minutes) the it will just freeze everything was working before the freeze (loco select, speed up/down, direction change, even change amount of usable loco's (1-4))

    i even turned on debug and the commented out section about recurring commands and i can see in the serial window when it stops updating.

    any ideas?
     
    Scott Eric Catalano likes this.
  7. David Bodnar

    David Bodnar TrainBoard Member

    264
    481
    13
    It sounds like it could be a power supply problem - are you powering it with a battery? What is the voltage? You might want to try a different power source.

    dave
     
    Scott Eric Catalano likes this.
  8. BruceV

    BruceV New Member

    6
    8
    4
    Hello Dave,

    Bruce from the UK.

    I have constructed your wireless DCC++ throttle using a rotary encoder. It is powered by 8 AAA rechargeable batteries. The batteries are charged by an external plug in charger. I have included the reset button shown on your schematic.
    When I get a chance I will post some photos of my hand held throttle in a future post.
    I aim on using this to control a G gauge garden railway.
    I have noticed the following 'bugs'.

    1. When the throttle is powered on the speed always shows S=1 but if I reset the Pro Mini by using the reset button speed shows S=0. In the video on the web page for the wireless throttle, at the part where you are showing the use of two throttles, throttle 1 shows S=0 but throttle 2 shows S=1 when you power them up. Do you think that this could be a rotary encoder problem? I'm using the same rotary encoder that you used.

    2. It is not possible to set the controller to control just one loco. The minimum is 2.

    I would like to see the following enhancements: -
    Ability to enter functions F0 to F28
    Ability to be able to control 6 locomotives.
    Ability to change speed steps to 14, 28 or 126 with resorting to reprogrammming the Arduino Pro Mini.

    Bruce
     
    Scott Eric Catalano likes this.
  9. David Bodnar

    David Bodnar TrainBoard Member

    264
    481
    13
    Hi, Bruce - thanks for letting me know of your progress with the throttle - As to bugs / enhancements I have left this project for other endeavors and haven't touched the code in the better part of a year - hopefully you or others will continue to do updates / upgrades

    enjoy!

    dave
     
    Scott Eric Catalano likes this.
  10. BruceV

    BruceV New Member

    6
    8
    4
    Hello Dave,

    The problem with S=1 on powering up was due to a dodgy rotary encoder.

    Bruce
     
    Scott Eric Catalano likes this.
  11. BruceV

    BruceV New Member

    6
    8
    4
    Hi,

    Are any members still continuing with updates and upgrades to Dave Bodnar's wireless DCC++ throttle?

    Bruce
     
    Scott Eric Catalano likes this.
  12. SP_fan_1951

    SP_fan_1951 TrainBoard Member

    93
    85
    6
    I have just completed my first throttle with a pot for speed control, and am waiting for an encoder and other parts. I have modified the code to use a 4x4 keypad, and am working on turnout control from the throttle.
     
    Scott Eric Catalano likes this.
  13. BruceV

    BruceV New Member

    6
    8
    4
    Have you had any problems with the encoder? I had to put a 0.1uf cap across the push button switch as the direction would intermittantly change as I was turning the encoder.
     
    Scott Eric Catalano likes this.
  14. SP_fan_1951

    SP_fan_1951 TrainBoard Member

    93
    85
    6
    I have not had the problem you are describing, but I modified the code to allow direction change only when the speed is zero. To reverse direction you have to dial the speed down, and then press the button. I am using the KY-040 modules to eliminate the need for a PCB and I had to rework the code to get reliable operation with these encoders. The .1uF caps across the CLK and DT lines were necessary to tame the switch bounce, but the code debounce seemed to work well for the reverse button. My current version is using a 4x20 display, and a 4x4 keypad. It is still very much a work in progress, but if you would like the code to play with I'll post it.
     
    Scott Eric Catalano and BruceV like this.
  15. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Another look at Potentiometers - There maybe some mileage in them yet!

    Hi All,

    Long time ago back in the early days of throttle design, it was common to see a single channel throttle using a potentiometer to adjust the loco speed.
    Nothing wrong with that until we wanted multi channel designs, with an ability to switch seamlessly between loco's and continue with their current speed settings. Hmmm, time for a rethink.....

    Somewhere among these pages I made a suggestion and provided a little code sample to use the pot to drive the counters as opposed to doing analogue map comparisons. The pot I suggested using was the little x,y joystick type which can be found easily and are quite cheap.

    This kind of thing..

    100098_C.jpg

    I left it there, as I'd no interest taking it further.

    However, recently I thought of enhancing the driver method, so with a little practice one could use these as an alternative to rotary encoders.
    You can test the 'action' with a 10k pot (value not critical) and this small Uno sketch.

    The math in the code is not set in stone, and can easily be modified to suit your individual taste.

    Basically I'm using the upper and lower analogue reading ranges, first and last 400 points, to modify a timer that drives the counter or multiple counters in the case of multi channel/loco throttles. The zone in the the mid range is the sprung detent position where nothing happens.

    So to test this, connect the outer pins of the pot to 5v and the other to GND. The centre wiper pin goes to A0. You should find as you move either side of centre, the count increments, the further you go the faster it increments. Imagine that with the short sweep joystick above, and this could be a neat way of adjusting throttle speeds.

    Steve.

    Edit: Forgot to add you can see the counter output in the serial monitor.

    Code:
    
    uint8_t stickPin = 0;
    uint16_t stickVal;
    uint16_t interval;
    uint32_t startTime = 0;
    uint16_t lastCount = 127;
    uint16_t count = 0;
    
    
    void setup() {
      Serial.begin(115200);
    }
    
    void loop() {
    
      stickVal = analogRead(stickPin);
    
      if (stickVal > 622) {
    
        interval = 1000 - ((stickVal - 622) * 2.465);
        if (lastCount != count) Serial.println(count);
        lastCount = count;
    
        if (millis() - startTime > interval) {
          if (count < 126) count ++;
          startTime = millis();
        }
    
      }
    
      if (stickVal < 401) {
    
        interval = 1000 - ((400 - stickVal) * 2.465);
        if (lastCount != count) Serial.println(count);
        lastCount = count;
    
        if (millis() - startTime > interval) {
          if (count > 0) count --;
          startTime = millis();
        }
      }
    }
     
    Scott Eric Catalano and esfeld like this.
  16. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Turns out Arduino's map() function is more adaptable than I thought. Now the ranges can easily be configured.

    A new sketch to play with....

    Code:
    uint8_t stickPin = 0;
    uint16_t stickVal;
    uint16_t interval;
    uint32_t startTime = 0;
    uint16_t lastCount = 127;
    uint16_t count = 0;
    
    
    void setup() {
      Serial.begin(115200);
    }
    
    void loop() {
    
      stickVal = analogRead(stickPin);
    
      if (stickVal > 622) {
     
        interval = map(stickVal, 623, 1023, 1000, 10);
        if (lastCount != count) {
          //Serial.print("A0 = ");
          //Serial.print(stickVal);
          //Serial.print(" Ival = ");
          //Serial.print(interval);
          //Serial.println("ms");
          Serial.println(count);
          lastCount = count;
        }
    
    
        if (millis() - startTime > interval) {
          if (count < 1000) count ++;//Range would be <126 for a DCC++ throttle
          startTime = millis();
        }
    
      }
    
      if (stickVal < 401) {
    
        interval = map(stickVal, 0, 400, 10, 1000);
        if (lastCount != count) {   
          //Serial.print("A0 = ");
          //Serial.print(stickVal);
          //Serial.print(" Ival = ");
          //Serial.print(interval);
          //Serial.println("ms");
          Serial.println(count);
          lastCount = count;
        }
        if (millis() - startTime > interval) {
          if (count > 0) count --;
          startTime = millis();
        }
      }
    }
    
    /*
    Throw in some more variables and a simple switch you can enter in Serial Monitor, just type 1,2 or 3[enter]
    We have a working 3 loco throttle controlled with an ordinary potentiometer :)
    You can code the fwd and rev.
    
    uint8_t stickPin = 0;
    uint16_t stickVal;
    uint16_t interval;
    uint32_t startTime = 0;
    uint16_t lastCount = 127;
    uint16_t count = 0;
    uint8_t lastOut;
    uint16_t cabs [4] = {0, 123, 777, 4371};
    uint16_t loco;
    uint8_t tNum = 1;
    uint8_t speeds [4] = {0, 0, 0, 0};
    
    
    void setup() {
      Serial.begin(115200);
      loco = cabs[1];
    }
    
    
    void loop() {
    
      while (Serial.available()){
        uint8_t num = Serial.parseInt();
        if ((num > 0) && (num < 4)) {
          loco = cabs[num];
          tNum = num;
          count = speeds[tNum];
        }
      }
    
      stickVal = analogRead(stickPin);
    
      if (stickVal > 622) {
    
        interval = map(stickVal, 623, 1023, 500, 10);
        if (lastCount != count) {
          Serial.println(count);
          lastCount = count;
          speeds[tNum] = count;
        }
    
    
        if (millis() - startTime > interval) {
          if (count < 126) count ++;
          startTime = millis();
        }
      }
    
      if (stickVal < 401) {
    
        interval = map(stickVal, 0, 400, 10, 500);
        if (lastCount != count) {
          Serial.println(count);
          lastCount = count;
          speeds[tNum] = count;
        }
        if (millis() - startTime > interval) {
          if (count > 0) count --;
          startTime = millis();
        }
      }
      if ((stickVal > 410) && (stickVal < 613)) {
        if (count != lastOut) {
          char throttle [18];
          sprintf(throttle, "<t%d %d %d 1>", tNum, loco, speeds[tNum]);
          Serial.println(throttle);
          lastOut = count;
        }
      }
    }
    */
    
     
    Last edited: Oct 1, 2017
    Scott Eric Catalano and esfeld like this.
  17. BruceV

    BruceV New Member

    6
    8
    4
    Yes please post your code as I would like to see how you are controlling turnouts etc.

    Attached picture of my wireless throttle. This will be used for a garden railway. The throttle uses a 16x2 display, a 4x3 keypad, a rotary encoder and 2 push buttons. The Yellow button is unused and the Red button is the Emergency Stop button which is wired between pin 12 on the Arduino Pro Mini and ground. Pressing this button stops ALL trains and gives you the option of removing Track Power or not. I have, for the time being, left out the reset switch. I was originally going to use it as an Emergency Stop but I found that it was taking nearly 4 seconds before it took effect. There are 8 rechargeable AAA batteries in throttle case and I use a plug in charger to recharge them.

    A friend has refactored Dave Bodnar's code for me. Attachment ds204 is the code in txt format. Copy and paste into Arduino IDE program. The STAR & HASH keys are mainly used as NO/YES keys. The code allows the throttle to store up to 8 Loco's. You can add or delete loco's without the trains coming to a halt. When you add a loco, the loco address can be entered as a single digit. The display will show the address as 4 digits. When entering the loco details you have the option of entering the number of speed steps 14, 28 or 126. Pressing the HASH key once steps you through to the next loco store. Pressing STAR takes you the control screen. Display shows loco address, direction and speed step on the first line. The second line show F0 and #and what ever loco store is selected to control. F0 is for functions Fo to F9, pressing STAR key will change F0 to F1 which is for F10 to F19. To select a function just press its function number key for example Function 4 just press key 4. The display will show 4 on the second line, pressing 4 again will turn the function off and the 4 will extinquish.

    Please download and try the code and let me know of any bugs or ideas.
     

    Attached Files:

  18. SP_fan_1951

    SP_fan_1951 TrainBoard Member

    93
    85
    6
    Here is my version. The turnout code is at the end of the program. I tried to comment it thoroughly enough to make it easier to follow,
     

    Attached Files:

    Scott Eric Catalano and BruceV like this.
  19. BruceV

    BruceV New Member

    6
    8
    4
    Ignore the part about adding or deleting loco's without the trains coming to a halt. It was decided to leave this out.
     
    Scott Eric Catalano likes this.
  20. William E Van Buskirk

    William E Van Buskirk TrainBoard Member

    40
    22
    3
    Hi all, have a code question maybe someone can answer. It's in regards to the throttle function void doDCC() and DCC++. As I understand the DCC++ base station expects a reg # after the 't' and in doDCC() this is hard coded as Serial.print("<t1 "); . It looks to me like switching to a different cab on the throttle would over write Register 1 in the Base station, making it hard/impossible to control 2, 3 or 4 locos from the throttle.
    I was thinking of changing it to
    Serial.print("<t ");
    Serial.print(ActiveAddress + 1); //DCC++ register= Array index value 0-3 + 1 for registers 1-4
    Serial.print(" ");
    So the throttle would use regs 1-4 in the base station. Does DCC++ handle these internal registers different then my understanding?
    Bill
     

Share This Page