Simond Posted February 4, 2015 Share Posted February 4, 2015 Ray H The sector plate does pose some problems, but in other ways, it's easier than a turntable. Wiring for example. You can drive it directly from the pivot end, after all, it's only half a turntable, and providing you arrange good, low friction, supports at the track end, this should not be a problem. I'd suggest small ball bearings screwed to the plate itself, and running on a hard surface - a piece of rail, or other metal, ideally. Might need a bigger motor for this approach, probably not suited to larger scales. If you choose the screw drive, your "stepper motor plus rod" assembly has to be able to maintain a straight line between the motor fixing (which I expect is the baseboard) and the nut (which I expect is the sector plate) and as the nut will move in an arc, as t'other Ray notes, the motor fixing must therefore be pivoted too. For this reason, I would not recommend the bellows coupling, as this is intended to be flexible - you need something rigid to connect the motor and threaded rod. This will certainly work but sounds like hard work to build, and will provide far more positional accuracy (assuming you can build it without slop in the pivots & nut) than you would need. An alternative which may prove simpler, would be a radio control servo - these are cheap, available if different sizes, and are easily driven by an Arduino. Arranging a linkage to use the maximum movement of the servo, to obtain the necessary movement of the sector plate is an interesting exercise in geometry (Google "four bar linkage") and will minimise the torque needed at the servo to move the plate with a loco on it, and increase the positional accuracy at the ends of travel, as a "free" bonus. I'd recommend this approach for anything less than 7mm, and I'd try if in 7mm too. I'd be less confident about 10mm and up. If you have more than two exits from the sector plate, and don't want to use DCC, it should be relatively easy to arrange the connection to the Arduino by rotary switch or row of buttons, certainly less programming than for DCC. HTH Simon Link to post Share on other sites More sharing options...
tender Posted February 4, 2015 Author Share Posted February 4, 2015 Hi Ray, Simon. When you mention sector plate, I'm assuming you mean something along the line that i use on my Camel Quay layout where the whole train sits on the sector plate and is pivoted from one end. If its just a loco sector plate then as Simon says you can treat it as a small sector of a turntable. Assuming the former, what about this. At the far end (from the pivot) cut a small slot along the line of the plate. Fix the screw thread nut under the slot in such a way that it can rotate and slide along the slot. Your screw thread could then be fixed by the motor at one end and a bearing at the other. Not sure I've explained that very well, if you don't get it i'll try and do a drawing. The length of the slot would be dependent on how much the sector plate needs to swing. Ray Link to post Share on other sites More sharing options...
Simond Posted February 4, 2015 Share Posted February 4, 2015 Thanks Ray - yes, I should have stated my assumption that we were talking about a loco release type of affair. If it's rather larger, train sized, for example, then indeed, the slot arrangement would work, but I fear it might suffer from friction. Perhaps a link to attach the nut to the plate? This would allow the necessary angular freedom of nut relative to plate, and accommodate the arc of the attachment to the plate itself. Two birds with one stone! Again, can sketch if it would help. Best Simon Link to post Share on other sites More sharing options...
73c Posted February 8, 2015 Share Posted February 8, 2015 Hi all Have just found this thread, brilliant stuff. Getting ready to start putting it all together for my own turntable. Just one thing tho' at the beginning, (post #8 ) the wiring diagram for the DCC - Arduino interface shows a reset switch but in the following photo's there's no sign of one or mention of one in the parts list. Link to post Share on other sites More sharing options...
Barry M Posted February 8, 2015 Share Posted February 8, 2015 Hi all Have just found this thread, brilliant stuff. Getting ready to start putting it all together for my own turntable. Just one thing tho' at the beginning, (post #8 ) the wiring diagram for the DCC - Arduino interface shows a reset switch but in the following photo's there's no sign of one or mention of one in the parts list. Any switch will do really. Just connect it as shown to the 2 terminals. This was my first attempt at a electronic circuit - it went better than I thought! Barry Link to post Share on other sites More sharing options...
73c Posted February 8, 2015 Share Posted February 8, 2015 Is that a N/O or a N/C switch? Link to post Share on other sites More sharing options...
Simond Posted February 8, 2015 Share Posted February 8, 2015 Go for NO Best Simon Link to post Share on other sites More sharing options...
jbsorocaba Posted February 8, 2015 Share Posted February 8, 2015 Hi guys I am trying to insert servo in a Pandassum sketch, ( # 38 ) to use in my traverser, and the servo will lock the table in position. At the time, I got the servo release and after reaching the sensor it returns the starting position (brake) during startup. The stepper also release during this process and after selecting the track. What I'm not getting, is to release the servo at the moment of selection the lanes. The stepper start but the servo ( brake )continues to operate. Any help will be appreciated. Sorry for my english.. The sketch: /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include <DCC_Decoder.h> #include <AccelStepper.h> #include <Wire.h> #include <Adafruit_MotorShield.h> #include "utility/Adafruit_PWMServoDriver.h" #include <Servo.h> ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Defines and structures // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #define kDCC_INTERRUPT 0 typedef struct { int address; // Address to respond to } DCCAccessoryAddress; DCCAccessoryAddress gAddresses[1]; const unsigned long releaseTimeout_ms = 2000; boolean isReleased = false; //Servo Stuff Servo brakeservo; // create servo object to control a servo const int servoBrake = 90; //value for brake position const int servoRelease = 5; //value for release position ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // 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); } void release2() { myStepper2->release(); // COMANDO PARA LIBERAR SERVO E MOTOR } // Now we'll wrap the stepper in an AccelStepper object AccelStepper stepper2 = AccelStepper(forwardstep2, backwardstep2); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Variables // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// long lngMotorPos; long lngTargetPosition; const long lngOneRev = 3200; // Essa é a linha de programação do curso: 400 é 45 graus - 3200 DÁ UMA VOLTA int intPos = 0; //set initial LED value ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // SETUP FOR LED DISPLAY // Bits representing segments A through G (and decimal point) for numerals 0-9 // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// const byte numeral[10] = { //ABCDEFG /dp B11111100, // 0 B01100000, // 1 B11011010, // 2 B11110010, // 3 B01100110, // 4 B10110110, // 5 B00111110, // 6 B11100000, // 7 B11111110, // 8 B11100110, // 9 }; // pins for decimal point and each segment // dp,G,F,E,D,C,B,A const int segmentPins[8] = { 7,11,10,9,8,6,5,4};//defines Arduino pins for each segment const int segmentSpin[6] = { 4,5,6,8,9,10};// used to "rotate" the segments while motor is moving to sensor position ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // 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; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // 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; // Check for DCC imput & determine entered address switch (address) { //Set target position based on address selected case 200: lngTargetPosition = lngOneRev*0; // ESSE VALOR FOI ALTERADO PARA QUE O ENDEREÇO 200 SEJA PONTO DE REFERENCIA - ERA 1 AQUI intPos=1; break; case 201: lngTargetPosition = lngOneRev*1; intPos=2; break; case 202: lngTargetPosition = lngOneRev*2; intPos=3; break; case 203: lngTargetPosition = lngOneRev*3; intPos=4; break; case 204: lngTargetPosition = lngOneRev*4; intPos=5; break; case 205: lngTargetPosition = lngOneRev*5; intPos=6; break; case 206: lngTargetPosition = lngOneRev*6; intPos=7; break; case 207: lngTargetPosition = lngOneRev*7; intPos=8; break; default: //nothing selected lngMotorPos=stepper2.currentPosition(); Serial.println(lngMotorPos,DEC); } if ( enable ) { Serial.print("Motor at: "); lngMotorPos=stepper2.currentPosition(); Serial.println(lngMotorPos,DEC); Serial.print("Moving to: "); Serial.println(lngTargetPosition); showDigit(intPos); stepper2.moveTo(lngTargetPosition); while (stepper2.currentPosition() != lngTargetPosition) // move to target position stepper2.run(); digitalWrite(segmentPins[0],0); /////////////////////////////// NEW ////////////////////////////////// { long lngTargetPosition; } //Set the servo brake brakeservo.write(servoBrake); delay(750); //release the motor release2(); Serial.println(" Brake Set & Motor Released "); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// } else { // stepper2.moveTo(2000); lngMotorPos=stepper2.currentPosition(); Serial.println(lngMotorPos,DEC); delay(1000); // showDigit(intPos); } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Setup // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void setup() //runs once to determine start position when sensor reached. { Serial.begin(9600); AFMStop.begin(); // Start the shield //servo brake release before stepp moves brakeservo.attach(10); // attaches the servo on pin 10 to the servo object brakeservo.write(servoRelease); delay (30); //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(100.0); stepper2.setAcceleration(20.0); for(int i=0; i < 8; i++)//assign pins for led display { pinMode(segmentPins, OUTPUT); // set segment and DP pins to output } showDigit(10); Serial.println("At switch off segments"); delay(1000); // if near reference point move away Serial.println("Check for reference point"); // sensorVal = digitalRead(3); // RETIRADO MOMENTANEAMENTE ATE CONCLUSÃO FINAL while (sensorVal == LOW) { sensorVal = digitalRead(3); Serial.println("At Sensor"); Serial.print("Motor at: "); lngMotorPos=stepper2.currentPosition(); Serial.println(lngMotorPos,DEC); intPos=0; showDigit(intPos); forwardstep2(); delay(50); } // step forward to sensor index point // sensorVal = digitalRead(3); //RETIRADO TEMPORARIAMENTE while (sensorVal == HIGH) { sensorVal = digitalRead(3); Serial.println("Moving to sensor"); lngMotorPos=stepper2.currentPosition(); Serial.println(lngMotorPos,DEC); intPos=0; showDigit(intPos); backwardstep2(); delay(50); } //when home- sets brake delay (500); brakeservo.write(servoBrake); //release the motor release2(); Serial.println(" Brake Set & Motor Released "); digitalWrite(segmentPins[0],0); //DP off //digitalWrite(segmentPins[1],1); for(int i=0; i < 7; i++) //Switch on segments { digitalWrite(segmentSpin,1); delay(50); digitalWrite(segmentPins[0],1); //DP on //digitalWrite(segmentPins[1],1); } DCC.SetBasicAccessoryDecoderPacketHandler(BasicAccDecoderPacket_Handler, true); ConfigureDecoder(); DCC.SetupDecoder( 0x00, 0x00, kDCC_INTERRUPT ); } void showDigit( int number) //display number on seven segment display { boolean isBitSet; for(int segment = 0; segment < 8; segment++) //was 1 { if( number < 0 || number > 9){ isBitSet = 0; // turn off all segments digitalWrite( segmentPins[segment], isBitSet); } else{ // isBitSet will be true if given bit is 1 isBitSet = bitRead(numeral[number], segment); } isBitSet = ! isBitSet; // remove this line if common cathode display digitalWrite( segmentPins[segment], isBitSet); } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Main loop // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void loop() { static int addr = 0; //////////////////////////////////////////////////////////////// // Loop DCC library DCC.loop(); //////////////////////////////////////////////////////////////// // Loop Stepper stepper2.run(); } /////////////////////////////////////////////// END /////////////////////////////////////////////////////////////////////////// Link to post Share on other sites More sharing options...
GdJ Posted February 18, 2015 Share Posted February 18, 2015 Hi Ray, Let me join the chorus and thank you for your excellent guide to motorizing a PECO turntable. I've been working on my PECO H0m turntable for a couple weeks now and am happy to report it's turning. Now on to the DCC part . Without your guide I would have never dared to venture here and it would probably have remained a dream forever. I'll post a video when I'm a bit further along, Thanks again, Gerard Link to post Share on other sites More sharing options...
GdJ Posted February 22, 2015 Share Posted February 22, 2015 (edited) As promised a work in progress video of my turntable, I'm still working on the DCC part but the mechanical part is close to ready. Gerard Edited March 9, 2015 by GdJ 1 Link to post Share on other sites More sharing options...
73c Posted February 27, 2015 Share Posted February 27, 2015 Hi all Everything seems to be going well with this set-up but just a couple of things I hope can get sorted. 1. The motor just 'pulses' round, not a smooth rotation. 2. Got as far as #17 the 180 degree test, motor finds the sensor, sits there for a few seconds then starts to pulse 1 step forward then 1 back for further few seconds, stops again and then moves off to do a 180 back round where it repeats the same sequence ( i.e. sits then pulses ) Any help with these is greatly appreciated Link to post Share on other sites More sharing options...
cambriancoaster Posted March 6, 2015 Share Posted March 6, 2015 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 4 Link to post Share on other sites More sharing options...
Simond Posted March 6, 2015 Share Posted March 6, 2015 Monty Python's Flying Circus. As far as they knew, there was not, nor had ever been anyone called Monty Python, it did not involve flying and it was not a circus. but it does look and function like a turntable! If and when you have more entry roads to the t/t, you will presumably be able to program an angle for each - but I suspect it would be easier to program a button as a preset for each road best Simon Link to post Share on other sites More sharing options...
tender Posted March 6, 2015 Author Share Posted March 6, 2015 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 Hi CC, nice one. As regards a new thread, it does have an Arduino and directly connected stepper so not too far away from the original. If you do decide to start a new thread please post a link here for us to follow. Ray. Link to post Share on other sites More sharing options...
GdJ Posted March 9, 2015 Share Posted March 9, 2015 Some more progress to report, The turntable is now working from DCC control. Since the turntable only needs to make 180 degrees turns I've installed magnets on both sides and use the hall sensor for determining the stop point at every turn. The direction of turn is determined by the thrown or closed selection for the switch on my Digitrax system. See a video here of the turntable installed on the layout: Gerard 1 Link to post Share on other sites More sharing options...
SouthernWay Posted March 15, 2015 Share Posted March 15, 2015 Hi all, this thread is great but I have read it time and time again and can't seem to get my head around how this works. I like the idea of how Cambriancoaster controls his turntable but like Simond ask, how would you go about programming it so a button is preset to a road? And would there be a limit to the amount of roads that could be accommodated? Any help and advice would be greatly appreciated. I also am having a hard time with what I would need to purchase to motorise the turntable? And you may think me a little dim, but how would you program the micro controller? Sorry everyone if this is taking you back to start but I'm as they say........confused.com!!! Link to post Share on other sites More sharing options...
Simond Posted March 15, 2015 Share Posted March 15, 2015 Ok, the issue here is the starting point. So forgive me if I'm starting at a point that's too basic. Let's start at the beginning... The Arduino is a micro computer. It runs programs. Programs are lists of instructions, written in a particular grammar. It has the option to switch on and switch off output pins, based on the program, and the state of input pins. It can switch things really, really quickly, which, a bit like TV & films, can make things appear to change smoothly. The output pins can be connected to various devices, such as LEDs, servos, stepper drivers, whatever. If you connect it to some switches, and a stepper driver, and install a suitable program, you can arrange to stop your t/t any number of times, any angle, go either way, light up indicators, have a screen telling you the status, all sorts. Have a look at the links in my Arduino thread, (there's a shopping list & links to suppliers IIRC & a turntable program on there too) and do do some searches on Google - I'm sure you can get some understanding of how it works. Have a go & see how you get on. Chances are pretty good that you can't do anything really damaging, and you will learn loads. If you want to ask specific questions, please do - you can use my Arduino thread, of this one, or start your own. There are lots of helpful folks on RMWeb! Best Simon Link to post Share on other sites More sharing options...
tender Posted March 16, 2015 Author Share Posted March 16, 2015 Hi all, this thread is great but I have read it time and time again and can't seem to get my head around how this works. I like the idea of how Cambriancoaster controls his turntable but like Simond ask, how would you go about programming it so a button is preset to a road? And would there be a limit to the amount of roads that could be accommodated? Any help and advice would be greatly appreciated. I also am having a hard time with what I would need to purchase to motorise the turntable? And you may think me a little dim, but how would you program the micro controller? Sorry everyone if this is taking you back to start but I'm as they say........confused.com!!! Hi SouthernWay.My advice is to start at page 1 and follow the 7 part step by step which includes what you need to buy and where to get the bits from. Once you have that working you can easily modify the code (or ask here) to operate from buttons with as many roads as you require. Ray. Link to post Share on other sites More sharing options...
cambriancoaster Posted March 17, 2015 Share Posted March 17, 2015 Hi SouthernWay. My advice is to start at page 1 and follow the 7 part step by step which includes what you need to buy and where to get the bits from. Once you have that working you can easily modify the code (or ask here) to operate from buttons with as many roads as you require. Ray. 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 3 Link to post Share on other sites More sharing options...
cambriancoaster Posted March 17, 2015 Share Posted March 17, 2015 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 Link to post Share on other sites More sharing options...
alangdance Posted March 24, 2015 Share Posted March 24, 2015 HI Ray If I was to use your sketch for a traverser is there any parts from the sketch that would need changing. I think you mentioned that on setup the stepper motor will go forward and backwards to find it 's reference point. I think this may be a issue with a traverser. Any help would be most grateful. Alan Link to post Share on other sites More sharing options...
tender Posted March 25, 2015 Author Share Posted March 25, 2015 HI RayIf I was to use your sketch for a traverser is there any parts from the sketch that would need changing. I think you mentioned that on setup the stepper motor will go forward and backwardsto find it 's reference point. I think this may be a issue with a traverser. Any help would be most grateful.Alan Hi Alan Without testing - If you change the line forwardstep2(); to backwardstep2(); in the part below and put the sensor just beyond the end of the normal operation of the Traverser that should do it. // step forward to sensor index point while (sensorVal == HIGH) { sensorVal = digitalRead(3); forwardstep2(); delay(50); } Like I've said i have not tested this as I dont have a Traverser so tread carefully. Ray. Link to post Share on other sites More sharing options...
alangdance Posted March 26, 2015 Share Posted March 26, 2015 Thanks Ray I had a similar idea myself once I work out the while function. I am still learning about the code for Arduino. I am not in a position yet to do any testing but hope to have the traverser built in the next few weeks. Alan Link to post Share on other sites More sharing options...
gz3xzf Posted May 15, 2015 Share Posted May 15, 2015 Well, this evening I have taken the plunge and purchased the bits, after watching this thread for about a year now. I am going to be using a Dapol (ex. Airfix) turntable that I have cut down so it is around 65' (rather than the 75' as molded), the final cost was a bit more than shown below (about £95), hopefully this will get me going to finish the turntable and start the proposed layout, but more of that later; for now I will be waiting for Mr Postman to drop the parcels off at the door. Part 1: The BitsComponents required for this project. (Plus approx. cost)ARDUINO UNO microcontroller (eBay) £16ADAFRUIT Motor Shield V2 (eBay) £16Stepper Motor (SM-42BYG011-25) (eBay) £16Hall Effect Sensor (RS370-6896) £5Magnet (RS189-5512) £6Bellows Coupling (RS693-2467) £17Opto Isolator 6N137 (RS671-1359) £22 off 10k resistors1 off 1K resistor1 off IN4148 diode4 off Rubber mountings (Farnell 1466996) £3 Sub Total (Approx.) £81 Part 1: The BitsComponents required for this project. (Plus approx. cost)ARDUINO UNO microcontroller (PiHut) £20ADAFRUIT Motor Shield V2 (PiHut) £17Stepper Motor (SM-42BYG011-25) (PiHut) £14.30Hall Effect Sensor (RS370-6896) £5.67Magnet (RS189-5512) £6.38Bellows Coupling (RS693-2467) £20.51Opto Isolator 6N137 (RS671-1359) £2.142 off 10k resistors £0.651 off 1K resistor £0.341 off IN4148 diode In-stock4 off Rubber mountings (RS720-3293) £6.74Sub Total (Approx.) £93.73 2 Link to post Share on other sites More sharing options...
tender Posted May 20, 2015 Author Share Posted May 20, 2015 Hi Bryan. Good luck with the build. Plenty of help on here if you run into a problem. Keep us updated as you progress. Ray. Link to post Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now