Servo moving to different position between Power On and Reset

Hi all

I've installed several Nanos with Sensor Shields (ext. Power Supply). On these shields I attached 8 to 12 Servos (9g, cheap china stuff).

Servos are attached with servo.h library, thus soft-pwm on digital pins. I write the last position to the eeprom, and on start-up the servos are set back to this position. Like that I can almost avoid jitter on startup.

Now I have the weird situation, that the Arduino sets the servos while initializing to a different position, than if pressed the reset button on the Arduino!

It's definitely not jittering, since I can see each servo after the other to be placed to its position with a programmed delay of 500ms, as intended. And I see the initializing actions on the Serial Monitor, including the correct set angle. Everything looks similar and correct.

I looks to me that the pulse width software simulation is different on power up than on reset. I don't have my code here (I'm at work); if needed, I'd be able to post this evening.

this happens on 4 different nanos, with 4 different shields of 2 different types. It happens when externally powered (12V) and also when powered by 5V over USB or Vin.

Any clues? Thank you Guido

Here is my code, maybe this helps to answer my question:

code_for_forum_shortened.ino (17.8 KB)

Help me out with the description of your problem.

Your sketch makes servos move.

Your sketch writes servo positions to the eeprom.

On startup, your sketch reads eeprom values and uses the as the start position of your servos.

This all works well.

If you hit the reset button, this does not work well.

Is that accurate? When does your sketch write to the eeprom? Does it write to the eeprom when you hit the reset?

Hi Vinceherman

thank you for your request for more information. I'm happy somebody tries to help.

  1. Yes, sketch moves servos to their right positions.
  2. After having reached its target position, it's new position gets written to the eeprom.
  3. Yes, during setup, eeprom gets read and this is the initialising position for the servos.
  4. Works, but not on power on, only on reset in my eyes.
  5. Eeprom only gets written after controlled movement between the two positions. Not on Startup.

I'm using the servos for switches on my model railway. Thus, I only have 2 positions hard coded for every servo. Eeprom remembers the position of the last actuation. Thus, there should be no jitter on start up like that. But with power on, servo moves to an unkwon position (at least some of them). Pressing reset then shows the expected behaviour and servos moves to the position saved in Eeprom.

I also compared the initial values during setup procedures: they are identical between power on and reset procedure. Thus, I shouldn't have any issue with eeprom, start sequence etc.