Diy Dcc Decoder For Lgb Turnout On Arduino (1 Day/5$)

BR95009

Registered
Hi, collegues,

Please find below demonstration of my self made prototype of DCC decode for LGB turnout.

To assemble this it will take one evening even for dummy and cost of this - about 5$ in total. :)

Welcome to IoT and fast prototyping world.

Later I will give all data to build it by you self.

 
So! Here it is:
1. Schematic:

LGB decoder schema.png LGB decoder maket.png soldering.png

2. First prototype with hang-on wires:

IMG_0804.jpg IMG_0811.jpg IMG_0813.jpg

3. Final design with ordered PCB:

IMG_0940.JPG IMG_0941.JPG
IMG_2296__.jpgIMG_2296.jpg


4. Sketch:
Code:
// LGB Decoder by BR95009. V02, on Arduino mini Pro
// DCC reading PIN = 2 (from opto coupler)

// DCC decoder library to use
#include <DCC_Decoder.h>

// DECODER PARAMETERS:
#define DECODER_ADDRESS  2     // Decoder address as in multiMouse.
#define TURN_DELAY     110   // milleconds to wait to move turnout. 
#define REVERS         0   // turn on reverse swithching if needed. - not realized yet

//Define interupt for DCC library
#define kDCC_INTERRUPT   0

//Driver control PINS for FAN8082 motor driver:
#define VIN1Pin 10
#define VIN2Pin  9

bool on_already = false; // flag to give command to turnout once but not for five consiquent similar DCC packets
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup(){
  //Serial.begin(9600);
  DCC.SetBasicAccessoryDecoderPacketHandler(BasicAccDecoderPacket_Handler, true);
  DCC.SetupDecoder( 0x00, 0x00, kDCC_INTERRUPT );
  pinMode(VIN1Pin, OUTPUT); pinMode(VIN2Pin, OUTPUT);
  //Serial.println("Decoder has started. Waiting for packets...");
  pinMode(13, OUTPUT); // set pin 13 as LED indicator for turnout state
  digitalWrite(13, LOW); //off at the beginnning
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop(){
  DCC.loop();// Loop DCC library
}
// Basic accessory packet handler
void BasicAccDecoderPacket_Handler(int address, boolean activate, byte data) {
  // Convert NMRA packet address format to human address (Roco multiMouse numbering)
  address -= 1; address *= 4; address += 1; address += (data & 0x06) >> 1; address += 4;
  boolean enable = (data & 0x01) ? 1 : 0;
  //Serial.print("Address sent: "); Serial.println(address, DEC);
  if ( address == DECODER_ADDRESS) { // if adress in packet matches adress of our decoder then do the actions
    //Serial.print("Basic addr: "); Serial.print(address, DEC); Serial.print(" enable(data): "); Serial.print(enable, DEC); Serial.print(" activate: "); Serial.println(enable, DEC);
    if ( enable && !on_already) { // TO in pos 0
      digitalWrite(VIN1Pin, HIGH); digitalWrite(VIN2Pin, LOW); digitalWrite(13, HIGH);
      delay(TURN_DELAY);
      digitalWrite(VIN1Pin, LOW); digitalWrite(VIN2Pin, LOW);
      //Serial.println("ON");
      on_already = true; //no more consequtive ONs.
    }
    if ( !enable && on_already) { // TO in pos 1
      digitalWrite(VIN1Pin, LOW); digitalWrite(VIN2Pin, HIGH); digitalWrite(13, LOW);
      delay(TURN_DELAY);
      digitalWrite(VIN1Pin, LOW); digitalWrite(VIN2Pin, LOW);
      //Serial.println("OFF");
      on_already = false;
    }
  }
}//End of sketch
 
Last edited:
Very nice job, but there looks to be some complicated Programmer Stuff that is beyond my ken.
JonD
 
That's why we pay intelligent people Jon.:D
Brilliant bit of work but I'm with Jon on this.
 
Looks like the code requires a library import? There seem to be various Arduino DCC libraries available on the 'net so not sure which one has been used here.

One of these days I must get round to playing with Arduino stuff, it should be "right up my street" but sadly don't seem to have the time to fiddle about with this sort of thing any more.
 
looks like a nice idea, I'd have the following questions:

1. what current can you handle through the optoisolator?
2. the $5 arduino is a "pro mini"?
3. I see these for $90$10, are you buying the cheapest clone and where?
4. You say $5 total, but you forgot the rest of the components, the optoisolators, the fw bridge, etc.

Nice idea, but what is the real cost, and can you make it handle the current of stall type motors, and how many could you handle from the same arduino?

I can buy sophisticated accessory decoders for abotu $10 per output, with local programming to change the address, motor type, and add local pushbuttons, in a box.

Greg
 
Answering shortly from Ipad:
- code is wrong, i will update it with right ones from my home pc.
- libraries for DCC decoder: i will give a link to github.
 
In the last picture, custom made PCB's? Are these available to purchase? Board layout designed in Eagle? Only reason for multiple questions, was looking to see if my 8FS adapter board could be made into a custom PCB
John

PCB i have ordered at local producer here in Moscow. Cost = 1 euro for board. Layout done in Fritzing software.
 
looks like a nice idea, I'd have the following questions:

1. what current can you handle through the optoisolator?
2. the $5 arduino is a "pro mini"?
3. I see these for $90$10, are you buying the cheapest clone and where?
4. You say $5 total, but you forgot the rest of the components, the optoisolators, the fw bridge, etc.

Nice idea, but what is the real cost, and can you make it handle the current of stall type motors, and how many could you handle from the same arduino?

I can buy sophisticated accessory decoders for abotu $10 per output, with local programming to change the address, motor type, and add local pushbuttons, in a box.

Greg

Hi, Greg,

Answering 1by1:
1. There no point to consider current for opto becouse there no load on it=> no current.

2. And 3. Yes, its arduino pro mini. 1,5$ at Banggood site, or you can find even cheaper.

3. I calculated in rubles in Russia and devided by exchange rate. Might be in UK a bit more expencive.

To handle the stall motors - its not a problem. I give very short impuls to the motor, so there no problem with overload.

How many motors?: one driver=2 logical pins. Arduino has 14.

But idea was to make single small decoder for single LGB drive.

By the way, the waterproof point is following: i use lacquer to cover the assembly and use simply fold box made of thin plastic of office folders.

For 10$ sofisticated decoders - a link could be very interesting to see. ;)
 
Maybe a little bit of misunderstanding here, so I will try better.

1. I could not get the schematic large enough to read the IC used to drive the turnout, I thought it was an optoisolator, but looks like it is a FAN8082, about $1 each.

2. I find even at banggood they are about $2.50 each

So I can see about $5 to make a single channel unit.

I use Digitrax DS-64 unit for driving 4 turnouts. I can get it for about $45.

Works for momentary and stall (continuous) turnouts, can get pulse, DC power, or reversing DC polarity.

3 status LEDs and 2 pushbuttons to set modes of operation and addresses for the 4 outputs. Pushbuttons can be added for local manual control.

So for $5 a turnout, the price is ok, but needs more features. I did not look at the current cabability of the FAN8082, but it appears sufficient for any turnout motor.

Greg
 
Hi, Greg, thanks for replay.

The point is the stand alone decoder for single particular turnout LGB.

For additional functions: there open software and rest of outputs of arduino so you can connect light signal or smth else and add any functionality.

LED and pushbuttons you could add outofbox.

Arduino at Banggood - 2$ now.
 
Hi all,

I have updated right sketch (see in few messages above).

And attached the library. Its from Kevin Snow (mynabay). Its disappeared from his site so I put it here.
 

Attachments

Hi there, there is a small error in the schematic, capacitor C4's orientation should be across to the Schottky Diode, thence to the positive to the 6N137 (Pin 8) and VCC on the Arduino, then the GND can be moved from C2 to C4

Well, may be. I not really catch the point what you mean "across". Better to draw.

Picture attached, circuit minus the FAN8002, constructed and works and no problems, voltage is stable.

I use FAN8082 driver, which is 18V rated indeed. But voltage impulse is too short, so 18V is ok even for 24V Massoth.

The Arduino Pro Mini and a Massoth 1210Z Central Station have real problems communicating with each other, further investigation may shed some light on this,

I have to notice that address space in sketch is adjusted to Roco multiMouse controller.

If you use for instance ESU Ecos or Lenz then address space is shifted to +4 addresses.

(or -4, i dont remember exectly). Comment "address += 4;" in sketch.
 
Well.., I not really got the point. My capacitor on VCC and GND. Yours - as well. Whats is the difference?
 
Back
Top Bottom