MTservo4wires
Event management for Uno, Nano, Mega
Parameter measurement
This program displays the two parameters to be put in the definition of MTservo4wires. If we put the right values, at power on the program will know the position of the servo and may not move.
The principle of function is as follows:

An control electronics receive a positioning order (in the form of a PWM signal). It compares it with the position of the output axis and acts on the engine accordingly. The position of the axis is measured thanks to a potentiometer, and to have a 4-wires servo, we will use the same measurement point by taking out the midfield of the potentiometer. The value can therefore vary between 0V and 5V, and we will read it with our Arduino using an analog input. We will thus have an idea of the position and at power-on we will ask for it. So the servo will not move and will not make a sudden jump.
There is not the possibility of knowing the value returned by the conversion to fun of the position other than by a measure. For position 0° we can read a value close to 0V or close to 5V, or even any value between the two, this will depend on the servo used. It's the same for the 180° position. The purpose of this program is therefore to indicate these two values.
We will therefore position the servo in position 0°, display the value after giving it time to stabilize, then do the same for 180°.
Complete program recommended
This program is completely under interruption, and releases loop which can be used to do something else.
// This program makes it possible to measure the two values to go into parameters // for a 4-wires servo #include <MTobjects.h> // V1.0.6 See http://arduino.dansetrad.fr/en/MTobjects const uint8_t PIN_SERVO = 9; // On Uno the usable commands pins are: 9, 10 // On Mega: 2, 3, 5, 6, 7, 8, 11, 12, 13, 44, 45, 46 const uint8_t POTENTIOMETER = A0; // Info on the position of the servo MTservo4wires Servo(PIN_SERVO, POTENTIOMETER, cad_for_0_degree 0, cad_for_180_degree 1023); // These two values are to be measured for each servo void setup() { Serial.begin(115200); // Console preparation } void loop() { Serial.print(F("cad_for_0_degree : ")); Servo.writeDegree(0); delay(2000 milli_seconds); // We must wait until the servo is well in place Serial.print(analogRead(POTENTIOMETER)); Serial.print(F(", cad_for_180_degree : ")); Servo.writeDegree(180); delay(2000 milli_seconds); // We must wait until the servo is well in place Serial.println(analogRead(POTENTIOMETER)); }
If the program returns
cad_for_0_degree : 823, cad_for_180_degree : 54 cad_for_0_degree : 822, cad_for_180_degree : 54 cad_for_0_degree : 823, cad_for_180_degree : 52 cad_for_0_degree : 824, cad_for_180_degree : 54 ....
We will put the next times:
MTservo4wires Servo(PIN_SERVO, POTENTIOMETER, cad_for_0_degree 823, cad_for_180_degree 54);