Jump to content
 

DCC Controlled (PECO) Turntable Project using a Arduino Uno


Recommended Posts

Good giornagiorno. First of all, thanks to everyone for the effort put in the projects presented in this tread! :no: In particular, Ray, I tried to implement your project, but loading the sketch in ArduinoUNO me the following error is reported:

 

sketch_feb07b.cpp.o: In function `__static_initialization_and_destruction_0':

C:\Programmi\Arduino_1.0.5/sketch_feb07b.ino:50: undefined reference to `AccelStepper::AccelStepper(void (*)(), void (*)())'

sketch_feb07b.cpp.o: In function `loop':

C:\Programmi\Arduino_1.0.5/sketch_feb07b.ino:208: undefined reference to `AccelStepper::run()'

sketch_feb07b.cpp.o: In function `BasicAccDecoderPacket_Handler(int, unsigned char, unsigned char)':

C:\Programmi\Arduino_1.0.5/sketch_feb07b.ino:139: undefined reference to `AccelStepper::moveTo(long)'

sketch_feb07b.cpp.o: In function `setup':

C:\Programmi\Arduino_1.0.5/sketch_feb07b.ino:164: undefined reference to `AccelStepper::setMaxSpeed(float)'

C:\Programmi\Arduino_1.0.5/sketch_feb07b.ino:165: undefined reference to `AccelStepper::setAcceleration(float)'

 

Someone is able to suggest a solution? :O Thank you very much & greetings. Rovilazz

 

Hi Rovilazz.

 

It sounds like you haven't installed all the drivers for the Adafruit board and the DCC routines

 

See part 4

 

http://www.rmweb.co.uk/community/index.php?/topic/78578-dcc-controlled-peco-turntable-project/?p=1231245

 

And the accelstepper routines here:

 

http://www.rmweb.co.uk/community/index.php?/topic/78578-dcc-controlled-peco-turntable-project/?p=1242019

 

If you still have problems get back and will try and sort you out.

Ray.

Edited by tender
Link to post
Share on other sites

Ray

You put your sensor on the outside of the pit, and your magnet on the table - logical! - but I wonder how far away you could have sensor and still get a reliable switch point. The Metalsmiths t/t is mounted on an MDF pit, and I don't really fancy digging up the reasonably-well scenic-ed bit to install it. It's about 6 mm thick. Will the sensor work reliably at that distance, plus the one or two mm of clearance? I can hide it under the centre of the table reasonably easily, but then it's angular discrimination will be much less than if it were mounted at the edge. I wonder if I could just stick it down in the pit somewhere and paint it to match the gravel, and hope nobody notices.....?

I'm planning to use something like this http://www.farnell.com/datasheets/608704.pdf

Sound reasonable?

SD

Hi SD

I think 6mm might be pushing it a bit. I have a Metalsmith 65ft GWR turntable on order so will have to think of a solution for this myself.

Fitting the sensor in the base of the well as you suggest seems like a good option but not sure if the sensor I used with the Peco T/T is a good shape for this. I'm not familiar with the one suggested but it's worth a try. I'll put one on my next Farnell order but if you get there first let us know how you get on.

 

Ray.

Link to post
Share on other sites

 

Ray, I have to give you some good news: I've made for your test project.

I just replaced the Hall Effect Sensor (RS370-6896) with an infrared optical sensor that I bought long ago on e-Bay.

The magnet has been replaced by a thin object that with the rotation of the bridge goes to interpose the sensor fork.

I did not even have to change your sketch!.

 

It all works very well, for the time being commanded by Intellibox from Uhlenbrock (first version).
:no: MANY THANKS FOR THE HELP!!!!!! :no:

 

You did not think even you add a seven segment display to signal the position?

Rovilazz

Link to post
Share on other sites

Hi Rovilazz,

 

Glad the project is working for you. Could you post a picture of your optical sensor setup as a few others have been asking about this for a sensor.

I've not considered a LED display to indicate position as I just wanted to see if a direct drive stepper motor control system was feasible but 'Pandasum' has incorporated this in his Traverser project so it could be easily adapted. See post 38.

 

I have a new Metalsmith turntable on order to replace the Peco turntable and will probably use an opto sensor for this and further develop the software.

 

Ray.

Edited by tender
Link to post
Share on other sites

Hi Roy.

Tomorrow evening I take a picture of the prototype.
For now I can tell you that the optical sensor is a YwRobot.

Angular position transducer, optical encoder

On the radio photoelectric sensor; speed sensor B infrared counting sensor; sensor module.
A pulse signal is issued when the sensing area of the infrared light is cut off, i.e.
A paragraph count, speed sensor.
Motor speed sensor, the robot making essential. The use of infrared light detection, anti-interference ability.
Schmitt trigger, high sensitivity, stable performance; suitable for motor speed measurement, workpiece count.
Operating voltage 5V, black line output low, output high white line
With fixed bolt hole for easy installation
A pulse signal is issued when the sensing area of the infrared light is cut off.

Specifications:
Output low when the beam is interrupted
Power supply: 5VDC
Strip Connection: 2.54mm
Dimensions: 32 x 11 x 20 mm

LED indicators:
- power presence
- status indicator output

Connection mode:
1. VCC
2. GND
3. OUT

 

Digita il testo o l'indirizzo di un sito web oppure traduci un documento.
 
Forse cercavi: A Domani.
 
See you tomorrow.

 

Rovilazz
Link to post
Share on other sites

Hello Roy.
Here are pictures of the sensor YwRobot used by me and my trial version of your turntable project.
Tomorrow I will receive two "hall effect sensor", so I can check which of the two systems for detecting the zero point seems more accurate.
Greetings.

 

Turntable

gc5q.jpg

 

 

Sensor in action

4ix8.jpg

 

Sensor side back

vih4.jpg

Link to post
Share on other sites

Ray, all

 

Quickie note as I'm travelling - I couldn't get a Hall effect sensor in Maplin, so I bought an optical reflectance sensor, which I wired up with the aid of two resistors to an analog input. I glued a piece of white plastic card under the t/t which clears the sensor by about a millimetre. The input value changes from around 700 to around 50 when the card covers the sensor. I have set it up to act as a zero reference point, but the software needs to be finished. It works, anyway

 

The sensor is tiny, around 3mm square, and cost £1.09

 

http://www.maplin.co.uk/p/photoreflector-ja26d

 

Best

SD

Link to post
Share on other sites

Quick question...

 

I have the v1 version of the adafruit motor control board.

 

Does your code rely on the new features of the v2 board?

 

The new board had i2c features and a higher amp limit. The old card had i2c but a the new card has a dedicated chip controlling it.

 

Thanks!

Edited by gcodori
Link to post
Share on other sites

Hello Roy.Here are pictures of the sensor YwRobot used by me and my trial version of your turntable project.Tomorrow I will receive two "hall effect sensor", so I can check which of the two systems for detecting the zero point seems more accurate.Greetings.

 

Turntable

gc5q.jpg

 

 

Sensor in action

4ix8.jpg

 

Sensor side back

vih4.jpg

 

 

Hi Rovilazz, where did you get the YwRobot stuff from. I can't find your sensor anywhere.

 

 

Ray, all

Quickie note as I'm travelling - I couldn't get a Hall effect sensor in Maplin, so I bought an optical reflectance sensor, which I wired up with the aid of two resistors to an analog input. I glued a piece of white plastic card under the t/t which clears the sensor by about a millimetre. The input value changes from around 700 to around 50 when the card covers the sensor. I have set it up to act as a zero reference point, but the software needs to be finished. It works, anyway

The sensor is tiny, around 3mm square, and cost £1.09

http://www.maplin.co.uk/p/photoreflector-ja26d

Best

SD

Good stuff SD, the reflectance sensor should be easier to implement mechanically than a slotted opto sensor.

 

  

Quick question...

I have the v1 version of the adafruit motor control board.

Does your code rely on the new features of the v2 board?

The new board had i2c features and a higher amp limit.

Thanks!

Hi gcodori, I don't think the v1 Adafruit board will work as like you say it doesn't have the i2c bus. You could try the V1 but I suspect you will have to download a different set of driver routine for the board. The stepper motor I used has a current load of about 250ma at 12 v.

 

Ray.

Link to post
Share on other sites

I edited my last post. The old card does have i2c just not a dedicated chip. I'm new to arduino so I'm not even sure what i2c is...

 

 

 

Hi gcodori, I don't think the v1 Adafruit board will work as like you say it doesn't have the i2c bus. You could try the V1 but I suspect you will have to download a different set of driver routine for the board. The stepper motor I used has a current load of about 250ma at 12 v.

 

Ray.

Edited by gcodori
Link to post
Share on other sites

Ray

 

I've only just found this and I'm seriously impressed. As I am going to have one on OP Mk2, the process of gathering information, knowledge and ideas is getting more interesting.

 

Looking forward to further developments.

 

Duncan

Link to post
Share on other sites

Hello Ray, how are you?

 

Very good your project. Thanks for sharing!

I was working on a turntable but it would not, at first, controlled by dcc. Only keyboard and LCD. I'm using an external drive microstep and Arduino Leonardo to generate the STEP and DIR signals. When I saw your project, I decided to test to see if I could incorporate the controler by DCC on my project . But I'm having a problem here ... Leonardo apparently does not recognize the DCC commands. Even the example that comes with the library is not working. The code is not highlighted with the commands.

Do you have any idea what might be happening? 

Could be an incompatibility with the Arduino Leonardo?

 

Could you help me?

Hi guys,

 

As I mentioned, I'm working on a turntable that would not be controlled via DCC. Still, was testing the library and it wasn´t working , and do not decode the DCC Packet. I decided rewrite the code, part by part and test the modifications, and I think I finally found the problem. I believe that there is a conflict occurring between the DCC Library and the LCD Library. Sometimes the code works for a time and then stops withiout a apparent reason and sometimes does not work (just DCC packet decoding). When it stops working, I delete the commands relating to LCD, recompile the code, and the program restart. I rewrite the lcd commands again and the error recurs. I´m thincking to replace the LCD by i2c seven segments display.Anyone ever had similar problems?

Link to post
Share on other sites

From reading on the Arduino Forum conflicts between libraries seem to be quite common. I am not aware of any protocol that would help library developers avoid them and, of course, the Arduino has relatively few resources so it's not unlikely that two ideas will need the same resource. As with every other open-source product the documentation is poor or non existent so that it can be hard to find out where the overlap is. It may be possible to modify the code in one or other library to remove the overlap. Multiple use of the same timer seems to be a common problem.

 

It would probably be useful to ask about your problem on the Arduino forum.

 

...R

Link to post
Share on other sites

Hi guys,

 

As I mentioned, I'm working on a turntable that would not be controlled via DCC. Still, was testing the library and it wasn´t working , and do not decode the DCC Packet. I decided rewrite the code, part by part and test the modifications, and I think I finally found the problem. I believe that there is a conflict occurring between the DCC Library and the LCD Library. Sometimes the code works for a time and then stops withiout a apparent reason and sometimes does not work (just DCC packet decoding). When it stops working, I delete the commands relating to LCD, recompile the code, and the program restart. I rewrite the lcd commands again and the error recurs. I´m thincking to replace the LCD by i2c seven segments display.Anyone ever had similar problems?

Hi,

 

This may not be a solution for you, but I've seen other people have a trouble trying to drive an LCD display from the same Arduino that they are using to decode/encode the DCC Packets. It's down to the timing frequencies required by the libraries. To combat this, I've seen two Arduino's used, one to decode/encode and one to handle the display.

 

This YouTube video may be of help -

 

Hope it helps.

 

Cheers, Mark.

Link to post
Share on other sites

  • 2 weeks later...

Hi,

 

This may not be a solution for you, but I've seen other people have a trouble trying to drive an LCD display from the same Arduino that they are using to decode/encode the DCC Packets. It's down to the timing frequencies required by the libraries. To combat this, I've seen two Arduino's used, one to decode/encode and one to handle the display.

 

This YouTube video may be of help -

 

Hope it helps.

 

Cheers, Mark.

Hi, Mark...

 

Thanks for the tip! It helped me see that I'm on the right way!

 

This is exactly the solution I imagined. I considered using an I2C display, but I'm not sure if the libraries will work well together, and maybe I have the same problem. Just a doubt, the design of your video? If yes, how do you transfer data from one arduino to another? Could you share the code?

 

Thanks!

Link to post
Share on other sites

Hi Ray,

 

This is a truly brilliant and informative thread, many thanks for taking the time to share your knowledge and experiences. On the strength of this thread, I've gone out and treated myself to an Adruino Uno, Adafruit V2 and the same stepper motor as yourself. The other bits I'll hoover up off the internet once I've finished writing this message!

 

I'm looking to power a sector plate using a very similar set up as you have used for the turntable. The total travel required is 120 degree and will not need to stop at intermediate points. Ideally, I would like to be able to control this from one turnout address on my Roco Multimaus (So if I throw the point on the Multimaus, it will travel 120 degees clockwise from position A to position B. When the close the same point on the Multimaus it will travel 120 degree anticlockwise from position B to position A). I'm presuming that the coding shown in Part 6 could be tweaked to accommodate this?

 

To keep things simple, if I presume that the reference point (the location of the Hall Effect Sensor) is mid way through the 120 degree of travel (So position A is 60 degrees counter clockwise of this point and position B is 60 degrees clockwise from it) my guess is I would have to alter the 400 and 2000 values (around mid way through the script) to something like 533 and 2667 if there is 3200 microsteps per rotation? Is there an element of the script that dictates whether the stepper motor travels clockwise or anticlockwise? Sorry if I've got this wrong, I've never even thought of programming before!  

 

One other concern, is that the swing of the sector plate will be physically limited to a travel of 120 degrees. In other words, if the stepper motor was to try and complete a full turn it'd smash through the walls of the sector plate well! I can remove the walls for the initial set up (as detailed in part 5) but in service is there any requirement for the stepper motor to be able to travel a full rotation?

 

Again, many thanks for writing this up and apologies if my questions are a little basic!

 

Thanks,

 

Steve

Link to post
Share on other sites

 

Part 7 - The Seven Road Turntable

Just for completeness, here's the complete code.

 

~~~~~~

(Content removed)

~~~~~~~

 

I said at the beginning that I'm no expert when it comes to programming so if you see any improvements or develop this further please add them to this thread.

 

Ray.

 

Ray-

 

I wanted to say thank you for all the work that went into this.  I have built the attached set-up to perform some trials on my own.  The turntable it is going on is one that previously had to be lined by eye.  This was getting harder as the scene was being built up around it.  I have modified your code a little, but I really like the simplicity of the code.  And it works!  I used a hall sensor that works very reliably.  I modified your code so that the table always approaches the sensor from the same side, so that it always reads the same value. I have it mocked up under the layout and tested it for alignment.  It works really well.  I am very impressed.  To work on some "advanced" features I have removed the assemly from the layout and put it on my desk.  See attached photo.  I made a breakout board with some wafer board, but it follows your design with only the addition of more inputs (see text below):

  

In Set-Up:

  

         // if near reference point move awaypost-22354-0-97950800-1395259853.jpg

             while (sensorVal == LOW) {

                  sensorVal = digitalRead(3);

                  forwardstep2();

              delay(50);

                       Serial.println("Stepper Home");

 }

 

       // step backrward to sensor index point

            while (sensorVal == HIGH) {

                  sensorVal = digitalRead(3);

                  backwardstep2();

             delay(50);

 

 

 

As I typically have long ops sessions I wanted a way to kill power to the stepper motor (reduce buzzing, power consumption and heat) when we were finished using the table.  I would like to know of a more elegant way to have the "release" command issued 2-3 minutes after the table is in position. 

                 case 1:

                    stepper2.moveTo(1902);

                       delay(500);

                       release2();

                  break;

 

The command "release2()" is defined as :   void release2()   {  myStepper2->release();

 

This code does work, but not very elegantly.  The way it works right now is that you just call up the same item (ie- 201 thrown) again and it will release the motor power after a half second.  I would like to make this automatic, but don't know how.

 

The final change is also a big change.  I would like to add some analog controls to the fascia of the turntable to allow you to just call up a road with a dial and push button.  I have a 10k pot and two normally open push buttons.  I have the push buttons wired into Digital I/O 4 & 5, and the pot wired into Analog In 1.  I also put a reset button for the fascia panel. 

 

I have had success with the push buttons.  All three work.  The two in the Digial I/O 4 & 5 are currently just set up to move the table to a defined position.  It works.  The Pot is set up to output a digit 1-12 based on its position.  That also works.  I don't know how to make the combined solution work with the software.

 

The goal of mine is to line the dial (potentiometer) up with the drawing for the road and then call up a track by pushing either pushbutton.  One pushbutton would be “head” end and the other would be the “tail” position.  This would relate to the “thrown” and “closed” positions in DCC.

 

To get me closer to the goal, I sketched up some code.  This is what I have typed up, but it doesn't work like I want (but it does show the inputs work correctly)

 in "void loop()"  after the text you provided, I wrote:

 

//configure pin4 as an input and enable the internal pull-up resistor

  pinMode(4, INPUT_PULLUP);

  //read the sensor (open collector type) value into a variable

  int sensorHead = digitalRead(4);

 

  //configure pin5 as an input and enable the internal pull-up resistor

  pinMode(5, INPUT_PULLUP);

  //read the sensor (open collector type) value into a variable

   int sensorTail = digitalRead(5);

 

   // if Head button pushed

  while (sensorHead == LOW) {

    sensorHead = digitalRead(4);

    stepper2.moveTo(150);

      delay(50);

    release2();

  }   

 

  // if Tail button pushed

  while (sensorTail == LOW) {

    sensorTail = digitalRead(5);

    stepper2.moveTo(287);

      delay(50);

    release2();

  } 

 

I put the Pot sensor in the "Basic AccessoryPacket Handler" section just so I would be able to see the values easily when I called a DCC track.

 

 //configure alalog pin 1 as an input

  int potDisp = 1;

  int reading = analogRead(potDisp);

   int analogout = reading / 79; //1023 / 13

Further down I put the serial print just ahead of the "basic address" serial output line, so that I can see the value

 

Serial.print("Analog Location: ");

          Serial.println(analogout);

 

That is what I have so far.  Any help would be greatly appreciated.  I am not sure where to go from here.  If anyone wants I can post the complete code in a separate posting for everyone to copy.

 

Thanks

-Eric S. 

Portland, OR USA

Link to post
Share on other sites

Here is another question for the topic.

 

Can the stepper be used with a reduction gear or two so the servo makes more than one rotation to turn the table 360 degrees? This would make the number of steps be a factor greater (like 20x the steps to complete the rotation) for finer resolution and more accurate table placement.

Link to post
Share on other sites

@estreetcar, it is more usual to put the

pinMode(5, INPUT_PULLUP);
statements into setup() so they are only called once rather than hundreds or thousands of times per second. (And see what putting the code into code tags - the <> icon - does).

 

@gcodori, stepper motors can easily work with gears. The problem is that any backlash in the gear train will make the alignment less precise. There are various ways to deal with that.

 

...R

Edited by Robin2
Link to post
Share on other sites

@estreetcar, it is more usual to put the

pinMode(5, INPUT_PULLUP);
statements into setup() so they are only called once rather than hundreds or thousands of times per second. (And see what putting the code into code tags - the <> icon - does).

 

@gcodori, stepper motors can easily work with gears. The problem is that any backlash in the gear train will make the alignment less precise. There are various ways to deal with that.

 

...R

 

Robin and All-

 

I think it would be best for me to just paste in the entire code as it is right now.  I moved the statements to setup, but I don't understand what you meant by "(And see what putting the code into code tags - the <> icon - does)." 

 

I am very new to any type of programming (which should be pretty obvious when you look at my edits!).  I really appreciate the help.

 

Thanks

-Eric

 

////////////////////////////////////////////////////////////////////////////////
//
//   DCC Turntable Rev_1 Mar_20_2014
//        based on code from rmweb.co.uk forum
//          edited by E.Sitiko
//     This is a work in progress, I need some help with programming
//        Changes desired are:
//            12 road turntable  (works)
//            DCC addresses 200 to 212  (works)
//            "Real World" interface
//                2- N.O. Push buttons to enable move to "Head" or "Tail"
//                1- 10k Continuous turn POT to select track.
//                1- N.O. Reset button on fascia  (works)
//            Address 200= continuous slow rotation, based on "Head" or "Tail" (future)
//            A "Release" function, universal to operation, that would release power
//              to the table after sitting idle for 2-3 min.  Right now, you just call up
//              the same function again and it will "release"
//
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
//
// DCC Turntable Control Routines

#include <DCC_Decoder.h>
#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Defines and structures
//
#define kDCC_INTERRUPT            0

typedef struct
{
    int               address;                // Address to respond to
   
} DCCAccessoryAddress;

DCCAccessoryAddress gAddresses[13];

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// Adafruit Setup

Adafruit_MotorShield AFMStop(0x60); // Default address, no jumpers

// Connect stepper with 200 steps per revolution (1.8 degree)
// to the M3, M4 terminals (blue,yellow,green,red)

Adafruit_StepperMotor *myStepper2 = AFMStop.getStepper(200, 2);

// you can change these to SINGLE, DOUBLE, INTERLEAVE or MICROSTEP!

// wrapper for the motor! (3200 Microsteps/revolution)
void forwardstep2() {  
  myStepper2->onestep(BACKWARD, MICROSTEP);
}
void backwardstep2() {  
  myStepper2->onestep(FORWARD, MICROSTEP);
}
void release2()   {
  myStepper2->release();
}

// Now we'll wrap the stepper in an AccelStepper object

AccelStepper stepper2(forwardstep2, backwardstep2);

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Decoder Init
//
void ConfigureDecoder()
{
    gAddresses[0].address = 200;      
    gAddresses[1].address = 201;
    gAddresses[2].address = 202;
    gAddresses[3].address = 203;
    gAddresses[4].address = 204;
    gAddresses[5].address = 205;
    gAddresses[6].address = 206;
    gAddresses[7].address = 207;
    gAddresses[8].address = 208;
    gAddresses[9].address = 209;
    gAddresses[10].address = 210;
    gAddresses[11].address = 211;
    gAddresses[12].address = 212;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Basic accessory packet handler
//

void BasicAccDecoderPacket_Handler(int address, boolean activate, byte data)
{
   //configure alalog pin 1 as an input
        int potDisp = 1;
        int reading = analogRead(potDisp);
        int analogout = reading / 79; //1023 / 13
   
   int delayvalue = 500;
           
        // Convert NMRA packet address format to human address
    address -= 1;
    address *= 4;
    address += 1;
    address += (data & 0x06) >> 1;
    
    boolean enable = (data & 0x01) ? 1 : 0;
    
    for(int i=0; i<(int)(sizeof(gAddresses)/sizeof(gAddresses[0])); i++)
    {
        if( address == gAddresses[i].address )
        {
          
          Serial.print("Analog Location: ");
          Serial.println(analogout);
            Serial.print("Basic addr: ");
            Serial.print(address,DEC);
            Serial.print("   activate: ");
            Serial.println(enable,DEC);
                
            if( enable )
            {
                switch (i) {
                  case 0:
                    stepper2.moveTo(150);
                       delay(delayvalue);
                       //release2();
                  break;
                  case 1:
                    stepper2.moveTo(45);
                       delay(delayvalue);
                       release2();
                  break;
                  case 2:
                    stepper2.moveTo(205);
                       delay(delayvalue);
                       release2();                  
                  break;
                  case 3:
                    stepper2.moveTo(490);
                       delay(delayvalue);
                       release2();
                  break;
                  case 4:
                    stepper2.moveTo(588);
                       delay(delayvalue);
                       release2();
                  break;
                  case 5:
                    stepper2.moveTo(765);
                       delay(delayvalue);
                       release2();
                  break;
                  case 6:
                    stepper2.moveTo(1939);
                       delay(delayvalue);
                       release2();
                  break;
                  case 7:
                    stepper2.moveTo(2072);
                       delay(delayvalue);
                       release2();
                  break;
                  case 8:
                    stepper2.moveTo(2205);
                       delay(delayvalue);
                       release2();
                  break;
                  case 9:
                    stepper2.moveTo(2499);
                       delay(delayvalue);
                       release2();
                  break;
                  case 10:
                    stepper2.moveTo(2623);
                       delay(delayvalue);
                       release2();
                  break;
                  case 11:
                    stepper2.moveTo(2739);
                       delay(delayvalue);
                       release2();
                  break;
                  case 12:
                    stepper2.moveTo(2872);
                       delay(delayvalue);
                       release2();
                  break;
                 }
            }else{
                switch (i) {
                  case 0:
                    stepper2.moveTo(1750);
                       delay(delayvalue);
                       release2();
                  break;
                  case 1:
                    stepper2.moveTo(1645);
                       delay(delayvalue);
                       release2();
                  break;
                  case 2:
                    stepper2.moveTo(1805);
                       delay(delayvalue);
                       release2();
                  break;
                  case 3:
                    stepper2.moveTo(2090);
                       delay(delayvalue);
                       release2();
                  break;
                  case 4:
                    stepper2.moveTo(2188);
                       delay(delayvalue);
                       release2();
                  break;
                  case 5:
                    stepper2.moveTo(2365);
                       delay(delayvalue);
                       release2();
                  break;
                  case 6:
                    stepper2.moveTo(339);
                       delay(delayvalue);
                       release2();
                  break;
                  case 7:
                    stepper2.moveTo(472);
                       delay(delayvalue);
                       release2();
                  break;
                  case 8:
                    stepper2.moveTo(605);
                       delay(delayvalue);
                       release2();
                  break;
                  case 9:
                    stepper2.moveTo(899);
                       delay(delayvalue);
                       release2();
                  break;
                  case 10:
                    stepper2.moveTo(1023);
                       delay(delayvalue);
                       release2();
                  break;
                  case 11:
                    stepper2.moveTo(1139);
                       delay(delayvalue);
                       release2();
                  break;
                  case 12:
                    stepper2.moveTo(1272);
                       delay(delayvalue);
                       release2();
                  break;
                }
            }
        }
      }
    }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Setup
//
void setup()
{
   Serial.begin(9600);
   
   AFMStop.begin(); // Start the shield

  //configure pin3 as an input and enable the internal pull-up resistor
  pinMode(3, INPUT_PULLUP);
    //configure pin4 as an input and enable the internal pull-up resistor
  pinMode(4, INPUT_PULLUP);
  //configure pin5 as an input and enable the internal pull-up resistor
  pinMode(5, INPUT_PULLUP);
 
  //read the sensoron Dig I/O #3 (open collector type) value into a variable
  int sensorVal = digitalRead(3);
 
  //set stepper motor speed and acceleration
  stepper2.setMaxSpeed(80.0);
  stepper2.setAcceleration(10.0);
    
// if near reference point move away
  while (sensorVal == LOW) {
    sensorVal = digitalRead(3);
    forwardstep2();
      delay(50);
      Serial.println("Stepper Home");
 }
 
// step backrward to sensor index point
  while (sensorVal == HIGH) {
    sensorVal = digitalRead(3);
    backwardstep2();
      delay(50);
  }

 
   DCC.SetBasicAccessoryDecoderPacketHandler(BasicAccDecoderPacket_Handler, true);
   ConfigureDecoder();
   DCC.SetupDecoder( 0x00, 0x00, kDCC_INTERRUPT );
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Main loop
//
void loop()
{
    static int addr = 0;
    
        ////////////////////////////////////////////////////////////////
        // Loop DCC library
    DCC.loop();
    
        ////////////////////////////////////////////////////////////////
        // Bump to next address to test
    if( ++addr >= (int)(sizeof(gAddresses)/sizeof(gAddresses[0])) )
    {
        addr = 0;
    }
    
    stepper2.run();
    

//   This is the questionable area.  Trying to make the buttons work.
//     Currently they just drive the table to a location.  I would like them
//      to direct the type of movement, ie- read analog input (POT) and
//      take the table to the correct road with either the "Head" or "Tail" end
//
  //read the sensor (open collector type) value into a variable
  int sensorHead = digitalRead(4);
  //read the sensor (open collector type) value into a variable
  int sensorTail = digitalRead(5);
 
   // if Head button pushed
  while (sensorHead == LOW) {
    sensorHead = digitalRead(4);
    stepper2.moveTo(45);
      delay(500);
    release2();
  }   

  // if Tail button pushed
  while (sensorTail == LOW) {
    sensorTail = digitalRead(5);
    stepper2.moveTo(1645);
      delay(500);
    release2();
  }  
 
 
  }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Also- See file in Arduino *.ino format

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

That is the end of it.

Thanks-

Eric

DCC_Turntable_Rev_1.ino

Edited by Estreetcar
Link to post
Share on other sites

Using the code tags (the <> icon above the edit window) just makes the code easier to read. You can edit your post, select all the text that represents the code and click the icon. This is an example using your setup function.

void setup()
{
   Serial.begin(9600);
   
   AFMStop.begin(); // Start the shield

  //configure pin3 as an input and enable the internal pull-up resistor
  pinMode(3, INPUT_PULLUP);
    //configure pin4 as an input and enable the internal pull-up resistor
  pinMode(4, INPUT_PULLUP);
  //configure pin5 as an input and enable the internal pull-up resistor
  pinMode(5, INPUT_PULLUP);
 
  //read the sensoron Dig I/O #3 (open collector type) value into a variable
  int sensorVal = digitalRead(3);
 
  //set stepper motor speed and acceleration
  stepper2.setMaxSpeed(80.0);
  stepper2.setAcceleration(10.0);
    
// if near reference point move away
  while (sensorVal == LOW) {
    sensorVal = digitalRead(3);
    forwardstep2();
      delay(50);
      Serial.println("Stepper Home");
 }
 
// step backrward to sensor index point
  while (sensorVal == HIGH) {
    sensorVal = digitalRead(3);
    backwardstep2();
      delay(50);
  }

 
   DCC.SetBasicAccessoryDecoderPacketHandler(BasicAccDecoderPacket_Handler, true);
   ConfigureDecoder();
   DCC.SetupDecoder( 0x00, 0x00, kDCC_INTERRUPT );
}

Having said that, I prefer to download long pieces of code and study them in my text editor rather than in the browser so it is helpful to include a copy of the code as a downloadable file.

 

...R

Link to post
Share on other sites

Using the code tags (the <> icon above the edit window) just makes the code easier to read. You can edit your post, select all the text that represents the code and click the icon. This is an example using your setup function.

Having said that, I prefer to download long pieces of code and study them in my text editor rather than in the browser so it is helpful to include a copy of the code as a downloadable file.

 

...R

Robin-

 

Thanks for the help.  I have fixed the previous posting and also included the arduino *.ino type file as an attachment.

 

-Eric

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...