Page 10 of 10 FirstFirst ... 678910
Results 181 to 197 of 197

Thread: The Arduino & Model Railroading

  1. #181
    Join Date
    Nov 2011
    Location
    Helena, Montana
    Posts
    356
    Blog Entries
    4
    Thanks
    3,260
    Thanked 310 Times in 156 Posts
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default

    If cost is a factor, consider looking into TI's Launchpad board that uses MSP430G2 chips. Not as feature filled as the ATMEL chips on the Arduino, but for the things we are doing (flashing lights, sensors, etc) they are just fine and pretty cheap. $10 vs $30.

    Additionally, depending on what you're trying to do, the MSP430G2 chips can be removed from the USB board and powered off of something as little as a coin cell battery. The 'high end' raw MSP430G2 chip weighs in at $2.50

    I'm in the middle of working on quite a few different projects with the Launchpads, if anyone's interested.
    -Dave L

    My simple site: http://therustyspike.com
    Join the discussion about our wonderful hobby: http://modelrailradio.com/
    Also listen to: The Model Railcast Show and The MRH Podcast

  2. The Following 2 Users Say Thank You to Claymore1977 For This Useful Post:


  3. #182
    Join Date
    Aug 2011
    Location
    Roanoke, Indiana, USA
    Posts
    128
    Thanks
    17
    Thanked 54 Times in 36 Posts
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Turntable Indexer/Controller - Arduino

    Turntable Indexer/Controller - Arduino

    This Arduino thread has been dormant for too long...

    Sorry, but this is going to be a long post.

    I have been noodling a design for an Arduino based, stepper motor controller/indexer for an old Heljan/ConCor turntable.

    I've gotten to the same stage as my new layout planning is going. Stagnation, paralysis by analysis, and the age old bug-a-boo of creeping feature-itis.

    So far I've got the motor running well using an old homemade transistor driver proto board, it seems to find 'home' and the index steps accurately and repeatably. The 2 line serial LCD displays user information. The rotary encoder will rotate the motor, but its skipping counts, may be eliminated. Two push buttons will rotate the motor by x steps CW & CCW, 2 more will 'turn' 180' CW & CCW. The run/program switch does its thing but, I just need to code it up. Therein lies the problem, I'm not a programmer, nor do I play one on TV!

    Messed around with Basic/MS Quick Basic, K&R C/MS Quick C, ANSI C (PC) and even a little C & assembly on an 8051, 2+ decades ago, any knowledge of any of that has since left me long, long ago.

    What I really need is focus. The Arduino environment is great for knocking out a proof of concept, but I'm having trouble putting setup() and loop() into finished "PROGRAM".

    I jotted down a Design Spec of sorts, it's more of a loose Givens & Druthers list. If anyone's interested in this I can include it in another post to this thread, as this is getting lengthy.

    Especially seeking input from from anyone that have some level of Arduino or Programming experience, but any input on how *_YOU_* would want an INDEXING system operate a turntable would help.

    How would *_You_* want to interface with it?
    What would *_You_* like to see on the display to make it more user friendly?
    Index/Presets - How many? Where?
    Setup menu - Save & Store (eeprom)

    Any takers????

    Thanks,
    GoPhast

  4. #183
    Join Date
    Aug 2011
    Location
    Roanoke, Indiana, USA
    Posts
    128
    Thanks
    17
    Thanked 54 Times in 36 Posts
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default VS Arduino Turntable Controller Design Spec

    As mentioned (threatened?)

    Be gentle, have fun.

    Turntable Controller Design Spec
    VS 2014

    This Arduino project is for controlling an old ConCor/Heljan turntable bridge position.

    Arduino Mega 2560 Works(duh!)
    Sparkfun 16x2 SerialLCD digital pin 12 Works!
    Bourns Rotary Encoder 200 ppr digital pin 2(A), 3(B) Works!
    TRW OPB 880T51 Opto Home sensor analog pin A0 Works!
    5 N/O micro switches (U,D,L,R,Sel) analog pin A1 Works!
    Vexta 5v 1a 200 step/rev 1.8 degree digital pin 4, 6, 5, 7 Works!
    Homemade Opto-isolated 2n3055 Transistor driver Works!

    5 - N/O SPST momentary switches for operation in Run mode and menu navigation in Program mode. Resistor ladder to the A1 pin. Up, Down, Left, Right, Enter/Select. Esc/Cancel will be via the Navigation keys. (i.e. Enter/Select HAS to be pressed to save any changes, otherwise the selection is ignored).

    The 6 stall roundhouse tracks are set to 7 1/2 degree stall spacing. This would allow for a maximum of 48 tracks around the circumference, and 96 index positions for both ends of the bridge (180 deg. apart).
    Realistically, I won't have the real estate for that many.

    The current layout has 9 tracks, 3 lead in tracks align with the first three of the 6 tracks to the stalls. 18 index positions, accounting for the "B" end of the bridge.


    200 motor steps
    400 half steps = 8.3333333333333333333333333333333 steps per track index
    Close enough????

    The AccelStepper library is excellent at keeping track of the Stepper motor position. In Half-step mode there are 400 steps per revolution. Storing the preset values directly to EEPROM should suffice for direct track positioning.

    I envision 2 modes of operation, Program and Run.

    Upon power up or reset, a "Turntable Controller" message is displayed, and after a (1.5 second) delay, the "Homing" routine is activated. Homing rotates the bridge counter clockwise attempting to align the bridge at the "0" motor position by breaking the IR beam of the opto detector on pin A0. All subsequent position calculations are referenced from this point.


    Run Mode is active after reset, the buttons (right now), Up and Down, rotate the bridge +/- 200 steps 180', Left and Right +/- 8 steps.

    The optical encoder steps the motor 1 step forward or reverse by one step, change of rotation direction is not missed and no steps are "lost" (AFAIK).
    **** No longer true, the program now has too many (blocking) delay() 's. ****

    There is no consideration for velocity.

    "Select" changes to Program mode.

    Program mode will be a "for loop" or switch-case stepping through the available options and "X" number of preset slots,

    Setup will have an option to reset "Home", if needed. Store up to "X" track preset values.

    Run mode will display the Current Track Preset Position # on line one of the LCD and the actual motor step position on line 2 (Just for Schnits-n-grins). The up and down buttons will rotate 180 degrees left or right for a "turn." Left or Right will step to the previous or next track preset number.

    WIP (work in progress)

    GoPhast

  5. #184
    Join Date
    Oct 2014
    Posts
    23
    Thanks
    31
    Thanked 39 Times in 10 Posts
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi GoPhast,

    I'm a very new modeler, but I've got a lot of Arduino and programming experience! In my day job as a theatrical electrician, I've done a lot of wiring of small intelligent lights/props under Arduino control, as well as some larger scale projects, including a 40,000 square-foot haunted house where each room had intelligent, responsive lighting controlled by Arduinos. What a blast!

    It sounds like you have a working version of the code currently, or a draft? I'd be happy to take a look at it, if you like. Eliminating delay()s is sometimes a matter of re-writing the program to use roughly a time-triggered loop, rather than delay()ing until the next scheduled event.

    Interface-wise, I love the idea of having both manual turntable controls in addition pre-programmed presets, which you'd probably use most often.

    The reset-to-home option is a great one, for restoring calibration during an ops session. Having the ability to calibrate presets on the fly might be nice too (i.e. if my preset for track #3 is 1 step off, it would be nice to move the motor one step, then save the new position as the preset for track #3).

    Maybe having the option to name the presets with alphanumeric names would be nice? Though perhaps cumbersome on an interface without a true keyboard.

    Anyways, what an exciting project!
    Keep one hand in your pocket, and two hands on your work.

  6. #185
    Join Date
    Aug 2011
    Location
    Roanoke, Indiana, USA
    Posts
    128
    Thanks
    17
    Thanked 54 Times in 36 Posts
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb

    Hi Sparky,

    Thanks for replying.

    The code, is more or less a work in 'draft-proto' stage at the moment. Mostly lifted (stolen) Sketch examples from the web, forums and the playground.

    I got the stepper turning first, then switched to the AccelStepper library. The display was next, followed by the Opto-encoder, and the opto home sensor. The 5 micro switches (keypad) were added last.

    Right now the hardware is loose, spread out across my desk. Nothing is mounted, the stepper motor has an electrical tape 'flag' to see the motion. The 5 micro switches, opto-encoder, and the home sensor are just mounted on a proto board.

    The delay()'s and *_all_* the Serail.print's are for debugging and will be removed once its done. I think that I may need to have a timer based delay for 'pausing' the display instead of just burning cpu ticks...

    Really about the only thing that is timing sensitive is the opto-encoder while it is rotating the motor. I went in and rem'med all the delays that were just slowing things down. The Opto seems to stepping by "2's" now so it is better than it had been.

    My biggest block is the 'elegant' UI and track preset management. I just can't seem to figure out what the best way to arrange the presets.
    I've never been successful working with arrays, but that's probably the best way to store them.

    There was another project similar to this that I ran across on the web, but that example only had (I think) 6 presets, he used discreet switches for the 'preset' selections. That's fine unless you have more than 6 tracks, especially if they are not 180 degrees across (enter/exit).

    http://learn.proto-pic.com/?p=119

    I will see if I can post the code. *_ IT AINT PRETTY _*

    I had to cut some of the meat from some of the functions, but the gist should remain...

    Thanks for your interest.

    GoPhast\Verlin

    Code:
    /
    
    ***********************************************************************
    Turntable Controller @ V.S. 2014
    /***********************************************************************
    SerLCD Example Code SparkFun Electronics Joel Bartlett December 20, 2012 
    SoftwareSerial NAME(x,y); // RX, TX
    where Name is the name of the new UART, x is the RX pin, and y is the TX pin.
    ************************************************************************/
    #include <SoftwareSerial.h>
    #include <SerLCD.h>
    #include <AccelStepper.h>
    #include <EEPROM.h>
    
    // SoftwareSerial LCD(11,12); // RX, TX
    SoftwareSerial NSS(0,12); // RX, TX
    SerLCD LCD(NSS); 
    
    //************************************************************************
    // Encoder Gray code 2 bit 
    #define encoder0PinA  2
    #define encoder0PinB  3
    
    volatile int encoder0Pos = 0;
    
    //************************************************************************/
    // Home Sensor variables:
    
    const byte HomeSensorPin = A0;     // pin that the sensor is attached to
    byte HomeSensorVal = 0;         // the sensor value
    const int HomeLEDpin = 13;
    
    //************************************************************************/
    // AccelStepper stepper(AccelStepper::FULL4WIRE, 4, 6, 5, 7);
    AccelStepper stepper(AccelStepper::HALF4WIRE, 4, 6, 5, 7);
    
    //************************************************************************/
    //-------------------------------------------------------------------------------------------
    // define some values used by buttons
    const int BtnKeyPin = A1;     // pin that the sensor is attached to
    int A_Key_In = 0;             // the sensor value
    
    #define btnRIGHT  0
    #define btnUP     1
    #define btnDOWN   2
    #define btnLEFT   3
    #define btnSELECT 4
    #define btnNONE   5
    //-------------------------------------------------------------------------------------------
    boolean RunMode = true;
    
    //-------------------------------------------------------------------------------------------
    void setup()
    {
      //-------------------------------------------------------------------------------------------
      // LCD Serial 
      // -------------------------------------
      NSS.begin(9600); 
      Serial.begin(9600);
      LCD.begin();   
      // LCD.begin(9600);// all SerLCDs come at 9600 Baud by default
      resetLCDdisplay();
      LCD.setBacklight(129);
      showTitle();
      // -------------------------------------  
      
      // Rotary Encoder -------------------------------------  
      pinMode(encoder0PinA, INPUT); 
      digitalWrite(encoder0PinA, HIGH);       // turn on pullup resistor
      pinMode(encoder0PinB, INPUT); 
      digitalWrite(encoder0PinB, HIGH);       // turn on pullup resistor
      attachInterrupt(0, doEncoder_Expanded, CHANGE);  // encoder pin on interrupt 0 - pin 2
      Serial.begin (9600);
      Serial.println("start");                // a personal quirk
      // Rotary Encoder -------------------------------------
    
      pinMode(HomeLEDpin, OUTPUT);
      digitalWrite(HomeLEDpin, LOW);
        
      Findhome();
    
    // Stepper Motor -------------------------------------
      stepper.setMaxSpeed(100.0);
      stepper.setAcceleration(100.0);
    // Stepper Motor -------------------------------------
    //  Serial.println("Exit mysetup");
    }
    //-------------------------------------------------------------------------------------------
    
    void loop()
    {
      int encoder0Pos;
      int BtnKeyPin;
      int TrackIndex[10] = { 8, 16, 24, 32, 40, 48, 56, 64, 72, 80 };
        
      if (RunMode == true) 
      {
        TTRunning();
      }
      else if (RunMode == false) 
      {
        TTProgramming();
      }
      stepper.run();
      // showDisplay(); 
    }
    
    //---------------------------------------------  
    void TTRunning()
    {
    //---------------------------------------------
      int encoder0Pos;
      int BtnKeyPin;
      
      RunMode = true;
      BtnKeyPin = read_buttons();    // read the buttons
      
      switch (BtnKeyPin){               // which button was pushed, we perform an action
           case btnRIGHT:{              //  button "RIGHT" on the screen
                Serial.println("TrackPreset++....");
                LCD.clear();
                LCD.setPosition(1,0);
                LCD.print("CW Preset");
                stepper.runToNewPosition(stepper.currentPosition()+8);
                showDisplay();
                Serial.println(stepper.currentPosition());
                break;
           }
           case btnLEFT:{              //  button "LEFT" on the screen
                Serial.println("TrackPreset--....");
                LCD.clear();
                LCD.setPosition(1,0);
                LCD.print("CCW Preset");
                stepper.runToNewPosition(stepper.currentPosition()-8);
                showDisplay();
                Serial.println(stepper.currentPosition());
                break;
           }    
           case btnUP:{                //  button "UP" on the screen
                Serial.println("TrackPreset+200.");
                LCD.clear();
                LCD.setPosition(1,0);
                LCD.print("CW 'Turn'");
                stepper.runToNewPosition(stepper.currentPosition()+200);
                showDisplay();
                Serial.println(stepper.currentPosition());
                break;
           }
           case btnDOWN:{              //  button "DOWN" on the screen
                Serial.println("TrackPreset -200.");
                LCD.clear();
                LCD.setPosition(1,0);
                LCD.print("CCW 'Turn'");
                stepper.runToNewPosition(stepper.currentPosition()-200);
                showDisplay();
                Serial.println(stepper.currentPosition());
                break;
           }
           case btnSELECT:{            //  button "SELECT" on the screen
                Serial.println("PRGM SELECT.....");   
                RunMode = false;
                break;
           }
           case btnNONE:{              //  No action "None" nothing on the screen
                // LCD.print("               ");  
                break;
           }
           showDisplay();
           // encoder0Pos = stepper.currentPosition();
       }
    //---------------------------------------------
    }
    //---------------------------------------------  
    //---------------------------------------------  
    void TTProgramming()
    {
    //---------------------------------------------  
      int encoder0Pos;
      int BtnKeyPin;
      int i;
      int j;
      int address;
      int value;
    
      RunMode = false;
      BtnKeyPin = read_buttons();    // read the buttons
      
      switch (BtnKeyPin){               // which button was pushed, we perform an action
           case btnRIGHT:{              //  button "RIGHT" on the screen
                for (i=0; i < 10; i++){
                   value = EEPROM.read(i);
                   Serial.print(value, DEC);
                   Serial.print("\t");
                }
                Serial.print("\n");
                Serial.println("PRGM Index ++  ");
                break;
           }
           case btnLEFT:{              //  button "LEFT" on the screen
                for (i=10; i > 0; i--){
                   value = EEPROM.read(i-1);
                   Serial.print(value, DEC);
                   Serial.print("\t");
                }
                Serial.print("\n");
                Serial.println("PRGM Index --  ");
                break;
           }    
           case btnUP:{                //  button "UP" on the screen
                for (i=0; i < 10; i++){
                  // Serial.print("PRGM Index ++  \t");
                  // value = value + 9;
                  // value = 0;
                  // EEPROM.write(i, value);
                  // value = EEPROM.read(i);
                  Serial.print(value, DEC);
                  Serial.print("\t");
                }
                Serial.print("\n");
                break;
           }
           case btnDOWN:{              //  button "DOWN" on the screen
                for (i=10; i > 0; i--){
                  // Serial.print("PRGM Index ++  \t");
                  // value = value + 9;
                  // EEPROM.write(i, value);
                  value = EEPROM.read(i-1);
                  Serial.print(value, DEC);
                  Serial.print("\t");
                }
                Serial.print("\n");
                break;
           }
           case btnSELECT:{            //  button "SELECT" on the screen
                Serial.println("RUN  SELECT.....");   
                RunMode = true;
                break;
           }
           case btnNONE:{              //  No action "None" nothing on the screen
                // LCD.print("               ");  
                break;
           }
           showDisplay();
           // encoder0Pos = stepper.currentPosition();
       }
       
    //---------------------------------------------
    }
    //-------------------------------------------------------------------------------------------
    //-------------------------------------------------------------------------------------------
    int read_buttons(){                         // read the buttons
        // Cut
    }
    //-------------------------------------------------------------------------------------------
    //-------------------------------------------------------------------------------------------
    void doEncoder() 
    {
      /* If pinA and pinB are both high or both low, it is spinning
       * forward. If they're different, it's going backward.
       *
       * For more information on speeding up this process, see
       * [Reference/PortManipulation], specifically the PIND register.
       */
      if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) 
      {
        encoder0Pos--;
        stepper.move(encoder0Pos);
      } 
      else
      {
        encoder0Pos++;
        stepper.move(encoder0Pos);
      }
    }
    /* See this expanded function to get a better understanding of the
     * meanings of the four possible (pinA, pinB) value pairs:
     */
    void doEncoder_Expanded()
    {
      if (digitalRead(encoder0PinA) == HIGH)     // found a low-to-high on channel A
      {
        if (digitalRead(encoder0PinB) == LOW)    // check channel B to see which way
        {
                                                 // encoder is turning
          encoder0Pos = encoder0Pos - 1;         // CCW
          // Serial.println(" L to H CCW");
          stepper.move(-1);
        } 
        else 
        {
          encoder0Pos = encoder0Pos + 1;         // CW
          // Serial.println(" L to H CW");
          stepper.move(+1);
        }
      }
      else                                        // found a high-to-low on channel A
      { 
        if (digitalRead(encoder0PinB) == LOW)     // check channel B to see which way
        {                                         // encoder is turning  
          encoder0Pos = encoder0Pos + 1;          // CW
          // Serial.println(" H to L CW");
          stepper.move(+1);
        } 
        else 
        {
          encoder0Pos = encoder0Pos - 1;          // CCW
          // Serial.println(" H to L CCW");
          stepper.move(-1);
        }
      showDisplay();
      }
      // Serial.println(encoder0Pos, DEC);         // debug - remember to comment out
      // Serial.println ('/ ');                    // before final program run
      //                                           // you don't want serial slowing down 
      //                                           // your program if not needed
    }
    //-------------------------------------------------------------------------------------------
    //-------------------------------------------------------------------------------------------
    void showTitle()
    {
    //This function displays text across the screen on both lines
      // Cut
    }
    //-------------------------------------------------------------------------------------------
    //-------------------------------------------------------------------------------------------
    void showDisplay()
    {
      // this function prints the rotation position
      // Cut
    }
    //-------------------------------------------------------------------------------------------
    //-------------------------------------------------------------------------------------------
    void Findhome()
    {
      stepper.setMaxSpeed(100.0);
      stepper.setAcceleration(100.0);
      //this routine should run the motor
      
      HomeSensorVal = analogRead(HomeSensorPin);  // this could be in setup()
                                       // before calling stepperHome function
      
      int encoder0Pos;
      LCD.clear();
      LCD.print("Finding Home...");
      Serial.println("Finding Home...");
      
      while (HomeSensorVal <= 100)
      {
        //backwards slowly till it hits the switch and stops
        stepper.moveTo(-10000);
        stepper.run();
        digitalWrite(HomeLEDpin, HIGH);
        HomeSensorVal = analogRead(HomeSensorPin);
      }
      Serial.println(stepper.currentPosition(), DEC);
      digitalWrite(HomeLEDpin, LOW); //
      stepper.stop();
      stepper.setCurrentPosition(0); //
      LCD.setPosition(1,0);
      LCD.print("Found Home.....");
      LCD.setPosition(2,0);              // move to the begining of the second line
      LCD.print("Pos=");
      LCD.setPosition(2,12);
      LCD.print(stepper.currentPosition());  
      Serial.println("Found Home.....");
      Serial.println(stepper.currentPosition(), DEC);
      stepper.setMaxSpeed(100.0);
      stepper.setAcceleration(100.0);
      delay(1500);
      stepper.runToNewPosition(10);
      stepper.runToNewPosition(-10);
      stepper.runToNewPosition(0);
      encoder0Pos = 0;
      LCD.clear();
      showDisplay();
      // Serial.println("Exit Home");
    }
    //-------------------------------------------------------------------------------------------
    //-------------------------------------------------------------------------------------------
    void resetLCDdisplay()
    {
      // Cut 
    }
    //-------------------------------------------------------------------------------------------

  7. The Following User Says Thank You to GoPhast For This Useful Post:


  8. #186
    Join Date
    Nov 2011
    Location
    Helena, Montana
    Posts
    356
    Blog Entries
    4
    Thanks
    3,260
    Thanked 310 Times in 156 Posts
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default

    GoPhast:

    I think an array of 16bit ints is the way to go for storing the halfstep positions of the tracks. If you store them sorted in order of increasing value, then iterating over the elements in the array is pretty simple:


    Code:
    const short stops[] = {10, 100,250,375};
    const short stopsCnt = 4;
    
    int index = 0;
    int currentStopValue = 0;
    
    for (index = 0;index < stopsCnt; ++index) 
    {
        currentStopValue =stops[index];
    
        //do something with currentStopValue
    }
    (Note this code was written in the web browser and not compiled nor tested)
    -Dave L

    My simple site: http://therustyspike.com
    Join the discussion about our wonderful hobby: http://modelrailradio.com/
    Also listen to: The Model Railcast Show and The MRH Podcast

  9. #187
    Join Date
    Oct 2014
    Posts
    23
    Thanks
    31
    Thanked 39 Times in 10 Posts
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Quote Originally Posted by Claymore1977 View Post
    GoPhast:

    I think an array of 16bit ints is the way to go for storing the halfstep positions of the tracks. If you store them sorted in order of increasing value, then iterating over the elements in the array is pretty simple...
    What he said! This goes back to your original spec of having "up to X" presets, which with EEPROM storage could easily be more than you'd ever practically need to store, say 50.

    There are a couple of ways I could see handling this. If you set a fixed maximum number of presets, you could initialize an array of stops and a count much like Dave did above, and then keep track of the total number of stops created. Something like

    Code:
    const int MAX_PRESETS = 50;
    const short stops[MAX_PRESETS] = {10, 100,250,375, 0, 0, 0, //SNIP. A TOTAL OF 50 ENTRIES
       };
    const short stopsCnt = 4;
    
    int currentStopValue = 0;
    
    void addPresetFromCurrentPosition(){
      stops[stopsCnt] = stepper.currentPosition();
      stopsCnt += 1;
    }
    You could do the same thing, but modify the addPreset function to always insert the new preset into the the Array so that the presets were always in increasing order. That way, you're not bouncing back and forth around the track as you step through presets. (But maybe that would be desirable in some way?)
    Code:
    void addPresetFromCurrentPosition(){
    int arrayPos = 0; //will be set to the array position appropriate to the preset being added.
    short currentPos = stepper.currentPosition(); //Find the appropriate place in the array to add this preset //Assumes existing presets are in ascending order; doesn't care about uninitialized presets for (int i = 0; i < MAX_PRESETS; i++){
    if (i >= stopsCnt){ //If we're past the end of our initialized presets and still are greater than the last preset
    arrayPos = i; break;
    }
    if (currentPos < stops[i]){ //If the existing preset we're looking at has a greater value than our preset to be inserted.
    arrayPos = i; break;
    }
    } //Work backward from the first uninitialized preset toward the position to add the new preset, and shift all values up one index. //Does not run if arrayPos == stopsCnt (i.e. if we're adding to the end of the array) for (int i = stopsCnt; i > arrayPos; i--){
    stops[i] = stops[i - 1];
    } stops[arrayPos] = currentPos(;
    }
    If you're "resizing" the array each time you add a new preet, you could write a similar function to find the appropriate place to add the new preset, then create a new array of the appropriate (larger) size and copy the values from the old array into a new one, inserting the new value in the appropriate place.

    This is a pretty rough and sloppy way to handle it, I'm sure. Also, written in a text editor, so no guarantees it will compile the first time.
    Last edited by Sparky; 8th Oct 2014 at 12:21 PM. Reason: Clarified "appropriate position in the Array"
    Keep one hand in your pocket, and two hands on your work.

  10. #188
    Join Date
    Aug 2011
    Location
    Roanoke, Indiana, USA
    Posts
    128
    Thanks
    17
    Thanked 54 Times in 36 Posts
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default

    Claymore and Sparky,

    Thanks for your interest, insights and confirming that I am most likely going to have to actually learn manipulating arrays and pointers.

    From the code I posted, 3 lines down from loop(), (probably should be in setup()), you can see the int TrackIndex[10] line - So I was sorta, reluctantly, headed there anyways!

    I've decided that I will proceed from here with an array of 10 preset positions. I've got the 'duino, I can change that # at any time in the future if need be, just by plugging it and reloading it.

    Old habits die hard. I can still remember putzing around with that old 8051. Code, compile, link, obj to hex, UV erase the eprom, reprogram that, stuff the eprom back into the target and then find more bugs. Lather, rinse, repeat - ad nausea. It's no wonder interest in that waned and died on the vine.

    So then, I still need to work out the programming menu/prompts for setting/changing index[i], saving it, and maybe keep track of what index position the bridge is at (nearest to?) while in run mode. Press the setup button and that track index is the [i] value to work with. That'll keep me busy for a spell.

    Aside from the coding challenges, I've got to get this stuff mounted to a base. Especially the stepper motor, get a shaft adapter (hub), 9" of a 12" ruler for a 'bridge', and mount the home sensor. I really should do that now. I'm fairly confident the home sensor will be fine, it detects a toothpick on the proto board. Not sure how much 1 step moves 4.5" out from the motor shaft. If it turns too far I may as well scrap the works or look for a stepper with more steps/rev.

    Lots to do, no time to do it.

    Thanks again guys!

    GoPhast/Verlin

  11. The Following 2 Users Say Thank You to GoPhast For This Useful Post:


  12. #189
    Join Date
    Mar 2011
    Location
    Windsor, Ontario, Canada
    Posts
    1,083
    Thanks
    1,663
    Thanked 2,371 Times in 602 Posts
    Mentioned
    19 Post(s)
    Tagged
    0 Thread(s)

    Default

    Verlin, sounds like an interesting project. Keep us apprised of your build as you go along.
    Peter

    Layout Depot (share your designs with others): www.LayoutDepot.com
    My Build Thread: www.nscale.net/forums/showthread.php?28081-Green-Valley-Railway

  13. #190
    Join Date
    Oct 2014
    Posts
    23
    Thanks
    31
    Thanked 39 Times in 10 Posts
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Sounds like you're off to a solid start, Verlin. Keep us posted as you progress - I'd love to see where you go with the interface, I'm sure you'll come up with something great.
    Keep one hand in your pocket, and two hands on your work.

  14. #191
    Join Date
    Aug 2011
    Location
    Roanoke, Indiana, USA
    Posts
    128
    Thanks
    17
    Thanked 54 Times in 36 Posts
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default VS Arduino Turntable Controller - Some progress.

    VS Arduino Turntable Controller - Some progress.

    Well, I've made just a little forward progress in the last few months. Most of it just today.

    Got a 1" x 9" strip of styrene, & a piece of c55 rerailer track mounted atop the stepper shaft. 4 1/2 inches out from the shaft does move quite a little too far. The old proto-board transistor stepper driver is gonna probably have to be replaced. Even in 1/2 step mode the bridge moves far enough & harsh enough to dislodge the wheels of an old, dead Bachmann F9.

    I'm thinking (hoping), that a Pololu DRV8825 driver or somesuch in 1/4, 1/8, or 1/16 micro stepping mode will 'tone it down a bit', and make the steps smaller. I'd rather not have go with a gear reduction (just yet, anyways). If I ever get it ordered, we'll see, I guess.

    I've tried most (all?) the Menu libraries that Google has pointed me towards, but I can't get my head around any of them to be of any use. The Switch/Case statements are gonna get UGLY!

    Set up an int TrackIndex[] = 20; array, initialized the elements to various semi-logical values. I can step through and change them on incrementing and decrementing order. Stepping under 0 or past 20 (and/or 21) was giving me fits, and where I quit for the day.

    Even if Glacially SLOW, progress is progress.

    Thanks for your interest.

    GoPhast/Verlin

  15. #192
    Join Date
    Mar 2011
    Location
    High Point, NC, USA
    Posts
    326
    Thanks
    453
    Thanked 211 Times in 123 Posts
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default

    This months Model Railroad Hobbyist has a great article on making crossing gates with servos using the Arduino.
    You can find it here:

    http://model-railroad-hobbyist.com/node/20176

    The sketch is very well written for both flashing lights and gate control.

    Harold
    HAROLDN212

  16. #193
    Join Date
    Mar 2011
    Location
    High Point, NC, USA
    Posts
    326
    Thanks
    453
    Thanked 211 Times in 123 Posts
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default

    Quote Originally Posted by Papahnash View Post
    This months Model Railroad Hobbyist has a great article on making crossing gates with servos using the Arduino.
    You can find it here:

    http://model-railroad-hobbyist.com/node/20176

    The sketch is very well written for both flashing lights and gate control.

    Harold
    BTW, the Arduino will not operate NJ international crossing gate lights directly because they are wired with positive (+) to a common wire and the Arduino output is also positive(+). I used a board with 2 relays to switch the lights and the Arduino to power the coil.
    HAROLDN212

  17. #194
    Join Date
    Aug 2014
    Posts
    7
    Thanks
    0
    Thanked 3 Times in 1 Post
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Quote Originally Posted by Papahnash View Post
    BTW, the Arduino will not operate NJ international crossing gate lights directly because they are wired with positive (+) to a common wire and the Arduino output is also positive(+). I used a board with 2 relays to switch the lights and the Arduino to power the coil.
    You can use the Arudino pins to Sink a current instead of providing it, that will allow it to work.

    Relays can draw too much power for the Arduino, you might damage your arduino by powering the relay coil directly off it.
    You'd generally want to use a MOSFET or Transistor to do it.


    I have an arduino project i'd like to share...

    My club is in the process of wiring up a turnout control system based on the MEGA2560.

    35 of the pins are set to input with the internal pullup resistor turned on. These pins are connected to push buttons which pull to ground when pressed.

    The program polls the input pins looking for them going "low", when it sees that it switches the state of the turn out (straight or deviate).

    The 35 output pins are connected to a PCB of my own design which has a pulldown resistor for the output pin, a current limiting resistor to make sure we don't burn out the Arduino and a MOSFET which is connected to a DPDT relay.
    When the output pin of the arduino pin is turned on, it turns on the MOSFET which then turns on the relay. The relay switches the polarity to the Cobalt making it through. When the output pin is turned off, the relay is turned off and the cobalt throws back.

    Using the push buttons means we can have multiple buttons control a single turnout.

    We will also be looking into an Ethernet shield for the Arduino and writing software to allow computer control over Ethernet. Possibly integrating with JMRI?

  18. The Following 3 Users Say Thank You to pantner For This Useful Post:


  19. #195
    Join Date
    Aug 2014
    Posts
    7
    Thanks
    0
    Thanked 3 Times in 1 Post
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default 740

    Quote Originally Posted by Papahnash View Post
    BTW, the Arduino will not operate NJ international crossing gate lights directly because they are wired with positive (+) to a common wire and the Arduino output is also positive(+). I used a board with 2 relays to switch the lights and the Arduino to power the coil.
    You can use the Arudino pins to Sink a current instead of providing it, that will allow it to work.
    Relays can draw too much power for the Arduino, you might damage your arduino by powering the relay coil directly off it.
    You'd generally want to use a MOSFET or Transistor to do it.

    I have an arduino project i'd like to share...
    My club is in the process of wiring up a turnout control system based on the MEGA2560.
    35 of the pins are set to input with the internal pullup resistor turned on. These pins are connected to push buttons which pull to ground when pressed.
    The program polls the input pins looking for them going "low", when it sees that it switches the state of the turn out (straight or deviate).
    The 35 output pins are connected to a PCB of my own design which has a pulldown resistor for the output pin, a current limiting resistor to make sure we don't burn out the Arduino and a MOSFET which is connected to a DPDT relay.
    When the output pin of the arduino pin is turned on, it turns on the MOSFET which then turns on the relay. The relay switches the polarity to the Cobalt making it through. When the output pin is turned off, the relay is turned off and the cobalt throws back.
    Using the push buttons means we can have multiple buttons control a single turnout.
    We will also be looking into an Ethernet shield for the Arduino and writing software to allow computer control over Ethernet. Possibly integrating with JMRI?

  20. #196
    Join Date
    Mar 2011
    Location
    High Point, NC, USA
    Posts
    326
    Thanks
    453
    Thanked 211 Times in 123 Posts
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default

    Quote Originally Posted by pantner View Post
    Relays can draw too much power for the Arduino, you might damage your arduino by powering the relay coil directly off it.
    You'd generally want to use a MOSFET or Transistor to do it.
    I used a reed relay with a 5 volt coil that draws 50mw and have had no problem.

    http://datasheet.octopart.com/W117SI...et-8325616.pdf

    There are also relay boards made for Arduino with the mosfit installed.

    http://www.mpja.com/Dual-SPDT-Relay-...nfo/31357%20MP

    Harold
    HAROLDN212

  21. #197
    Join Date
    Mar 2011
    Location
    High Point, NC, USA
    Posts
    326
    Thanks
    453
    Thanked 211 Times in 123 Posts
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default

    Quote Originally Posted by pantner View Post
    You can use the Arudino pins to Sink a current instead of providing it, that will allow it to work.
    I think that would require changing the highs to lows but my programming skills aren't up to the challenge, but thanks for the advice.

    Harold
    HAROLDN212

Similar Threads

  1. Model Power Haunted House using Arduino Micro Controller
    By ndronet in forum Structures & Scenery
    Replies: 7
    Last Post: 12th Oct 2018, 10:24 AM
  2. 3D printing and model railroading
    By vikingservices in forum General Rail Discussion
    Replies: 0
    Last Post: 11th Feb 2013, 11:58 AM
  3. Your interest in railroading/model railroading?
    By simpdogg in forum General Rail Discussion
    Replies: 22
    Last Post: 10th Jul 2007, 11:39 PM
  4. Model Railroading subscription
    By ragnarock4 in forum General Rail Discussion
    Replies: 14
    Last Post: 28th Apr 2006, 03:38 PM
  5. Digitrax/DCC/Model Railroading on DIY
    By colonel_26 in forum DCC
    Replies: 2
    Last Post: 6th Jun 2004, 12:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •