Geoff Bunza geoffb

One of my earlier entries:  SMA10 – Build a 17-Function DCC Decoder for about $5 ( https://forum.mrhmag.com/post/sma10-%E2%80%93-build-a-17function-dcc-decoder-for-about-5-12197796 ) generated a considerable amount of interest regarding the possible enhancement for controlling Servomotors (Servos). This is my next version of a 17 Channel Multifunction DCC Decoder based on a low cost $2.56 Arduino Pro Mini. This version supports configuring each of the 17 function pins for On/Off (LED/TTL) Control, or Configurable Blinking Control, or Configurable Servo Control, or Configurable Pairs Blinking Control. Yes, that does mean it can support 17 servos, each with rate, start point, and end point setting via DCC CV’s, per pin, as well as new LED configurable functions. Read On. Additional doc found here: http://model-railroad-hobbyist.com/node/19775There is another decoder version added herein. Look for "New Decoder Version to Control Lighting Groups" in Page 12 of the Comments: http://model-railroad-hobbyist.com/node/19446?page=11   The most recent Update can be found here: SMA20 New Low Cost 17 Channel DCC Decoders with PC Boards & Dual Motor, LED, & Servo Control    https://forum.mrhmag.com/post/sma20-low-cost-17-channel-dcc-decoders-ver-6-01-with-soundtriggered-soundstepperdual-motorled-and-12201920

Bemchtop.JPG 

Jim at BSME

LEDs don't work that way

An LED works at a fixed voltage, changing the voltage will only delay when the LED turns on/off, so we have to do it a different way.  You might see a difference if you varied the current over the operating range of the LED, but I don't think it would really be noticeable and it would not start at off, it would be on and may get brighter, so we have to do it another way.

What we do is trick our eyes into thinking the LED is dim and gets brighter by Pulse Width Modulation (PWM), of which the Arduino pro mini has 6 pins that can do that. Other versions of the Arduino have more/less PWM pins. To create this PWM signal we use the function analogWrite, what happens under the hood is the Arduino pulses the LED with an square wave on/off. The pulses are at the full voltage needed for the LED to operate, length of the on pulse is determined by the value passed to analogWrite. As the on pulse width increases the amount of time the LED is on increases.  The LED turns on and off with these pulses, but this happens so fast we can not see the individual pulse, our eye averages the pulses giving the impression the LED is dim and gets brighter.  There is example code provided with the Arduino IDE to do a fade, it starts the LED off, fades up to full "brightness" and then fades back down to off, and continues as long as there is power to the Arduino.

/*
Fade
This example shows how to fade an LED on pin 9
using the analogWrite() function.
This example code is in the public domain.
*/
int led = 9; // the pin that the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 9:
analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0
fadeAmount = -fadeAmount ; } // wait for 30 milliseconds to see the dimming effect delay(30); }
Reply 0
Geoff Bunza geoffb

@Michael D and Jim B RE: LED Fading

Hi,

Michael, the resistor/capacitor solution can be made to work but has enough problems and adds extra cost that it commonly is avoided. The output circuit of the processor in the Pro Mini doesn't like to drive a heavy capacitive load. I'm going to leave it at that unless you really want the technical details.

Jim's comments are mostly correct but could use a little clarification. LEDs work over a very narrow voltage range, like 2.5 - 3.2 Volts for a modern ultrabrite green LED. An old (1986) red LED might operate over a 1.65-1.9 Volt range-- not much. But the real specification you need to pay attention to is that the brightness of a LED is proportional to the current through the LED, usually maxing out at 20ma for the most common. You can also find a few LEDs that have a maximum current of 10ma and a bunch of the really new ones that want over an amp! I am ignoring those for now.

Since the operating current range (and voltage range) is so small, the common technique to control LED brightness (as Jim pints out) is to vary the duration of the "ON" time at a (usually) constant frequency, hence the LED receives a repeated ON "pulse," and changing the pulse duration changes the perceived brightness of the LED, hence Pulse Width Modulation or PWM. This is not a square wave, which has equal on and off times, and which would create some intermediate brightness point. Also the mechanism in the Arduino using analogWrite is limited to a select set of pins per each different Arduino model because this is a hardware feature.

You may already know that some of the standard Arduino libraries use these hardware functions to control servos, and they are limited to the same pin sets. However, ANY Arduino Digital Output pin can be programmed to generate an appropriate PWM signal, it simply requires more work on the programmer's part. Note, for example, that this decoder can be configured to control 17 servos. It does this exclusive of the hardware PWM features. Remember that this little processor can execute 20,000,000 instructions (or so) a second-- that's a few to play with !

Fading a LED in the decoder was already discussed here:

http://model-railroad-hobbyist.com/node/19446?page=2

Look for @Tom Fading On a LED

There is a small explanation and code to download for a decoder configuration.

The fact that there are several ways to accomplish this, should be a big indicator for the reader that this is a very flexible tool. That is the point to remember, and why it's worth the effort to learn to use it in modeling.

Have fun! 

Best Regards,

Geoff Bunza

 

Reply 0
Loeter

Hi Geoff, which processor

Hi Geoff,

which processor will be the best for signaling? As I have no experience with different type of Atmel's and Arduino boards, I cannot give you an answer. With your example of fading I've made some tests and it looks good. But when I look to the signal aspects I have no idea how to solve the fact that two LEDs respectively two outputs must be linked. Maybe you have some helpful hints or a program.

Best Regards

Loeter

Reply 0
Geoff Bunza geoffb

@Loeter re: Signaling

Hi Loeter,

Since your questions have been directed at controlling the lights on a signal mast, I am answering your question in this context, as opposed to controlling signaling logic for a portion or the whole of a layout.

Virtually any of the Arduino boards will handle signal mast control. Any version of the Pro Mini (which I use because of cost and size), and Arduino Uno, Nano, Due, Micro, etc. can do the job too. These versions exist because they were optimized for different purposes. The Uno line has a wide variety of interface boards, called shields, which you can get to do many things including motor control, GPS interfaces, small LCD displays, Bluetooth, BLE, and LAn interfaces, etc -- quite a bit and there are many more. There are differences among these concerning speed, number and kind of interface pins, size, and power consumption. Virtually all the sketches I post will run without modification on the Pro Mini and Uno types and most of the others too. Look for price differences and availability too. You can learn about their feature comparisons here: 

https://www.arduino.cc/en/Main/Products

I'll try to put an example sketch together for you to control multiple output as discussed, with fade, but you will have to wait until I get through the NMRA convention this month. I will need an answer to my last question "To be precise, four function keys (say F0-F3) would control a set of 5 LEDs: 2 red, 1 green, 1 yellow, and 2 white? Does this account for the full pattern?" I will put something together assuming you need to control 5 independent LEDs per signal mast unless you advise otherwise.

Have fun! 

Best regards,

Geoff

 

Reply 0
Loeter

Signal Aspects

orHello Geoff,

here are the signal aspects and why four funtions are needed.

The abbreviations Hp0...Sh1 were defined by the German Railways and show the aspects:

Hp0 = Stop (two red LEDs)

Hp1 = Clear (one green LED)

Hp2 = Approach slow (one green and one yellow LED)

Sh1 = Clear for Switching (one red and two white LEDs)

As you can see now, four F-Keys are needed.

I hope it helps to understand the funktion of this type of signals.

Best Regards

Loeter

Reply 0
Loeter

(No subject)

ignal(1).jpg 

Reply 0
Geoff Bunza geoffb

@Loeter

Hi Loeter,

OK... it looks like you will need to control 5 independent LEDs (the two White ones are on or off together) with four functions. This should be pretty easy. I am going to assume the "decoder" will function entirely as a manual signal decoder, so out of the 17 controllable digital pins, I will build a configuration so a set of 4 functions can control a configurable group of 5 outputs. This should allow one :decoder" to control 3 signals or signal groups.

Do you really want this to be a function decoder or an accessory decoder?

Sound right?

Have fun! 

Best Regards,

Geoff

Reply 0
Loeter

Top Solution

Hi Geoff,

you are completely right and I think a function decoder is the right choice. Combined with fading it will show perfect signal aspects. I hope I do not disturbe you too much and I appreciate that you help so much with your deep knowledge.

Best Regards

Loeter  

Reply 0
Geoff Bunza geoffb

@Loeter

Hi Loeter,

OK, I will run with this definition. 

Please have patience for a couple of weeks until I survive the NMRA national convention. This should not be difficult and I'll work with you until it works for you.

Have fun!  

Best regards,

Geoff

Reply 0
Loeter

Great! Thanks a lot. Loeter

Great!

Thanks a lot.

Loeter

Reply 0
Geoff Bunza geoffb

New Decoder Version to Control Lighting Groups w/Fading On/Off

New Decoder Version to Control Lighting Groups of 5 Pins with 3 Groups of 4 Functions w/Fading

Hi All with special attention to Loeter.

I have uploaded a new decoder version which will control 3 Groups of 5 I/O pins (as in for LEDs), with each lighting group having a configurable pin pattern, and each function having a configurable set of lights to turn on and off. When any of the lights/LEDs turn on or off they will do so with a gradual fade, rather than instantaneously.

The folder and Arduino sketch can be downloaded here:
http://model-railroad-hobbyist.com/sites/model-railroad-hobbyist.com/files/users/geoffb/decoder_sma12_led_groups.zip

After unzipping, place the folder into your Arduino folder on your computer, start the Arduino IDE/Editor and load it into your decoder.

In the sketch/program you will find:
byte FPins_Assigned [12][5] = {   // This array defines the pins controlled by each function
    {3,4,5,6,7},  // F0
    {3,4,5,6,7},  // F1
    {3,4,5,6,7},  // F2
    {3,4,5,6,7},  // F3
    {8,9,10,11,12},  // F4
    {8,9,10,11,12},  // F5
    {8,9,10,11,12},  // F6
    {8,9,10,11,12},  // F7
    {13,14,15,16,17},  // F8
    {13,14,15,16,17},  // F9
    {13,14,15,16,17},  // F10
    {13,14,15,16,17}   // F11

Each group specifies the actual IO pins that the respective function will control.
And this:
byte Function_Lites [12][5] = {  // This array defines the Lights/LEDs controlled in each light group per function
    {1,1,0,0,0},  // F0 Hp0
    {0,0,1,0,0},  // F1 Hp1
    {0,0,1,0,1},  // F2 Hp2
    {0,0,1,1,0},  // F3 Sh1
    {1,1,0,0,0},  // F4 Hp0
    {0,0,1,0,0},  // F5 Hp1
    {0,0,1,0,1},  // F6 Hp2
    {0,0,1,1,0},  // F7 Sh1
    {1,1,0,0,0},  // F8 Hp0
    {0,0,1,0,0},  // F9 Hp1
    {0,0,1,0,1},  // F10 Hp2
    {0,0,1,1,0}   // F11 Sh1

Each group here defines which Pins/LEDs will be turned ON/OFF by the respective Function.

When each LED comes ON or turns OFF it will fade On or Fade Off respectively.
Note Bene: Turn Off all functions in a group before turning the next Function in the same group ON.
Change one function at a time. I did not bother with any special overlapping timing here.

The preset configuration should match the German Signaling configuration Loeter had asked for, but
this Decoder can be used and configured to control any groupings you want (within the limits of the definition).

So, in summary... there are 3 groups of 5 pins controlled by 4 functions each. (Loeter requested a function (mobile decoder) configuration too). The fading is (by my eye) a bit better than my last attempt, too.

I will have another decoder version coming soon, dealling with LED control with fading, influenced by direcion too.

Have Fun!  

Best regards,
Geoff

 

Reply 0
Loeter

Hello Geoff, thank you very

Hello Geoff,

thank you very much for the "special" version of the decoder program. When I try to compile it, I receive an error message " ´FN_GROUP´ has not been declared". 

Have tried to find the problem, but could not solve it. Do you have a hint for me?

Best Regards

Loeter

 

Reply 0
Geoff Bunza geoffb

@Loeter

Hi Loeter,

Yoe are welcome! 

I strongly suspect you are not using the newer NmraDcc library (Since this is SMA 12-- look in my blog for the later entries-- http://model-railroad-hobbyist.com/blog/geoff-bunza). You can download the later library and examples here-- http://home.comcast.net/~gbglacier/Articles/New-Dual-MULTIFunction-Decoder.zip

Remember to delete the old library in your .../Arduino/libraries/...  folder, usually found (in Windows machines) in your Documents folder.

Have fun! 

Best regards,

Geoff

Reply 0
Toniwryan

Control panel

Geoff,

  After reading most of the threads related to this project, I am curios about the possibilities of using an NCE "mini panel" or a second Arduino pro-mini to read the input switches and send a "DCC message" to the SMA 17.  This would ease up the timing constraints and complex coding issues.  A third SMA 17 could be set to respond to the same address messages as the servo controller, but be used to control indicators, and signalling.  Is there a simple library to allow us to SEND DCC commands from the Arduino?  I am envisioning this being used on a small shelf style layout, so the Arduino DCC bus would not necessarily be connected to the main DCC bus (though that might be nice to consider). 

The other question is related to crossovers and controlling two servos off one output.  Would this be possible, or would it be better to "gang" the servos in software to have them controlled by one input?

All these separate Arduino controls are starting to sound like LCC ...

Toni

 

Reply 0
Geoff Bunza geoffb

@Toni re: Arduino as a DCC Control / Interface

Hi Toni,

You are right on target.Not only is it possible, it's desirable in many modeling instances to use an Arduino as the DCC command originator.

Preamble (Bear with me for a bit):
Realize that what is standardized with DCC decoders is fundamentally the communication protocol, not their use. Consider any decoder as a 2-wire control interface to motors, lights servos, relays, etc. This decoder series attempts to show you can control all these with a 2-wire connection. In really small animated models --like a helicopter (http://model-railroad-hobbyist.com/node/23598) or small float plane (http://model-railroad-hobbyist.com/node/14762) minimizing the wire connections is important.

Further, there is no reason why you couldn't run multiple DCC busses around a layout-- say one for train control, one for signalling and one for animation. Cost would be an obvious limitation. But suppose you could have DCC control without the overhead that an NCE, Digitrax, or other system provides-- Much fewer features, but radically less cost-- say for $8 or less. I am not talking about a DCC base station / throttle look-alike.

Back to your question Toni:

Quote:


Is there a simple library to allow us to SEND DCC commands from the Arduino?

Answer-- Yes-- There are a couple. The one I used in both the operating helicopter and the Floatplane animation orchestration were conducted by a single Arduino Pro Mini running the CmdrArduino library by Don Goodman-Wilson (see http://railstars.com/software/cmdrarduino/and download from https://github.com/Railstars/CmdrArduino).It takes a little getting used to, but it does work! Following here is the Arduino Sketch I used for controlling the Helicopter. You'll note that DCC commands are often resent to the decoder. Much of what a commercial base station does for you is in your hands when you do something like this.

But realize, that it becomes entirely possible to have a dedicated "DCC Command Station" (in principle) for a single animation-- pretty neat!

As an aside I am getting some encouragement to write these up, so they are being put on the pile of "to-do" projects-- no timeframe or ETA.

Quote:

The other question is related to crossovers and controlling two servos off one output.  Would this be possible, or would it be better to "gang" the servos in software to have them controlled by one input?

I have successfully driven 2 servos with one output pin-- However, the cheap 9G servos I use do not  behave alike at all. One may swing from 15-175 and the next from 35-168. The reason why this can be a problem is that the current draw from many of these goes way up when you attempt to drive them beyond their limits. It is easy to simply modify the Arduino sketch so one function or Accessory address drives 2 or more servos on different pins. If you need help with this, just ask.

Quote:

All these separate Arduino controls are starting to sound like LCC ...

In a way, perhaps yes. But my use of these is not for "global layout control" (my words alone), but rather for what might be considered to be "local" or "distributed" control. It's a bit different way of viewing the modeling world. I believe both are entirely appropriate, and I think LCC has much potential.

Have fun!  

Best regards,
Geoff Bunza


/********************
SOUND via custom programmed Digitrax SDN144PS
* The DCC waveform is output on Pin 9, and 10 (inverted)
*
********************/
#include < DCCPacket.h>
#include < DCCPacketQueue.h>
#include < DCCPacketScheduler.h>
#define funct0 0x01
#define funct1 0x02
#define funct2 0x04
#define funct3 0x08
#define funct4 0x10
#define DCC_EN 2
#define p1     8    // F0 Red/Green Navigation Lights
#define p2     7    // F2 Rear Red Rotating Beacon
#define p3     6    // F3 Cabin Light and Lower Spot Light
#define p4     5    // F1 Engine Control Turbine Start/Stop & Engine Revs
DCCPacketScheduler dps;
uint8_t functs = 0;
uint8_t F0 = 0;
uint8_t F1 = 0;
uint8_t F2 = 0;
uint8_t F3 = 0;
uint8_t F4 = 0;
uint8_t F40 = 0;
uint16_t decoder = 3;
int8_t last_locoSpeed=0;
uint16_t locoAdr=3;  
unsigned long timing_start,timing_end;
int lit_time= 5 ;
int8_t dcc_speed = 1;

void setup() {
  pinMode(p1, INPUT);    
  pinMode(p2, INPUT);  
  pinMode(p3, INPUT);  
  pinMode(p4, INPUT);
  digitalWrite (p1,HIGH);
  digitalWrite (p2,HIGH);
  digitalWrite (p3,HIGH);
  digitalWrite (p4,HIGH);
  dcc_speed = 1;
  functs = 0;
  pinMode(DCC_EN,OUTPUT);    // will be kept high, DCC_EN pin
  digitalWrite(DCC_EN, 1);
  delay(6000);
  dps.setup();
  delay (5);
  dps.setSpeed128(locoAdr,DCC_SHORT_ADDRESS,dcc_speed); // Speed 0 forward
  delay (10);
}
void loop() {  
    if ((digitalRead(p1)&&digitalRead(p2)&&digitalRead(p3)&&digitalRead(p4))==HIGH) {
      while (true) {
        functs = funct2;                  // Rotating Rear Beacon ON
        dcc_cmd_repeat ( lit_time );
        functs = funct0

        dcc_cmd_repeat ( lit_time );
        functs = funct0
        dcc_cmd_repeat ( lit_time );
        functs = funct0
        dcc_cmd_repeat ( 8 );
        dcc_speed = 7 ;                      // Start Engine Rotation
        dcc_cmd_repeat ( 1 );
        dcc_speed = 8 ;                      // Start Engine
        dcc_cmd_repeat ( 1 );
        wait_dcc(50);
        dcc_speed = 9;                      // Rev Up Engine
        dcc_cmd_repeat ( 2 );
        dcc_speed = 10;                      // Rev Up Engine
        dcc_cmd_repeat ( 2 );
        dcc_speed = 11;                      // Rev Up Engine
        dcc_cmd_repeat ( 3 );
        dcc_speed = 12;                      // Rev Up Engine
        dcc_cmd_repeat ( 3 );
        dcc_speed = 13;                      // Rev Up Engine
        dcc_cmd_repeat ( 2 );
        dcc_speed = 14;                      // Rev Up Engine
        dcc_cmd_repeat ( 1 );
        wait_dcc(700);
        dcc_speed = 15;                      // Rev Up Engine
        dcc_cmd_repeat ( 14 );
        functs = funct0
        dcc_cmd_repeat ( 1 );
        dcc_speed = 15;                      // Rev Down Engine
        dcc_cmd_repeat ( 3 );
        dcc_speed = 14;                      // Rev Down Engine
        dcc_cmd_repeat ( 2 );
        dcc_speed = 13;                      // Rev Down Engine
        dcc_cmd_repeat ( 3 );
        dcc_speed = 12;                      // Rev Down Engine
        dcc_cmd_repeat ( 2 );
        dcc_speed = 11;                      // Rev Down Engine
        dcc_cmd_repeat ( 4 );
        dcc_speed = 10;                      // Rev Down Engine
        dcc_cmd_repeat ( 4 );
        dcc_speed = 9;                      // Rev Down Engine
        dcc_cmd_repeat ( 4 );
        dcc_speed = 8;                      // Rev Down Engine
        dcc_cmd_repeat ( 4 );
        dcc_speed = 6;                      // Rev Down Engine
        dcc_cmd_repeat ( 5 );
        dcc_speed = 1;                      // Rev Down Engine
        dcc_cmd_repeat ( 4 );
        functs = funct2
        dps.setFunctions0to4(locoAdr,DCC_SHORT_ADDRESS,functs); // Nav Lights Off
        wait_dcc(lit_time*600);
        functs = funct3;
        dps.setFunctions0to4(locoAdr,DCC_SHORT_ADDRESS,functs); // Top Light Off
        wait_dcc(lit_time*600);
        functs = 0;
        dps.setFunctions0to4(locoAdr,DCC_SHORT_ADDRESS,functs); // F3 cabin lights Off
        wait_dcc(lit_time*600);
        functs = 0;
        dps.setFunctions0to4(locoAdr,DCC_SHORT_ADDRESS,functs); // F3 cabin lights Off
        wait_dcc(lit_time*600);
        functs = 0;
        dps.setFunctions0to4(locoAdr,DCC_SHORT_ADDRESS,functs); // F3 cabin lights Off
        wait_dcc(lit_time*2200);
      }
    }
    else {
      while (true) {
        if (digitalRead(p4)==HIGH) {
          
          functs
          dcc_cmd_rpt ( 8 );
          dcc_speed = 7 ;                      // Start Engine
          dcc_cmd_rpt ( 1 );
          dcc_speed = 8 ;                      // Start Engine
          dcc_cmd_rpt ( 1 );
          wait_dcc(50);
          dcc_speed = 9;                      // Rev Up Engine
          dcc_cmd_rpt ( 2 );
          dcc_speed = 10;                      // Rev Up Engine
          dcc_cmd_rpt ( 2 );
          dcc_speed = 11;                      // Rev Up Engine
          dcc_cmd_rpt ( 3 );
          dcc_speed = 12;                      // Rev Up Engine
          dcc_cmd_rpt ( 3 );
          dcc_speed = 13;                      // Rev Up Engine
          dcc_cmd_rpt ( 2 );
          dcc_speed = 14;                      // Rev Up Engine
          dcc_cmd_rpt ( 1 );
          wait_dcc(700);
          dcc_speed = 15;                      // Rev Up Engine
          dcc_cmd_rpt ( 8 );
          while (digitalRead(p4)==HIGH) {
            dcc_cmd_rpt ( 2 );
          }
          functs = (functs&(~funct1))&0x1f ;  // Start Turn Off Engine
          dcc_cmd_rpt ( 1 );
          dcc_speed = 15;                      // Rev Down Engine
          dcc_cmd_rpt ( 3 );
          dcc_speed = 14;                      // Rev Down Engine
          dcc_cmd_rpt ( 2 );
          dcc_speed = 13;                      // Rev Down Engine
          dcc_cmd_rpt ( 3 );
          dcc_speed = 12;                      // Rev Down Engine
          dcc_cmd_rpt ( 2 );
          dcc_speed = 11;                      // Rev Down Engine
          dcc_cmd_rpt ( 4 );
          dcc_speed = 10;                      // Rev Down Engine
          dcc_cmd_rpt ( 4 );
          dcc_speed = 9;                      // Rev Down Engine
          dcc_cmd_rpt ( 4 );
          dcc_speed = 8;                      // Rev Down Engine
          dcc_cmd_rpt ( 4 );
          dcc_speed = 6;                      // Rev Down Engine
          dcc_cmd_rpt ( 5 );
          dcc_speed = 1;                      // Rev Down Engine
          dcc_cmd_rpt ( 4 );
          wait_dcc(lit_time*2600);
        }
        dcc_cmd_rpt ( 1 );
      }
    }
}
void dcc_cmd_rpt (int seconds_cnt ) {
   for (int ii=0; ii < seconds_cnt; ii++)  {
        if (digitalRead(p1)==HIGH) functs
          else functs = (functs&(~funct0))&0x1f ;
        if (digitalRead(p2)==HIGH) functs
          else functs = (functs&(~funct2))&0x1f ;
        if (digitalRead(p3)==HIGH) functs
          else functs = (functs&(~funct3))&0x1f ;
        dps.setSpeed128(locoAdr,DCC_SHORT_ADDRESS,dcc_speed); // Start
        dps.setFunctions0to4(locoAdr,DCC_SHORT_ADDRESS,functs); // Turbine sound on
        wait_dcc(949);
      }
}
void dcc_cmd_repeat (int seconds_cnt ) {
   for (int ii=0; ii < seconds_cnt; ii++)  {
        dps.setSpeed128(locoAdr,DCC_SHORT_ADDRESS,dcc_speed); // Start
        dps.setFunctions0to4(locoAdr,DCC_SHORT_ADDRESS,functs); // Turbine sound on
        wait_dcc(950);
      }
}
int wait_dcc (int wait_time) {
  unsigned long tempul;
  tempul = wait_time;
  timing_start = millis();
  timing_end = timing_start+ tempul;
  while (timing_start< timing_end) {
  dps.update();
  timing_start = millis();
  }
}

 

Reply 0
Loeter

Very Nice Result

Hello Geoff,

after adding the actual version of nmracdcc.h, it works fine. Now I understood the use of arrays and it is very easy to change the signal aspect to other types of signals. Your program has a big potential for further features and after seeing the result, I try to find additional applications.

Thanks a lot and

Best Regards

Loeter 

Reply 0
Geoff Bunza geoffb

@Loeter re:Very Nice Result

Hi Loeter,

I'm glad you like your results.

I tried to adjust the fade on and off to something that looked realistic. You can adjust the fade timing yourself by changing the value of fadedelay. Also, the value of 60 incremental steps for the fade was chosen experimentally (that is by trial and error) until it looked appropriate. This is another value you can adjust. See the partial example code below:

void exec_function (int f_index, int FuncState)  {
  #define fadedelay 5
       if ((FuncState==1) && (!Last_Function_State[f_index])) {
              for (int i=0; i< 60; i++) {
                for (int j=0; j< 5; j++) if (Function_Lites[f_index][j]==1) digitalWrite( FPins_Assigned[f_index][j],1);
                delay(fadedelay*i/60.0);

There are a couple of unused pins, too. So you could consider using them to activate a relay or servo in conjunction with the signal change. This is one of the real values in using these-- they are really flexible and very low cost. Enjoy.

Have fun! 

Best regards,

Geoff

Reply 0
Ingo

Help Wanted

Hi Geoff,

Please excuse my English, I use the Google Translater.

I have been following with great interest and admiration of your performance your publications.
I can set the decoder from the article SMA10 successfully worked super on my Z21 Roco as an accessory decoder.
Unfortunately, I do not understand the procedure for the following decoders.

Unfortunately I have no end levels to understand'deine following versions:

--------------------------------------------------------------------------------------------------------------------
Open one of the sketches (programs), set your decoder address, and you are good to go! Once you have loaded the Pro
Mini, remove the “//” in the line: “//#define DECODER_LOADED” so it looks like below:

/ ******** UNLESS YOU WANT ALL CV'S RESET UPON EVERY POWER UP

// ******** AFTER THE INITIAL DECODER LOAD REMOVE THE "//" IN THE FOOLOWING LINE!!

#define DECODER_LOADED

And then RELOAD the Pro Mini. This will set up all the default CV’s and then permit you to modify them with your DCC
controller of choice. You can even reset the short address in CV 1.
--------------------------------------------------------------------------------------------------------------------

If time permits, ask a few words of explanation. I'll unfortunately else
not further.

Thank you for your work, Geoff

Ingo

Ingo.Faehse@t-online.de

Reply 0
Geoff Bunza geoffb

@Ingo re:Start-Up Code Explanation

Guten Tag Ingo,

I'm glad you got your decoder to work.

Your question about this portion of the sketch (program) is a good one!

Like commercial decoders, we want to program an address and starting CV Values into our decoders and have the decoder remember these values. In the Arduino Pro Mini there is a small memory (called an eeprom -- Electrically Erasable Programmable Read Only Memory) which can be read and written that will retain its values even when powered off and on. This memory is used to store the decoder address. However, when you purchase a new Arduino, there is no guarantee whatsoever of what is in the eeprom memory. Unfortunately the Arduino does not have a way of setting the eeprom memory to known values before the program starts. Some people have relied on hoping that the values of the eeprom are all 0's but in reality this is not reliable. Many manufacturers load the boot program and the "Blink" program to test their Arduinos, and others may run more thorough tests-- including testing the eeprom, so we cannot rely on what is in the eeprom.

The code You refer to is used to do a first load, or a "cold" load of the Arduino with no assumptions made. Once the initial values are set, you can program them with Ops Mode DCC Programming. But to allow the new values to be programmed and saved, the address needs to be set, and the initialization code needs to be "turned off."

When you remove the “//” in the line: “//#define DECODER_LOADED” your action is un-commenting the line, making it:  #define DECODER_LOADED  which tells the program not to initialize the eeprom CV's later in the startup()  code .

If you always wanted the initial address and CV values to be reset every time the decoder powers on, leave the line commented (untouched).

I hope this makes it more clear. If not,  please ask more questions.

Have fun! 

Best Regards,

Geoff Bunza

Reply 0
chubber

You lost me at the first hurdle

Geoff,

You are clearly  an intelligent  and informed man, but your first paragraph  lost me entirely.

I'm  not ignorant or uneducated but it is just gobbly-gook to me because I don't  speak  your  language.

If I started a thread with 'Practical waste removal on hand-cut concealed  mitre dovetails ' would you be  any wiser, or want to look deeper into my  offering?

Perhaps if I had written 'How to cut an invisible strong joint in wood so that no end-grain is left showing' I might have helped you decide whether or not the subject was for you.

What I often find is that we tend to think that everyone reading MRH speaks our own technical patois,  it ain't  so.

I accept that you don't  need to explain what a servo is/does, but, 'Arduino'? It sounds like an

Italian sea-food dish....

Electronic threads that start with 'How to stop your locomotives hitting the buffers...' or controlling  a semaphore signals and interlocking them with turnouts using servos' woulld grabmy attention.

I once went to a school to give a talk on 'Trees, and the part they play in our daily lives' and on arrival discovered my audience were 8-9 year olds. My charts with range and distribution, xylem structure, photosynthesis etc went out the window, we drew trees onthe chalk-board with little birds in them, and stressed how no-one shold vandalise a tree.
Please give your stuff a 'chalk-board' title for electronic 8-9 year olds like me, I might even be encouraged to try and learn something....

Respectfully, Doug.

Reply 0
Jim at BSME

Starting point

Doug, of course that is one of the problems with this type of forum, if you don't start at the beginning of the thought process, one can easily be lost. And since the threads get displayed on the recent blog posts by when any response happens, you might see this post even though you haven't see the beginning threads to give you background.

Geoff has written many blog posts about Scale Model Animation (SMA) I think he is up to 18!  I don't remember what all they are, but if you type scale model animation in the MRH search box and hit search, you will find them all.  Some of the early ones were showcases of Geoff's work, but for the Ardunio I would start at:  Scale Model Animation 8: Starting Projects and Virtual Rooms for Modeling.

You can always Google Ardunio to find out what it is, here is the technical definition: "Arduino is an open-source computer hardware and software company, project and user community that designs and manufactures microcontroller-based kits for building digital devices and interactive objects that can sense and control the physical world."  This definition to me is overly complicated knowing what an Ardunio is and having used them. I think the best way is to think of it as a micro sized (~3/4" x ~1.5" for the mini pro) computer that you write programs (called sketches) for to read input (e.g. button push), and write output (e.g. turn on/off LEDs)

By the way Ardunio started at Interaction Design Institute Ivrea in Ivrea, Italy.

Doug can you edit your post to remove all the blank lines after you signature?  If they are not in your post then it just must be a bug in the display of your post.

Thanks, and I hope my explanation helps,

Reply 0
Craigdhepburn

Doug I think that is an

Doug I think that is an insult to Geoff and the hundreds of hours He has spent giving us all his sketches and projects and answering all our questions

it is not for him to explain to grade twelve work to grade ones

Geoff thanks once again for getting me started with Arduinos 

four super projects completed, grade crossing, servo control, loco net input for light control, loco net output from infra red detection, all working thru Digitrax and Railroad and co computer control

next project is going to be automated control of faller car systems

 

keep up the good work Geoff

Reply 0
Babbo_Enzo

"Ardunio started at

"Ardunio started at Interaction Design Institute in Ivrea, Italy" , yes, he born in Italy but, friends, please, don't put any Arduino "in" the sea, and never "eat" ... it helps at a different "interaction" level

definively... it's NOT a "Sea food"!

Reply 0
joef

Not at all

Quote:

Doug I think that is an insult to Geoff and the hundreds of hours He has spent giving us all his sketches and projects and answering all our questions ...

In the spirit of "the only stupid question is the unasked question", then I don't think Doug's post is insulting - he's just pointing out how some basic context every so often could be helpful, and he did sign his post "Respectfully, " ... so I don't think Geoff would see it as an insult.

We face the same thing with MRH. We regularly get requests from readers who are having problems getting a download of MRH to work - and when we tell them things like "do a right click", we may get back "what's a right click?"

Every so often we find we just need to tutor folks in the basics of using a computer device. It's just the way it works with technical stuff, and my advice is: get used to it.

Same here - repeating the basics every so often is a good idea. People aren't being mean, we're just getting new folks show up regularly and we need to remember to bring them up to speed by repeating a few basics.

Reply 0
Geoff Bunza geoffb

@Doug and a Path to Clarity -- Hopefully !

Hi Doug,

Quote:

your first paragraph  lost me entirely.

I'm not sure which paragraph you read first along the way, as this blog has evolved extensively
since the first entry, but I will try to make this more clear.

The Arduino is a set of tiny processors (computers) on boards, set up to allow easy use by people who want to use them as a tool, rather than focus on the details of the technology. They were originally conceived as a teaching tool in Italy. All aspects of their design and construction are available for public use with no restrictions. These are manufactured and distributed by many companies worldwide, some for as little as $2 quantity one including shipping!

With such a cheap and powerful tool, I have built and offered to the modeling community a series of tested, working, and packaged instructions (called Sketches or programs) to set up one of the smallest and cheapest of this family of modules, called the "Arduino Pro Mini" to act as a very low cost and versatile DCC decoder with many practical functions-- that is what these blogs are all about-- sharing my efforts with other modelers-- gratis. Yhis is not a commercial product, but I dare say there are hundreds, maybe thousands of these that are in use by modelers around the world-- judging from the feedback.

In the original effort, I pointed out that I am not a proponent of asking modelers to learn how to program-- just learn how to use these new tools. You can stop there or take it as far as you want. These are used in high schools and colleges all over the world to teach basic concepts. I am not trying to do that here, merely trying to show others that these little guys can add a great deal to your modeling enjoyment.

If you are interested, A step by step cookbook for the modeler can be found here:
Starting from Scratch with an Arduino Pro Mini (or Moteino):
http://mrhpub.com/2014-11-nov/land/#99

A good start for the Arduino Learning curve would be the tutorials at:
http://arduino.cc/en/Tutorial/HomePage
/> and there are allot of topics there for search for a subject or browse
or
http://www.instructables.com/files/orig/F3J/MTJN/FVW22MXN/F3JMTJNFVW22MXN.pdf
/> or
http://www.richardvannoy.info/arduino.php
/> or
http://arduino-info.wikispaces.com/TUTORIALS

Now these offer info at different learning levels so pick one you are comfortable with, or ask a specific question and I will try to point you in the right direction.

If you are using an Arduino Pro Mini (cheapest full function available) you can also trytry:
http://arduino.cc/en/Guide/ArduinoProMini
/> for getting started. I have been told that the "Arduinos for Dummies" has been a good starting point for some people too.

This has become immensely popular and has provoked over 20 variations at modelers requests from around the world, most of which are covered in the following blog entries (including comments) in chronological order:

SMA10 – Build a 17-Function DCC Decoder for about $5  http://model-railroad-hobbyist.com/node/19070

SMA12 - 17 Channel Configurable Multifunction $5 DCC Decoder For Servos  http://model-railroad-hobbyist.com/node/19446

SMA 13 - Update to the 17 Pin Configurable Multi Function Decoder / Accessory Decoder Version Added  http://model-railroad-hobbyist.com/node/19775

SMA15: New Dual Acessory-Multifunctionl 17 Channel Configurable DCC Decoders for about $5 with Configurable Servo Support  http://model-railroad-hobbyist.com/node/20739

Scale Model Animation 18: DCC Control for Random Building Lighting  http://model-railroad-hobbyist.com/node/23026

There are lots of great ideas in the blog comments from many modelers, so I think it might be somewhat useful to work your way through the discussions.

I have encouraged, and still encourage people to ask questions along the way, and if I can help, I will try, time permitting. There are many others in this forum who have contributed their ideas, encouragement, explanations, and insights too! All these are appreciated and welcomed! I hope this offers you, Doug, a bit clearer view of this effort.

And most important-- Have fun !

Best Regards,
Geoff Bunza

Reply 0
Reply