Raspberry Pi base station with JMRI?

DougL Apr 18, 2016

  1. DougL

    DougL TrainBoard Member

    82
    46
    10
    Is there software and hardware for the Pi to create a DCC base station?

    If this has been answered, please link to it. Several searches did not have a definite answer. I am a newbie to microcontroller electronics, I just got the DCC++ Arduino base station up and running.
    • JMRI can be loaded and run on the Pi
    • Pi boards have bluetooth and wifi, and can be controlled by engine driver
    • If the Pi could also supply DCC to the track, then it could be an all-in-one wireless DCC base station.
     
  2. Dunks

    Dunks New Member

    5
    0
    2
    Yes. But you do need a Sprog or similar to plug into one of the USB sockets.
    See here on RMWeb .
     
  3. DougL

    DougL TrainBoard Member

    82
    46
    10
    Yes, I see. With that setup I could connect the RPi to the Arduino base station instead of a Sprog.

    I thought the Rpi could control stepper motors with an additional board.
    The Arduino uses a motor shield to provide the PWM at sufficient voltage and amps. Is there a similar stepper board for the RPi?

    If the RPi can control stepper motors and JMRI, that leaves the USB port free for a WIFI dongle.
     
  4. TwinDad

    TwinDad TrainBoard Member

    1,844
    551
    34
    The RPi has a set of GPIO pins and a library included in the OS to access them from software. I don't know if there are boards already made, but certainly the GPIOs from the RPi could be connected to, say, an Arduino Motor Shield (without the Arduino itself) to drive the rails.

    What I *don't* know is whether the RPi has timer modules (or fast enough software interrupt capability) to create the raw DCC signal itself.

    I'm not sure what the issue is with tying up a USB port? The RPi 2 has four, each of which can drive a (powered) hub. I have my RPi hooked up to a wifi dongle, a wireless keyboard, a wired mouse (only because the wireless one died) and a Digitrax PR3.

    And the RPi 3 has WiFi built in at basically the same price point. So it might actually be easier to connect an RPi 3 to a SPROG or DCC++ base station than to hard-wire the RPi GPIO to a motor driver, just to save a USB port.

    Unless you're in it for the challenge, in which case by all means go for it!
     
  5. DougL

    DougL TrainBoard Member

    82
    46
    10
    The point was to have a single unit. Freeing a USB port is not important at all

    an RPi with its communications abilities and top it with a stepper motor controller.
     
  6. DougL

    DougL TrainBoard Member

    82
    46
    10
  7. TwinDad

    TwinDad TrainBoard Member

    1,844
    551
    34
    Oh, OK. Well, based on a very quick Google search, something like this might work: https://learn.adafruit.com/adafruit-dc-and-stepper-motor-hat-for-raspberry-pi/overview

    It's only 1.2A per channel, but you could parallel up all 4 channels for some decent output (better get a heatsink, though).

    Combine this with the code you found and you could probably do something cool.

    There are probably other, possibly higher current "hats" available...

    ETA: What you are doing is basically the same thing DCC++ does with the Arduino, only substituting a much more powerful core processor than the Arduino's core. You could pick up a lot of how the electrical side needs to work by following the DCC++ design, only using a "hat" for Pi rather than an Arduino Shield.

    ET(also)A: The trickiest part of this is probably getting JMRI to "talk" to the dccpi code... but at worst case that's writing or adapting one of JMRI's hardware interface modules to mimic the input interface to dccpi
     
  8. Dunks

    Dunks New Member

    5
    0
    2
    I am a newbie to the Rpi and Arduino thing. Setting up a basic Rpi/Sprog is fine, and I can easily set up WiThrottle on my phone, etc, but I would prefer to create my own, simple controller with speed control via a knob, a physical switch for direction, and one or two push buttons for frequently used functions, and a simple way to select engines from the stack (I only have two to worry about). My thinking made me wonder if the Rpi might be the basis for this.

    Can anyone help here?

    Simon
     
  9. TwinDad

    TwinDad TrainBoard Member

    1,844
    551
    34
    At the risk of sounding like a DCC++ salesman, I'm going to suggest you take a look at what they are doing with the Arduino. It's non-trivial to generate a DCC control signal, so you're probably going to need a microcontroller/microprocessor of some kind. For what you are describing, a RPi would be overkill IMHO. If you want a handheld controller similar in concept to the NCE PowerCab (but simpler), you could put an Arduino ProMini and a motor driver into a handheld case, and wire the buttons and knobs to IO on the ProMini...
     
  10. Dunks

    Dunks New Member

    5
    0
    2
    Not sure how clear I was, but I am looking to use the Rpi as a command station (it may be overkill, but I have one plus a Sprog) but to dispense with wires to connect it to the layout or the controllers. I also have the Tam Valley DRS tx and rx, plus Zimo sound decoders with reprogrammed features, and also battery power. The think I am missing is a simple, remote hand controller with physical buttons, but ideally not using a local wifi network.

    As I have already got the kit, and can lay my hands on an older Rpi (my son upgraded, and a simple deal can bear ranged) this might be the way forward.

    Had I known about DCC++ sooner, I might well have looked at that as a solution, but I would rather use what I have. Can probably find out/teach myself how to do all this, but if someone already knows, then it saves me several precious hobby hours.


    Sent from my iPhone using Tapatalk
     
  11. DougL

    DougL TrainBoard Member

    82
    46
    10
    Poifect!

    Hat vs shield - ok, I understand the jargon now. Yes, that hat is exactly it. There are some higher output hat/shield solutions if more than 1A per channel is desired - later.

    "
    The trickiest part of this is probably getting JMRI to "talk" to the dccpi code"
    Yeah, I thought of that. It probably will be the trickiest part. Meh, I can learn.
     
  12. TwinDad

    TwinDad TrainBoard Member

    1,844
    551
    34
    Do keep us posted on your progress. It would certainly be an interesting setup.
     
  13. Paul Bender

    Paul Bender TrainBoard Member

    176
    1
    24
    Andrew Crosslamd, who makes the SPROG line is working on versions of the SPROG and SPROG Nano that plug directly into the Raspberry Pi's GPIO header, so you will be able to to do this without taking up a USB slot.

    I don't know what the ETA is for these being available, but Andrew has already mentioned these on other forums ( which included photos of the boards) and added support for them to JMRI.

    Paul
     
  14. Dunks

    Dunks New Member

    5
    0
    2
    Now that is interesting.


    Sent from my iPhone using Tapatalk
     
  15. Dunks

    Dunks New Member

    5
    0
    2
    Have been in communication with Andrew. He is quite taken with the idea, but busy with other commitments.


    Sent from my iPhone using Tapatalk
     
  16. crusader27529

    crusader27529 TrainBoard Member

    247
    167
    11
    Generating the timing sequences for DCC on a LINUX based machine of any kind will be problematic because of the internal complexities of Linux and its scheduler and task manager.

    The DCC++ solution is basically a dedicated module for generating the required signals. It is dedicating all it's resources and particularly its entire intgerrupt structure to make the timing correct. Trying to do that on a general purpose Linux system might be doable, but a detailed analysis of the internal HW and SW design of the processor on the PI will be required.

    Years ago, trying to generate consistent, reliable milisecond timing on a UNIX machine was next to impossible because of the internal dispatcher and scheduler that's inherent to it's operatrion. It required crippling many functions on Unix, making it a single process system, completely defeating the purpose of having a multi-task, general purpose OS. Linux essentially is engineered almost the exactly same way, and even with faster processors, timing down to the 50 microsecond granularity seems unlikely.

    All this is based on previous experience with real-time programming, and almost always required dedicated segments of HW & SW to get the timing granularity that was needed. Just be warned, that it probably won't be as easy as doing it on a simple single-chip dedicated microprocessor.
     
  17. DougL

    DougL TrainBoard Member

    82
    46
    10
    Crusader, let me see if I understand -

    1. The Arduino in the DCC++ command station is dedicated to producing the DCC PWM signal (TrainBoard project link here )
    2. It does receive and translate commands via USB
    3. The command sender is a computer running JMRI
    4. An RPi could be dedicated instead of an Arduino
    5. However, for either RPi or Arduino, adding the overhead of JMRI would disturb the PWM signal.

    Is that about right?

    Again, the original question is, Can RPi be used in a back box to do this?:
    1. Engine Driver or similar app on smartphone (no point in building a hand-held controller)
    2. WiFi or BT to black box
    3. black box interperates commands (JMRI but other could be substituted) and generates DCC signal for track
     
  18. crusader27529

    crusader27529 TrainBoard Member

    247
    167
    11
    Sort of.....

    The PI could certainly generate the appropriate and correct signals to generate DCC signals, but NOT as part of a multi-user, multi-tasking OS like Unix/Linux.

    The basic operation of Unix/Linux of the process manager and scheduler (not the correct names of the functions) would be enough to probably cause the DCC timing to be inaccurate, because of the interrupts generated by the processes.

    The only guaranteed way to generate the correct, accurate timing would be to disable the interrupts that the rest of the OS uses and generates. It's much more complex, and disabling interrupts can cause lots of other issues, but like I said, crippling the OS to get the correct timing seems counter-productive, since some of the other applications and processes are required to operate the JMRI (and other parts) part of the system.
     
  19. RBrodzinsky

    RBrodzinsky November 18, 2022 Staff Member TrainBoard Supporter In Memoriam

    5,685
    2,786
    98
    But, the question is: Can a board that plugs directly in the RPi's GPIO header generate all the necessaries, with the commands coming from the Pi (say via JMRI). Said differently, can the GPIO be used as a way for a Pi to talk with a SPROG or DCC++ Arduino? This basically combines the two distinct components (JMRI/computer & command station) into a single "black box", but with two different processors at work under the covers. (Note, I really don't know what is/isn't capable over the GPIO vs any other method).
     
  20. crusader27529

    crusader27529 TrainBoard Member

    247
    167
    11
    Sure, but that's alot of effort just not to use a USB connection to talk to something like DCC++ Arduino system.....
     

Share This Page