HackSpace_-_October_2019

(Rick Simeone) #1
FORGE

The main loop of our code is a simple conditional
statement (if, elif). The touchio library makes it
easy to use capacitive touch inputs to trigger events.
If the capacitive input is touched and the wing is
down, the servo will move to 60 degrees and the
value of wingUP will be set to True. However, if the
capacitive input is touched and the wing is up, the
servo will move back to 0, and the value of wingUp
will be set to False. A short time.sleep in each
condition helps us avoid multiple triggers per touch.


while True:
if buttonTouch.value and wingUp is not True:
my_servo.angle = upAngle
wingUp = True
print(“wingUp = True”)
time.sleep (0.5)
elif buttonTouch.value and wingUp is True:
my_servo.angle = 0
wingUp = False
print(“wingUp = False”)
time.sleep (0.5)

That’s it for our code! Saving this code in the
code.py text file will automatically restart the board
and run the program. Touching the wire connected
to A1 should make the motor turn 60 degrees and
stop. Touching the wire again should make it turn
back to zero and stop. If you haven’t connected a
servo horn to the spindle yet, a piece of tape can
help track the servo’s movement while testing.
Once assembled, you may need to tune the
upAngle value to make your wing open completely.
Increase the value in small increments, and be
careful as you approach the maximum angle of your
servo (usually about 180 degrees): pushing the servo
too far can damage it.


BUILD YOUR CIRCUIT
(FOR REAL THIS TIME)
Now that you’re sure your servo is working properly,
it’s time to solder the circuit together for good. Start
by adding an on/off switch to the LiPoly backpack.
Use a craft knife to cut the exposed trace between
the two switch pins. Then solder one short wire to
each pin of the switch.
Solder each wire to one of the pins on the on/off
switch. We used a LilyPad sewable on/off switch that
we love for both sewn and soldered circuits – the flat
bottom makes it easy to secure to wearable projects.

Next, solder three wires into the remaining pins on
the LiPoly backpack: BAT, G, and 5 V. The backpack
is ready to be connected to the ItsyBitsy, but don’t
solder it quite yet. The ItsyBitsy M0 only has one
ground pin, and both the LiPoly backpack and the
servo need to connect to it. The pins on the ItsyBitsy
are small, so we’ll need to solder both wires at once.
Snip the connector off the servo wires and pull the
three individual wires apart for about five or six
centimetres. Insert the ground wire from the servo
and the ground wire from the LiPoly backpack into
the ground pin on the ItsyBitsy M0 and solder them
in place. Then, finish soldering the servo by
connecting its power wire to the Vhi pin, and its data
wire to the 5! pin on the ItsyBitsy M0. Finish
soldering the LiPoly backpack by connecting the 5 V

Increase the value in small increments, and
be careful as you approach the maximum angle
of your servo (usually about 180 degrees)



Below
The ItsyBitsy lives up to its name

Figure 2
The final circuit
Free download pdf