Jump to content
 

cambriancoaster

Members
  • Posts

    137
  • Joined

  • Last visited

Everything posted by cambriancoaster

  1. Phil: Many thanks for posting the superb photos of Rhyd-y-Clafdy - they are really impressive. On another topic I would appreciate it if you could let me know how you obtained the excellent Cambrian Coast Express headboard. I am also in need of your advice for constructing bracket signals for Pwllheli! Best wishes CC
  2. Phil: I'm absolutely delighted to see that you have taken the plunge and started a thread for "Ellesmere" on RMWeb. It looks to be a fantastic layout and I'm very much looking forward to seeing it "in the flesh". It is a real bonus that we will be able to keep up to date on its progress with this thread. Perhaps, now that you have got to grips with posting on RM web, you could be tempted on starting a topic for Rhyd-y-Clafdy - your original iconic Cambrian layout. Best wishes CC
  3. Derek A really fascinating topic and read - please keep the posts coming. It seems that we have quite a lot in common too. Like you I took an ONC/HNC in Chemistry and then did a degree in the subject at about the same point in time (I started my career as a Lab Assistant at ICI in 1955). We are also currently facing an identical challenge in constructing a turntable for our layouts. Mine is a GWR 55ft table - the deck of which has been built from a Mercian Models brass kit. If you are interested you can view it on my own topic: Pwllheli next stop. My wife thinks I am spending far too much time on it! So I am looking forward to your updates and experiences with keen anticipation. Best wishes CC
  4. Hi: Immediately after posting my previous post I noticed that I have written in the paragraph just below the sketch: This sketch is set for clockwise and anticlockwise movements for 160, 45, 135 degrees and nudge. It should of course read: This sketch is set for clockwise and anticlockwise movements for 180, 45, 135 degrees and nudge. Apologies CC
  5. Hello Ray, Southern Way and everyone I have been away for a few days and haven't had the opportunity to post the sketch for my version of the Arduino/Stepper motor turntable controller before now so I am taking this opportunity to do so. Before I post it I thought I would include a few images of the connections between the pushbutton panel and the Adafruit Motor Shield. This is a view of the underside of the turntable and you can see the stepper motor and shaft coupler connecting to the turntable shaft, and also the Adafruit Motor Shield (mounted on top of the Arduino) with its connections to the pushbutton panel. Behind the stepper motor is a DCC Specialities auto polarity reverser. All these items are mounted on a turntable sub base which is attached (using four dome headed screws and wing nuts) to the main baseboard. The simple pushbutton panel used to control the turntable. The buttons are basic push to make pushbuttons though in this case used in push to break mode. The rear of the pushbutton panel with the Adafruit Motor Shield and the connections between them. There are eight pushbuttons in my configuration and a single (red wire) from each button goes an appropriate i/o pin on the motor shield. In the Arduino sketch below you will see these are wired to pins 4 to 11. The black wire is from the ground pin on the motor shield and connects to the copper tape on the panel (which then acts as the common ground for all the buttons) . And here is the Arduino sketch I have constructed to control the turntable. I have tried to keep this as simple as I can and have annotated it heavily to remind me what I did when I come to look at the code in the future and have forgotten everything I learnt about C++ coding for the Arduino! /* This sketch is for an Arduino Uno micro controller equipped with an Adadfruit Motor Shield and will drive a stepper motor directly connected to a model railway turntable. The inspiration and many of the ideas behind this sketch came from the thread: http://www.rmweb.co.uk/community/index.php?/topic/78578-dcc-controlled-peco-turntable-project/ started by Tender on 12-Nov-2013 */ /* The shaft of the Stepper Motor is directly connected to the turntable shaft with a shaft coupler (note: for this example a Mercury Stepper Motor SM42BY0011-25 was used). The sketch requires the Adafruit_Motorshield v2 library - downloadable from https://github.com/adafruit/Adafruit_Motor_Shield_V2_Library and the AccelStepper library with AFMotor support https://github.com/adafruit/AccelStepper The sketch will only work with Adafruit Motorshield v2. for the Arduino Uno. It not work with v1 shields*/ /* set the system up to include the following libraries:*/ #include <AccelStepper.h> #include <Wire.h> #include <Adafruit_MotorShield.h> #include "utility/Adafruit_PWMServoDriver.h" /* Create the motor shield object with the default I2C address Or, create it with a different I2C address (say for stacking) Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); Connect a stepper motor with 200 steps per revolution (1.8 degree per step) to motor port no.2 (M3 and M4) */ Adafruit_MotorShield AFMS = Adafruit_MotorShield(); Adafruit_StepperMotor *myStepper1 = AFMS.getStepper(200, 2); // you can change these to DOUBLE or INTERLEAVE or MICROSTEP! void forwardstep1() { myStepper1->onestep(FORWARD, MICROSTEP); // sets forward mode at 3200 steps per revolution (0.1125 degree per step) } void backwardstep1() { myStepper1->onestep(BACKWARD, MICROSTEP); // sets backward mode at 3200 steps per revolution (0.1125 degree per step) } AccelStepper Astepper1(forwardstep1, backwardstep1); // use functions to step void setup() { Serial.begin(9600); // sets up Serial library at 9600 bps for a serial monitor connected to the Artduino Serial.println("Stepper test for turntable"); // prints the comment between the "" on the serial monitor when starting. AFMS.begin(); // create with the default frequency 1.6KHz //AFMS.begin(1000); // OR with a different frequency, say 1KHz Astepper1.setMaxSpeed(50.0); // sets the maximum rotational speed of the stepper in steps per second. // (the value of 50 will rotate the turntable for a full revolution // in about 3200/50 seconds (i.e around 64 seconds). Astepper1.setAcceleration(10.0); // The following commands set I/O pins numbers 4 through 11 on the Arduino/Adadfruit to a nominal 5V: pinMode(4, INPUT_PULLUP); pinMode(5, INPUT_PULLUP); pinMode(6, INPUT_PULLUP); pinMode(7, INPUT_PULLUP); pinMode(8, INPUT_PULLUP); pinMode(9, INPUT_PULLUP); pinMode(10, INPUT_PULLUP); pinMode(11, INPUT_PULLUP); } void loop() { int PinState4=digitalRead(4); if (PinState4==LOW){ Serial.println("rotating 180 degrees clockwise"); Astepper1.setCurrentPosition(0); Astepper1.moveTo(-1600); Astepper1.run(); Astepper1.runToPosition();} int PinState5=digitalRead(5); if (PinState5==LOW){ Serial.println("rotating 180 degrees anticlockwise"); Astepper1.setCurrentPosition(0); Astepper1.moveTo(1600); Astepper1.run(); Astepper1.runToPosition();} int PinState6=digitalRead(6); if (PinState6==LOW){ Serial.println("rotating 45 degrees clockwise"); Astepper1.setCurrentPosition(0); Astepper1.moveTo(-400); Astepper1.run(); Astepper1.runToPosition();} int PinState7=digitalRead(7); if (PinState7==LOW){ Serial.println("rotating 45 degrees anticlockwise"); Astepper1.setCurrentPosition(0); Astepper1.moveTo(400); Astepper1.run(); Astepper1.runToPosition();} int PinState8=digitalRead(8); if (PinState8==LOW){ Serial.println("rotating 135 degrees clockwise"); Astepper1.setCurrentPosition(0); Astepper1.moveTo(-1200); Astepper1.run(); Astepper1.runToPosition(); } int PinState9=digitalRead(9); if (PinState9==LOW){ Serial.println("rotating 135 degrees anticlockwise"); Astepper1.setCurrentPosition(0); Astepper1.moveTo(1200); Astepper1.run(); Astepper1.runToPosition(); } int PinState10=digitalRead(10); if (PinState10==LOW){ Serial.println("rotating nudge clockwise"); Astepper1.setCurrentPosition(0); Astepper1.moveTo(-2); Astepper1.run(); Astepper1.runToPosition(); } int PinState11=digitalRead(11); if (PinState11==LOW){ Serial.println("starting nudge anticlockwise"); Astepper1.setCurrentPosition(0); Astepper1.move(2); Astepper1.run(); Astepper1.runToPosition(); /* delay(100);} */ } } This sketch is set for clockwise and anticlockwise movements for 160, 45, 135 degrees and nudge. You will see (digital reads 10 and 11) that I have set the nudge value for 2 steps which means that a single push of a nudge button will advance the stepper just 0.225 of a degree. If a more precise nudge factor is needed you can always set this to 1 (i.e. each step is 0.1125 degrees). Keeping a finger on a nudge button will result in the table turning continuously (but slowly) until you take the finger off the button. In this way you can correct any misalignment (should it occur) by eye. There are 14 i/o pins on the motor shield which would allow you to set up 14 different movements. I hope this all helps the general discussion on the topic but if you have any queries please let me know and I will do my best to answer them. Regards CC
  6. Hello Ray & Everyone It is a while since I posted anything on this topic because I wasn't making much progress. However in the last few weeks I have been much more successful. As mentioned in previous posts I don't really understand the DCC library functions used in the sketches, and so, not wanting to become an electronics engineer, I have persevered with an alternative strategy which sets road positions by the difference in steps (or if you like the angle) between them. In this variant the rotation of the table is governed by simple push-to-break pushbuttons directly wired to the input/output terminals on the Adafruit Motor Shield. The I/O pin states on the shield are defined as INPUT_PULLUP which means that they are set as high (i.e.5V). The push buttons are each wired to an input terminal and to a common ground. When a button is depressed the Arduino notes that the input is now low, sets the current position of the stepper motor as zero, and then rotates the turntable the number of steps predefined for that input (e.g. 1600 steps for 180 degrees, 400 steps for 45 degrees etc.). I am very pleased to say it now works fine as you can see from this video taken of my turntable test track which I have just posted on UTube: I hope you like it. As my version is now not DCC controlled and doesn't use a PECO turntable I am wondering whether I ought to start a different thread for it? Best wishes CC
  7. Hello Clarkis Nothing special - I just use the Silhouette Studio (version 3) rectangle drawing facility, adjust the rectangle to size and, where applicable, use the copy/paste facility to produce any duplicates (of windows, doors etc.). Its all very easy and its surprising what you can accomplish in an evening. Regards CC
  8. Hello Neil Thanks for the kind comment. The frame elements between the panes are about 0,5 mm in width (equating to a prototype 1.5 inches in 4 mm to the foot scale). They are cut from 10 thou styrene. If I try and reduce the width below 0.5 mm the window elements tear during the cutting process.. Best wishes CC
  9. Hello Clarkis & JCL Here are images of my first attempts with the Silhouette Cameo/Studio combination. They are the start of what I hope will ultimately be a low relief block of shops for my Pwllheli layout (see http://www.rmweb.co.uk/community/index.php?/topic/60560-pwllheli-next-stop/) for more details. Prototype shops Walls are constructed from 20thou styrene Doors and window frames from 10thou styrene Windows from 10thou glazing Signage from 10thou styrene. Best wishes CC
  10. Hello Ray and Polly I enjoyed meeting you both at Stafford last weekend. Camel Quay is a super layout and I was very impressed with it and its operation - especially the hands free shunting. Congratulations are due to you both. I only hope that my efforts are ultimately half as good. Best wishes CC
  11. Andy Y

    1. yorkie_pudd

      yorkie_pudd

      is going to grow dreadlocks with a ponytail ....?

  12. Thanks Jason and to everyone else who has contributed to this fascinating thread. You have convinced me enough to purchase a Silhouette Cameo cutter. This arrived just before Christmas. Although I haven't powered it up yet I intend to use it to help construct buildings for my Pwllheli layout (see Pwllheli next stop thread) So now the learning curve and hard work begins..... Best wishes CC
  13. I have recently posted a video of Phil Greaves' Rhyd-y-Clafdy layout onto Utube which I thought you might like to view. To my mind Phil's layout is a superb portrait of the proposed extension of the Cambrian Coast Railway to the north coast of the Llyn Peninsula as it might have been in the early 1960s. CC
  14. Hello JB: I am afraid it will only work with V2 of the motor shield. I suggest you deal directly with the manufacturers Adafruit Industries (USA). Their website is at: www.adafruit.com The specific link to the motor shield (v2) is: www.adafruit.com/product/1438 However they do have an agent in Argentina: www.openhacks.com I hope this helps you. Regards CC
  15. Hello Alan: I obtained my stepper motor from Proto-pic for £13.32 (including VAT). The following link should take you directly to the stepper motor at their website: http://proto-pic.co.uk/stepper-motor-with-cable/ (Note you might have to copy and post the above web address into your Browser). I also got my Arduino Uno and Adafruit Motor Shield from them, Best wishes CC
  16. And here is the video: https://www.youtube.com/watch?v=XsKdb_QYrfg The video was produced from a single take of what happened as I videoed the turntable and is uncut - so it comes with warts and all. The delay between movements is largely due to the fact that I am changing the values of the variables on the computer and then uploading the sketch to the Arduino. Once I get the hang of the DCC aspects of Tender's sketch it would not be necessary to do this although I will still need to select the appropriate road from the computer with a DCC entry. You will mnote that sometimes (though not always) when changing the direction of rotation there is a jerk as the table starts. I am baffled as to why this happens. As regards the initial alignment on power up....one could always leave the table aligned with the selected reference road before powering down. Alternatively you could always position it by hand (as was done prototypically at Pwllheli!) and then fine tune the alignment with the nudge facility. CC
  17. Many thanks Robin for your very valid observations. Of course the system described would require an appropriate reference position in lieu of a sensor. However this could be the accurately aligned position of a designated turntable road (say road 1). The positions of the other roads of the turntable would be defined relative to this reference by the number of steps needed to move the table to each individual road from road 1 (as set by the appropriate step values in the switch case commands). Tender uses the same technique in his sketch with the sensor for the 7 road turntable. Once the turntable has moved to a selected road it can then be rotated 180 degrees to turn a locomotive using the subroutine shown in case 2 of my sketch. The sketch could (hopefully relatively easily) be refined to enable movement backwards and forwards between individual roads (and not only from the reference road). Just as with Tender's sketch care would be needed when setting up the system in the first place to ensure that the reference (in this case road1 or in Tender's case the sensor) was precisely aligned and that the number of steps in the moveTo functions were correct. Precise alignment of the track in road1 would be helped by the "nudge" facility provided in the default case of my sketch. The nudge facility would also be useful if ever road1 (or indeed any other road) got out of alignment or if someone moved the table by hand. And to round off here is a picture of my test bed. At the moment the table is missing its wheels and is secured to the spindle of the stepper motor with Bluetack...but it works. I might even have a go a videoing it for a future post. Best wishes CC
  18. Ray and everyone: Although I am very much a beginner in the field of Arduino use and programming (and a little knowledge is a dangerous thing...), I have, in trying to understand the Accelstepper functions, begun to wonder whether it is possible to omit the sensor altogether by incorporating a facility into the code of a sketch to enable any required fine adjustment of the alignment of the turntable to be made by eye. The sketch below includes such a facility (as the default action in the switch case function in the void loop() section) to move the turntable one step at a time for final adjustment as defined by the variable a. In order to function a pushbutton would also need to be provided (instead of the sensor) and an appropriate "while" statement included. A delay is provided between each step (or steps if a is set >1) which could be set to give a user a sufficient interval to precisely align the track using a digitalRead function allied to a pushbutton. You will see that the sketch does not, at present, include a DCC library call because I don't yet understand how to use it. However it seems to me that the code might be usable for turntable control on analogue layouts. As set in this example the six cases following the switch case statement allow: 1. A full revolution forward (3200 steps) 2. A half revolution forward (1600 steps) 3. A quarter revolution forward (800) steps 4. A full revolution backward (-3200) steps 5. A half revolution backward (-1600) steps 6 A quarter revolution backward (-800) steps as set by the value entered for variable i. For an analogue layout the value of i could be set manually by incorporating a potentiometer or selector switch combined with an analogueRead facility. I feel sure that this would work for my own layout where I have a turntable with just two roads. However it should be possible to add additional roads by including extra cases in the switch case facility. /* This test sketch (which is still under development) is for the Arduino Uno micro controller and illustrates how a model railway turntable may be rotated between defined positions (roads) using a stepper motor. It has been adapted by CC from example sketches in the Adadfruit stepper motor and Accelstepper libraries. The ideas and inspiration behind this sketch came from the thread: http://www.rmweb.co.uk/community/index.php?/topic/78578-dcc-controlled-peco-turntable-project/ started by Tender on 12-Nov-2013 */ // The Stepper Motor is directly connected to the turntable shaft // (in this example a Mercury Motor SM42BY0011-25 was used). // This sketch requires the Adafruit_Motorshield v2 library - downloadable from // https://github.com/adafruit/Adafruit_Motor_Shield_V2_Library // and the AccelStepper library with AFMotor support // https://github.com/adafruit/AccelStepper // The sketch will only work with Adafruit Motorshield v2. // for the Arduino Uno. It not work with v1 shields #include <AccelStepper.h> #include <Wire.h> #include <Adafruit_MotorShield.h> #include "utility/Adafruit_PWMServoDriver.h" // Create the motor shield object with the default I2C address Adafruit_MotorShield AFMS = Adafruit_MotorShield(); // Or, create it with a different I2C address (say for stacking) // Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); // Connect a stepper motor with 200 steps per revolution (1.8 degree) // to motor port #2 (M3 and M4) Adafruit_StepperMotor *myStepper1 = AFMS.getStepper(200, 2); // you can change these to DOUBLE or INTERLEAVE or MICROSTEP! void forwardstep1() { myStepper1->onestep(FORWARD, MICROSTEP); // sets the stepper at 3200 steps per revolution } void backwardstep1() { myStepper1->onestep(BACKWARD, MICROSTEP); // sets the stepper at 3200 steps per revolution } AccelStepper Astepper1(forwardstep1, backwardstep1); // use functions to step void setup() { Serial.begin(9600); // sets up Serial library at 9600 bps for a serial monitor connected to the Artduino Serial.println("Stepper test for turntable"); // prints the comment between the "" on the serial monitor when starting. AFMS.begin(); // create with the default frequency 1.6KHz //AFMS.begin(1000); // OR with a different frequency, say 1KHz Astepper1.setMaxSpeed(50.0); // sets the maximum rotational speed of the stepper in steps per second. // (the value of 50 will rotate the turntable for a full revolution // in about 3200/50 seconds (i.e around 64 seconds). Astepper1.setAcceleration(10.0); } void loop() { Astepper1.moveTo(0); int i; // The variable i is used to set the amount of rotation between the roads of the turntable i=2; // according to the case below. Here i is set at 2 and so will select case 2 below. This // will cause the routine to rotate the the turntable 1600 steps; i.e. half a revolution forwards. // Because there are only 6 cases set up selected actions will only be activated if i // has a value of 1 to 6. If it is ourside these values the DEFAULT action is taken governed // by the value set in the variable a. // (Note that more cases could be added to this sketch if required). int a; // Variable a can be considered to be the "nudge" variable. It is used to fine tune the a=1; // alignment of the turntable between roads by eye if a road is not properly aligned. // A value of 1 will cause the turntable to turn one step (0.11 degree) at a time // and will pause between steps for the interval set by the delay funnction in the // default case. Serial.println(i); //prints the selected value of i on the monitor Serial.println("starting loop"); //and lets you know it has started switch (i) { case 1: //rotates turntable one revolution (3200 steps) forward when i = 1 Astepper1.moveTo(3200); Astepper1.run(); Astepper1.runToPosition(); break; case 2: //rotates turntable half revolution (1600 steps) forward when i = 2 Astepper1.moveTo(1600); Astepper1.run(); Astepper1.runToPosition(); break; case 3: //rotates turntable a quarter revolution (800 steps) forward when i = 3 Astepper1.moveTo(800); Astepper1.run(); Astepper1.runToPosition(); break; case 4: //rotates turntable one revolution (3200 steps) backward when i = 4 Astepper1.moveTo(-3200); Astepper1.run(); Astepper1.runToPosition(); break; case 5: //rotates turntable one revolution (1600 steps) backward when i = 5 Astepper1.moveTo(-1600); Astepper1.run(); Astepper1.runToPosition(); break; case 6: //rotates turntable quarter revolution (800 steps) backward when i = 6 Astepper1.moveTo(-800); Astepper1.run(); Astepper1.runToPosition(); break; default: Serial.println(a); // prints the number of steps selected // (A negative value of a will cause // the turntable to move in the opposite // direction) Astepper1.move(0); Serial.println("starting default case"); delay(100); // delay between steps in millisecond Astepper1.move(a); Astepper1.run(); I would be grateful for any observations/comments/suggestions/advice you might care to give Regards CC
  19. Mark/Ray: I have moved the DCC_Decoder and _MACOSX folders up a level to the libraries folder as you suggest and the sketch compiles as it should. I have also tried compiling the two examples (DCC_BasicAcc_Decoder and DCC_Monitor) provided in the DCC Decoder library and they also compile OK. So many thanks to both of you - I would never have figured it out myself. Best wishes CC
  20. Ray Thanks for the very prompt response. I have looked in my Arduino Folder and see that I have downloaded the appropriate libraries as you see in the screenshot pictures below: Arduino Folder I have checked your code and all the requisite declarations are there but I still get the same message as you see - I cannot understand what is happening Regards CC
  21. Hello Ray At long last I'm beginning to get to grips with the AccerStepper functions though I'm still struggling a bit. As I am making just a little bit of progress I thought that I would start to look at the DCC aspects of your program in the complete code (Arduino Sketch) for turntable control in your post #48. When I entered this into the Arduino IDE as a sketch and then tried to verify it I get an error message for the line: DCC.SetBasicAccessoryDecoderPacketHandler(BasicAccDecoderPacket_Handler, true); saying 'DCC' was not declared in this scope. I haven't a clue why this is occurring. Can you help? Best wishes CC
  22. Ray/Simon Problem sorted and in the end it wasn't a problem with the code at all! When I assembled the motor shield I was guided the instructions on the Adafruit website. The instructions also show a stepper motor connected to the M3/M4 terminals of the shield and so I therefore placed the four coloured wires from the motor into the same slots shown on the Adafruit website. Having exhausted all my ideas for modifying the code I went back through the first page of this topic and realised they were not in the same slots that you had used. My error. Changing to the slots shown in your picture in post #8 has had a dramatic effect and I can now run the stepper smoothly using the MICROSTEP function. So beware any of you that use the Adafruit photo of the connected stepper motor as a reference. It is for left hand drive models only! I wouldn't say that the time I have spent has all been wasted - I have learnt a lot about the code in the Adafruit stepper motor Arduino code examples. In fact I have constructed about the simplest Sketch possible to run the stepper a full revolution backwards and forwards smoothly, slowly and very quietly. It is based on the Adafruit stepper example and you will see that it does not does not include the Accelstepper library. This means that the number of steps you can set in one revolution is limited to 200 even though it is microstepping between steps. Now I progress to explore your code further and investigate how the Accelstepper library of functions can give more precise control. Presumably it enables each step to be divided up into 16 segments giving an overall 3200 step resolution per revolution. Once I have mastered this I will be building the DCC interface using Simond's last post on the topic as a very helpful guide. The simple sketch mentioned earlier appears below: /* This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2 It won't work with v1.x motor shields! Only for the v2's with built in PWM control. The original ADAfruit sample sketch has been adapted by CC on 31-Mar-2014 to rotate a stepper motor forward for one revolution (200 steps) using the MICROSTEP function, pauses for one second and then reverses for one revolution. It will continue this cycle until powered down. Speed has been set to 2 revolutions per minute but this can easily be changed by altering the variable in the setSpeed command. As set up a complete cycle takes around one and a half minutes to complete. Serial print commands have been incorporated in the sketch to enable operation to be monitored with the serial monitor facility of the Arduino IDE. The sketch is the precursor to using the stepper to control the movements of a turntable under DCC as described by Tender's thread on RMWeb "DCC Controlled (PECO) Turntable Project started on 12-Nov-2013. For use with the Adafruit Motor Shield v2 ----> http://www.adafruit.com/products/1438 */ #include <Wire.h> #include <Adafruit_MotorShield.h> #include "utility/Adafruit_PWMServoDriver.h" // Create the motor shield object with the default I2C address Adafruit_MotorShield AFMS = Adafruit_MotorShield(); // Or, create it with a different I2C address (say for stacking) // Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); // Connect a stepper motor with 200 steps per revolution (1.8 degree) // to motor port #2 (M3 and M4) Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2); void setup() { Serial.begin(9600); // set up Serial library at 9600 bps Serial.println("Stepper test with microsteps for turntable"); AFMS.begin(); // create with the default frequency 1.6KHz //AFMS.begin(1000); // OR with a different frequency, say 1KHz myMotor->setSpeed(2); // 2 rpm } void loop() { Serial.println("starting loop with microsteps"); myMotor->step(200, FORWARD, MICROSTEP); Serial.println("gone through loop forwards"); delay(1000); myMotor->step(200, BACKWARD, MICROSTEP); Serial.println("gone through loop backwards"); } Best wishes CC
  23. Ray - Many thanks for your very prompt response. I have tried out your suggestion (stepper2.moveTo(1600)) but unfortunately nothing changes and the stepper motor still oscillates backward and forward about two degrees for several seconds and then slowly stops. I'm still scratching my head on this one and trying various changes to the code but to no avail up until now. I will let you know if I succeed. Meanwhile if you have any other suggestions I would be most grateful for them. Below I include the sketch for continuous rotation of the stepper at 200 dpi which is a modification of one of the Adafruit stepper motor examples. I have included some print statements in the code so that I can see what is happening on the serial monitor /* This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2 It won't work with v1.x motor shields! Only for the v2's with built in PWM control. The sketch is adapted to provide continuous rotation of the stepper at 200 steps per revolution. For use with the Adafruit Motor Shield v2 ----> http://www.adafruit.com/products/1438 This sketch enables continuous rotation of a stepper motor Connect a unipolar/bipolar stepper to M3/M4 */ #include <Wire.h> #include <Adafruit_MotorShield.h> #include "utility/Adafruit_PWMServoDriver.h" // Create the motor shield object with the default I2C address Adafruit_MotorShield AFMS = Adafruit_MotorShield(); // Or, create it with a different I2C address (say for stacking) // Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); // Connect a stepper motor with 200 steps per revolution (1.8 degree) // to motor port #2 (M3 and M4) Adafruit_StepperMotor *myStepper = AFMS.getStepper(200, 2); void setup() { Serial.begin(9600); // set up Serial library at 9600 bps Serial.println("Stepper motor continuous!"); AFMS.begin(); // create with the default frequency 1.6KHz //AFMS.begin(1000); // OR with a different frequency, say 1KHz // setup the stepper myStepper->setSpeed(10); // 10 rpm } int i; void loop() { for (i=0; i<255; i++) { myStepper->step(1, FORWARD, DOUBLE); delay(0); Serial.println("Stepper motor going!"); for (i=255; i!=0; i--) myStepper->step(1, FORWARD, DOUBLE); delay(0); Serial.println("Stepper motor continuing!"); } } Simond - Thanks very much for your response and the included pictures (which I will study carefully!). Regards to you both CC .
  24. I noticed that the attached .ino file was not visible as text in my previous post so I am attaching a text version: /*This interim test routine attempts to enable the continuous rotation of a stepper motor at 3200 steps/revolution and is adapted by CC from the Turntabable routine posted by Tender on RM Web on 19 Nov 2013 under the topic DCC Controlled (PECO) turntable project post #17. Requires the Adafruit_Motorshield v2 library https://github.com/adafruit/Adafruit_Motor_Shield_V2_Library And AccelStepper with AFMotor support https://github.com/adafruit/AccelStepper This sketch is for Adafruit Motorshield v2 only! Will not work with v1 shields */ #include <AccelStepper.h> #include <Wire.h> #include <Adafruit_MotorShield.h> #include "utility/Adafruit_PWMServoDriver.h" Adafruit_MotorShield AFMStop(0x60); // Default address, no jumpers // Connect a stepper motor with 200 steps per revolution (1.8 degree) // to motor port #2 (M3 and M4) 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); void setup() { AFMStop.begin(); // Start the shield // set stepper speed, acceleration and position stepper2.setMaxSpeed(100.0); stepper2.setAcceleration(10.0); stepper2.moveTo(3200); } void loop() { stepper2.run(); } PS how do you include .ino files as visible text in your posts? CC
  25. Ray: Inspired by your thread (and although not a programmer) I am attempting to understand the code used in the DCC Stepper Motor Controlled (PECO) turntable project. I haven’t yet built the DCC interface board so I have been trying to get to grips with the basic stepper motor control. I have adapted one of the Adafruit stepper motor sketches so that it allows me to run the stepper motor continuously at 200 steps per revolution. I then tried to adapt the sketch in your post #17 (19 Nov 2013) to see if I could get it to continuously rotate at 3200 steps per revolution. In doing this I have deleted your references to the sensor pins. The resulting sketch (below) compiles OK but on uploading to the Arduino the stepper motor clicks away backward and forward a couple of degrees or so for a few seconds and then stops. I would be most grateful for any help you could provide on what I am doing wrong. DEVELOPMENT_TURNTABLE.ino Simond: Although I haven't yet build the DCC interface board I have purchased a couple of Maplin reflector sensors as mentioned in your post 57 on this topic. They are indeed very small (3mm square) and I wondered if you have used one for this application. If so a picture of the wired device would be extremely useful! Thanks and Best wishes CC
×
×
  • Create New...