Hardware Reference
In-Depth Information
2. Change into your MyAdventures folder by typing the cd command.
cd MyAdventures
3. Run your Python program using sudo (read about this in the Digging into the
Code sidebar):
sudo python testLED.py
Did your LED flash? It seems like such a small thing but in fact you have taken a huge
step by getting to this point. Now that you can control electronic circuits, you have
broken outside the boundaries of the computer!
You may see a warning here “Channel already in use . Don't worry, this is normal,
and later in this adventure you will learn how to use GPIO.cleanup() to prevent
this warning message.
The last thing for you to do is to link this program up to the Minecraft world, and this
is what you will turn to next.
Remember that flashing an LED from a Python program is the electronics
equivalent of “Hello World . When you link computers up to electronic circuits, it
is important always to try to get this working first, before advancing to things that
are more involved. If your LED does not flash, check your wiring very carefully,
and make sure that you have the wire between the LED and the GPIO pin in the
correct hole in the breadboard. You tested earlier that your LED was working by
powering it from the 3.3 volt power supply of the computer, so if it does not
work, either your Python program is wrong, or the wire between the LED and
the GPIO pin is wrong.
DIGGING INTO THE CODE
There are two bits of magic that you have just used that you might like to under-
stand a little better.
First, what is the try/finally/GPIO.cleanup() for?
To prevent warnings from appearing every time you run your program, always
call GPIO.cleanup() before the program finishes. By doing this, it puts all of
the GPIO pins back as inputs and disables the GPIO circuitry. “To put back as an
continued
 
Search WWH ::




Custom Search