An interactive Advent calendar
Gifts
The most difficult part of the project proved to be setting up the daily gift delivery. The servomotors were not at all as easy to control as I had hoped. The unforeseen difficulties led to a three-gift limit for each servomotor. The original plan had called for one servomotor to handle six gifts. Reloading the calendar with a second set of 12 gifts after the first set of 12 gifts had been disbursed proved to be a successful workaround.
Both the servos and the LEDs are connected to the second voltage regulator. Optocouplers provide the signaling necessary to uncouple the I/O ports of the Rasp Pi from the servomotors. The wiring diagram (Servo.sch
) shows the structure of the amplifier stages. The ServoBlaster tool, which controls the servos, is available on GitHub as source code:
$ git clone git://github.com/richardghirst/PiBits.git $ cd PiBits/ServoBlaster/user $ make
Following this process, you should start the server to load the userspace device driver for the four servomotors:
$ sudo ./servod --p1pins=7,11,12,15 --pcm
If you forget the --pcm
switch, ServoBlaster could destroy the sound output of the Rasp Pi. Servod manufactures a device driver that is straightforward to use and can be controlled with the echo
command. Using the parameter 2=140
, you can write a value of 140 to servo 2:
$ echo 2=140 > /dev/servoblaster
This sets the shaft about mid-position. The values written to the servos used in the project vary between 90 and 190, which in turn correspond to a 120-degree angle. Each servo behaves differently, so it makes sense to play around with the values.
The script Load.pl
from the calender/servo/
folder should be used to bring all of the servos to a loading position. Just as is the case with the LEDs, the folder contains a script for each day. To stop ServoBlaster, you should enter the command
$ sudo killall servod
to end all servod
processes.
Stepper Motor and a Button
A stepper motor turns a round disk to the appropriate day for display of the current calendar date. After doing some research, I decided against building a stepper motor driver control and instead chose to use a TB6560 module (Figure 5).
The stepper motor used for the project was taken from an old printer (see the "Step by Step" box). A floppy disk drive would also serve as a good donor for this project. The motor selected was configured so that it completed a full turn in 48 steps, which meant that the motor turned two steps each day of the Advent calendar. I connected the control module directly to the Rasp Pi, because the module has galvanically isolated control inputs. The wiring diagram (Stepper.sch
) shows the wiring. You can use the GPIO pins to test whether the control function works:
$ gpio mode 11 out $ gpio write 11 1 $ gpio write 11 0
When considering the button that will be used to release a gift each day (Stepper.sch
), bear in mind that the GPIO interface for the Rasp Pi can only tolerate 3.3V. You can test it with the command gpio readall
.
Step by Step
As is evident from the name, a stepper motor positions its rotor in a step-by-step process. This makes it possible to achieve exact positioning. As a rule, the rotor of a stepper motor is made from a permanent magnet, and the strator consists of numerous coils wound in precise angles. If the rotor generates a magnetic field, then the coils that compose the strator are activated in a cyclic order, and the motor begins to turn. The rotor generates a rotating magnetic field for smooth rotation.
Controlling a stepper motor is not necessarily trivial, so special chips have been developed to accomplish this task, such as the TB6560AHQ stepper motor driver IC chosen for this project. This particular chip supports various operating modes, including half and quarter steps, and it also monitors current. These features guarantee that the motor performs as intended.
Buy this article as PDF
Pages: 6
(incl. VAT)