You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: worksheet.md
+24-30Lines changed: 24 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,18 @@
1
-
# Getting started with Physical Computing
1
+
# Getting started with physical computing
2
2
3
3
## GPIO pins
4
4
5
5
One powerful feature of the Raspberry Pi is the row of GPIO pins along the top edge of the board. GPIO stands for General-Purpose Input/Output. These pins are a physical interface between the Raspberry Pi and the outside world. At the simplest level, you can think of them as switches that you can turn on or off (input) or that the Pi can turn on or off (output).
6
6
7
-
The GPIO pins are a way in which the Raspberry Pi can control and monitor the outside world by being connected to electronic circuits. The Pi is able to control LEDs, turning them on or off, or motors, or many other things. It is also able to detect whether a switch has been pressed, or temperature, or light. We refer to this as physical computing.
7
+
The GPIO pins allow the Raspberry Pi to control and monitor the outside world by being connected to electronic circuits. The Pi is able to control LEDs, turning them on or off, run motors, and many other things. It's also able to detect whether a switch has been pressed, the temperature, and light. We refer to this as physical computing.
8
8
9
-
There are 40 pins on the Raspberry Pi (26 pins on early models), and the pins provide various different functions.
9
+
There are 40 pins on the Raspberry Pi (26 pins on early models), and they provide various different functions.
10
10
11
-
If you have a RasPIO pin label, it can help to identify what each pin is used for. Make sure your pin label is placed with the keyring hole facing the USB ports, pointed outwards.
11
+
If you have a RasPiO pin label, it can help to identify what each pin is used for. Make sure your pin label is placed with the keyring hole facing the USB ports, pointed outwards.
12
12
13
13

14
14
15
-
If you don't have a pin label then this guide can help you to identify the pin numbers:
15
+
If you don't have a pin label, then this guide can help you to identify the pin numbers:
16
16
17
17

18
18
@@ -25,13 +25,13 @@ You'll see pins labelled as 3V3, 5V, GND and GP2, GP3, etc:
25
25
| GP2 | GPIO pin 2 | These pins are for general-purpose use and can be configured as input or output pins |
26
26
| ID_SC/ID_SD/DNC | Special purpose pins ||
27
27
28
-
**WARNING**: If you follow the instructions, then playing about with the GPIO pins is safe and fun. Randomly plugging wires and power sources into your Pi, however, may destroy it, especially if using the 5V pins. Bad things can also happen if you try to connect things to your Pi that use a lot of power; LEDs are fine, motors are not. If you are worried about this, then you might want to consider using an add-on board such as the [Explorer HAT](https://shop.pimoroni.com/products/explorer-hat) until you are confident enough to use the GPIO directly.
28
+
**WARNING**: If you follow the instructions, then playing about with the GPIO pins is safe and fun. Randomly plugging wires and power sources into your Pi, however, may destroy it, especially if using the 5V pins. Bad things can also happen if you try to connect things to your Pi that use a lot of power; LEDs are fine, motors are not. If you're worried about this, then you might want to consider using an add-on board such as the [Explorer HAT](https://shop.pimoroni.com/products/explorer-hat) until you're confident enough to use the GPIO directly.
29
29
30
30
## Lighting an LED
31
31
32
-
LEDs are delicate little things. If you put too much current through them they will pop (sometimes quite spectacularly). To limit the current going through the LED, you should always use a resitor in series with it.
32
+
LEDs are delicate little things. If you put too much current through them they will pop (sometimes quite spectacularly). To limit the current going through the LED, you should always use a resistor in series with it.
33
33
34
-
Try connecting an LED to the Pi's 3V3 and GND pins with a resistor, anything over about 50Ω should do the trick:
34
+
Try connecting an LED to the Pi's 3V3 and GND pins with a resistor. Anything over about 50Ω should do the trick:
35
35
36
36

37
37
@@ -45,11 +45,11 @@ The LED should now turn off, but now it's on a GPIO pin, and can therefore be co
45
45
46
46
## Switching an LED on and off
47
47
48
-
GPIO Zero is a new Python library which provides a simple interface to everyday GPIO components, it comes installed by default in Raspbian
48
+
GPIO Zero is a new Python library which provides a simple interface to everyday GPIO components. It comes installed by default in Raspbian.
49
49
50
-
1. Open IDLE from the main menu (`Menu`>`Programming`>`IDLE (Python 3)`.
50
+
1. Open IDLE from the main menu (`Menu`>`Programming`>`Python 3 (IDLE)`.
51
51
52
-
1. You can switch an LED on and off by typing commands directly into the Python interpretor window (also known as the Python shell). Let's do this by first, importing the GPIO Zero library. You also need to tell the Pi which GPIO pin you are using - in this case pin 17. Next to the chevrons `>>>`, type:
52
+
1. You can switch an LED on and off by typing commands directly into the Python interpreter window (also known as the Python **shell**). Let's do this by first importing the GPIO Zero library. You also need to tell the Pi which GPIO pin you are using - in this case pin 17. Next to the chevrons `>>>`, type:
53
53
54
54
```python
55
55
from gpiozero import LED
@@ -58,7 +58,7 @@ GPIO Zero is a new Python library which provides a simple interface to everyday
58
58
```
59
59
Press **Enter** on the keyboard.
60
60
61
-
1. To make the LED switch on, type the following and press enter:
61
+
1. To make the LED switch on, type the following and press **Enter**:
62
62
63
63
```python
64
64
led.on()
@@ -70,17 +70,15 @@ GPIO Zero is a new Python library which provides a simple interface to everyday
70
70
led.off()
71
71
```
72
72
73
-
1. Your LED should switch on and the off again. But that's not all you can do.
73
+
1. Your LED should switch on and then off again. But that's not all you can do.
74
74
75
75
## Flashing an LED
76
76
77
77
With the help of the `time` library and a little loop, you can make the LED flash.
78
78
79
79
1. Create a new file by clicking **File > New file**.
80
80
81
-
1. Save the new file by clicking **File > Save**.
82
-
83
-
1. Save the file as `gpio_led.py`.
81
+
1. Save the new file by clicking **File > Save**. Save the file as `gpio_led.py`.
84
82
85
83
1. Enter the following code to get started:
86
84
@@ -103,19 +101,17 @@ With the help of the `time` library and a little loop, you can make the LED flas
103
101
104
102
## Using buttons to get input
105
103
106
-
Now you are able to control an output component -an LED, let's connect and control an input component - a button.
104
+
Now you're able to control an output component (an LED), let's connect and control an input component: a button.
107
105
108
-
1. Connect a button to another GND pin andGPIO pin 2 like this:
106
+
1. Connect a button to another GND pin andGPIO pin 2, like this:
109
107
110
108

111
109
112
110
1. Create a new file by clicking **File > New file**.
113
111
114
-
1. Save the new file by clicking **File > Save**.
115
-
116
-
1. Save the fileas`gpio_button.py`.
112
+
1. Save the new file by clicking **File > Save**. Save the fileas`gpio_button.py`.
117
113
118
-
1. This time you'll need the Button class, and to tell it that the button is on pin 2. Write the following code in your new file:
114
+
1. This time you'll need the `Button` class, and to tell it that the button is on pin 2. Write the following code in your new file:
119
115
120
116
```python
121
117
from gpiozero import Button
@@ -129,17 +125,15 @@ Now you are able to control an output component - an LED, let's connect and cont
129
125
print('You pushed me')
130
126
```
131
127
1. Save with**Ctrl + S**and run the code with**F5**.
132
-
1. Press the button for your text to appear.
128
+
1. Press the button and your text will appear.
133
129
134
130
## Manually controlling the LED
135
131
136
132
You can now combine your two programs written so far to control the LED using the button.
137
133
138
134
1. Create a new file by clicking **File > New file**.
139
135
140
-
1. Save the new file by clicking **File > Save**.
141
-
142
-
1. Save the fileas`gpio_control.py`.
136
+
1. Save the new file by clicking **File > Save**. Save the fileas`gpio_control.py`.
143
137
144
138
1. Now write the following code:
145
139
@@ -185,7 +179,7 @@ With a switch, a single press and release on the button would turn the LED on, a
185
179
186
180
It would be great if you could make the LED switch on only when the button is being held down. With GPIO Zero, that's easy.
187
181
188
-
1. There are two methods of the Button class called `when_pressed`and`when_released`. These don't block the flow of the program, so if they are placed in a loop, the program will continue to cycle indefinitely.
182
+
1. There are two methods of the `Button`class called `when_pressed`and`when_released`. These don't block the flow of the program, so if they are placed in a loop, the program will continue to cycle indefinitely.
189
183
190
184
1. Modify your code to look like this:
191
185
@@ -208,8 +202,8 @@ It would be great if you could make the LED switch on only when the button is be
208
202
209
203
There are lots of other things you can control or monitor with your Raspberry Pi. Have a look at the worksheets below, to see how easily this can be done.
210
204
211
-
[Using an Active Buzzer](buzzer.md)
212
-
[Making Traffic Lights](trafficlights.md)
213
-
[Using a Light Dependent Resistor](ldr.md)
205
+
[Using an active buzzer](buzzer.md)
206
+
[Making traffic lights](trafficlights.md)
207
+
[Using a light-dependent resistor](ldr.md)
214
208
[Using a PIR Sensor](pir.md)
215
209
[Using an ultrasonic distance sensor](distance.md)
0 commit comments