MyIdaho

I'm a luddite who is giving servos a try for operating turnouts.  I am trying to complete Dr Geoff's servo projects from the Dec 2016 MRH.  The article does not mention how to finetune servo position.  I understand that the "IDE sketch" specifies the beginning and ending point for each servo.  What is the process to finetune?  My guess is a sequential approximation (SA) for each start and end position.  In other words, change the values, reflash the sketch to the Uno and operate, rinse and repeat until servo and turnout are correctly aligned.  While SA works, it  quickly becomes tedious and leads one to want a better way...  I'm hoping experienced Arduino users can provide me with a quicker process for finetuning servo position!

The commercial servo systems such as Tam Valley Depot, Micro Miniatures, and MegaPoints Controllers all have a built-in system for aligning servos and do not require modifying sketches, SA, and frequent reflashing.  A big plus!  However, if I truly want a fair comparison, I need to try a basic arduino/servo setup and decide if there are enough advantages (or not) to justify a more expensive yet very consumer friendly system.

Reply 0
ACR_Forever

@MyIdaho

Three things I did, one I will do.  

1) I wrote my sketch to work with an array of 16 servos using a PCA9685 (working from memory here).  The values for all 16 are stored in EEPROM.  Makes it really easy to plug in my PC and start tuning any servo.

2) I wrote my sketch so that using the serial monitor in the environment, I could tune a servo's end positions using "U" and "D".

3) I wrote my sketch so that the first time it ran, it used default values.  Then, when I type "S", it stores the whole set to EEPROM.  Next time it starts up, it detects that there are values in the EEPROM, and uses those.  Since the serial monitor is active, I can continue to tune the values, and then save them again using "S".

4) I considered, but have not done, an upgrade to use a small button pad and a 2-line LCD instead of the PC and the serial monitor.  The code is structured to allow me to substitute those in with, of course, a bit of fiddling.

Yes, I've not revealed a lot of the details here, but these ideas should get you started.  Feel free to reach out.

Since I came across a trove of tortoises (enough to complete both my staging yards, meaning I don't need my servo stuff just yet), I haven't commissioned this, but it does work "on the bench".  I will need it for staging yards 3 and 4, so at some point I will be revisiting it.

Blair

 

 

Reply 0
Ron Ventura Notace

Be like Blair

Blair has done something similar to what I did, although he incorporated it into his main sketch. As a test rig, I used a separate Arduino, with an LCD with attached button pad. This allowed me to adjust the position of a servo by either 5 or 1 degrees at a time, in either direction. I had a +5, +1, -5 and -1 button. After installing my servos, I connected each in turn to this test rig. Then I adjusted the position of the servo until it felt right in the normal and thrown position. The current position was displayed on the LCD. I noted the values for later use in my controlling sketch. You could just as easily use the serial monitor if you didn’t want to fuss with the LCD.

Having done all the testing, I then plugged the values I gathered into an array of “normal” and “thrown” positions for each servo/turnout. As you can probably guess, there was a fair amount of variation from servo to servo. My solution is not as elegant as Blair’s, but it works.

Ron Ventura

Melbourne, Australia

Reply 0
Ted Becker rail.bird

Serial Monitor EEPROM Load

I use the following functions.  Call them in setup() as shown.  Serial.end() is optional.  Use any Baud rate.  Start the serial monitor.  After the initial dump you have 5 seconds to type in any character to start the load process.  If it prints "Quitting" you were too late.  When prompted enter an address from the Dump list.  When prompted enter the new value.  It will dump the EEPROM again so you can verify the result and ask for the next address.  Enter any number higher than the highest address to exit.  Crude but it works.  I usually set all the values at 1500 before connecting any servos then I use a HJ servo tester to get the end point values. https://www.amazon.com/GoolRC-Tester-Consistency-Helicopter-Airplane/dp/B00LTOD4F4 .I always work with microSecond pulse widths.  If you use degrees you are on your own.

void setup()
{
  Serial.begin(9600);
  EEPROM_Dump();
  EEPROM_Load();
  Serial.end();

// other setup stuff

}


void EEPROM_Dump(void) {
  Serial.println();
  Serial.println("Servo  Addr LEFT   Addr RIGHT");
  for ( int ww = 0; ww < NumServo; ww++) {
    int servoVal, EEPromAdd ;
    Serial.print("   ");
    Serial.print(ww);
    Serial.print("    ");
    EEPromAdd = (ww * 2 + LEFT) * 2;
    if (EEPromAdd < 10 )  Serial.print("0");
    Serial.print(EEPromAdd);
    Serial.print("  ");
    EEPROM.get(EEPromAdd, servoVal);
    Serial.print(servoVal);
    Serial.print("    ");
    EEPromAdd = (ww * 2 + RIGHT) * 2;
    if (EEPromAdd < 10 )  Serial.print("0");
    Serial.print(EEPromAdd);
    Serial.print("  ");
    EEPROM.get(EEPromAdd, servoVal);
    Serial.println(servoVal);
  }
}

void EEPROM_Load(void) {
  unsigned int EE_Add, EE_Val = 1500;
  unsigned long start;
  byte xx_input[200];

  Serial.println("Enter any character:  ");
  while (Serial.available() == 0) {
    if (start + 5000 < millis()) {
      Serial.print("Quitting  ");
      return;
    }
  }

  while (1) {
    Serial.readBytes(xx_input, 200);
    Serial.print("Enter EEPROM address:  ");
    start = millis();
    while (Serial.available() == 0);
    EE_Add = Serial.parseInt();
    if (EE_Add> NumServo * 4 - 2) {
      Serial.print("Quitting  ");
      return;
    }
    Serial.println(EE_Add);
    Serial.readBytes(xx_input, 200);
    Serial.print("Enter EEPROM value:  ");
    while (Serial.available() == 0) ;
    EE_Val = Serial.parseInt();
    EE_Val = constrain(EE_Val, 500, 2500);
    Serial.println(EE_Val);
    EEPROM.put(EE_Add, EE_Val );
    EEPROM_Dump();
  }
}

 


Ted Becker

Granite Falls, WA

Reply 0
ACR_Forever

MyIdaho

re-reading your post, I suspect you may be overwhelmed by the suggestions made so far.  I've reached out to you by email for further discussion.

Blair

 

Reply 0
Tim Lynch

dealing with cold startup of servos and resetting to "zero"

I understand the concept of setting and storing custom endpoints of servo movement for Through and Diverge in my arduino code.  But how do your servo installations deal with the servo swinging to absolute zero when doing a cold power on?  You know: when power is first applied, the servo will swing to full absolute zero to, I assume, do an internal calibration to establish the absolute 0/180 travel endpoints.

All the little servos I have do this reset. This reset does not appear to have anything to do with the arduino code - the servo resets whenever power is first applied, before any code executes.

Do you just design your mechanical setup to allow this reset to occur without damaging the turnout, or, is there a way to permanently prevent the servo from doing the reset? I've not seen any arduino code that reliably eliminates the reset; all my installs employ sufficient physical "springy-ness" to allow the reset to occur without harm.

If you are using servos that don't do this cold reset, could you specify what model you use?

 

 

Reply 0
Prof_Klyzlr

Servo "initialisation swing"

Dear Tim,

Quote:

But how do your servo installations deal with the servo swinging to absolute zero when doing a cold power on?  You know: when power is first applied, the servo will swing to full absolute zero to, I assume, do an internal calibration to establish the absolute 0/180 travel endpoints.

Reccomend checking out Dr Geoff Bunza's "6 switched servo" Arduino example,
https://model-railroad-hobbyist.com/magazine/mrh2016-12-dec/arduino
/> it does not exhibit this "initial power-on wild-full-range-swing" behaviour you are concerned about.
(or, more-appropriately, it is deliberately coded such that the "default starting-position" initialisation point = one of the User-defined "servo end point" positions, not "blindly full-range").

Also pls NB that servos are not like stepper-motors, they do not need a "where is Zero Position?" calibration-check for every cold-power-on. By defintion, Servos are equipped with a fixed-length/value resistor-pot position-feedback system, which means their position is deterministic and absolute,
not relative to some arbitrary "Zero position" like a Stepper-motor.

https://www.sparkfun.com/servos

The reason for the "wild full-range-swing" behaviour of some Servo Control systems is typically a failure to appropriately-initialize the Servo Driver Circuit which is powering/driving the Servo,
IE it's not an issue, fault, or technical need of the (SG/MG90) Servo itself.

If the Servo Driver cold-boots blindly "at Zero Volts/GND" or "at VCC", due to combination of:

- Servo Driver Board/Shield hardware circuit design,

- power-on <>  command-signal initialization sequence,
(particularly when the Host Arduino and Servo Driver Board/Shield are powered by seperate independent PSUs!
Can you say "Race Condition"? )

- and/or Code support

then the Servo will (understandably/blindly) do exactly as it's told,
and slew "hard to one-or-other end of its mechanical travel" limits...

Upshot,
- design the Arduino code/sketch
- and choose the Servo Driver appropriately,
- and power-on the individual components of the complete "servo control system" in appropriate sequence

and any "uncontrolled full-range slew" startup movement can be engineered-out of a Servo-based turnout-control unit...

Happy Modelling,
Aim to Improve,
Prof Klyzlr

Reply 0
Ted Becker rail.bird

Power-on swing

The servos on my layout DO NOT do any kind of power-on glitch.  If they move at all it is because they are commanded to move to a start-up position by the software immediately after being 'attached'.  The Arduino servo library is used for the software.

If you have external power to the servos be sure the power to the processor comes on first.  The boards I use have a 5Volt regulator that powers both the Arduino and the servos.

PinMode should not be used for servo pins with the Arduino servo library.

On a somewhat related note:  I do not 'detach' the servos after they've moved.  Some people do this because the servos buzz.  Servos buzz when they are commanded to move beyond the point they can freely move.  The proper way to stop the buzz is back off the value sent to the servo or free up the movement.

 


Ted Becker

Granite Falls, WA

Reply 0
john holt

Easy for me

I plan to use servos on my layout for turnout control with 2 lever arm type micro switches to control frog polarity and to operate LEDs on my control panel. At age 73 and not having a background in electronics,  I don't have time to learn all it takes to program an Arduino device. The MegaPoints Controller is in next months hobby budget. Hey, for me, it is a quick and easy solution. Just saying, for guys like myself, someone else has done all the heavy lifting. Ah.....to be young again with all that time and energy.

Reply 0
MyIdaho

I hear you John!

I agree with you John, I am just a few years younger than you!  The commercial systems have lots of advantages over a DIY system but are more expensive.  I'm giving DIY a try but may decide to go with a commercial system.  I really like the Tam Valley Depot system but their servo controllers are no longer being sold.  Micro Miniatures and Mega Controllers are both very good systems.  If I go commercial, I'm leaning toward the Micro Miniatures 8 servo controller as it matches my needs at a lower price point.  Wish you well with your new system!  Report back with your experience! 

Reply 0
MyIdaho

Email sent

Thank you, Blair, I have sent you an email.  I am a novice and very early in the learning curve!  I greatly appreciate your offer of assistance!  Best, Rick

Reply 0
Steves VR

Mardec...

Rick, 

I urge you to take a look at Mardec from ARCOMORA No writing code, fussing around with plugging numbers in for servo position, Arcomora has its own software interface for fine tuning done in real time on screen. You can buy his products or just load the sketch onto your own Arduinos. 

The only "issue" is that you need your PC connected to the Arduino for making adjustments. I have a laptop that I take to the layout and  plug into the Uno.

Regards,

Steve.

 

Reply 0
MyIdaho

Appears to be for DCC control?

Steve, this device appears to be for DCC control of turnouts.  Is that correct?  I prefer DCC for operating trains only, not turnouts.  My preference.

Reply 0
Steves VR

Yes, it is designed to work

Yes, it is designed to work with DCC, however it is not necessary, you can assign io's to be inputs and use a momentary push button or toggle sw to control the turnout, it's very flexible, and no writing code.

I had put off using servos to control turnouts, but bit the bullet a couple of years ago given I can buy a servo for Aus$ 2.50. Tortoise have got too dear with current exchange rate. 

I played around with some sketches, but really didnt want to go down another rabbit hole,  Mardec suits me best, ymmv.

Cheers,

Steve

 

Reply 0
john holt

Suppliers

Thank you, MyIdaho for a heads up on the Micro Miniatures items. Always good to find an alternate supplier.

Another supplier I have purchased from is a place called Block Signaling. They are located in the UK and offer a nice line of items at a reasonable price and shipping is very reasonable. I believe a certain amount of the selling price also goes for cancer research. With the lower shipping prices a little longer shipping time is required.....about a month for my items. So order early. By the way I am in no way connected with Block Signaling, just a satisfied customer.

Reply 0
MyIdaho

Mardec needs better documentation

Maybe a good choice but the documentation does not describe how to set up the system for non-DCC control of turnouts with servos + turnout route indication.  No discussion on how to adjust servo positions.  The documentation says it can but does not say how, not very helpful.  Google search comes up empty for Mardec and/or DCCNext for user reviews and experiences with the product.  The marketing plan says for everyone but clearly requires an advanced user at this stage of development.  Steve, do a write up, show us what you've done!

Reply 0
ACR_Forever

MyIdaho

I sent a reply, let me know here or by re-reply if you got it.  

Blair

Reply 0
MyIdaho

received and reply sent  

received and reply sent

Reply 0
Steves VR

Re : Documentation

I suspect that English is not the author's first language.

The instructions may be  a bit hard to understand, but in practice it's pretty straight forward.

Essentially you assign a port to be an output,  allocate a DCC address to that port. (even if you're not using DCC)

For inputs, you assign a port to be an input, then assign the DCC address of the output you want to be operated from this input.

Inputs are covered p12-13 of doc.

I don't have time atm to do a write up, but happy to assist you (or anyone else) as best I can if you have any questions.

Cheers,

Steve

Reply 0
Ron Ventura Notace

@Blair - re: your sketch

Hi Blair.

Would you be willing to share your sketch? I like the idea of incorporating the calibration code into the sketch as opposed to having a separate sketch. I’m also intrigued by the idea of using EEPROM to store the endpoint values. I’m aware there is a limit to the number of times (about 100,000) you can write to EEPROM, but in this instance I think that’s irrelevant.

Ron Ventura

Melbourne, Australia

Reply 0
ACR_Forever

@Ron

Absolutely.  I've reached out off-list to make contact, but bear in mind, as I said,

Quote:

Since I came across a trove of tortoises (enough to complete both my staging yards, meaning I don't need my servo stuff just yet), I haven't commissioned this, but it does work "on the bench".  I will need it for staging yards 3 and 4, so at some point I will be revisiting it.

It's very rough.  I'll dig it up and send it to you later this morning, it's on the PC in the layout room.

Blair

Reply 0
ACR_Forever

@Ron

Absolutely.  I've reached out off-list to make contact, but bear in mind, as I said,

Quote:

Since I came across a trove of tortoises (enough to complete both my staging yards, meaning I don't need my servo stuff just yet), I haven't commissioned this, but it does work "on the bench".  I will need it for staging yards 3 and 4, so at some point I will be revisiting it.

It's very rough.  I'll dig it up and send it to you later this morning, it's on the PC in the layout room.

Blair

Reply 0
Terry Chamberlain jterryc

Quad Servo Decoder - Manual and/or DCC Operation

Sorry that this is a bit late - I didn't see your post until now - but you might find the article that I had published in  the  February and  March 2020 issues of MRH Magazine on building a Quad Servo DCC Decoder (QSDD) of interest, since it seems to satisfy your requirements. Although intended primarily to be operated via DCC, it has the facility for the servos to be operated via pushbuttons - which are also used to fine tune all of the servo throws and the rate at which they move.

There have been a couple of updates to the original article ( https://forum.mrhmag.com/post/quad-servo-dcc-decoder-%E2%80%93-improved-version-12217939 and  https://forum.mrhmag.com/post/quad-servo-dcc-decoder-%E2%80%93-arduino-software-update-12218580) and all of the updated information can be found on my website at  https://www.a-train-systems.co.uk/projects.htm#QuadServo (downloads at  https://www.a-train-systems.co.uk/download.htm#Projects).

I hope this will all be of some help.

Terry Chamberlain

Back_320.png     A Free Windows application for NCE Systems

https://www.a-train-systems.co.uk/atrack.htm

Reply 0
Reply