Jump to content
 

DCC Controlled (PECO) Turntable Project using a Arduino Uno


Recommended Posts

  • RMweb Gold

OK Geoff, Looks like the sensor is working ok so you should be able to get the voltage to drop to almost zero with the magnet on the turntable deck and the sensor on the outside of the well. Try with the sensor the other way around. Have another look at post 4 for reference. Are you using the PECO turntable?

 

Ray.

Crossed posts I think Ray. No my turntable is a SEF (Wills Finecast). I had the sensor printed side to the wall, as you did I believe, but as you will see from my previous post it just seemed to need repositioning. I will do that and report back.

 

Geoff

Link to post
Share on other sites

Crossed posts I think Ray. No my turntable is a SEF (Wills Finecast). I had the sensor printed side to the wall, as you did I believe, but as you will see from my previous post it just seemed to need repositioning. I will do that and report back.

 

Geoff

 

 

As long as its working, it doesn't matter which way around the sensor is mounted. Like you say, it probably just needs its position tweaked a bit.

 

Ray.

Link to post
Share on other sites

  • RMweb Gold

Bingo Ray. It is rotating back and forth between the two marks nicely now. I will let it run for a bit before I attempt the DCC bit. I will have to use a different DCC address but you have already told me where to alter the code for that so that will be the next task.

Thank you so much for your patience and help.

 

Geoff

  • Like 3
Link to post
Share on other sites

Bingo Ray. It is rotating back and forth between the two marks nicely now. I will let it run for a bit before I attempt the DCC bit. I will have to use a different DCC address but you have already told me where to alter the code for that so that will be the next task.

Thank you so much for your patience and help.

 

Geoff

 

No problem. Keep us posted on progress, if you need any more help just shout.

 

Ray

  • Like 1
Link to post
Share on other sites

  • RMweb Gold

Well after burning the midnight oil I have a working turntable, albeit with some mechanical issues I need to think about. It took a little head scratching to get the DCC test to work because again the ' _MS_ ' was required in the preamble and then I struggled for some reason to get programme into the correct place in the 'Libraries'. Anyway it all works nicely from my Digitrax DT402.

It took me some considerable time to get to the appropriate values to line up with the approach track and it is fine now provided I don't allow it to reverse. There is some friction in one direction which I think results in a few steps being missed so I will have to try to resolve that. Otherwise the Arduino is all working just as it should.

My two remaining questions are how can I power the Arduino so that I do not have to have the MacBook hooked up to it? Can I put the 12v supply into the Arduino jack and use the jumper link on the Adafruit shield, or does that work in reverse using the jumper link to power the Arduino from the Adafruit shield?

the second question concerns the reset wire from the DCC interface which is currently not connected to anything. Should it be connected to the Arduino and if so would that be through a switch?

Ray, thank you for the time you have given over to help me with this. I would not have been able to make this work at all without your help and support. Thank you too to Ian and Robin for your input to help me in my struggle with this. 

I knew it would not be plain sailing and that was one of the reasons for tackling it, to keep the "little grey cells" exercised. Thank you all, it has been challenging but have enjoyed it.

 

Geoff

Link to post
Share on other sites

Well done Geoff, glad you got there in the end.

With the power you should be able to insert the Vin link on the Adafruit board and power both boards from either the Arduino power jack or the Adafruit power connector without the USB connection. I say 'should be' as i've never tried it as yet. 

Connect the 'reset' wire through a push to make switch to GND and you can then just restart the program should anything get out of sync.

 

Many thanks for posting your experience with a MacOS setup, I'm sure it will be useful for those using a Mac, me included.

 

Ray.

Link to post
Share on other sites

  • RMweb Gold

Well done Geoff, glad you got there in the end.

With the power you should be able to insert the Vin link on the Adafruit board and power both boards from either the Arduino power jack or the Adafruit power connector without the USB connection. I say 'should be' as i've never tried it as yet. 

Connect the 'reset' wire through a push to make switch to GND and you can then just restart the program should anything get out of sync.

 

Many thanks for posting your experience with a MacOS setup, I'm sure it will be useful for those using a Mac, me included.

 

Ray.

 

Good morning Ray,

Thank you for that, I will have a go at it this evening I hope. I am glad I could make a small contribution to the thread and I will try to post some screen shots to show where all the technical bits finished up on a Mac.

 

Many thanks.

 

Geoff

Link to post
Share on other sites

  • RMweb Gold

Good evening Ray,

 

Well after the euphoria of yesterday evening this evening's session has been disappointing. But first the good news. The power connection via the Arduino coax socket and jumper plug works fine so that will be my normal running setup.

The less good news is that although I can set it to align with the approach road on the first command © and rotate through 180deg with the second command (T) and line up nicely, when I send a further © command the motor reverses, not an issue, but stops short by about 3 or 4 rail widths. I have tried many combinations of settings but all to no avail. I suspect it is probably a mechanical issue, too much friction in one direction but I have not yet been able to resolve it.

 

A couple of other things puzzle me. When I first power up the set up I have to upload the programme before I can use the turntable. Does the Arduino not keep the last operation in its memory ready to use as soon as it is powered up? The motor always starts off rotating anti-clockwise, not an issue, but after the first two commands just turns back and forth through 180 deg. with each command, it never just continues round to the next stop. In its self that is not an issue, I am just curious as to what I should expect. Finally, the motor does seem to get very hot but that might be because of friction in the turntable, oh and when I run a loco on, thus loading the deck, the motor is not able to rotate fully to either position. I think that confirms there to be some significant frictional problems with the turntable.

 

I have never been very impressed with this turntable kit but at the time it was the only one available for the size I wanted, 50ft if I remember correctly.

 

I have attached some screen shots to show what it looks like on a Mac and where things end up. Also there are a couple of shots showing the DCC test sketch and the step settings I was using. I understand 180 deg equals 1600 steps so why does the sum of the two settings not equal 3200?

 

Anyway, we are off on holiday on Saturday so I doubt I will do any more work on it until we get back and then I might have to consider a major rebuild.

 

 

Thank you again for all your help. At least we know that the set up works in principle.

 

Geoff

post-224-0-50315800-1502400784_thumb.png

post-224-0-42198700-1502400822.png

post-224-0-50600900-1502400848_thumb.png

post-224-0-60788300-1502400875_thumb.png

post-224-0-66849000-1502400901_thumb.png

Link to post
Share on other sites

Good evening Ray,

 

Well after the euphoria of yesterday evening this evening's session has been disappointing. But first the good news. The power connection via the Arduino coax socket and jumper plug works fine so that will be my normal running setup.

The less good news is that although I can set it to align with the approach road on the first command © and rotate through 180deg with the second command (T) and line up nicely, when I send a further © command the motor reverses, not an issue, but stops short by about 3 or 4 rail widths. I have tried many combinations of settings but all to no avail. I suspect it is probably a mechanical issue, too much friction in one direction but I have not yet been able to resolve it.

 

A couple of other things puzzle me. When I first power up the set up I have to upload the programme before I can use the turntable. Does the Arduino not keep the last operation in its memory ready to use as soon as it is powered up? The motor always starts off rotating anti-clockwise, not an issue, but after the first two commands just turns back and forth through 180 deg. with each command, it never just continues round to the next stop. In its self that is not an issue, I am just curious as to what I should expect. Finally, the motor does seem to get very hot but that might be because of friction in the turntable, oh and when I run a loco on, thus loading the deck, the motor is not able to rotate fully to either position. I think that confirms there to be some significant frictional problems with the turntable.

 

I have never been very impressed with this turntable kit but at the time it was the only one available for the size I wanted, 50ft if I remember correctly.

 

I have attached some screen shots to show what it looks like on a Mac and where things end up. Also there are a couple of shots showing the DCC test sketch and the step settings I was using. I understand 180 deg equals 1600 steps so why does the sum of the two settings not equal 3200?

 

Anyway, we are off on holiday on Saturday so I doubt I will do any more work on it until we get back and then I might have to consider a major rebuild.

 

 

Thank you again for all your help. At least we know that the set up works in principle.

 

Geoff

attachicon.gifScreenshot 2017-08-10 16.29.45.png

attachicon.gifScreenshot 2017-08-10 16.32.10.png

attachicon.gifScreenshot 2017-08-10 16.33.00.png

attachicon.gifScreenshot 2017-08-10 21.43.23.png

attachicon.gifScreenshot 2017-08-10 21.57.29.png

 

Hi Geoff.

 

Firstly, the motor does run hot as to use micro stepping it has to be powered continuously. I hope to do a modification using toothed pulley/belts so as not to use micro stepping which would allow the motor to be powered down when not rotating. But i've a lot on at present so to won't happen soon.

 

Not sure about the power up issue, i thought the arduino retained the last program as well, i'll look into that.

 

If you're not getting a full 180 degrees rotation it suggests missing steps usually due to friction caused by mis-alignment. Although I'm not sure why you have the values of 1072 and 2704 in the goto commands which may be the reason as they don't subtract to give 1600 or have you adjusted them to over come the friction?

 

So using my values of 400 and 2000, why don't they add up to 3200? Well they do if you keep counting in the same direction, from 400 to 2000 clockwise is 1600 steps (2000-400) and then from 2000 to 400 clockwise is another 1600 steps (3200-2000+400)

 

Using your values of 1072 and 2704 we get 2704-1072=1632 and from 2704 to 1072  we get 3200-2704+1072=1568. 1632+1568=3200

 

Did you try the sketch where the turntable just rotates back an forth between two marks (post 17 Part 5)? Might be worth revisiting this as it will show up any friction in the mechanics.

 

Ray.

Edited by tender
Link to post
Share on other sites

  • RMweb Gold

Hi Geoff.

 

Firstly, the motor does run hot as to use micro stepping it has to be powered continuously. I hope to do a modification using toothed pulley/belts so as not to use micro stepping which would allow the motor to be powered down when not rotating. But i've a lot on at present so to won't happen soon.

 

Not sure about the power up issue, i thought the arduino retained the last program as well, i'll look into that.

 

If you're not getting a full 180 degrees rotation it suggests missing steps usually due to friction caused by mis-alignment. Although I'm not sure why you have the values of 1072 and 2704 in the goto commands which may be the reason as they don't subtract to give 1600 or have you adjusted them to over come the friction?

 

So using my values of 400 and 2000, why don't they add up to 3200? Well they do if you keep counting in the same direction, from 400 to 2000 clockwise is 1600 steps (2000-400) and then from 2000 to 400 clockwise is another 1600 steps (3200-2000+400)

 

Using your values of 1072 and 2704 we get 2704-1072=1632 and from 2704 to 1072  we get 3200-2704+1072=1568. 1632+1568=3200

 

Did you try the sketch where the turntable just rotates back an forth between two marks (post 17 Part 5)? Might be worth revisiting this as it will show up any friction in the mechanics.

 

Ray.

 

Hello Ray, I am back on dry ground after a week aboard a narrow boat.

Thank you for your reply.

I did run the turntable test and this was working accurately and reliably, however, this test only had the turntable operating in a different sector of the whole circle to that which the table turns through when running the DCC Test.

Your reassurance that the motor will run hot because of the continuous power required foe micro stepping was helpful as I wondered if it was because of a mechanical load on the motor.

I realised the different values should be 1600 apart, the figures I quoted were just where I finished up trying to sort out why it wouldn't make the full 180 deg. turn. I will look to see if I can find any possible friction points in the operating section which might be causing the problem.

When I power up the Arduino it always starts up with the Turntable Test. Should that be over written by the DCC Test?

Once again thank you for your continuing help with this.

 

Geoff

Link to post
Share on other sites

  • RMweb Gold

Hi Geoff,

Try running the turntable test routine with values of say 1400 and 3000. That should make it operate in a different sector to check again for friction.

 

Ray.

 

Hello Ray,

I have sorted the Arduino starting with the turntable test. I waited until I had uploaded the DCC Test and then closed the Turntable Test. I shut down the Arduino software and then restarted and it came up with the DCC Test ready to go.

The turn table always starts from the sensor and on the 'C' command will line up exactly if I put in the right value, around 1106, it will then rotate 180 degrees, value  +1600 on the 'T' command and line correctly but when I again send the 'C' command it will stop half a track width, 9mm, short, my layout is EM gauge. I can replicate this with a variety of values around the 1100 and 2700. 

I will give your suggested values a go tomorrow if I get the chance. I have checked for friction points and cannot find any so far.

Thank you.

 

Geoff

 

Geoff

Link to post
Share on other sites

Hi Geoff..

 

sorry to but in, but it seems that your are thinking that what ever sketch loads up in the IDE is what is on the board?

 

this is not the case.... what is in the IDE is not related to what has been downloaded to the board - its simply the last sketch you had open the last time it was closed down.

Link to post
Share on other sites

  • RMweb Gold

Hi Geoff..

 

sorry to but in, but it seems that your are thinking that what ever sketch loads up in the IDE is what is on the board?

 

this is not the case.... what is in the IDE is not related to what has been downloaded to the board - its simply the last sketch you had open the last time it was closed down.

 

Hello Ian, 

Yes I sussed that out eventually and I have it sorted now. I have just spent 3 or 4 hours trying Ray's suggested settings and many others and always when the table reverses it stops short of the mark by about 6mm. It responds accurately to the first two command but of course then it is only going forwards but on the third command to return to the original position it stops short. That applies wherever in the circle I try it yet oddly it executes the Turntable Test, oscillating between two positions, perfectly. Anyway I am going to give it a rest for now before the motor catches fire. Even though Ray assured me they run hot when micro stepping I am a little concerned, it is way too hot to touch. As far as my motor is concerned there seems to be sufficient inertia inbuilt to hold the turntable in position, certainly when it is not powered I can drive locos on and off with no issues so I wonder if the programme can be adjusted to cut the power when the table has reached the assigned position.

 

 

Geoff

Link to post
Share on other sites

  • RMweb Gold

Hi Geoff,

Try running the turntable test routine with values of say 1400 and 3000. That should make it operate in a different sector to check again for friction.

 

Ray.

 

Good morning Ray,

I tried your settings and many others but all gave the same result, when the turntable reverses it stops short. I spent several hours trying to fine tune it but the end result was always that it stopped short when turning in the reverse direction. In the end I was so concerned about the temperature of the motor that I packed up for the evening. I have, as far as I can tell, eliminated any significant friction, any that remains is there for the turntable test which it performs perfectly and consistently. If you have seen my reply to Ian you will have read all this so I apologise for repeating myself.

When the system is shut down I find that the turntable stays nicely in position just with the inertia of the motor so is there a way to build into the programming a command to cut the motor power at each stopping position and then restart it for the next move? I wonder too what would be the effect of setting a second stopping command, as in for a second track, to over come the short stopping on the reverse turn? Alternatively is it practical to have the turntable turn in one direction only?

Sorry for so many questions.

 

Regards

 

Geoff

Link to post
Share on other sites

Hi Geoff.

Can you post the Sketch that you're having trouble with the turntable stopping short and i'll upload it into my system and see if does the same.

Might take me a bit of time to get it all together as its not been used for some time so don't expect an instant reply.

 

With regards to powering down the motor, i'm not sure if the Adafruit module can do this, we might have to introduce a relay to remove the power from the adafuit board. I'll look into this as well.

 

Ray.

Link to post
Share on other sites

  • RMweb Gold

Hi Geoff.

Can you post the Sketch that you're having trouble with the turntable stopping short and i'll upload it into my system and see if does the same.

Might take me a bit of time to get it all together as its not been used for some time so don't expect an instant reply.

 

With regards to powering down the motor, i'm not sure if the Adafruit module can do this, we might have to introduce a relay to remove the power from the adafuit board. I'll look into this as well.

 

Ray.

 

Hello Ray,
Below is the sketch I am using. I hope it is essentially the one you posted but with a different DCC address of 400 and the values which align the turntable with my approach track. Of course it is always possible that I have inadvertently altered something accidentally when making the the changes I needed, or indeed not changed something I needed to change.
Thank you again for giving this so much time and effort.
 
Geoff
 
 
DCC_Test
 
////////////////////////////////////////////////////////////////////////////////
//
// DCC Turntable Control Test Routines (Accessory Address 200)
 
#include <DCC_Decoder.h>
#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Defines and structures
//
#define kDCC_INTERRUPT            0
 
typedef struct
{
    int               address;                // Address to respond to
 
 
DCCAccessoryAddress;
 
DCCAccessoryAddress gAddresses[1];
 
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// 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(FORWARD, MICROSTEP);
}
void backwardstep2() {  
  myStepper2->onestep(BACKWARD, MICROSTEP);
}
 
// Now we'll wrap the stepper in an AccelStepper object
 
AccelStepper stepper2(forwardstep2, backwardstep2);
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Decoder Init 
//
void ConfigureDecoder()
 {
    gAddresses[0].address = 400;
 }
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Basic accessory packet handler 
//
void BasicAccDecoderPacket_Handler(int address, boolean activate, byte data)
{
        // Convert NMRA packet address format to human address
    address -= 1;
    address *= 4;
    address += 1;
    address += (data & 0x06) >> 1;
    
    boolean enable = (data & 0x01) ? 1 : 0;
    
        if( address == 400 )
        {
            Serial.print("Basic addr: ");
            Serial.print(address,DEC);
            Serial.print("   activate: ");
            Serial.println(enable,DEC);
            
            if( enable )
              {
                stepper2.moveTo(1106);
              }
           else
              {
                stepper2.moveTo(2706);
              }
       }
}
 
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Setup
//
void setup() 
   Serial.begin(9600);
   
   AFMStop.begin(); // Start the shiel
  
  //configure pin3 as an input and enable the internal pull-up resistor
  pinMode(3, INPUT_PULLUP);
  //read the sensor (open collector type) value into a variable
  int sensorVal = digitalRead(3);
   
  //set stepper motor speed and acceleration 
  stepper2.setMaxSpeed(30.0);
  stepper2.setAcceleration(20.0);
//  stepper2.moveTo(800);
 
// if near reference point move away
  sensorVal = digitalRead(3);
  while (sensorVal == LOW) {
    sensorVal = digitalRead(3);
    forwardstep2();
      delay(50);
  }
  
// step forward to sensor index point
  while (sensorVal == HIGH) {
    sensorVal = digitalRead(3);
    forwardstep2();
      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();
    
        ////////////////////////////////////////////////////////////////
        // Loop Stepper
    
    stepper2.run();
}
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 

 

Link to post
Share on other sites

Hi Geoff, I'm back. Sorry it took so long. The last time I complied the turntable code was a few years ago when I was running version 1.05 of the IDE.

I now have the latest version and some some reason it wouldn't complie the DCC libraries. Took a bit of head scratching for the last day or so, then I remembered somewhere back in the thread that there was a new download location for them.

So I downloaded a new set of DCC libraries and hey presto I have a working system again.

 

I have just reloaded my version of DCC Test from page 1 just to male sure it does what it supposed to and I think I have reproduced your problem.

With the two 'goto' values of 400 and 2000 there's about a rails width error when rotating back and forth 180deg.

I think the reason is that micro stepping isn't very accurate as we are trying to hold the stepper between two steps but it is repeatable.

 

I found by adjusting the values to 398 and 2000 the turntable would rotate back and forth 180deg without any error.

 

You will probably have to set the values for your system as you have a different exit position but found setting the highest value position first (after the sensor detect) and then working back to the lower value position gave the best result.

 

i.e. when rotating back to the lower value position if it overshoots increase the goto value, if it undershoots decrease the goto value.

 

You should end up with two goto values 1600 steps apart within about  +/- 4.

 

I'm going to now copy paste your code just to make sure it works and i'll get back with the values I needed for 180deg rotation.

 

Ray.

Edited by tender
Link to post
Share on other sites

Hi Geoff,

 

Just uploaded your code and using the higher goto (2706) as the 'correct' position I had to tweak the lower goto (1106) to 1102 to get a repeatable 180deg rotation back and forth.

 

As for the motor getting hot, well yes it is, but it's been on now for about 3 hours and I can hold a finger on it for about 10 seconds before it starts getting uncomfortable. It's well under 100deg, so I think it's within its working spec. It's drawing about 300mA from the power supply at 12Volts.

 

Ray.

Link to post
Share on other sites

  • RMweb Gold

Hi Geoff, I'm back. Sorry it took so long. The last time I complied the turntable code was a few years ago when I was running version 1.05 of the IDE.

I now have the latest version and some some reason it wouldn't complie the DCC libraries. Took a bit of head scratching for the last day or so, then I remembered somewhere back in the thread that there was a new download location for them.

So I downloaded a new set of DCC libraries and hey presto I have a working system again.

 

I have just reloaded my version of DCC Test from page 1 just to male sure it does what it supposed to and I think I have reproduced your problem.

With the two 'goto' values of 400 and 2000 there's about a rails width error when rotating back and forth 180deg.

I think the reason is that micro stepping isn't very accurate as we are trying to hold the stepper between two steps but it is repeatable.

 

I found by adjusting the values to 398 and 2000 the turntable would rotate back and forth 180deg without any error.

 

You will probably have to set the values for your system as you have a different exit position but found setting the highest value position first (after the sensor detect) and then working back to the lower value position gave the best result.

 

i.e. when rotating back to the lower value position if it overshoots increase the goto value, if it undershoots decrease the goto value.

 

You should end up with two goto values 1600 steps apart within about  +/- 4.

 

I'm going to now copy paste your code just to make sure it works and i'll get back with the values I needed for 180deg rotation.

 

Ray.

 

Ray, I am putting you to an awful lot of trouble. Thank you so much for bearing with me.

 

Geoff

Link to post
Share on other sites

Ray, I am putting you to an awful lot of trouble. Thank you so much for bearing with me.

 

Geoff

 

No problem Geoff, I've been meaning to get back into this for some time.

 

So to summarise the above.

 

Adjust the higher (moveTo) value for the correct position, then tweak the lower (moveTo) value for 180deg rotation.

 

Ray

Link to post
Share on other sites

  • RMweb Gold

No problem Geoff, I've been meaning to get back into this for some time.

 

So to summarise the above.

 

Adjust the higher (moveTo) value for the correct position, then tweak the lower (moveTo) value for 180deg rotation.

 

Ray

 

Thanks Ray. I will give that a go tomorrow sometime and report back.

 

Geoff

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...