24 IN / 48 OUT card for JMRI

nopxor Apr 16, 2018

  1. nopxor

    nopxor New Member

    6
    14
    3
    Hello,

    It's a SMINI C/MRI clone with an Arduino Nano.
    https://www.utrainia.com/65-arduinocmri-and-rs485

    It can control turnouts, lights, signals leds.
    You can connect block detection modules or push buttons.

    [​IMG]

    The card is connected to the PC with a RS485 bus. There are USB-RS485 adapters @ 1$ on Ebay.
    With such bus, you can connect many cards to JMRI. Each card has a node identifier in JMRI.
    http://jmri.sourceforge.net/help/en/html/hardware/cmri/CMRI.shtml

    The board uses 6 IC 74HC595 for the 48 outputs and 3 IC 74HC165 for the 24 inputs (pulled-up)

    [​IMG]

    [​IMG]

    I used Eagle for the schematic & PCB (100 x 100 mm).
    I ordered the PCB at JLCPCB (2$ for 10 pcs !)
    https://jlcpcb.com
    For ordering PCB, you can directly upload the file "Arduino-CMRI_Gerber.zip" on the site.

    The Nano's sketch is very simple with the CMRI and Auto485 libraries from Michael Adams: https://github.com/madleech
    You just have to define the node number.

    Code:
    /**
     * C/MRI -> JMRI via RS485
     * =======================
     * Sets up an SMINI 24 inputs, 48 outputs with an Arduino Nano.
     * Uses an RS485 bus to transparently talk support multiple ArduinoCMRI nodes on one bus.
     * By passing in an Auto485 object to the CMRI constructor, we are able to automatically
     * control the DE and RE pins on our RS485 bus transceiver.
     * The PC with JMRI has an USB-RS485 adapter connected to the bus.
     *
     * IN control:
     * Nano pin:             74HC165 pin:
     *     9        LATCH ->     1
     *     13       SCK   ->     2
     *     12       MISO  ->     9
     *     
     *     
     * OUT control:   
     * Nano pin:             74HC595 pin:
     *     6      verrou ->     12
     *     7      donnee ->     14
     *     8     horloge ->     11
     *     
     *     
     * Change the CMRI_ADDR for each board.  Each node must have its own address.   
     * ====================================
     **/
    
    #include <Auto485.h>
    #include <CMRI.h>
    #include <SPI.h>
    
    #define CMRI_ADDR 0                  // select the CMRI node address
    #define    DE_PIN 2                  // Arduino pin 2 -> MAX485 DE and RE pins
    
    // pin 74HC165
    const byte LATCH = 9;
    
    // pins 74HC595
    const byte verrou = 6;
    const byte donnee = 7;
    const byte horloge = 8;
    
    Auto485 bus(DE_PIN);                 // RS485 bus transceiver
    CMRI cmri(CMRI_ADDR, 24, 48, bus);   // sets up an SMINI. SMINI = 24 inputs, 48 outputs
    
    void setup() {
      bus.begin(9600, SERIAL_8N2);       // open the RS485 bus at 9600bps
      pinMode(verrou, OUTPUT);
      pinMode(donnee, OUTPUT);
      pinMode(horloge, OUTPUT);
      SPI.begin ();                      // serial data protocol used to control 74HC165
      pinMode (LATCH, OUTPUT);
      digitalWrite (LATCH, HIGH);
    }
    
    void loop() {
      // 1: main processing node of cmri library
      cmri.process();
     
      // 2: update output
      digitalWrite(verrou, LOW);                                // on commence par mettre le verrou
      shiftOut(donnee, horloge, MSBFIRST, cmri.get_byte(5));    // on envoie la sixieme donnée d'abord
      shiftOut(donnee, horloge, MSBFIRST, cmri.get_byte(4));    // on envoie la cinquieme donnée ensuite
      shiftOut(donnee, horloge, MSBFIRST, cmri.get_byte(3));    // on envoie la quatrieme donnée ensuite
      shiftOut(donnee, horloge, MSBFIRST, cmri.get_byte(2));    // on envoie la troisieme donnée ensuite
      shiftOut(donnee, horloge, MSBFIRST, cmri.get_byte(1));    // on envoie la seconde donnée ensuite
      shiftOut(donnee, horloge, MSBFIRST, cmri.get_byte(0));    // et on envoie la première donnée
      digitalWrite(verrou, HIGH);                               // et on relache le verrou pour mettre à jour les données
        
      // 3: update inputs
      digitalWrite (LATCH, LOW);                                // pulse the parallel load latch
      delay(1);                                                 // wait while data loads
      digitalWrite (LATCH, HIGH);
      cmri.set_byte(0, ~(SPI.transfer(0)));
      cmri.set_byte(1, ~(SPI.transfer(0)));
      cmri.set_byte(2, ~(SPI.transfer(0)));
    }
    
    There are two jumpers on the board connected to TX and RX.
    You mut disconnect them during the USB Nano upload.

    The 5V power supply must be disconnected during the USB Nano upload.

    There are two RS485 connectors on the board for easy chaining.
    No need to use 120 ohm termination resistors for RS485.
    For small distances (several meters) they may be omitted.

    The connectors pitch is 3.5mm as here:
    https://www.ebay.fr/itm/262957982206

    Load currents should not exceed 35 mA per output and 70 mA total for one 74HC595 (8 outputs)
     

    Attached Files:

    Erik84750, Crisco and vasilis like this.
  2. TwinDad

    TwinDad TrainBoard Member

    1,844
    551
    34
    SWEET!

    And a new cheap board vendor to add to my list, to boot!

    Very cool.

    Two questions about the design, pondering your preferences vs. mine...

    (1) I see you soldered the Nano down... I tend to socket them, even though it costs a bit more, in case I want/need to change them out. Your rationale for soldering is??

    (2) Why such a large IO count? Is this planned for a particular area where there is a great concentration of sensors/signals/turnouts/etc.? Like an urban area or a yard or something? Are you concerned about maximizing utilization of the Nano? So far I've tended to build smaller, more specialized boards (less than 8 IO each, generally) so that they can be placed close to the (geographically spaced-out) devices under control, with relatively longer (LocoNet) bus wires for connectivity. I know I'm (relatively) under-utilizing the Arduino's horsepower, but they're so cheap these days... I have about a dozen scattered about 50 square feet of layout.

    I'm certainly not implying that you are wrong at all. But clearly you had different thoughts on the design than my usual assumptions, so I'd like to understand your thinking. I may learn something!
     
  3. nopxor

    nopxor New Member

    6
    14
    3
    I soldered the Nano because it's more simple and I don't know which socket I can use for a Nano.

    The I/O count match the exact SMINI count of a node recognized by JMRI. And I need many outputs for signaling on my layout.
     
  4. TwinDad

    TwinDad TrainBoard Member

    1,844
    551
    34
    Ah. OK. That makes sense.

    For the Arduino ProMini, I use two of these 12-pin headers, but unfortunately the 15-pin version is rarely if ever in stock. One could cobble together shorter length sockets I guess. Mostly I use the ProMini because I like the slightly smaller size and don't care about the lack of built-in USB port.

    As for the I/O count, I can definitely think up some scenarios where signaling, especially say on a multi-track main or in an congested area, could eat up a lot of pins very quickly in a small space.

    Well done on the design. My hat's off to you.
     
  5. KE4NYV

    KE4NYV TrainBoard Member

    219
    281
    17
    This is interesting. I would be interested in making an all SMT version of this and going to 2.54 MM terminal blocks to squeeze it down into a smaller foot print.

    Recently I started playing the idea of making a Raspberry Pi Zero W based DCC decoder/controller that could be duplicated easily and cheaply to place several around my layout. I like the idea of it being either a standalone option that get's everything from the DCC buss directly or network them all wirelessly and feed it commands through the network. I started looking at whether JMRI supported any kind of TCP/IP socket to do this and so far I'm not really finding what I am looking for.

    One more point to TwinDad's comment on soldering the Nano on directly. I too would socket it using 2.54 mm header sockets (I buy the 40 pin version 100 at a time) and just cut them down. However, this is a good candidate to just put the Arduino Nano (Pro) right on the board as an integrated part of the design. I recently did a board (in Eagle) for a customer that has a product based on the Pro Mini 5V version. I embedded the Pro Mini circuit into the board, so there is no module to solder on now. Just included the ICSP header to flash the 328P with the Arduino bootloader after I reflow the board. So far that is working out well for them.

    For me, I'm a PIC guy ;)
     
    John Balogh likes this.
  6. vasilis

    vasilis TrainBoard Member

    110
    39
    10
    (y)Very very nice, thank you.
    With a socket for arduino, as twindad suggests and sockets for shift registers will be a little better.
    Nice simple sketch and the arduino gives the abillity to add special i/o handlers (buttons with debounce, turnouts servos with spdt swithces for feedback, smd rgb leds,...)
    I'm newbie in all this and i'm wondering if the shiftpwm library (pwm shift registers for rgb leds) can be used with spi lib without conflicts. (i found some interesting posts)
    Thanks again for the strong kick start for speculations.
     
  7. William E Van Buskirk

    William E Van Buskirk TrainBoard Member

    40
    22
    3
    Very cool NOPXOR, I just received my box from JLCPCB :) At $2 per board it's very hard to build a less expensive SMINI node. I plan to use up some Pro Micros I have, gathering dust. A couple jumpers and a slight change to the sketch, very easy. Will post my progress (was going to post @Locodinuo but no skillz at speaking/writing French).
    By the way, for other builders, this deal also comes with a $18 shipping charge. So the total is ~$20 for 10 boards, still cheap and shipped very FAST via DHL. Stick to the 10 boards per order; I found that if I changed to 20 boards there were Eng and Layout fees. So the price jumped quite a bit. Better to do two orders if you need a ton of boards. Also thought I'd combine two of your ULN driver boards into a panel, to fit the JLCPCB 10cm x 10cm '10 for $2' deal.

    One can scale down the OUTs/INs but at $.20 or less per shift registers, just seems prudent to go ahead and stuff the board and use as much or little of the SMINI. Rather then having some boards with 8&8 or 16&8 or ...
    @TwinDad I agree with the idea of a minimal Pro Mini node but I have been eyeing https://www.diymore.cc/products/diy...a16u2-microcontroller-compatible-with-arduino Really like the 3pin layout and the price is not too bad.
    Bill
     
  8. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    Hi nopxor,

    I am planning to make an SMD version of your board, with a Pro Mini. When ready I will post the .sch, .brd and .lbr file here.
    I have a question though: in order to save space and reduce the board size as much as possible I would like to use pinheaders instead of the screwconnectors you use. Would that be ok and reliable enough for standard usage? The disadvantage would be that every single wire would need to be identified at the board in case somehow wires would be inadvertently snatched.
     
  9. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    And here is the SMD version, adapted for Arduino Pro Mini and compressed to a 50x100mm board: .sch, .brd, .lbr and gerber files useable with elecrow.com

    Please let me know if you want changes.
    Erik

    upload_2019-12-26_14-17-0.png
     

    Attached Files:

    Last edited: Dec 26, 2019
  10. vasilis

    vasilis TrainBoard Member

    110
    39
    10
    :eek:sorry I couldn't resist. you are involved in too many projects! Is this good?:confused: Sometimes I am wondering if you are a perfectionist, a visionist of total completeness and sometimes I'm thinking of the deadly sin of gluttony.:ROFLMAO: Sometimes I sin this way too. As far as i am concerned i only talk and do nothing because i have moved and my stuff are in the boxes and I'm a little bit :whistle: lazy. I found a way to enjoy looking at others progress.:ROFLMAO:
    Imagine that we have a similar to nopxor's card that controls servos. The way with the arduino,cmri,jmri is opened and it is a low cost solution for anyone who want to enter the hobby or has financial limitations.
    I have no intention to underrate neither your nor anyone else's efforts and achievements. No "BUT..." here
    To the point,
    IMHO, nopxor's card is an easy built, I like the tht components because I'm not so skilled in soldering. I believe it can be built on a proto perforated PCB.
    As Twindad pointed is better, more flexible, have the arduino inserted into pin sockets and have the abillity to replace it. I add that would be usefull to have the shift registers in sockects in case of malfunction or in case I would to use some of the free arduino pins or in case I don't need all theese i/o at a certain place of the layout (i think is better to keep the cards near to the devices and avoid the "spaghetti" wiring, it is not so critical though).
    Complete the servo controller! Upload the hw, sketch and a demo video!:D I'm ready to criticize.
     
  11. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    Hi Vasilis! No not gluttony, that is a selfish trait, here I distribute my work for the benefit of others. And I have no time during a whole summer and autumn due to work and business, so I have this immense need to catch up during wintertime; and hey, you sound like my wife when I am awake during night hours busy with my projects (and to be honest, I admit she is right; but meanwhile I get my projects accomplished).

    I fully agree that DIL needs to be in a socket: otherwise virtually impossible to remove a defective IC. Yet another big advantage of SMD is that it takes a few seconds te remove a defective IC.

    And my layout provides for the use of sockets to insert the Pro Mini.

    And now, ready to proceed with the servo controller for this board..

    Greets!
    Erik
     
    vasilis likes this.
  12. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    Here a version with M4 mounting hole and some minor corrections.
    upload_2019-12-27_10-21-24.png
     

    Attached Files:

    vasilis likes this.
  13. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    How to drive 48 servo motors from this board, with just 1 Pro Mini:
    1. develop a new addressable and interruptable I2C interface board with 4 MCP23017 chips (16 I/O each); a bit like this, but for less than USD4.00/pcb with parts soldered.
    2. Pro Mini (software from https://www.best-microcontroller-projects.com/mcp23017-interrupt.html and from https://learn.adafruit.com/16-channel-pwm-servo-driver
    3. develop on a separate board an interface for PCA9685 I2C 16ch PWM controller (link above).
    4. think of a userfriendly way to somehow stack the above together; or not.
    Give me a few weeks. Meanwhile the MCP23017 have been ordered (not cheap, the best I could get was 20 for 11,60EUR shipping included), the PCA9685 ordered as well.
     
  14. vasilis

    vasilis TrainBoard Member

    110
    39
    10
    Hi Erik,
    I'm not against the exploration, inventing, enjoy, "I do it because I can" etc.
    Some thoughts.
    Is it worth developing this controller for the turnout servos or servos that are controlling things on a mrr layout? How far from the controller can be a servo and work? 10m for the signal? What cabel? Supposed the power is from an independed bus, the signal cables will be single or cat5 and then will be splited? Again, is too much wires from a point. Where I would need a such large amount of servos from one point? A large yard maybe.
    Do I throw out the advantage of having devices hanged on a two wire bus? Do I throw out the flexibility of having a mix of I/Os and servos near the place I need them? Beside the above there is a lot of code to put together and debug it.
    I think the "open source" solutions are to help people "today" and are open to further development.
    When I'm thinking over an arduino node, I'm thinking about the flexibility. I would like to have, the abillity to choose the type of node I need, to define its address, without reprogram it, by dip switches(?). I would like to have, on board or on a handy scheme, the numbers of the ports for each configuration. Every part of the development needs lot of work, so keep this in mind if you want to share something to and with others. The cmri, the cpnodes are already here. What will add the magic? My answer is the simplicity and the low cost.
    I'm an enemy of "the effectiveness rules", but we have to be effective with respect to the priorities.
    Do we need "kiss" watchers?:ROFLMAO:
     
    Erik84750 likes this.
  15. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    Good input Vasilis, I appreciate your tempering and reflective mood.
    You make me think. Again.
    Grts,
    Erik
     
    vasilis likes this.
  16. Keith Ledbetter

    Keith Ledbetter TrainBoard Member

    279
    195
    12
    I just ordered the stuff for this tonight. I think it's a fantastic node and will let you know my progress
     
  17. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    Why are the images on the first post gone? Since the OP cannot have this done himself (edit time lapsed) I wonder why and who did this?
     
  18. Jimbo20

    Jimbo20 TrainBoard Member

    274
    178
    11
    The links to the image urls are still in the post, (eg https://img2.lght.pics/jAcn.jpg) unfortunately it looks like the server at lght.pics is no longer there....
     
  19. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    Is that server linked to trainboard.com, or is that a server used by the OP?
     
  20. Keith Ledbetter

    Keith Ledbetter TrainBoard Member

    279
    195
    12
    I will post a picture of one of mine finished with sockets and headers which can help. Eric could you copy and paste the schematic pic from your ea GB le file? Think that would fill in the missing pic info.

    I can also post the Arduino sketch where I translated all the French names and Americanized.
     
    vasilis and Erik84750 like this.

Share This Page