DCC++ Hardware - Throttles

KE4NYV Jan 25, 2016

  1. PGW

    PGW TrainBoard Member

    13
    16
    3
    Sorry I didn't mean to knock it as such. Not being familiar with the IDE and the code sources etc. Just wanted to make sure that I wasn't doing something against the grain and report what I experienced in case others experience the same.

    Thanks for the work.
     
    Scott Eric Catalano likes this.
  2. Atani

    Atani TrainBoard Member

    1,474
    1,781
    37
    You may not be a C programmer but the code is not that bad. I have been a software engineer for over 20 years now, I have seen a lot of bad examples. Yours are far from the bad end.

    I have taken your wireless code and updated it considerably locally for my own throttles that I am assembling. I will be doing a wired setup since I don't want to hassle with batteries and charging.

    My version of the throttle now supports:
    • Functions 0-28 (0-9 available via keypad, all available via menu).
    • A menu to configure things.
    • Select register to send to base station.
    Planned enhancements:
    • Base station to support something like "<t1 ?>" which would be a "tell me the last settings for the loco on register 1" so the handheld itself is "dumb" and there is no need to store data in EEPROM long term other than register number.
    • Toggle Turnouts (menu item is there but not implemented yet).
    • Move most of the code into a C++ class that responds to the loop() code calling into it.
    • RS485 control bus vs text based connection to base station.
    I have a bunch of pro minis that I am putting in strategic places for detection and throwing of switches with servos (3.7g ones). I was planning an RS485 bus for those and looking to extend it further to use that idea as a general layout bus for throttles, detection, switches, signals.

    Can you share some details on your RS485 bus implementation? I am looking at this still for my setup.
     
    Scott Eric Catalano likes this.
  3. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    @Atani,

    Hello and welcome to this area of the forum.
    If you can share some of your ideas along with code improvements, I'm sure this would be eagerly received by other members.

    To answer the first point in your Planned enhancements. Base Station already includes code for exactly that return information by default.
    Every throttle command will receive an instant reply along the format of <T1 23 1> Throttle 1 Speed 23 Forward 1.
    Indeed I use this in my own throttle code for the same reason. Store the strings as global variables then slice out the info when you next need it.
    You can also call all active throttle status on demand using the <s> command. This is great for Synchronising a throttle into a currently running session.
    Hope this helps.

    Steve.
     
    Scott Eric Catalano and esfeld like this.
  4. David Bodnar

    David Bodnar TrainBoard Member

    264
    481
    13
    @Atani,, I would be interested in seeing your code, too.

    thanks!

    dave
     
    Scott Eric Catalano likes this.
  5. Atani

    Atani TrainBoard Member

    1,474
    1,781
    37
    I have prepared a github repo for it today and will push it this afternoon: https://github.com/atanisoft/DCCThrottle

    Picked GPL v3 initially as I am looking at leveraging MRBus as long as I can get it working on the pro mini. Also keeping inline with BaseStation etc.

    Based on a quick read of the docs and code for base station it would seem that I would need to send <tX Y Z> with some values to get back the current settings, this won't work if I have just plugged in the throttle to the bus unfortunately.

    The only problem I see with this is that I would need to capture/parse the entire <s> output to get just one loco var set. It is doable but is inefficient. This certainly makes sense for something that is connected for a long time or that persists a lot of data.

    What I am thinking is modify the base station to support an RS485 connection with a similar command set as the text based serial connection today. This interface would be used by the throttle and possibly other devices to send commands or receive status updates etc. Unfortunately MRBus is hardcoded to use a certain set of pins, will need to figure out how to shift this over to serial3 on base station and do something similar on the pro mini if it interferes with I2C
     
    KC Smith and Scott Eric Catalano like this.
  6. Atani

    Atani TrainBoard Member

    1,474
    1,781
    37
    Scott Eric Catalano likes this.
  7. sboyer2

    sboyer2 TrainBoard Member

    35
    41
    6
    Looks great, but is there a schematic of the hardware? i'd like to do a test build. and i'll be using a Nano v3 (builtin USB, make it easier to reprogram without needing a seperate part to do so, and is only 50c more than the pro-mini on fleabay)

    Steph!
     
    Scott Eric Catalano likes this.
  8. Atani

    Atani TrainBoard Member

    1,474
    1,781
    37
    I based it on http://trainelectronics.com/DCC_Ard....htm#Rotary_Encoder_in_place_of_Potentiometer with some pin changes. You can adjust all pins used in config.h (just pushed that a few mins back). I tried to include everything that was needed to build within the Arduino Eclipse by just importing the project as-is (hopefully there aren't too many hardcoded paths from the IDE in files, .cproject has a few).

    My local test setup has the rotary encoder pins on 2, 3, the encoder button is on pin 13. Keypad rows connected to 4-7, columns 10-12. I am using the default serial port for communication currently. My LCD screens are i2c, if yours are not you may need to adjust pins a bit more and change from LiquidCrystal_I2C.h to LiquidCrystal.h.

    I picked up a bunch of pro minis last year from china for under $2 each. So far I have one dead board, not sure what happened to it exactly but it won't accept new programs and both LEDs are both on when it has power. I suspect a voltage mixup fried one of the components.
     
    Scott Eric Catalano and sboyer2 like this.
  9. sboyer2

    sboyer2 TrainBoard Member

    35
    41
    6
    Thanks
    for now i'm just gonna breadboard this, (as canadapost is going on strike xor lockout ;-) i'm gonna rip out the optical encoder for an old mouse to use temporarily), don't have an LCD yet, have to wait for that.

    about your dead board, it's probably not dead, simply missing is bootloader, this happens a lot with fleabay arduinos, a friend ordered 3 UNO's and all arrived without the bootloader, google using 1 arduino to program bootloader into another, very easy and fast takes less than 5 minutes to do.

    instructions are on the arduino.cc site.

    Steph!
     
    Scott Eric Catalano likes this.
  10. Atani

    Atani TrainBoard Member

    1,474
    1,781
    37
    Scott Eric Catalano likes this.
  11. sboyer2

    sboyer2 TrainBoard Member

    35
    41
    6
    here's the direct link to the arduino bootloader setup/programming

    https://www.arduino.cc/en/Tutorial/ArduinoISP
     
    Scott Eric Catalano likes this.
  12. David Bodnar

    David Bodnar TrainBoard Member

    264
    481
    13
    @Atani - do you have a link to the proper library for your encoder.h? There are a number of them on the web.

    thanks!

    dave
     
    Scott Eric Catalano likes this.
  13. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    I'm guessing it's this one Dave https://github.com/PaulStoffregen/Encoder/blob/master/Encoder.h
    Same one I've been testing this week, very well written and very stable.
    It's about the only example I can find on the internet that ports directly to an ESP8266.

    Steve.
     
    Last edited: Jul 1, 2016
    Scott Eric Catalano likes this.
  14. David Bodnar

    David Bodnar TrainBoard Member

    264
    481
    13
    Scott Eric Catalano likes this.
  15. esfeld

    esfeld TrainBoard Member

    443
    382
    17
    Dave
    Moving on to Rotary Encoder .. upon compiling I get a " 'byte' does not contain a type" error in the ......number of locos section..... I tried to define it with "#define unsigned char byte" ... but that didn't seem to help. Any ideas?
    Steve F
     
    Scott Eric Catalano likes this.
  16. Atani

    Atani TrainBoard Member

    1,474
    1,781
    37
    Yeah, I am looking at including all libraries in the git repo so that it is much easier to get going. I also updated the readme today to have links to the libraries that are not included yet.

    Here is the Encoder lib that EclipseArduino is including: http://www.pjrc.com/teensy/td_libs_Encoder.html This is the same one as linked above by @UK Steve.

    I also added a few more commits this morning to add some error checking in functions and throttle id (register). I will need to add one for loco number since we can only go to 5 digits (I think my code currently limits to 4!), adding this to my TODO list.
     
    Scott Eric Catalano likes this.
  17. Atani

    Atani TrainBoard Member

    1,474
    1,781
    37
    This is defined as uint8_t by Arduino.h which comes from the core libs. It is only used on two lines in DCCThrottle.ino (36 & 37 on latest code) and can be safely changed to "char" or uint8_t. I will clean this up as this is the only usage of "byte".

    edit: just checked and it is referenced in Keypad/Keypad.h and Keypad/Keypad.cpp as well. I will clean up all of these refs to uint8_t, can you confirm that it works for you as that @esfeld?
     
    Last edited: Jul 1, 2016
  18. David Bodnar

    David Bodnar TrainBoard Member

    264
    481
    13
    Steve - not sure about the error - it is possible that the copying of the code missed something - I put a ZIP file of the program on my web page - give this a try as it works properly on my system:

    trainelectronics.com/DCC_Arduino/DCC++/Throttle/DCC_Throttle-lcd-RotaryEncoder-keypad--v2-6a.zip

    I am using Arduino version 1.6.7 on Windows 10

    dave
     
    Scott Eric Catalano likes this.
  19. David Bodnar

    David Bodnar TrainBoard Member

    264
    481
    13

    Thank you!

    dave
     
    Scott Eric Catalano likes this.
  20. PGW

    PGW TrainBoard Member

    13
    16
    3
    You can try moving all the include lines to the top of the code, before all variable declarations.
     
    Scott Eric Catalano likes this.

Share This Page