If your servo follows the potentiometer you are done, and you do not need to come to tomorrow’s x-hour. If not, the x-hour is for completing today’s steps.
On Thursday we’ll remove the potentiometer from the setup, add two photocells to the servo’s arm, and start on the solar tracker. Thursday’s reading is about the photocell.
The reading said the servo is powered from a separate supply and never from the Nucleo. Here is the reason: the servo may draw about 250 mA while moving, and much more if it is stalled, while your laptop’s USB port supplies at most 500 mA for the whole board and everything on it. High current draw by the servo can starve the Nucleo, causing it to brown out and reset itself. A GPIO pin is worse still: the STM32C031C6 datasheet gives an absolute maximum of 20 mA for any single I/O pin, so a servo’s power lead on a pin would exceed that rating many times over. So we power it from the same regulator board we used for the motor (Figure 11.2.21): the servo’s power lead goes to the regulator board’s 5 V pin, and never to its Vin pin. Vin is the regulator’s input, the adapter’s raw, unregulated voltage, up to 12 V, and a servo rated for 4.8 to 6 V would be destroyed there. Figure 13.2.28 shows how the servo connects to the regulator board. Do not connect the servo yet: the order in which it is wired and powered is Activity 13.2.12, below.
Why the servo is powered from a separate supply and never from the Nucleo: the servo may draw about 250 mA while moving, and much more if it is stalled, while your laptop’s USB port supplies at most 500 mA for the whole board and everything on it.
High current draw by the servo can starve the Nucleo, causing it to brown out and reset itself. A GPIO pin is worse still: the STM32C031C6 datasheet gives an absolute maximum of 20 mA for any single I/O pin, so a servo’s power lead on a pin would exceed that rating many times over.
So we power it from the same regulator board we used for the motor: the servo’s power lead goes to the regulator board’s 5 V pin, never to Vin. Vin is the adapter’s raw, unregulated input, up to 12 V, and the servo is rated for 4.8 to 6 V.
Figure13.2.28.How the servo is powered. The regulator board is plugged into the breadboard, so each of its pins is reached through the row it sits in. The servo’s red lead, the middle one, goes to the row of the regulator board’s 5 V pin, and never to Vin, and also never to the Nucleo’s 3.3 V or 5 V pin. Its brown lead goes to the breadboard’s ground rail, and so does a wire from the regulator board’s GND pin, so the servo, the regulator board and the Nucleo, whose GND also feeds that rail, share one ground. The signal lead, orange on the servo and drawn yellow here, goes to D11 (PA7). The Nucleo’s 3.3 V feeds the other rail, and nothing on the Nucleo powers the servo.
Red, the middle lead, to the row of the regulator board’s 5 V pin, never Vin and never a Nucleo pin. Brown to the breadboard’s ground rail, which the regulator board’s GND pin and the Nucleo’s GND also feed. Orange to D11 (PA7). Do not wire it yet; the activity gives the order.
On the Tower Pro SG92R in your kit the three leads are brown, red and orange (the signal lead is called orange and photographs yellow, Figure 13.2.30), and Figure 13.2.28 shows where each one goes.
This is the Tower Pro SG92R in your kit, on its stand with the solar tracker’s arm bolted to the horn. Its three leads leave at the right; the signal lead is called orange and photographs yellow.
Figure13.2.32.The circuit with the potentiometer and the servo together: the potentiometer on A0 (PA0), its wiper on the rightmost pin of the AIN header, and one ground shared by the servo, the regulator board, the potentiometer and the Nucleo. The servo’s brown lead is drawn black here, and its orange signal lead is drawn yellow.
The potentiometer on A0 and the servo on the regulator board’s 5 V. Wire it once your pulse is verified, with nothing powered.
Unplug power before making any changes to wiring: no USB cable in the Nucleo and no adapter in the regulator board while a wire is being moved. When you are ready to power up, plug in the USB cable first, and then the power adapter into the regulator board, as we did for the motor, so that the STM32C031C6 is running and PA7 is at a defined level before the servo has any power.
Do this once your pulse is verified on the oscilloscope, and work through it in order. Unplug power before making any changes to wiring: no USB cable in the Nucleo and no adapter in the regulator board while a wire is being moved.
With nothing powered, remove the AD2 from PA7, plug the regulator board into the breadboard, and run a wire from the row of its GND pin to the breadboard’s ground rail, the rail the Nucleo’s GND already feeds. Leave the row of its 5 V pin empty for now.
Plug the power adapter into the regulator board, and nothing else. With the multimeter on DC volts, the black probe on the breadboard’s ground rail and the red probe in the row of the regulator board’s 5 V pin, you should read 5 V. We measure before the servo is connected, and we do not want to connect the servo until the 5 V is confirmed. A reading of 0 V means nothing is reaching the board, so check the adapter and how it is seated. A reading near the adapter’s own voltage means the 5 V and Vin rows are swapped or the regulator has failed. Then unplug the adapter.
With nothing powered, connect the servo’s three leads: the brown lead to the breadboard’s ground rail, the red center lead into the row of the regulator board’s 5 V pin, not its GND or Vin pin, and the orange signal lead to D11 (PA7). Then check your wiring with an instructor.
Plug in the USB cable first, then the power adapter into the regulator board, as we did for the motor, so that the STM32C031C6 is running and PA7 is at a defined level before the servo has any power. Turn the knob, and you should see the servo rotate, smoothly, as you adjust the potentiometer.
The servo does not move at all, and the pulse was verified. The fault is in power or ground (check this first) or in the signal (check if power and ground are okay). Measure the row of the regulator board’s 5 V pin again, with the servo connected; it should be 5 V. Check the wire from the regulator board’s GND pin to the breadboard’s ground rail, and check that the red lead is in the 5 V row. Then check the signal: the orange lead should be on D11 (PA7). If all of that is right and the arm still does not move, let us know; the servo itself may have been damaged.
The servo twitches, or the terminal’s printout starts over from its first line. The Nucleo is resetting. The restarting printout is the proof of the reset; a twitch on its own is also consistent with supply noise. The likely cause is that the servo is drawing its current from the Nucleo, which is wrong: its red lead has accidentally been put on the 3.3 V rail or on a Nucleo pin instead of the row of the regulator board’s 5 V pin. Remove power, the adapter first and then the USB cable, and move the lead to the regulator board’s 5 V row.
The servo moves but does not follow the knob, or holds one end. Look at CoolTerm. If pot_value is not changing, the wiper has come off A0 or the potentiometer’s outer legs are off their rails. If pot_value is changing and the servo is not following it, the program on the board is not your completed template; build and flash it again.
The servo buzzes at one end of the knob’s travel. That servo’s travel is shorter than the convention’s, and it is holding against its own stop. Turn the knob a little toward the center.
The servo does not move at all, and the pulse was verified. The fault is in power or ground (check this first) or in the signal (check if power and ground are okay). Measure the row of the regulator board’s 5 V pin again, with the servo connected; it should be 5 V. Check the wire from the regulator board’s GND pin to the breadboard’s ground rail, and check that the red lead is in the 5 V row. Then check the signal: the orange lead should be on D11 (PA7). If all of that is right and the arm still does not move, let us know; the servo itself may have been damaged.
The servo twitches, or the terminal’s printout starts over from its first line. The Nucleo is resetting. The restarting printout is the proof of the reset; a twitch on its own is also consistent with supply noise. The likely cause is that the servo is drawing its current from the Nucleo, which is wrong: its red lead has accidentally been put on the 3.3 V rail or on a Nucleo pin instead of the row of the regulator board’s 5 V pin. Remove power, the adapter first and then the USB cable, and move the lead to the regulator board’s 5 V row.
The servo moves but does not follow the knob, or holds one end. Look at CoolTerm. If pot_value is not changing, the wiper has come off A0 or the potentiometer’s outer legs are off their rails. If pot_value is changing and the servo is not following it, the program on the board is not your completed template; build and flash it again.
The servo buzzes at one end of the knob’s travel. That servo’s travel is shorter than the convention’s, and it is holding against its own stop. Turn the knob a little toward the center.
If your servo follows the potentiometer you are done, and you do not need to come to tomorrow’s x-hour; if not, the x-hour is for completing today’s steps. On Thursday we’ll remove the potentiometer from the setup, add two photocells to the servo’s arm, and start on the solar tracker. Thursday’s reading is about the photocell.