31 Toggling an LED
Toggle LED by running the program on the board:
1. Connect the USB cable of the keyboard and the mouse to the Board.
Connect the board and the monitor with an HDMI cable.
2. Make sure the SD card is in the socket on the board.
3. Power up the board and just wait for a bit. You should see the Linux
operating system desktop similar to this: (may have a different
Click the Raspberry icon on the top-left corner of the
view, select Programming - Python 3 (IDLE) to open the console.
open an independent script file, select File - New File. In the new
window, select File - Save As. Ust test.py as the file name and save it
on the desktop of the linux system.
Open a linux
terminal, install rpi.gpio package: (make sure you have
the wifi connection first)
According to the
Pin Map of the PI board, connect BCM 23 to the
resistor, and connect any of the GROUND pin to the cathode of the LED.
The Pin Map can
be found below:
following code into your new script window and save it.
This will turn
on Pin 23 permanently. A dead loop is bad, the PI will
run this forever, which is power-consuming.
You can make the
LED flash for a certain period of time and turn it
Modify the code:
Then, run this
code at the Linux terminal:
sudo python test.py
The LED will be
turned on for 1 second and then off. You can modify the
number in the 'sleep()' function to change the delay time. It can be
even 0.1s, or 0.01s, etc.
2. Toggle LED by GUI
the following code into a new script file, test_1.py, click Run in the
short demo video can be found below:
1. Repeat my work to toggle the LED by downloading the code to the
board. (50 points)
2. Toggle the LED using a GUI button in Linux. (50 points)