Chris Higgs Posted October 1, 2016 Share Posted October 1, 2016 I have the following issue with the Arduino controlled servo: every time I power up the board the servo moves quickly, about 30 degrees (see here a very short clip). As this might brake the turnout, is any way I can edit the code in order to prevent this movement? I copied the sketch from the "N Scaler Blog": #include <Servo.h> // constant variables used to set servo angles, in degrees const int straight = 90; const int divergent = 99; // constant variables holding the ids of the pins we are using const int buttonpin = 8; const int servopin = 9; // servo movement step delay, in milliseconds const int step_delay = 100; // create a servo object Servo myservo; // global variables to store servo position int pos = current; // current int old_pos = pos; // previous void setup() { // set the mode for the digital pins in use pinMode(buttonpin, INPUT); // setup the servo myservo.attach(servopin); // attach to the servo on pin 9 myservo.write(pos); // set the initial servo position } void loop() { // start each iteration of the loop by reading the button // if the button is pressed (reads HIGH), move the servo int button_state = digitalRead(buttonpin); if(button_state == HIGH){ old_pos = pos; // save the current position // Toggle the position to the opposite value pos = pos == straight ? divergent: straight; // Move the servo to its new position if(old_pos < pos){ // if the new angle is higher // increment the servo position from oldpos to pos for(int i = old_pos + 1; i <= pos; i++){ myservo.write(i); // write the next position to the servo delay(step_delay); // wait } } else { // otherwise the new angle is equal or lower // decrement the servo position from oldpos to pos for(int i = old_pos - 1; i >= pos; i--){ myservo.write(i); // write the next position to the servo delay(step_delay); // wait } } } }// end of loop What is the value of "current"? Indeed where is it declared? Looks like unless current (and hence old_pos) is set to the current actual position of the servo, you are going to tell it to move to a position perhaps far from where it actually is. This line in particular: myservo.write(pos); // set the initial servo position I think I would expect a line like int current = myservo.read(); to get it set correctly. Chris Link to post Share on other sites More sharing options...
RMweb Premium nick_bastable Posted October 1, 2016 RMweb Premium Share Posted October 1, 2016 (edited) What is the value of "current"? Indeed where is it declared? Looks like unless current (and hence old_pos) is set to the current actual position of the servo, you are going to tell it to move to a position perhaps far from where it actually is. This line in particular: myservo.write(pos); // set the initial servo position I think I would expect a line like int current = myservo.read(); to get it set correctly. Chris similar to this sketch perhaps for a nano although change the pins will work with any board however this still twitches on start up to home to the positions and if any servo fails to complete its declared movement hangs #include <VarSpeedServo.h> // Copyright2015 - SERVO SWITCH CONTROL - SSC - PaulDMV // a maximum of seven servo objects can be installed on the nano // a maximum of eight servo objects can be created // only change ** lines (speedx, range_x_low and range_x_high) // install the VarSpeedServo.h Library before use! VarSpeedServo myservo1; // create servo object to control a servo, connected to pin 3 int pos1 = 0; // variable to store the servo position int button1 = 4; // The button will be on Pin 4 int speed1= 32;// **variable to store the servo speed int delay1= 50; // sets the delay time to reach position int range_1_low= 120;//sets the lower limit int range_1_high= 155;//ts the uper limit int range_1_diff= range_1_high - range_1_low; //diffence to go to position VarSpeedServo myservo2; // create servo object to control a servo, connected to pin 5 int pos2 = 0; // variable to store the servo position int button2 = 8; // The button will be on Pin 8 int speed2= 20; // **variable to store the servo speed int delay2= 51; // sets the delay time to reach position int range_2_low= 45;// the lower limit int range_2_high=75;// the uper limit int range_2_diff= range_2_high - range_2_low; //diffence to go to position VarSpeedServo myservo3; // create servo object to control a servo, connected to pin 6 int pos3 = 0; // variable to store the servo position int button3 = 18; // The button will be on Pin 18 int speed3= 59; // **variable to store the servo speed int delay3= 50; // **sets the delay time to reach position int range_3_low= 60;// the lower limit int range_3_high= 80; //**sets the uper limit int range_3_diff= range_3_high - range_3_low; //diffence to go to position VarSpeedServo myservo4; // create servo object to control a servo, connected to pin 9 int pos4 = 0; // variable to store the servo position int button4 = 11; // The button will be on Pin 11 int speed4= 27; // **variable to store the servo speed int delay4= 50; // **sets the delay time to reach position int range_4_low= 125;// **sets the lower limit int range_4_high= 175; //**sets the uper limit int range_4_diff= range_4_high - range_4_low; //diffence to go to po VarSpeedServo myservo5; // create servo object to control a servo, connected to pin 10 int pos5 = 0; // variable to store the servo position int button5 = 13; // The button will be on Pin 13 int speed5= 37; // **variable to store the servo speed int delay5= 50; // **sets the delay time to reach position int range_5_low= 75;// the lower limit int range_5_high= 115;// sets upper limit int range_5_diff= range_5_high - range_5_low; //diffence to go to po void setup() { myservo1.attach(3); // attaches the servo on pin 7 to the servo object pinMode(pos1, OUTPUT); pinMode(button1, INPUT); digitalWrite (button1, LOW); myservo2.attach(5); // attaches the servo on pin 8 to the servo object pinMode(pos2, OUTPUT); pinMode(button2, INPUT); digitalWrite (button2, LOW); myservo3.attach(6); // attaches the servo on pin 9 to the servo object pinMode(pos3, OUTPUT); pinMode(button3, INPUT); digitalWrite (button3, LOW); myservo4.attach(9); // attaches the servo on pin 10 to the servo object pinMode(pos4, OUTPUT); pinMode(button4, INPUT); digitalWrite (button4, LOW); myservo5.attach(10); // attaches the servo on pin 10 to the servo object pinMode(pos5, OUTPUT); pinMode(button5, INPUT); digitalWrite (button5, LOW); } void loop() { { if (digitalRead(button1) == LOW) for(pos1 = range_1_low; pos1 < range_1_high; pos1 += range_1_diff) // goes from 85 degrees to 95 degrees in steps of 1 degree { myservo1.slowmove(pos1,speed1); // tell servo to go to position in variable 'pos' delay(delay1); // waits x ms for the servo to reach the position } if (digitalRead(button1) == HIGH) for(pos1 = range_1_high; pos1>=range_1_high; pos1-=range_1_diff) // goes from 95 degrees to 85 degrees in steps of 1 degree { myservo1.slowmove(pos1,speed1); // tell servo to go to position in variable 'pos' delay(delay1); // waits x ms for the servo to reach the position } { if (digitalRead(button2) == LOW) for(pos2 = range_2_low; pos2 < range_2_high; pos2 += range_2_diff) // goes from 85 degrees to 95 degrees in steps of 1 degree { myservo2.slowmove(pos2,speed2); // tell servo to go to position in variable 'pos' delay(delay2); // waits x ms for the servo to reach the position } if (digitalRead(button2) == HIGH) for(pos2 = range_2_high; pos2>=range_2_high; pos2-=range_2_diff) // goes from 95 degrees to 85 degrees in steps of 1 degree { myservo2.slowmove(pos2,speed2); // tell servo to go to position in variable 'pos' delay(delay2); // waits x ms for the servo to reach the position } { if (digitalRead(button3) == LOW) for(pos3 = range_3_low; pos3 < range_3_high; pos3 += range_3_diff) // goes from 85 degrees to 95 degrees in steps of 1 degree { myservo3.slowmove(pos3,speed3); // tell servo to go to position in variable 'pos' delay(delay3); // waits x ms for the servo to reach the position } if (digitalRead(button3) == HIGH) for(pos3 = range_3_high; pos3>=range_3_high; pos3-=range_3_diff) // goes from 95 degrees to 85 degrees in steps of 1 degree { myservo3.slowmove(pos3,speed3); // tell servo to go to position in variable 'pos' delay(delay3); // waits x ms for the servo to reach the position } { if (digitalRead(button4) == LOW) for(pos4 = range_4_low; pos4 < range_4_high; pos4 += range_4_diff) // goes from 85 degrees to 95 degrees in steps of 1 degree { myservo4.slowmove(pos4,speed4); // tell servo to go to position in variable 'pos' delay(delay4); // waits x ms for the servo to reach the position } if (digitalRead(button4) == HIGH) for(pos4 = range_4_high; pos4>=range_4_high; pos4-=range_4_diff) // goes from 95 degrees to 85 degrees in steps of 1 degree { myservo4.slowmove(pos4,speed4); // tell servo to go to position in variable 'pos' delay(delay4); // waits x ms for the servo to reach the position } { if (digitalRead(button5) == LOW) for(pos5 = range_5_low; pos5 < range_5_high; pos5 += range_5_diff) // goes from 85 degrees to 95 degrees in steps of 1 degree { myservo5.slowmove(pos5,speed5); // tell servo to go to position in variable 'pos' delay(delay5); // waits x ms for the servo to reach the position } if (digitalRead(button5) == HIGH) for(pos5 = range_5_high; pos5>=range_5_high; pos5-=range_5_diff) // goes from 95 degrees to 85 degrees in steps of 1 degree { myservo5.slowmove(pos5,speed5); // tell servo to go to position in variable 'pos' delay(delay5); // waits x ms for the servo to reach the position } }}}}} // 5x close bracket, one for each servo } Nick Edited October 1, 2016 by nick_bastable Link to post Share on other sites More sharing options...
MinerChris Posted October 1, 2016 Share Posted October 1, 2016 Chris, I am using a push button for testing purposes but in the final design I would very much like to use DPDT switches. Based on your feedback and the sketch I take you're using a diagram similar to the one bellow? I know there a couple of resistor involved but for simplicity I chose not to depict them. Thats pritty much it, but I have just used one side of the DPDT as how a push button would be wired, but that's not to say that how you've wired it wouldn't work too. I've just retested my circuit again, and I remember that the servo's do still buzz from startup until the switch polarity is changed, which I think may be because my transistor is only dropping the feed voltage to 4V across the servo when the pin is low and when the board starts up it seems to put 2V into the signal lead, which I have solved by setting up the servopins as outputs Best Regards, Chris Link to post Share on other sites More sharing options...
MinerChris Posted October 1, 2016 Share Posted October 1, 2016 What is the value of "current"? Indeed where is it declared? Looks like unless current (and hence old_pos) is set to the current actual position of the servo, you are going to tell it to move to a position perhaps far from where it actually is. This line in particular: myservo.write(pos); // set the initial servo position I think I would expect a line like int current = myservo.read(); to get it set correctly. Chris myservo.read is only the last command sent to the servo, not the position of the servo itself, and is consequently lost when the Arduino is powered off, hence why I think it is slightly better to get a switch to read where it should be (you will still get a rapid movement if the switch state is changed with no power, when everything is turned back on again) Or even better, attach a microswitch to the movement to see where it actually is... Best Regards, Chris. Link to post Share on other sites More sharing options...
PeteDavey Posted October 2, 2016 Share Posted October 2, 2016 Can anyone point me in the direction of the parts required to convert a Dapol 0-6-0 Pannier Tank to 2fs please? I have searched the association shop and have found the part numbers mean very little to me. Is this an ideal Steam outline Loco to start with or can anyone recommend an easier alternative circa 1940-50 that's readily available and already DCC compatible that would be ideal as a first steam conversion? Pete Link to post Share on other sites More sharing options...
RMweb Gold queensquare Posted October 2, 2016 RMweb Gold Share Posted October 2, 2016 Can anyone point me in the direction of the parts required to convert a Dapol 0-6-0 Pannier Tank to 2fs please? I have searched the association shop and have found the part numbers mean very little to me. Is this an ideal Steam outline Loco to start with or can anyone recommend an easier alternative circa 1940-50 that's readily available and already DCC compatible that would be ideal as a first steam conversion? Pete The Dapol pannier is not an ideal first steam conversion, the options are either a fairly major rebuild or, much better, a new chassis. The best option for a first steamer is the latest generation Farish Jinty which is about as close to drop in wheels as you are likely to get in 2FS. If you want GWR then the new 64xx is mechanically very similar. A conversion kit for the latter should be available very soon. Chairman Andy and Publicity Mick are preparing a press release and I will be doing an article for MRJ as soon as the bits are available. Jerry 1 Link to post Share on other sites More sharing options...
RMweb Gold Donw Posted October 2, 2016 RMweb Gold Share Posted October 2, 2016 (edited) I look forward to the 64xx article Jerry. It does sound like a good bet. Don ps re the servo topic. using a servo motor with microswitches does not equate to a stall motor. With a stall motor the operating arm should be flexible enough to cope with overrun but rigid enough to hold the blades in place. Possibly using a flexible enough operating arm might alleviate some servo problems making the precise positioning less critical and protecting the turnout. ONe possible idea is to drive the turnout using a torsion rod where extra movement is taken up in the torsion rod. Edited October 2, 2016 by Donw Link to post Share on other sites More sharing options...
PeteDavey Posted October 3, 2016 Share Posted October 3, 2016 (edited) Regarding the conversion of a Steam Loco to 2mmfs, is such a service available commercially? Or does anyone on here offer this service for a fee? I'm currently building track for a rather ambitious (for me) layout which involves a helix each end and would rather like to test gradients with both a small tank such as an 0-6-0 and a tender loco before I get too far in and find its not viable. Having never converted anything that doesn't involve drop in replacement axles before I thought my efforts may be better spent getting some track for a Loco to run on before fettling with Locos (walk before I can run so to speak). Pete Edited October 3, 2016 by PeteDavey Link to post Share on other sites More sharing options...
RMweb Gold queensquare Posted October 3, 2016 RMweb Gold Share Posted October 3, 2016 Regarding the conversion of a Steam Loco to 2mmfs, is such a service available commercially? Or does anyone on here offer this service for a fee? I'm currently building track for a rather ambitious (for me) layout which involves a helix each end and would rather like to test gradients with both a small tank such as an 0-6-0 and a tender loco before I get too far in and find its not viable. Having never converted anything that doesn't involve drop in replacement axles before I thought my efforts may be better spent getting some track for a Loco to run on before fettling with Locos (walk before I can run so to speak). Pete Hi Pete, I do this sort of thing commercially. Either PM me or email via my website. Website link is in my signature below. Jerry 1 Link to post Share on other sites More sharing options...
Valentin Posted October 9, 2016 Share Posted October 9, 2016 (edited) Hi, Many thanks to all who tried to help me with my Arduino code for the turnouts. I ended up writing again the code from (near) scratch. Of great help was using another library that the one built into the Arduino IDE: VarSpeedServo, which is a modified Servo library. It really makes it simple to move the servo at slow speeds. It can be downloaded from here. And, for those who are interested here is my sketch (only one servo): #include <VarSpeedServo.h> // create a servo object: VarSpeedServo servo1; // constants used to set pin numbers: const int switch1commonPin = 2; // the coomon pin of the SWITCH 1 const int led1Pin = 13; // the LED 1 pin const int servo1Pin = 9; // the signal pin of SERVO 1 // constant variables used to set SERVO 1 angles and speed: const int straight1 = 30; const int divergent1 = 150; const int servo1Speed = 10; // variables: int switch1State = 0; // variable for reading the switch 1 status void setup() { // set the mode for the digital pins in use: pinMode(led1Pin, OUTPUT); // initialize the LED 1 pin as an output pinMode(switch1commonPin, INPUT); // initialize the SWITCH 1 pins as an input servo1.attach(servo1Pin); // attaches the servo1 on servo1Pin to the servo object } void loop() { // read the state of the SWITCH 1 value: int switch1State = digitalRead(switch1commonPin); // check the SWITCH 1 position: if(switch1State == HIGH) { // switch the turnout to DIVERGENT: servo1.slowmove(divergent1,servo1Speed); // and turn the LED on: digitalWrite(led1Pin, HIGH); } else { // switch the turnout to STRAIGHT: servo1.slowmove(straight1,servo1Speed); // and turn the LED off: digitalWrite(led1Pin, LOW); } } Edited October 9, 2016 by Valentin Link to post Share on other sites More sharing options...
Valentin Posted October 30, 2016 Share Posted October 30, 2016 What's the most suitable tool to make 3.3 - 3.5 holes in 0.2 mm Plastikard? Drilling doesn't work, even if started with a small drill, as I can't get a clean edge hole. It works fine with an office puncher but the hole is too large (5.5 mm). I've seen these on eBay: hollow punch tool and screw/hole punch. Link to post Share on other sites More sharing options...
Orange Cat Posted October 30, 2016 Share Posted October 30, 2016 What's the most suitable tool to make 3.3 - 3.5 holes in 0.2 mm Plastikard? Drilling doesn't work, even if started with a small drill, as I can't get a clean edge hole. It works fine with an office puncher but the hole is too large (5.5 mm). I've seen these on eBay: hollow punch tool and screw/hole punch. Drill a smal hole and then use a broach to enlarge it? Link to post Share on other sites More sharing options...
Caley Jim Posted October 30, 2016 Share Posted October 30, 2016 (edited) What's the most suitable tool to make 3.3 - 3.5 holes in 0.2 mm Plastikard? Drilling doesn't work, even if started with a small drill, as I can't get a clean edge hole. It works fine with an office puncher but the hole is too large (5.5 mm). I've seen these on eBay: hollow punch tool and screw/hole punch. I have a leather punch similar to this. http://www.ebay.co.uk/itm/TRIXES-Revolving-Leather-Belt-Eyelet-Hole-Punch-Puncher-Plier-Craft-Tool-6-Sizes-/390537852570?hash=item5aeddeb69a:g:fQgAAOSwBLlU9JFk with a rotating head with punches from 2mm - 5mm in 0.5mm steps. I would think this easier to work than the others as you can do it with one hand. Jim Edited October 30, 2016 by Caley Jim Link to post Share on other sites More sharing options...
£1.38 Posted October 30, 2016 Share Posted October 30, 2016 Sandwich the plastic sheet between 2 pieces of scrap plywood and drill through the lot. Link to post Share on other sites More sharing options...
RMweb Gold Donw Posted October 30, 2016 RMweb Gold Share Posted October 30, 2016 You refer to holes as though you will be making a fair few. If so I would clamp a bit of scrap plastikard in a cheap hinge and drill through the hinge and all. you should then be able to drill as many as you want with clean edges. However for a one off or just a few drill through slightly undersize into scrap (hardboard is handy) then use the broach to open out to the right size. The broach is good if the hole has to be different from a nominal drill size. Don Link to post Share on other sites More sharing options...
RMweb Premium PaulCheffus Posted October 30, 2016 RMweb Premium Share Posted October 30, 2016 What's the most suitable tool to make 3.3 - 3.5 holes in 0.2 mm Plastikard? Drilling doesn't work, even if started with a small drill, as I can't get a clean edge hole. It works fine with an office puncher but the hole is too large (5.5 mm). I've seen these on eBay: hollow punch tool and screw/hole punch. Hi I use one of these https://www.historexagents.com/shop/hxproductdetail.php?ProductCode=RPTPD However the price these days is rather high. Mine was around £25 ten years ago. Cheers Paul Link to post Share on other sites More sharing options...
Valentin Posted October 30, 2016 Share Posted October 30, 2016 Thank you all for your help. I need to make only 8 holes; the Plastikard is going to be used for insulation; I try to scratch build a 0-6-0 chassis and I am using for this two 1 mm brass strips for frames and three strips (1mm + 2 mm + 2 mm = 5 mm) sandwiched by the frames. I used P/B bushes therefore I need 3.3 - 3.5 holes in the Plastikard sheet. Link to post Share on other sites More sharing options...
Chris Higgs Posted October 31, 2016 Share Posted October 31, 2016 Thank you all for your help. I need to make only 8 holes; the Plastikard is going to be used for insulation; I try to scratch build a 0-6-0 chassis and I am using for this two 1 mm brass strips for frames and three strips (1mm + 2 mm + 2 mm = 5 mm) sandwiched by the frames. I used P/B bushes therefore I need 3.3 - 3.5 holes in the Plastikard sheet. So, does it really matter then that the holes are precisely round? The insulation should still work even if they are bigger than required and a bit rough around the edges. Chris Link to post Share on other sites More sharing options...
Chris Higgs Posted October 31, 2016 Share Posted October 31, 2016 (edited) Hi I use one of these https://www.historexagents.com/shop/hxproductdetail.php?ProductCode=RPTPD However the price these days is rather high. Mine was around £25 ten years ago. Cheers Paul It is EUR 70.00 direct from the manufacturer. So perhaps a bit cheaper that way. These guys do some interesting stuff. I find the leaf cutter particularly amusing. Not that 2mm modellers are likely to be cutting individual leaves for their trees. Edited October 31, 2016 by Chris Higgs Link to post Share on other sites More sharing options...
Valentin Posted October 31, 2016 Share Posted October 31, 2016 So, does it really matter then that the holes are precisely round? The insulation should still work even if they are bigger than required and a bit rough around the edges. Chris I don't know how to explain it exactly but the Plastikard sheet I have somehow it splits and it bends upwards and downwards... I will take a picture of it when I get back home later in the week. Anyway, I am going to get a cheap belt hole puncher like this one. Link to post Share on other sites More sharing options...
Chris Higgs Posted October 31, 2016 Share Posted October 31, 2016 I don't know how to explain it exactly but the Plastikard sheet I have somehow it splits and it bends upwards and downwards... I will take a picture of it when I get back home later in the week. Anyway, I am going to get a cheap belt hole puncher like this one. Hopefully this will work. Otherwise try just cutting square holes using a normal sharp craft knife. Chris Link to post Share on other sites More sharing options...
Caley Jim Posted October 31, 2016 Share Posted October 31, 2016 Anyway, I am going to get a cheap belt hole puncher like this one. That's the type of thing I was talking about. You may find that the sheet bows slightly in the area round the hole, but if you file or shave the back flat it should be perfectly OK. Jim Link to post Share on other sites More sharing options...
Crosland Posted November 1, 2016 Share Posted November 1, 2016 I have used a piece of brass tubing for something similar. Sharpen the end and use as a punch or file a few teeth and use like a core drill or hole saw (in the hand!). Andrew Link to post Share on other sites More sharing options...
ukpepsi Posted November 3, 2016 Share Posted November 3, 2016 (edited) I've moved the question to the questions, help and tips section as suggested. http://www.rmweb.co....-help-and-tips/ Pepsi Edited November 4, 2016 by ukpepsi Link to post Share on other sites More sharing options...
modfather Posted November 3, 2016 Share Posted November 3, 2016 Hi, I'm putting together a representation of an oil terminal, (or at least, small section of it) from a Kibri kit. The kit comes with signs in German naturally, however I wish to Anglicise it with company logo's more familiar to the UK, more specifically Scotland. Does anyone know if anyone produces signage for UK oil terminals? I've looked in the usual places like scalescenes, but have drawn a blank. Any help or suggestions would be appreciated. Pepsi PS, I may have posted this on the wrong board as I need the signs to be in 4mm. Hope people don't mind. You would be better off asking in the structures or in the questions, help and tips section http://www.rmweb.co.uk/community/index.php?/forum/25-modelling-questions-help-and-tips/ 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