├── CONTRIBUTING.md ├── LICENCE.md ├── README.md ├── camera ├── README.md ├── activated-capture-python.md ├── cam-libraries.md ├── camcorders-python.md ├── capture-bash.md ├── capture-python.md ├── circular-buffers.md ├── countdown-capture-python.md ├── images-2-video-bash.md ├── images │ ├── Camera_Module.png │ └── camera-noir.png ├── quick-camera-setup.md ├── schedule-capture-bash.md ├── stop-motion-animation.md ├── test-camera.md └── time-lapse.md ├── command-line ├── README.md ├── command-line-guide.md ├── files-directories.md ├── navigating-the-file-system.md ├── read-edit-cl.md └── sudo.md ├── file-sharing ├── README.md ├── network.md ├── scp.md └── server.md ├── minecraft-pi ├── README.md ├── images │ ├── mcpi-flying.png │ ├── mcpi-game.png │ ├── mcpi-inventory.png │ ├── mcpi-start.png │ └── minecraft-pi-banner.png ├── playing.md └── programming.md ├── physical-computing ├── README.md ├── breadboard.md ├── connect-led.md ├── connect-leds.md ├── connect-pir.md ├── connecting-button.md ├── gpio-plus-and-pi2.md ├── images │ ├── Scratch-interface.png │ ├── a-and-b-gpio-numbers.png │ ├── a-and-b-physical-pin-numbers.png │ ├── breadboard.png │ ├── finished-circuit.png │ ├── gpio-complete-circuit.png │ ├── gpio-connect-button.png │ ├── gpio-connect-ground-mini.png │ ├── gpio-connect-ground.png │ ├── gpio-connect-red-led.png │ ├── gpio-connect-resistor.png │ ├── gpio-led-pi2.png │ ├── gpio-led.png │ ├── gpio-numbers-pi2.png │ ├── gpio-pins-pi2.jpg │ ├── gpio-pins.jpg │ ├── led-wired.png │ ├── led.png │ ├── physical-pin-numbers.png │ ├── pin11off.png │ ├── pin11on.png │ ├── pir_module.png │ ├── pir_potentiometers.png │ ├── pir_wiring.png │ ├── pull_down.png │ ├── pull_up.png │ ├── resistor-330r.png │ ├── scratch-icon.png │ ├── sensing-blocks.png │ ├── simple-circuit.png │ └── terminal-icon.png ├── led.md ├── pin-numbering.md ├── pir.md ├── pull_up_down.md ├── resistor.md ├── test-led-python.md ├── test-led-scratch.md ├── test-pir-python.md ├── test-pir-scratch.md └── wiring-diagrams.md ├── pi ├── README.md ├── booting-logging-in.md ├── checking-sd-space.md ├── images │ ├── Ethernet_Cable.png │ ├── HDMI_Lead.png │ ├── Headphones.png │ ├── Monitor.png │ ├── NOOBS_Card.png │ ├── NOOBS_Card_small.png │ ├── Raspberry_Pi_B+.png │ ├── TV.png │ ├── USB_Keyboard.png │ ├── USB_Mouse.png │ ├── USB_Power_Supply.png │ └── Video_Composite_Lead.png ├── install-apps.md ├── quick-pi-setup.md ├── update-sd-card.md ├── wifi.md └── writing-sd-card-image.md ├── sense-hat ├── CONTRIBUTING.md ├── LICENCE.md ├── README.md ├── assemble.md ├── board.md ├── files │ └── AstroPi-Cheatsheet.pdf ├── hardware.md ├── hardware.yml ├── images │ ├── Astro_Pi_Diagram.jpg │ ├── Astro_Pi_Logo_WEB.png │ ├── astro_pi_features.jpg │ └── cover.png ├── inputs-outputs │ ├── images │ │ ├── additive_color_mixing.png │ │ ├── closeup_of_pixels.jpg │ │ ├── coordinates.png │ │ ├── cursor_keys.jpg │ │ └── pointer_close.jpg │ ├── joystick.md │ └── led-matrix.md ├── meta.yml ├── overview.md ├── program.md ├── sensors │ ├── humidity.md │ ├── images │ │ ├── Astro_Pi_Diagrams-01.png │ │ ├── Astro_Pi_Diagrams-02.png │ │ ├── Astro_Pi_Diagrams-03.png │ │ ├── Astro_Pi_Diagrams-04.png │ │ ├── apollo_imu.jpg │ │ ├── apollo_soyuz.jpg │ │ ├── bottle.jpg │ │ ├── condensation.jpg │ │ ├── orientation.png │ │ └── thermometer.jpg │ ├── movement.md │ ├── pressure.md │ └── temperature.md └── software.md ├── vnc ├── README.md ├── images │ ├── vnc_firefox.png │ └── vnc_ie.png ├── vnc-browser-guide.md ├── vnc-classroom-guide.md └── zeroconf.md └── wifi ├── README.md ├── wifi-cli.md └── wifi.md /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | All contributions are assumed to be licensed under the same license as the source, i.e. CC BY-SA. This license must remain in all derivatives of this work. 4 | 5 | ## Issues 6 | 7 | If you find a mistake, bug or other problem, please [open an issue](https://github.com/raspberrypilearning/guides/issues) in this repository. 8 | 9 | ## Pull Requests 10 | 11 | If you fix a mistake, bug or problem or have something to contribute, please create a pull request for each modification. Please consider grouping modifications sensibly, i.e. don't bundle typo fixes in the same pull request as code changes, instead file them separately. 12 | 13 | Please note that sometimes things are done for pedagogical reasons so changes which make sense from a software engineering perspective (reducing duplication or making use of more advanced programming language features) may not be suitable to maintain the intended educational value. 14 | 15 | ## Derivatives 16 | 17 | The licence must remain in all derivatives of this work. 18 | 19 | ## Licence 20 | 21 | Unless otherwise specified, everything in this repository is covered by the following licence: 22 | 23 | ![Creative Commons License](http://i.creativecommons.org/l/by-sa/4.0/88x31.png) 24 | 25 | ***Sonic Pi Lessons*** by the [Raspberry Pi Foundation](http://raspberrypi.org) is licenced under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by-sa/4.0/). 26 | 27 | Based on a work at https://github.com/raspberrypilearning/guides 28 | -------------------------------------------------------------------------------- /LICENCE.md: -------------------------------------------------------------------------------- 1 | # Licence 2 | 3 | Unless otherwise specified, everything in this repository is covered by the following licence: 4 | 5 | ![Creative Commons License](http://i.creativecommons.org/l/by-sa/4.0/88x31.png) 6 | 7 | ***Guides*** by the [Raspberry Pi Foundation](http://raspberrypi.org) is licenced under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by-sa/4.0/). 8 | 9 | Based on a work at https://github.com/raspberrypilearning/guides 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Raspberry Pi Learning Guides 2 | 3 | - [Getting Started with Raspberry Pi Guide](pi/README.md) 4 | - [Camera Module Guide](camera/README.md) 5 | - [A Guide to Physical Computing](physical-computing/README.md) 6 | - [VNC Guide](vnc/README.md) 7 | - [Wifi Guide](wifi/README.md) 8 | - [Minecraft Pi Guide](minecraft-pi/README.md) 9 | - [Sense Hat Guide](astro-pi/README.md) 10 | - [Sharing Files](file-sharing/README.md) 11 | -------------------------------------------------------------------------------- /camera/README.md: -------------------------------------------------------------------------------- 1 | # The Raspberry Pi Camera Module 2 | 3 | The Raspberry Pi camera can take full HD 1080p photo and videos. It can also be programmed using code. There are two versions of the camera, standard and Pi Noir. Both are connected to a Raspberry Pi in the same way. 4 | 5 | ## Camera Module 6 | ![](images/Camera_Module.png) 7 | 8 | Pictured above is the standard Raspberry Pi camera module. 9 | 10 | ## Pi Noir Camera Module 11 | ![](images/camera-noir.png) 12 | 13 | Pictured above is the special version of the Raspberry Pi camera board called Pi NoIR. It is identical to the normal green camera but it has no infrared filter, meaning that it lets in infrared light. This camera, combined with an infrared light source, will give you night vision. 14 | 15 | ## Camera Guides 16 | - [Quick Camera Setup Guide](quick-camera-setup.md) 17 | - [Test Camera](test-camera.md) 18 | 19 | ## Programming the Camera Module 20 | - [Camera Libraries](cam-libraries.md) 21 | 22 | ### Python 23 | - [Capture an image](capture-python.md) 24 | - [Capture an image when activated](activated-capture-python.md) 25 | - [Capture an image after a countdown](countdown-capture-python.md) 26 | - [Capture video](camcorders-python.md) 27 | - [Record circular buffers](circular-buffers.md) 28 | 29 | ### Bash 30 | - [Capture an image](capture-bash.md) 31 | - [Schedule image capture](schedule-capture-bash.md) 32 | - [Turn still images into a video](image-2-video.md) 33 | 34 | ## Project Ideas 35 | - [Time lapse photography](time-lapse.md) 36 | - [Stop motion animation](stop-motion-animation.md) 37 | 38 | -------------------------------------------------------------------------------- /camera/activated-capture-python.md: -------------------------------------------------------------------------------- 1 | ## Capture when activated in Python 2 | 3 | 1. Connect the Pi to the button as shown in the diagram below: 4 | 5 | ![](picamera-gpio-setup.png) 6 | 7 | 2. In the text editor, import the `RPi.GPIO` module, set up GPIO pin 17 and change the `sleep` line to use `GPIO.wait_for_edge` like so: 8 | 9 | ```python 10 | import time 11 | import picamera 12 | import RPi.GPIO as GPIO # new 13 | 14 | GPIO.setmode(GPIO.BCM) # new 15 | GPIO.setup(17, GPIO.IN, GPIO.PUD_UP) # new 16 | 17 | with picamera.PiCamera() as camera: 18 | camera.start_preview() 19 | GPIO.wait_for_edge(17, GPIO.FALLING) # new 20 | camera.capture('/home/pi/Desktop/image.jpg') 21 | camera.stop_preview() 22 | ``` 23 | 24 | 3. Delete `image.jpg` from the desktop 25 | 4. Save and run your script 26 | 5. Once the preview has started, press the button connected to your Pi to capture an image 27 | -------------------------------------------------------------------------------- /camera/cam-libraries.md: -------------------------------------------------------------------------------- 1 | # Using the camera 2 | 3 | There are libraries avaliable for using the camera in: 4 | 5 | - [Shell](http://www.raspberrypi.org/documentation/usage/camera/raspicam/README.md) (Linux command line) 6 | - [Python](http://www.raspberrypi.org/documentation/usage/camera/python/README.md) 7 | 8 | See detailed [technical specs](http://www.raspberrypi.org/documentation/hardware/camera.md) of the camera hardware and software. 9 | 10 | -------------------------------------------------------------------------------- /camera/camcorders-python.md: -------------------------------------------------------------------------------- 1 | ## Capturing video with Python 2 | 3 | 1. Modify your program to record video instead: 4 | 5 | ```python 6 | import time 7 | import picamera 8 | import RPi.GPIO as GPIO 9 | 10 | GPIO.setmode(GPIO.BCM) 11 | GPIO.setup(17, GPIO.IN, GPIO.PUD_UP) 12 | 13 | with picamera.PiCamera() as camera: 14 | camera.start_preview() 15 | GPIO.wait_for_edge(17, GPIO.FALLING) 16 | camera.start_recording('/home/pi/Desktop/video.h264') 17 | time.sleep(1) 18 | GPIO.wait_for_edge(17, GPIO.FALLING) 19 | camera.stop_recording() 20 | camera.stop_preview() 21 | ``` 22 | 23 | 2. Save and run your script 24 | 3. Press the button to start recording video; press it again to stop and exit the program 25 | -------------------------------------------------------------------------------- /camera/capture-bash.md: -------------------------------------------------------------------------------- 1 | ## Write a script 2 | 3 | Now we'll write a Bash script which will take a picture and save it with the date and time. It can be as simple as this: 4 | 5 | ```bash 6 | #!/bin/bash 7 | 8 | DATE=$(date +"%Y-%m-%d_%H%M") 9 | 10 | raspistill -o /home/pi/camera/$DATE.jpg 11 | ``` 12 | 13 | Remember to use the `-vf` and `-hf` flags if your camera is pointed upside-down. 14 | 15 | Create a new file called `camera.sh` by opening with a text editor, e.g. `nano camera.sh`, paste or otherwise enter the lines from above and save the file. 16 | 17 | Now make this file executable with the following command: 18 | 19 | ```bash 20 | chmod +x camera.sh 21 | ``` 22 | 23 | Running this script will save a picture with the timestamp as the filename in a folder called `camera` in your home directory. First we'll create this folder: 24 | 25 | ```bash 26 | mkdir camera 27 | ``` 28 | 29 | Make sure you're in the home directory when you do this. If you're not, or you're not sure, just type `cd` and hit `Enter` to return to your home directory. 30 | 31 | You can use `pwd` (present working directory) to verify your location and `ls` to show the contents. After running `mkdir` you should see a new folder there. 32 | 33 | Before continuing, test the script works as intended by running it from the command line (first return to the home directory with `cd`): 34 | 35 | ```bash 36 | ./camera.sh 37 | ``` 38 | 39 | You should see the preview again as the picture is taken. Now use `ls camera` to look inside the `camera` folder to see the picture you just captured on disk. 40 | 41 | Open the file browser and preview the image to see the picture itself. If you're happy this worked as intended, and the date and time were given in the filename, continue to automation. 42 | -------------------------------------------------------------------------------- /camera/capture-python.md: -------------------------------------------------------------------------------- 1 | ## Capture an image using Python 2 | 3 | 1. At the command prompt enter `startx` to start the graphical desktop environment 4 | 2. Double click on `LXTerminal` to start a command line, and enter `sudo idle &` to start the Python environment 5 | 3. Select `File > New Window` from the menu to start a text editor 6 | 4. Enter the following code (case is important!): 7 | 8 | ```python 9 | import time 10 | import picamera 11 | 12 | with picamera.PiCamera() as camera: 13 | camera.start_preview() 14 | time.sleep(5) 15 | camera.capture('/home/pi/Desktop/image.jpg') 16 | camera.stop_preview() 17 | ``` 18 | 19 | 5. Select `File > Save` from the menu and give your script a name, e.g. `workshop.py` 20 | 6. Select `Run > Run Module` from the menu (or just press `F5`) to run the script 21 | -------------------------------------------------------------------------------- /camera/circular-buffers.md: -------------------------------------------------------------------------------- 1 | ## Circular buffers with Python 2 | 3 | 1. Modify your program to continually record to a circular buffer, and write it to disk when the button is pressed: 4 | 5 | ```python 6 | import io 7 | import time 8 | import picamera 9 | import RPi.GPIO as GPIO 10 | 11 | GPIO.setmode(GPIO.BCM) 12 | GPIO.setup(17, GPIO.IN, GPIO.PUD_UP) 13 | 14 | with picamera.PiCamera() as camera: 15 | stream = picamera.PiCameraCircularIO(camera, seconds=20) 16 | camera.start_preview() 17 | camera.start_recording(stream, format='h264') 18 | GPIO.wait_for_edge(17, GPIO.FALLING) 19 | camera.stop_recording() 20 | camera.stop_preview() 21 | for frame in stream.frames: 22 | if frame.header: 23 | stream.seek(frame.position) 24 | break 25 | with io.open('/home/pi/Desktop/video.h264', 'wb') as output: 26 | while True: 27 | data = stream.read1() 28 | if not data: 29 | break 30 | output.write(data) 31 | ``` 32 | 33 | 2. Delete `video.h264` from the desktop 34 | 3. Save and run your script 35 | 4. Press the button to save the last 20+ seconds of video to the drive 36 | -------------------------------------------------------------------------------- /camera/countdown-capture-python.md: -------------------------------------------------------------------------------- 1 | ## Countdown capture (selfies!) in Python 2 | 3 | 1. Modify your program to include the delay after the button wait: 4 | 5 | ```python 6 | import time 7 | import picamera 8 | import RPi.GPIO as GPIO 9 | 10 | GPIO.setmode(GPIO.BCM) 11 | GPIO.setup(17, GPIO.IN, GPIO.PUD_UP) 12 | 13 | with picamera.PiCamera() as camera: 14 | camera.start_preview() 15 | GPIO.wait_for_edge(17, GPIO.FALLING) 16 | time.sleep(5) # new 17 | camera.capture('/home/pi/Desktop/image.jpg') 18 | camera.stop_preview() 19 | ``` 20 | 21 | 2. Delete `image.jpg` from the desktop 22 | 3. Save and run your script 23 | 4. Press the button and try to take a selfie 24 | -------------------------------------------------------------------------------- /camera/images-2-video-bash.md: -------------------------------------------------------------------------------- 1 | # Turn still images in to a video 2 | 3 | You can do this on the Pi using `mencoder` but the processing will be slow. You may prefer to transfer the image files to your desktop computer or laptop and processing the video there. 4 | 5 | Navigate to the folder containing all your images and list the file names in to a text file. For example: 6 | 7 | ```bash 8 | ls *.jpg > stills.txt 9 | ``` 10 | 11 | ### On Raspberry Pi or other Linux computer 12 | 13 | Install the package mencoder: 14 | 15 | ```bash 16 | sudo apt-get install mencoder 17 | ``` 18 | 19 | Now run the following command: 20 | 21 | ```bash 22 | mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=1920:1080 -o timelapse.avi -mf type=jpeg:fps=24 mf://@stills.txt 23 | ``` 24 | 25 | This will save a video called `timelapse.avi` 26 | -------------------------------------------------------------------------------- /camera/images/Camera_Module.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/camera/images/Camera_Module.png -------------------------------------------------------------------------------- /camera/images/camera-noir.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/camera/images/camera-noir.png -------------------------------------------------------------------------------- /camera/quick-camera-setup.md: -------------------------------------------------------------------------------- 1 | # Quick Camera Setup Guide 2 | 3 | ## Connecting the camera 4 | 5 | 1. Take a look at the camera module. You will notice that there is a long white cable running from fromone end of the camera. This is called a flex cable and will connect the cmaera to a Raspberry Pi. 6 | 1. Next, locate the connector on your Raspberry Pi between the Ethernet and HDMI ports, with the silver connectors facing the HDMI port. See the image below to help you. 7 | 8 | ![](images/pi-camera-connector.png) 9 | 10 | 1. The connector can be opened by pulling the tabs on the top of the connector upwards then towards the Ethernet port. 11 | 1. Once opened, insert the flex firmly into the connector. Take care not to bend the flex at too much. 12 | 1. Finally, the top part of the connector can then be pushed towards the HDMI connector and down, while the flex cable is held in place. 13 | 14 | Watch the following video to see a demonstration of the camera being connected: 15 | 16 | [![Camera connection screenshot](http://img.youtube.com/vi/GImeVqHQzsE/0.jpg)](http://www.youtube.com/watch?v=GImeVqHQzsE) 17 | 18 | *Note: The camera may come with a small piece of translucent blue plastic film covering the lens. This is only present to protect the lens while it is being mailed to you, and needs to be removed by gently peeling it off 19 | 20 | ## Enabling the camera 21 | 22 | 1. Once the camera is connected, boot your Raspberry Pi by connecting the power cable. 23 | 1. Once you have logged in type the following onto the command line, or if you are in the desktop environment open a Terminal window and type: 24 | 25 | ```bash 26 | sudo raspi-config 27 | ``` 28 | This command opens the Pi configuration menu. 29 | 30 | 1. With your keyboard arrows, select `Enable camera` and hit `Enter`, then go to `Finish` and you'll be asked to reboot. Press `Enter` and once the Pi has booted your camera will be ready to use. 31 | 32 | 33 | -------------------------------------------------------------------------------- /camera/schedule-capture-bash.md: -------------------------------------------------------------------------------- 1 | ## Schedule taking pictures with bash script 2 | 3 | Now you have a Bash script which takes pictures and timestamps them, you can schedule the script to be run at an interval, say every minute. 4 | 5 | To do this we'll use `cron`. First open the cron table for editing: 6 | 7 | ```bash 8 | sudo crontab -e 9 | ``` 10 | 11 | If you've not run `crontab` before you'll be prompted to select an editor - if you don't know the difference, choose `nano` by hitting `Enter`. 12 | 13 | Now you'll see the `cron` file, scroll to the bottom where you'll see a line with the following column headers: 14 | 15 | ```bash 16 | # m h dom mon dow command 17 | ``` 18 | 19 | The layout for a cron entry is made up of six components: 20 | 21 | Minute, Hour, Day of Month, Month of Year, Day of Week and the command to be executed. 22 | 23 | ``` 24 | # * * * * * command to execute 25 | # ┬ ┬ ┬ ┬ ┬ 26 | # │ │ │ │ │ 27 | # │ │ │ │ │ 28 | # │ │ │ │ └───── day of week (0 - 7) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0) 29 | # │ │ │ └────────── month (1 - 12) 30 | # │ │ └─────────────── day of month (1 - 31) 31 | # │ └──────────────────── hour (0 - 23) 32 | # └───────────────────────── min (0 - 59) 33 | ``` 34 | 35 | To schedule for the `camera.sh` script to be executed every minute, add the following line: 36 | 37 | ```bash 38 | * * * * * /home/pi/camera.sh 2>&1 39 | ``` 40 | 41 | Now save and exit. If you're using `nano` as your editor, that's `Ctrl + O` to save and `Ctrl + X` to exit. 42 | 43 | You should see the following message: 44 | 45 | ```bash 46 | crontab: installing new crontab 47 | ``` 48 | 49 | Now return to the camera directory to see the photos start to appear: 50 | 51 | ```bash 52 | cd ~/camera/ 53 | ``` 54 | 55 | and use `ls` to see the contents of the folder. Enter `date` to see how close you are to the minute (`00` seconds) as a new picture should be captured at this precise time. 56 | 57 | Use `watch ls` to see changes to the contents of the folder. `watch` runs the command runs every 2 seconds (by default). 58 | -------------------------------------------------------------------------------- /camera/stop-motion-animation.md: -------------------------------------------------------------------------------- 1 | ## Stop-motion animation with Picamera and Python 2 | 3 | In a similar vein, it's quite easy to construct a stop-motion animation system with the Pi's camera. The "capture when activated" program can be run in a loop (as in the timelapse program above) to continually capture images when the button is pressed. The same FFMPEG command line can then be used to construct the final video. The major challenge with stop-motion animation is keeping the camera and the target scene sufficiently static. Here is some example code: 4 | 5 | ```python 6 | import picamera 7 | import RPi.GPIO as GPIO 8 | 9 | GPIO.setmode(GPIO.BCM) 10 | GPIO.setup(17, GPIO.IN, GPIO.PUD_UP) 11 | 12 | with picamera.PiCamera() as camera: 13 | camera.start_preview() 14 | frame = 1 15 | while True: 16 | GPIO.wait_for_edge(17, GPIO.FALLING) 17 | camera.capture('/home/pi/Desktop/frame%03d.jpg' % frame) 18 | frame += 1 19 | camera.stop_preview() 20 | ``` 21 | 22 | Once the frames have all been captured, a similar FFMPEG command line to the one presented above can be used to convert the frames into a video: 23 | 24 | ``` 25 | ffmpeg -y -f image2 -i /home/pi/Desktop/frame%03d.jpg -r 24 -vcodec libx264 -profile high -preset slow /home/pi/Desktop/stop_motion.mp4 26 | ``` 27 | -------------------------------------------------------------------------------- /camera/test-camera.md: -------------------------------------------------------------------------------- 1 | ## Test the camera 2 | 3 | With the camera module connected and enabled, enter the following command in the Terminal to take a picture: 4 | 5 | ```bash 6 | raspistill -o cam.jpg 7 | ``` 8 | 9 | You should see a preview on screen as the picture is taken. 10 | 11 | Now type `ls` and you should see a file called `cam.jpg`. Open your home folder in the file browser and view the image (right click and select `Open with image preview`). If there's a picture of what your camera was pointed at - then your camera works! 12 | 13 | If your picture was upside-down this is because your camera is pointed upside-down - that's ok - sometimes it's easier to have it that way up, and you can flip the image over. 14 | 15 | If you intend to have your camera positioned upside-down, pass in the `-hf` and `-vf` flags to horizontally and vertically flip the image (otherwise skip to Step 2): 16 | 17 | ```bash 18 | raspistill -hf -vf -o cam2.jpg 19 | ``` 20 | 21 | Now check again, there should now be a `cam2.jpg` file. Open the image and check it's the right way up. 22 | -------------------------------------------------------------------------------- /camera/time-lapse.md: -------------------------------------------------------------------------------- 1 | ### Time-lapse photography with Picamera and Python 2 | 3 | A time-lapse sequence can be easily constructed by running the basic capture program in a loop, and adjusting the delay to the gap required. Timelapse sequences can be used to visualise many natural processes that are not easy to see otherwise such as plant growth and decay, long term construction projects and weather cycles. Here is some example code: 4 | 5 | ```python 6 | import time 7 | import picamera 8 | 9 | VIDEO_DAYS = 5 10 | FRAMES_PER_HOUR = 1 11 | FRAMES = FRAMES_PER_HOUR * 24 * VIDEO_DAYS 12 | 13 | def capture_frame(frame): 14 | with picamera.PiCamera() as cam: 15 | time.sleep(2) 16 | cam.capture('/home/pi/Desktop/frame%03d.jpg' % frame) 17 | 18 | # Capture the images 19 | for frame in range(FRAMES): 20 | # Note the time before the capture 21 | start = time.time() 22 | capture_frame(frame) 23 | # Wait for the next capture. Note that we take into 24 | # account the length of time it took to capture the 25 | # image when calculating the delay 26 | time.sleep( 27 | int(60 * 60 / FRAMES_PER_HOUR) - (time.time() - start) 28 | ) 29 | ``` 30 | 31 | Once the images have been captured you can use the following FFMPEG command line to construct a video from the images, after installing `ffmpeg` with `sudo apt-get install ffmpeg`: 32 | 33 | ``` 34 | ffmpeg -y -f image2 -i /home/pi/Desktop/frame%03d.jpg -r 24 -vcodec libx264 -profile high -preset slow /home/pi/Desktop/timelapse.mp4 35 | ``` 36 | 37 | Be aware that encoding will take at least half an hour of computation on the Pi to produce the video! You may wish to perform this step on a faster machine. 38 | -------------------------------------------------------------------------------- /command-line/README.md: -------------------------------------------------------------------------------- 1 | # Command Line Guide 2 | 3 | Using text is a quick and simple way to interact with a computer. The command line interface does not include any graphics like a mouse pointer or task bar. Instead you can use text commands to create, find and edit files. 4 | 5 | - [The Command Line](command-line-guide.md) 6 | - [Commands to navigate the file system](navigating-the-file-system.md) 7 | - [Files and directory commands](files-directories.md) 8 | - [Commands to read and edit files](read-edit-cl.md) 9 | - [Being the superuser or sudo](sudo.md) -------------------------------------------------------------------------------- /command-line/command-line-guide.md: -------------------------------------------------------------------------------- 1 | # What is the Command Line? 2 | 3 | Potential Subjects: 4 | - [ ] intro - whats it for, why is it useful 5 | - [ ] how are commands structured (command -options parameters) 6 | - [x] navigating the file system (cd, ls, pwd, .., ., ~, *) 7 | - [x] files & directories (cp, mv, rm, mkdir, rmdir) 8 | - [x] reading and editing files (cat, head, tail, nano) 9 | - [x] sudo 10 | - [ ] running a program (providing full paths, using &) 11 | - [ ] using the manual (man) 12 | - [ ] useful commands (passwd, shutdown, reboot, halt, cat, wget) 13 | 14 | Other subjects: 15 | - [ ] installing software - this feels like it should be a seperate guide 16 | - [ ] file properties (chmod, chown) - useful but feels a bit specific 17 | -------------------------------------------------------------------------------- /command-line/files-directories.md: -------------------------------------------------------------------------------- 1 | # Files and directory commands 2 | 3 | The following commands used on the command line or in a terminal window in Raspbian will help you work with files and directories. 4 | 5 | ## cp 6 | 7 | `cp` stands for **copy**. 8 | 9 | To copy a file type `cp` followed by the name of the file you wish to copy followed by a new name for the copied file and press enter on your keyboard. For eaxmple: `cp first-program.py copy-first-program.py`. 10 | 11 | To copy a file into a different directory type `cp` followed by the name of the file you wish to copy followed by the name of the folder you want to copy it to. Then press enter. For example:`cp first-program.py documents`. 12 | 13 | ## mv 14 | 15 | `mv` stands for **move**. 16 | 17 | To move a file type `mv` followed by the name of the file you wish to move followed by the name of the directory you want to move the file to. Then press enter. For example: `mv first-program.py documents`. 18 | 19 | ## rm 20 | 21 | `rv` stands for **remove**. 22 | 23 | To remove a file type `rv` followed by the name of the file you wish to remove. Then press enter. For example: `mv copy-first-program.py`. 24 | 25 | ## mkdir 26 | 27 | `mkdir` stands for **make directory**. 28 | 29 | To make a new directory type `mkdir` followed by a name for the new directory and then press enter. For example: `mkdir my-programs`. 30 | 31 | ## rmdir 32 | 33 | `rmdir` stands for **remove directory**. 34 | 35 | To remove a directory type `rmdir` followed by the name of the directory you wish to delete and press enter. For example: `rmdir my-programs`. 36 | -------------------------------------------------------------------------------- /command-line/navigating-the-file-system.md: -------------------------------------------------------------------------------- 1 | # Commands to navigate the file system from the command line 2 | 3 | When you log into a Pi and open a terminal window, or you boot to the command line instead of the graphical user interface, you start in your home folder; this is located at `/home/pi`, assuming your username is `pi`. 4 | 5 | This is where the user's own files are kept. In this case you are the user called `pi`. The contents of the user's desktop is in a directory here called Desktop, along with other files and folders. 6 | 7 | Here are some helpful commands to use on the command line or terminal window in Raspbian that allow you to naviagte around the file system on your Raspberry Pi. 8 | 9 | ## ls 10 | 11 | Type `ls` and press enter on your keyboard. A list of all the files and directories (sometimes called folders) will be listed for you to see. `ls` is an abbreviation for **list**. 12 | 13 | ## cd 14 | 15 | If you want to move into a directory, perhaps to see what files are in it type `cd` followed by the name of the directory and press enter on your keyboard. E.g. `cd Documents`. 16 | 17 | To move up a directory to a higher level in the file system type `cd ..` 18 | 19 | ## pwd 20 | 21 | You can find out where you are within the file system on Raspbian and typing `pwd` and pressing enter. It will return a location similar to this `/home/pi` depedning on where you are. 22 | -------------------------------------------------------------------------------- /command-line/read-edit-cl.md: -------------------------------------------------------------------------------- 1 | # Commands for reading and editing files 2 | 3 | The following commands used on the command line or in a terminal window in Raspbian will help you access more information about files and help you to edit them. 4 | 5 | ## cat 6 | 7 | The `cat` command will list the contents of a file. 8 | 9 | Type `cat` followed by the name of the file and press enter on your keyboard. For example `cat first-program.py` will display the contents of `first-program.py`. The command can be used to list the contents of multiple files too. For example: `cat *.txt` will list the contents of all `.txt` files in the current directory. 10 | 11 | ## head 12 | 13 | The `head` command displays the beginning of a file. 14 | 15 | Type `head` followed by the name of the file and press enter. For example: `head first-program.py`. 16 | 17 | The command can be used with `-n` to specify the number of lines to show (by default 10), or with `-c` to specify the number of bytes. 18 | 19 | ## tail 20 | 21 | The `tail` command displays the end of a file. 22 | 23 | Type `tail` followed by the name of the file and press enter. For example: `tail first-program.py`. 24 | 25 | The starting point in the file can be specified either through using `-b` for 512 byte blocks, `-c` for bytes, or `-n` for number of lines. 26 | 27 | ## man 28 | 29 | The `man` command shows the manual page for a file. To find out more, type `man man` and press enter. The manual page will give your more information for the `man` command. 30 | 31 | ## nano 32 | 33 | `nano` is a command line text editor. You can use it to either create a new file or to edit a file. 34 | 35 | Type `nano` followed by a name for your new file and press enter. A text editor window will open in which you can type your text. You might use this to write or ammend code. 36 | 37 | To quit nano press `Ctrl` and `q` on your keyboard. Followed by `y` to confirm. -------------------------------------------------------------------------------- /command-line/sudo.md: -------------------------------------------------------------------------------- 1 | # Being the superuser 2 | 3 | The Linux operating system of which Raspbian is an example of, is a multi-user operating system which allows multiple users to login and use the computer. To protect the computer (and privacy of other users), users are restricted in what they can do. 4 | 5 | Most users are allowed to run most programs, and to save and edit files stored in their own home folder. Normal users are not normally allowed to edit files in other users folders or any of the system files. 6 | 7 | There is a special user in Linux known as the **superuser**, which is usually given the username `root`. The superuser has unrestricted access to the computer and can do almost anything. 8 | 9 | ## sudo 10 | 11 | You will not normally log into to the computer as `root`, but can instead use the `sudo` command to provide access as the superuser. It stands for **superuser do**. If you log into your Raspberry Pi as the pi user then you are logging in as a normal user. You can run commands as the root user by using the sudo command before the program you want to run. 12 | 13 | For example if you want to install extra software on Raspbian then you normally use the `apt-get` tool. To be able to update the list of available software then you need to prefix the apt-get command with sudo. For example: `sudo apt-get update`. 14 | 15 | When running commands as a superuser there is nothing to protect against mistakes that could damage the system. It is like disabling the safety guards on a machine. It makes it easier to access the insides, but the risk of damage is far greater. It is recommended that you only run commands as the superuser when required. 16 | 17 | ## Who can use sudo? 18 | 19 | It would defeat the point if anyone could just put sudo in front of their commands, so only approved users can use sudo to gain administrator privileges. The pi user is included in the sudoers file. To allow other users to act as a superuser then you could add the user to the sudo group or add them using `visudo`. -------------------------------------------------------------------------------- /file-sharing/README.md: -------------------------------------------------------------------------------- 1 | # Sharing files from your Raspberry Pi 2 | 3 | Sometime you might want to share files from your Raspberry Pi with other users, whether they are also using Pis or other computers. There are several ways of achieving this. 4 | 5 | ## Sharing over a Windows network 6 | - [Share over a Windows network](network.md) 7 | 8 | ## Sharing via Python's simple server 9 | - [Share via Python sever](server.md) 10 | 11 | ## Sharing via scp 12 | - [Share via scp](scp.md) 13 | -------------------------------------------------------------------------------- /file-sharing/network.md: -------------------------------------------------------------------------------- 1 | # Sharing files over a Windows network 2 | 3 | If you have access to a Windows network and a file server, you can share files by placing them into a shared folder on the network. 4 | 5 | 1. You'll need some software from the Raspbian repositories to begin with. Open up LXTerminal and type the following: 6 | 7 | ```bash 8 | sudo apt-get smbclient smbfs 9 | ``` 10 | 11 | 2. Now you need to create a directory where you can mount the shared folder. 12 | 13 | ```bash 14 | sudo mkdir /media/share 15 | ``` 16 | 17 | 3. To mount the shared folder you can type the following command, but you'll need to know the name of the file server you are using. 18 | 19 | ```bash 20 | mount –t cifs –o username=Your_Username,password=Your_Password //Name_File_Server/Path/To/Folder /media/share 21 | ``` 22 | 23 | 4. Now you can copy the files you want to share into the mounted folder, and they'll be available to everyone on the Windows network. 24 | 25 | ```bash 26 | cp name_of_file /media/share/. 27 | ``` 28 | -------------------------------------------------------------------------------- /file-sharing/scp.md: -------------------------------------------------------------------------------- 1 | # Sharing files via scp 2 | 3 | If you are happy to give your password to those that you want to share files with (or you haven't changed the default password for Raspbian), then the easiest way to share files is via scp. 4 | 5 | 1. Open up LXTerminal and type the following command to reveal your IP address. 6 | 7 | ```bash 8 | hostname -I 9 | ``` 10 | 11 | 2. The users you want to share the files with also need to open up LXTerminal. They can then type the following command to copy the file via the ssh protocol, but the IP address and filenames obviously need to be ammended for your situation. 12 | 13 | ```bash 14 | scp pi@192.168.1.123:~/path/to/file ~/. 15 | ``` 16 | 17 | 3. They'll be prompted for your password, and then the file will be copied over. 18 | -------------------------------------------------------------------------------- /file-sharing/server.md: -------------------------------------------------------------------------------- 1 | # Sharing files via a Python server 2 | 3 | Python provides an easy method of setting up a simple http server, allowing you to share files with others, accessible via a web browser or wget. 4 | 5 | 1. The first thing you'll need is the IP address of you Raspberry Pi. Open up LXTerminal and type: 6 | 7 | ```bash 8 | hostname -I 9 | ``` 10 | 11 | 2. The IP address needs to be shared with those that need access to the files. 12 | 13 | 3. Next you need to make sure you are in the directory containing the file or files to be shared. 14 | 15 | ```bash 16 | cd name/of/directory 17 | ``` 18 | 19 | 4. Now you need to start the Python server. 20 | 21 | ```bash 22 | python3 -m http.server 23 | ``` 24 | 25 | 5. All the files in your current directory are now available to anyone on your network. To access the files they can open up a webbrowser and type your Pi's IP address along with `:8000/name_of_file`. For instance: 26 | 27 | ``` 28 | 192.168.1.123:8000/name_of_file 29 | ``` 30 | 6. The webbrowser will either display the file (if html or txt) or download the file. 31 | 32 | 8. Alternatively the file can be collected using wget, if the people you are sharing with are using a Unix based system or Putty. 33 | 34 | ```bash 35 | wget 192.168.1.123:8000/name_of_file 36 | ``` 37 | -------------------------------------------------------------------------------- /minecraft-pi/README.md: -------------------------------------------------------------------------------- 1 | # Minecraft - Pi Edition 2 | 3 | ![Minecraft Pi Logo](images/minecraft-pi-banner.png) 4 | 5 | Minecraft is a popular sandbox open-world building game. A free version of Minecraft is available for the Raspberry Pi; it also comes with a programming interface. Using this interface you can control the minecraft world by writing programs in the Python programming language. You can also use Sonic Pi to build your own musical minecraft creations. 6 | 7 | Using this guide you will learn how to control the minecraft player and write a simple program in both Python and Sonic Pi. 8 | 9 | ## Play guides 10 | - [What is minecraft and how do I play?](playing.md) 11 | - [Playing a network game](network.md) 12 | 13 | 14 | ## Programming guides 15 | - [How to play and program Minecraft at the same time](programming.md) 16 | 17 | 18 | ## Where next? 19 | - [Getting started with Python & Minecraft Pi](https://www.raspberrypi.org/learning/getting-started-with-minecraft-pi/) 20 | -------------------------------------------------------------------------------- /minecraft-pi/images/mcpi-flying.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/minecraft-pi/images/mcpi-flying.png -------------------------------------------------------------------------------- /minecraft-pi/images/mcpi-game.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/minecraft-pi/images/mcpi-game.png -------------------------------------------------------------------------------- /minecraft-pi/images/mcpi-inventory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/minecraft-pi/images/mcpi-inventory.png -------------------------------------------------------------------------------- /minecraft-pi/images/mcpi-start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/minecraft-pi/images/mcpi-start.png -------------------------------------------------------------------------------- /minecraft-pi/images/minecraft-pi-banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/minecraft-pi/images/minecraft-pi-banner.png -------------------------------------------------------------------------------- /minecraft-pi/playing.md: -------------------------------------------------------------------------------- 1 | # Playing & controlling Minecraft Pi 2 | 3 | ![Minecraft Pi banner](images/minecraft-pi-banner.png) 4 | 5 | If you've never played minecraft before here's the place to start. The guide below explains how to get started playing minecraft, or you could watch this video. 6 | 7 | 8 | 9 | ## Launching Minecraft 10 | 11 | To run Minecraft, select the icon under the **games** menu or enter `minecraft-pi` in the terminal. 12 | 13 | ![](images/mcpi-start.png) 14 | 15 | When Minecraft Pi has loaded, click on **Start Game**, followed by **Create new**. You'll notice that the containing window is offset slightly. This means to drag the window around you have to grab the title bar behind the Minecraft window. 16 | 17 | ![](images/mcpi-game.png) 18 | 19 | ## Moving around 20 | 21 | You are now in a game of Minecraft! Go walk around, hack things, and build things! 22 | 23 | You and use the mouse to control which direction the player is looking in and the keyboard to control movement. 24 | 25 | | Key | Action | 26 | | :---: | :-----: | 27 | | W | Walk Forward | 28 | | A | Step Left | 29 | | S | Walk Backward | 30 | | D | Step Right | 31 | | Space | Jump | 32 | | Control | Crouch | 33 | 34 | You can also switch to what's called "creative mode" which allows you to fly! 35 | 36 | | Key | Action | 37 | | :---: | :-----: | 38 | | Double Space | Enter / Exit "Creative Mode" | 39 | | Space | Fly Up | 40 | | Control | Fly Down | 41 | | W,A,S,D | Fly Forward,Left,Back,Right | 42 | 43 | 44 | ## Placing / Smashing Blocks 45 | 46 | The entire Minecraft World is made up of blocks, which can be placed or destroyed in order to create things. 47 | 48 | 49 | 50 | 51 | 52 | | E | Inventory | 53 | 54 | 55 | | Esc | Pause / Game menu | 56 | | Tab | Release mouse cursor | 57 | 58 | You can select an item from the quick draw panel with the mouse's scroll wheel (or use the numbers on your keyboard), or press `E` and select something from the inventory. 59 | 60 | ![](images/mcpi-inventory.png) 61 | 62 | You can also double tap the space bar to fly into the air. You'll stop flying when you release the space bar, and if you double tap it again you'll fall back to the ground. 63 | 64 | ![](images/mcpi-flying.png) 65 | 66 | With the sword in your hand, you can click on blocks in front of you to break them (or to dig). With a block in your hand, you can use right click to place that block in front of you, or left click to remove a block. 67 | 68 | Spend some time getting familar with moving around the world if you've not played it before, you can explore, build something cool, whatever you want. 69 | -------------------------------------------------------------------------------- /minecraft-pi/programming.md: -------------------------------------------------------------------------------- 1 | # Minecraft - Pi Edition 2 | 3 | ![Minecraft Pi Logo](images/minecraft-pi-banner.png) 4 | 5 | Your minecraft world can be controlled and programmed using a number of tools including Sonic Pi and Python. In order to use these tools at the same time as minecraft you need to set up you screen and be able to switch between them easily. Watch the following video which shows you how to work with minecraft and a programming interface. 6 | 7 | 8 | 9 | The key points mentioned in the video are: 10 | - Arrange your minecraft and programming windows side by side to allow easy switching between them. (don't use minecraft in fullscreen mode. 11 | - Open a minecraft world before trying to run your program. 12 | - Use either the `esc` key or the `tab` key to release the cursor from game. 13 | - Click back on the game window to regain control of the player. 14 | 15 | ##What Next? 16 | - Follow the [Getting started with Minecraft & Python](https://www.raspberrypi.org/learning/getting-started-with-minecraft-pi/) resource which will show you how to control your Minecraft world. 17 | 18 | -------------------------------------------------------------------------------- /physical-computing/README.md: -------------------------------------------------------------------------------- 1 | # A Guide to Physical Computing 2 | 3 | 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 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). 4 | 5 | ![GPIO pins](images/gpio-pins-pi2.jpg) 6 | 7 | It is 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**. 8 | 9 | ## GPIO 10 | - [Raspberry Pi GPIO Introduction](gpio-plus-and-pi2.md) 11 | - [GPIO Pin Numbering](pin-numbering.md) 12 | - [Pull up and pull down resistors](pull_up_down.md) 13 | 14 | ## Components 15 | - [What is a breadboard?](breadboard.md) 16 | - [What is a resistor?](resistor.md) 17 | 18 | ### Inputs 19 | - [Connecting a push button](connecting-button.md) 20 | 21 | ### Outputs 22 | - [What is an LED?](led.md) 23 | - [Connecting LEDs without a breadboard](connect-led.md) 24 | - [Connecting an LED with a breadboard](connect-leds.md) 25 | - [Testing a connected LED in Python](test-led-python.md) 26 | - [Testing a connected LED in Scratch](test-led-scratch.md) 27 | 28 | ## Motors 29 | - [What is a geared motor?]() 30 | 31 | ## Sensors 32 | 33 | ### Motion Sensors 34 | - [What is a PIR Motion Sensor?](pir.md) 35 | - [Connecting a PIR sensor](connect-pir.md) 36 | - [Test a PIR sensor with Python](test-pir-python.md) 37 | - [Test a PIR sensor with Scratch](test-pir-scratch.md) 38 | -------------------------------------------------------------------------------- /physical-computing/breadboard.md: -------------------------------------------------------------------------------- 1 | # Breadboard 2 | 3 | ![](images/breadboard.png) 4 | 5 | You can think of a breadboard as being something like an artist's canvas, but without any of what we create on the canvas being permanent. Whilst it is possible to make a circuit without a breadboard, it keeps components organised rather than being a mess of wires without clear indication of how every wire connects to each other. Secondly, if you were to take a circuit and design it to fit on a PCB, a breadboard allows you to organise components logically before making the design permanent. 6 | 7 | From an electronics perspective, horizontal lines of holes are connected together inside the breadboard by metal connections, with the components inside the holes clipping onto each connection. 8 | 9 | Along the sides of the breadboard are power and ground rails - these connect vertically instead of horizontally, and are used to tidy up the circuits by being a union point for any power connections. It's also safer this way, as all power can be disconnected from components by pulling the power source's connection to these rails, rather than pulling the connection to each individual component requiring power. 10 | -------------------------------------------------------------------------------- /physical-computing/connect-led.md: -------------------------------------------------------------------------------- 1 | # Connecting an LED without a Breadboard 2 | 3 | 1. The LED has a short leg and a long leg. Slot a jumper wire onto the long leg. 4 | 5 | 2. Slot the resistor into the other end of the same jumper wire. 6 | 7 | 3. Add another jumper wire the other end of the resistor. 8 | 9 | 4. Make another jumper wire and slot one end onto the short leg of the LED. You should end up with something that looks like this: 10 | 11 | ![](images/led-wired.png) 12 | 13 | 5. Find pin 1 and pin 6 on your Raspberry Pi using the diagram below: 14 | 15 | ![](images/finished-circuit.png "The Raspberry Pi GPIO pins") 16 | 17 | The general purpose input ouput (GPIO) pins on the Raspberry Pi speak and listen to the outside world and can be controlled or programmed. Each pin has a specific role. To make life easier the pins are numbered for reference. Pin 1 is for power. Pin 6 is for grounding. 18 | 19 | 6. Plug the resistor jumper wire into pin 1 on your Raspberry Pi and the other jumper wire into pin 6. 20 | 21 | 7. Plug in the micro USB power supply and you should see some text appear on your screen. 22 | 23 | Now you have a circuit and the LED should be on. If it is not, make sure that you have plugged the jumper wires into the correct pins by checking the diagram above. 24 | 25 | *Why does the LED shine? When the circuit is plugged into the Raspberry Pi GPIO pins, electricity flows through the circuit. The flow is called the current. The LED lights up only when electric current flows from the long leg through the bulb to the short leg. The resistor reduces the amount of electric current passing through the circuit. This protects the LED from breaking, as a high current will make the light shine more brightly and then stop working.* 26 | -------------------------------------------------------------------------------- /physical-computing/connect-leds.md: -------------------------------------------------------------------------------- 1 | # Connecting and controlling an LED with Python 2 | 3 | In this circuit, you will be connecting an LED to the GPIO header of your Raspberry Pi and using Python to turn it on and off. 4 | 5 | 1. Beign by looking at the following GPIO diagram and comapre it to your Raspberry Pi. 6 | 7 | *GPIO stands for **General Purpose Input Output**. It is 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.* 8 | 9 | You'll be using a single ground pin (marked `GND`) and several GPIO pins (marked `GPIO`): 10 | 11 | | | | 12 | |-----------:|:-----------| 13 | | 3V3 | 5V | 14 | | **GPIO2** | 5V | 15 | | **GPIO3** | GND | 16 | | **GPIO4** | **GPIO14** | 17 | | GND | **GPIO15** | 18 | | **GPIO17** | **GPIO18** | 19 | | **GPIO27** | GND | 20 | | **GPIO22** | **GPIO23** | 21 | | 3V3 | **GPIO24** | 22 | | **GPIO10** | GND | 23 | | **GPIO9** | **GPIO25** | 24 | | **GPIO11** | **GPIO8** | 25 | | GND | **GPIO7** | 26 | | DNC | DNC | 27 | | **GPIO5** | GND | 28 | | **GPIO6** | **GPIO12** | 29 | | **GPIO13** | GND | 30 | | **GPIO19** | **GPIO16** | 31 | | **GPIO26** | **GPIO20** | 32 | | GND | **GPIO21** | 33 | 34 | Note that if you have an older Raspberry Pi model you'll only have 26 pins but they have the same layout, starting at the top row (`3V3` and `5V` and ending at `GND` and `GPIO7`). 35 | 36 | You are going to connect your Raspberry Pi to a breadboard to allow you to build a circuit. 37 | 38 | *Using a breadboard allows you to connect electronic components to each other without having to solder them together. They are often used to test a circuit design before creating a Printed Circuit Board (PCB). The holes on the breadboard are connected in a pattern. With the breadboard in the CamJam EduKit, the top row of holes are all connected together – marked with red dots. And so are the second row of holes – marked with blue dots and we call this the ground rail. The same goes for the two rows of holes at the bottom of the breadboard. In the middle, the columns of wires are connected together with a break in the middle.* 39 | 40 | 1. Take a black female to male jumper wire and connect the female end to a ground GPIO pin on the Raspberry Pi. Push the other end of the jumper wire into a hole on the ground rail on your breadboard like so: 41 | 42 | ![](images/gpio-connect-ground.png) 43 | 44 | 1. Now take a red colour LED and have a look at it. Note which leg is longer than the other. 45 | 46 | *LED stands for Light Emitting Diode, and glows when electricity is passed through it. It has one leg longer than the other. This is important as it tells us which way round the LED should be placed into a circuit in order for the current to flow through it and make it work. The longer leg (known as the ‘anode’), is always connected to the positive supply of the circuit. The shorter leg (known as the ‘cathode’) is connected to the negative side of the power supply, known as ‘ground’.* 47 | 48 | 1. Push the long leg of the LED into a hole on the 'e' row of the breadboard e.g. e3 and the shorter leg into a hole next to it on the same row e.g. e2 like this: 49 | 50 | ![](images/gpio-connect-red-led.png) 51 | 52 | 1. Locate a resistor and take a closer look at it. 53 | 54 | *Resistors are a way of limiting the amount of electricity going through a circuit; specifically, they limit the amount of ‘current’ that is allowed to flow. The measure of resistance is called the Ohm (Ω), and the larger the resistance, the more it limits the current. The value of a resistor is marked with coloured bands along the length of the resistor body. In this circuit a 330Ω should provide enough resistance so that too much current does not overpower the LED.* 55 | 56 | 1. Connect one leg of the 330Ω resistor into a hole on the ground rail and the other leg into hole on the breadbord that lines up to the shorter leg of your LED e.g. a2. It does not matter which way around the resistor goes. You will need to bend the legs of each of the resistors to fit, but please make sure that the wires of each leg do not cross each other. 57 | 58 | ![](images/gpio-connect-resistor.png) 59 | 60 | 1. Now you need to complete the circuit in order for current to flow around it from the Raspberry Pi to light up the LED. To do this you are going to use another jumper wire. 61 | 62 | *Jumper wires are used on breadboards to ‘jump’ from one connection to another. The ones you will be using in this circuit have different connectors on each end. The end with the ‘pin’ will go into the Breadboard. The end with the piece of plastic with a hole in it will go onto the Raspberry Pi’s GPIO pins.* 63 | 64 | Take a red female to male jumper wire and connect the female end to `GPIO 18` on your Raspberry Pi. This is the pin located 3 pins down from where you connected the black jumper wire to a `GND` pin. Then push the male end of the jumper wire into a hole on the breadboard that lines up with the longer leg of the LED e.g. a3 65 | 66 | ![](images/gpio-complete-circuit.png) 67 | 68 | 69 | -------------------------------------------------------------------------------- /physical-computing/connect-pir.md: -------------------------------------------------------------------------------- 1 | # Connecting a PIR Motion Sensor 2 | 3 | Before booting your Raspberry Pi, connect the PIR module to the Raspberry Pi. 4 | 5 | Using three female-to-female jumper cables, you'll need to connect each of the PIR sensor's connectors to the appropriate pins on the Raspberry Pi. 6 | 7 | Connect the top one labelled `VCC` on the PIR sensor to the 5V pin on the Raspberry Pi, connect the middle one labelled `OUT` to GPIO pin 4, and connect the bottom one labelled `GND` to a ground pin also marked `GND`. All shown in the following diagram: 8 | 9 | ![](images/pir_wiring.png) 10 | 11 | Now boot your Pi and log in. 12 | -------------------------------------------------------------------------------- /physical-computing/connecting-button.md: -------------------------------------------------------------------------------- 1 | # Connecting a push button 2 | 3 | A push button will complete a circuit when the button is pressed. What that means is that a current will not flow across the button until it is pressed. When it is released, the circuit will be ‘broken’. 4 | 5 | Firstly, observe the following GPIO diagram. You'll be using a single ground pin (marked `GND`) and several GPIO pins (marked `GPIO`): 6 | 7 | | | | 8 | |-----------:|:-----------| 9 | | 3V3 | 5V | 10 | | **GPIO2** | 5V | 11 | | **GPIO3** | GND | 12 | | **GPIO4** | **GPIO14** | 13 | | GND | **GPIO15** | 14 | | **GPIO17** | **GPIO18** | 15 | | **GPIO27** | GND | 16 | | **GPIO22** | **GPIO23** | 17 | | 3V3 | **GPIO24** | 18 | | **GPIO10** | GND | 19 | | **GPIO9** | **GPIO25** | 20 | | **GPIO11** | **GPIO8** | 21 | | GND | **GPIO7** | 22 | | DNC | DNC | 23 | | **GPIO5** | GND | 24 | | **GPIO6** | **GPIO12** | 25 | | **GPIO13** | GND | 26 | | **GPIO19** | **GPIO16** | 27 | | **GPIO26** | **GPIO20** | 28 | | GND | **GPIO21** | 29 | 30 | Note that if you have an older Raspberry Pi model you'll only have 26 pins but they have the same layout, starting at the top row (`3V3` and `5V` and ending at `GND` and `GPIO7`). 31 | 32 | 1. Find a ground pin (marked `GND`) on the diagram of the Raspberry Pi's pin layout above. 33 | 34 | 1. Attach a wire to a ground pin on the Raspberry Pi and connect it to the ground rail on your breadboard like so: 35 | 36 | ![](images/gpio-connect-ground.png) 37 | 38 | 1. Place the button on the breadboard and connect one of its feet to the ground rail. 39 | 40 | 1. Connect the button's other foot (on the same side) to GPIO pin 2 like so: 41 | 42 | ![](images/gpio-connect-button.png) 43 | 44 | If you're using a mini breadboard without a designated ground rail, you'll have to use one of the rows as the ground rail. Connect a row to a ground pin and the other points in that row will be connected to ground like so: 45 | 46 | ![](images/gpio-connect-ground-mini.png) 47 | -------------------------------------------------------------------------------- /physical-computing/gpio-plus-and-pi2.md: -------------------------------------------------------------------------------- 1 | # An introduction to GPIO and physical computing on the Raspberry Pi 2 | 3 | One powerful feature of the Raspberry Pi is the row of GPIO (general purpose input/output) pins along the top edge of the board. Models A+, B+ and Pi 2 have 40 pins that look like this: 4 | 5 | ![GPIO pins](images/gpio-pins-pi2.jpg) 6 | 7 | These pins are a physical interface between the 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). Of the 40 pins, 26 are GPIO pins and the others are power or ground pins (plus two ID EEPROM pins which you should not play with unless you know your stuff!) 8 | 9 | ![GPIO layout](images/gpio-numbers-pi2.png) 10 | 11 | Models A and B have only 26 pins and look like this: 12 | 13 | ![](images/gpio-pins.jpg) 14 | 15 | Note that the numbering of the GPIO pins is rather weird. *Appendix 1: A note on pin numbering* below explains why. 16 | 17 | ## What are they for? What can I do with them? 18 | 19 | You can program the pins to interact in amazing ways with the real world. Inputs don't have to come from a physical switch; it could be input from a sensor or a signal from another computer or device, for example. The output can also do anything, from turning on an LED to sending a signal or data to another device. If the Raspberry Pi is on a network, you can control devices that are attached to it from anywhere\*\* and those devices can send data back. Connectivity and control of physical devices over the internet is a powerful and exciting thing, and the Raspberry Pi is ideal for this. There are lots of brilliant examples of physical computing on [our blog](http://www.raspberrypi.org/blog/). 20 | 21 | **Note**: Not **literally** anywhere, of course. You need things like access to the network, a network capable computing device, and electricity. Please do not write to us to point this out. :) 22 | 23 | ## How the GPIO pins work 24 | 25 | ### Output 26 | 27 | **WARNING**: If you follow the instructions, then messing about with the GPIO is safe and fun. Randomly plugging wires and power sources into your Pi, however, may kill it. 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 a breakout board such as the [Pibrella](http://pibrella.com/) until you are confident enough to use the GPIO directly. 28 | 29 | Ignoring the Pi for a moment, one of the simplest electrical circuits that you can build is a battery connected to a light source and a switch (the resistor is there to protect the LED): 30 | 31 | ![Simple circuit](images/simple-circuit.png) 32 | 33 | When we use a GPIO pin as an output, the Raspberry Pi replaces **both the switch and the battery** in the above diagram. Each pin can turn on or off,or go HIGH or LOW in computing terms. When the pin is HIGH it outputs 3.3 volts (3v3); when the pin is LOW it is off. 34 | 35 | Here's the same circuit using the Raspberry Pi. The LED is connected to a GPIO pin (which can output +3v3) and a ground pin (which is 0v and acts like the negative terminal of the battery): 36 | 37 | ![GPIO wth LED](images/gpio-led-pi2.png) 38 | 39 | The next step is to write a program to tell the pin to go HIGH or LOW. Here's an example using [Python](http://www.raspberrypi.org/learning/quick-reaction-game/) (see Step 2), and here's how to do it in [Scratch](http://www.raspberrypi.org/learning/robot-antenna/). 40 | 41 | ### Input 42 | 43 | GPIO **outputs** are easy; they are on or off, HIGH or LOW, 3v3 or 0v. **Inputs** are a bit trickier because of the way that digital devices work. Although it might seem reasonable just to connect a button across an input pin and a ground pin, the Pi can get confused as to whether the button is on or off. It might work properly, it might not. It's a bit like floating about in deep space; without a reference it would be hard to tell if you were going up or down, or even what up or down meant! 44 | 45 | This is why you will see phrases like "pull up" and "pull down" in Raspberry Pi GPIO tutorials. It's a way of giving the input pin a reference so it knows for certain when an input is received. 46 | 47 | If you'd like to have a go at using the GPIO as an input then have a look at our [screaming jelly baby](http://www.raspberrypi.org/learning/screaming-jellybaby/) and [quick reaction game](http://www.raspberrypi.org/learning/quick-reaction-game/) tutorials for Python, or a [reaction game](http://www.raspberrypi.org/learning/reaction-game/) for Scratch. 48 | 49 | ## The end of the guide. The start of something amazing 50 | 51 | We hope that this has encouraged you to have a go at physical computing using the Pi's GPIO; it's really not as daunting as it looks. It all starts with a simple LED, but it can take you to incredible places. Do not underestimate the fun, creativity and sense of achievement you can get from a little computer and a bunch of pins. Have fun! And if you do make something cool please let us know. :) 52 | 53 | --- 54 | 55 | ## Glossary 56 | 57 | ### GPIO 58 | 59 | General purpose input/output; in this specific case the pins on the Raspberry Pi and what you can do with them. So called because you can use them for all sorts of purposes; most can be used as either inputs or outputs, depending on your program. 60 | 61 | ### LED 62 | 63 | Light-emitting diode- a small, low-power light source used widely in electronics. Ideal as an introduction to physical computing on the Pi. 64 | 65 | ### Physical computing 66 | 67 | Computing that involves tangible things connected to a computer, beyond standard input and output devices like keyboards and monitors. Think buttons, lights, robots, alarms, sensors, home automation, teddy bears called Babbage in near space and so on. We love physical computing because as well as being lots of fun, it's such a powerful teaching and learning tool and encourages creativity, problem solving, and collaboration. Computing **beyond the screen** engages children of all ages, and you can make very cool stuff! 68 | 69 | -------------------------------------------------------------------------------- /physical-computing/images/Scratch-interface.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/Scratch-interface.png -------------------------------------------------------------------------------- /physical-computing/images/a-and-b-gpio-numbers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/a-and-b-gpio-numbers.png -------------------------------------------------------------------------------- /physical-computing/images/a-and-b-physical-pin-numbers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/a-and-b-physical-pin-numbers.png -------------------------------------------------------------------------------- /physical-computing/images/breadboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/breadboard.png -------------------------------------------------------------------------------- /physical-computing/images/finished-circuit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/finished-circuit.png -------------------------------------------------------------------------------- /physical-computing/images/gpio-complete-circuit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/gpio-complete-circuit.png -------------------------------------------------------------------------------- /physical-computing/images/gpio-connect-button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/gpio-connect-button.png -------------------------------------------------------------------------------- /physical-computing/images/gpio-connect-ground-mini.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/gpio-connect-ground-mini.png -------------------------------------------------------------------------------- /physical-computing/images/gpio-connect-ground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/gpio-connect-ground.png -------------------------------------------------------------------------------- /physical-computing/images/gpio-connect-red-led.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/gpio-connect-red-led.png -------------------------------------------------------------------------------- /physical-computing/images/gpio-connect-resistor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/gpio-connect-resistor.png -------------------------------------------------------------------------------- /physical-computing/images/gpio-led-pi2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/gpio-led-pi2.png -------------------------------------------------------------------------------- /physical-computing/images/gpio-led.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/gpio-led.png -------------------------------------------------------------------------------- /physical-computing/images/gpio-numbers-pi2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/gpio-numbers-pi2.png -------------------------------------------------------------------------------- /physical-computing/images/gpio-pins-pi2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/gpio-pins-pi2.jpg -------------------------------------------------------------------------------- /physical-computing/images/gpio-pins.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/gpio-pins.jpg -------------------------------------------------------------------------------- /physical-computing/images/led-wired.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/led-wired.png -------------------------------------------------------------------------------- /physical-computing/images/led.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/led.png -------------------------------------------------------------------------------- /physical-computing/images/physical-pin-numbers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/physical-pin-numbers.png -------------------------------------------------------------------------------- /physical-computing/images/pin11off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/pin11off.png -------------------------------------------------------------------------------- /physical-computing/images/pin11on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/pin11on.png -------------------------------------------------------------------------------- /physical-computing/images/pir_module.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/pir_module.png -------------------------------------------------------------------------------- /physical-computing/images/pir_potentiometers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/pir_potentiometers.png -------------------------------------------------------------------------------- /physical-computing/images/pir_wiring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/pir_wiring.png -------------------------------------------------------------------------------- /physical-computing/images/pull_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/pull_down.png -------------------------------------------------------------------------------- /physical-computing/images/pull_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/pull_up.png -------------------------------------------------------------------------------- /physical-computing/images/resistor-330r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/resistor-330r.png -------------------------------------------------------------------------------- /physical-computing/images/scratch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/scratch-icon.png -------------------------------------------------------------------------------- /physical-computing/images/sensing-blocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/sensing-blocks.png -------------------------------------------------------------------------------- /physical-computing/images/simple-circuit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/simple-circuit.png -------------------------------------------------------------------------------- /physical-computing/images/terminal-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/physical-computing/images/terminal-icon.png -------------------------------------------------------------------------------- /physical-computing/led.md: -------------------------------------------------------------------------------- 1 | # What is an LED? 2 | 3 | ![](images/led.png) 4 | 5 | LED stands for Light Emitting Diode, and glows when electricity is passed through it. When you pick up the LED, you will notice that one leg is longer than the other.The longer leg (known as the `anode`), is always connected to the positive supply of the circuit. The shorter leg (known as the `cathode`) is connected to the negative side of the power supply, known as `ground`.LEDs will only work if power is supplied the correct way round (i.e. if the `polarity` is correct). You will not break the LEDs if you connect them the wrong way round, they simply will not glow.If you find that they do not light in your circuit, it may be because they have been connected the wrong way round. 6 | 7 | ## Why does the LED shine? 8 | 9 | When a circuit is plugged into the Raspberry Pi GPIO pins, electricity flows through the circuit. The flow is called the current. The LED lights up only when electric current flows from the long leg through the bulb to the short leg. The resistor reduces the amount of electric current passing through the circuit. This protects the LED from breaking, as a high current will make the light shine more brightly and then stop working. 10 | -------------------------------------------------------------------------------- /physical-computing/pin-numbering.md: -------------------------------------------------------------------------------- 1 | # GPIO Pin Numbering 2 | 3 | When programming the GPIO pins there are two different ways to refer to them: GPIO numbering and physical numbering. 4 | 5 | #### GPIO numbering 6 | 7 | These are the GPIO pins as the computer sees them. The numbers don't make any sense to humans, they jump about all over the place, so there is no easy way to remember them. However, you can use a printed reference or a reference board that fits over the pins to help you out. 8 | 9 | #### Physical numbering 10 | 11 | The other way to refer to the pins is by simply counting across and down from pin 1 at the top left (nearest to the SD card). This is 'physical numbering' and it looks like this: 12 | 13 | ![GPIO layout](images/physical-pin-numbers.png) 14 | 15 | #### Which system should I use? 16 | 17 | Beginners and young children may find the physical numbering system simpler -- you simply count the pins. You'll still need a diagram like the one above to know which are GPIO pins, which are ground and which are power though. 18 | 19 | Generally we recommend using the GPIO numbering. It's good practice and most resources use this system. Take your pick though -- as long as you use the same system within a program then all will be well. Note that pin numbering can also depend on what programming language you are using: Scratch GPIO, for example, uses physical pin numbers whereas in Python you can choose which to use. 20 | 21 | For more details on the advanced capabilities of the GPIO pins see gadgetoid's [interactive pinout diagram](http://pi.gadgetoid.com/pinout). 22 | -------------------------------------------------------------------------------- /physical-computing/pir.md: -------------------------------------------------------------------------------- 1 | ## What is a PIR Motion Sesnor? 2 | 3 | PIR stands for Passive Infra Red. You might have seen these before as they are very common these days. You would most often find them in the corners of rooms for burglar alarm systems. All objects whose temperatures are above absolute zero emit infra red radiation. Infra red wavelengths are not visible to the human eye, but they can be detected by the electronics inside one of these modules. 4 | 5 | The sensor is regarded as passive because it doesn't send out any signal in order to detect movement. It adjusts itself to the infra red signature of the room it's in and then watches for any changes. Any object moving through the room will disturb the infra red signature, and will cause a change to be noticed by the PIR module. 6 | 7 | ![](images/pir_module.png) 8 | 9 | We don't need to worry about its inner workings. What we're interested in are the three pins on it; we can connect those to the Raspberry Pi GPIO pins. One pin is for +5 volts, one pin is for ground and the other is the sensor pin (the middle pin on our Pi). This sensor pin will receive power whenever motion is detected by the PIR module. We can then see that happening on the Raspberry Pi and take action accordingly. 10 | -------------------------------------------------------------------------------- /physical-computing/pull_up_down.md: -------------------------------------------------------------------------------- 1 | # Pull Up & Pull Down Resistors 2 | 3 | When a GPIO pin is in input mode the pin is said to be *floating*, meaning that it has no fixed voltage level. That's no good for what we want, as the pin will randomly float between HIGH and LOW. We need to categorically know that the wires have touched. So we need to fix the voltage level to HIGH or LOW, and then make it change *only* when the we touch the wires together. 4 | 5 | We can do this in two ways: 6 | 7 | - A pull up circuit 8 | 9 | Wire the GPIO pin to 3.3 volts through a large 10kΩ resistor so that it always reads HIGH. Then we can short the pin to ground by touching the wires together so that the pin will go LOW. 10 | 11 | ![](../../../images/pull_up.png) 12 | 13 | - A pull down circuit 14 | 15 | Wire the GPIO pin to ground through a large 10kΩ resistor so that it always reads LOW. Then we can short the pin to 3.3 volts by touching the wires together so that it goes HIGH. When the wires touch there is a lower resistance path to 3.3 volts, and therefore the pin will read HIGH. 16 | 17 | ![](../../../images/pull_down.png) 18 | 19 | *Note: The 1kΩ R2 resistor is there in both circuits to give the GPIO pin a fail-safe protection, in case we mistakenly set the pin to be in OUTPUT mode.* 20 | 21 | ## An Analogy 22 | > Image a gate to a field which has the smoothest hinges ever, the slightest knock, gently breeze or landing of an insect could move it. 23 | > We'd never know whether the gate was being opened or closed as it could constantly swing gently between these two posistions. 24 | > If we were to add a spring to the gate to pull it closed, the gate would be held in place, except for a deliberate push which could open it. 25 | > 26 | > In this situation the Gate's position represents the Voltage which can fluctuate, the spring represents the resistor which fixes the voltage either **high** or **low**. 27 | 28 | 29 | Fortunately, the Raspberry Pi has all the above circuitry built in. It can be helpful to imagine that the two resistors `R1` and `R2` from the diagrams above are *inside* the circuitry of the Raspberry Pi and they can be enabled or disabled as we desire. We can select either a pull up or a pull down *in our code* for each GPIO pin. 30 | 31 | ## Pull up circuit 32 | 33 | Here we are going to use the internal pull up resistor to make GPIO 4 always read HIGH, then we will short it to ground through the wires so that it will read LOW when we touch the wires together. 34 | 35 | *Note: The first 26 pins on a B+ are the same as those on a model A or B.* 36 | 37 | 1. Attach the female ends of the jumper wires to the Raspberry Pi GPIO pins as shown below. Take care to select the correct pins. 38 | 39 | ![](../../../images/pull_up_wire.png) 40 | 41 | 1. Go to the Linux command prompt, either Exit the desktop or open LX Terminal. 42 | 1. Enter the command `nano pullup.py` and press Enter (nano is a text editor program). 43 | 1. Enter the code below. 44 | ```python 45 | #!/usr/bin/python 46 | import RPi.GPIO as GPIO 47 | import time 48 | 49 | pin = 4 50 | 51 | GPIO.setmode(GPIO.BCM) 52 | GPIO.setup(pin, GPIO.IN, GPIO.PUD_UP) 53 | 54 | while True: 55 | pin_value = GPIO.input(pin) 56 | print "HIGH" if pin_value else "LOW" 57 | time.sleep(0.5) 58 | ``` 59 | 60 | 1. Press `Ctrl - O` then Enter to save, followed by `Ctrl - X` to quit from nano. 61 | 1. Change the permissions of the program to make it executable by typing 'chmod 755 pullup.py`, follow by enter. 62 | 1. Run the code by typing `sudo pullup.py` followed by enter. 63 | 64 | 1. The text `LOW` should begin scrolling up the screen, when you hold the wires together (close the switch) for a few seconds you'll see the text `HIGH` because you're shorting the pin to 3.3 volts. Release the wires (open the switch) and it will return to `LOW` because of the internal pull *down* resistor. 65 | 66 | ``` 67 | HIGH 68 | HIGH 69 | HIGH 70 | HIGH 71 | LOW 72 | LOW 73 | LOW 74 | LOW 75 | HIGH 76 | HIGH 77 | HIGH 78 | HIGH 79 | ``` 80 | 81 | ## Pull down circuit 82 | 83 | 1. Remove the jumper cables from the Raspberry Pi GPIO pins and reattach them as shown in the diagram below. Take care to select the correct pins. 84 | 85 | ![](../../../images/pull_down_wire.png) 86 | 87 | 1. The code required to test the pull down circuit is almost identical to that for the pull up so to save time we will just make a copy of your file and change one thing. Enter the command below (this takes a copy of `pullup.py` and saves it as `pulldown.py`): 88 | 89 | `cp pullup.py pulldown.py` 90 | 91 | 1. Enter the command below to edit the new file: 92 | 93 | `nano pulldown.py` 94 | 95 | 1. Find the `GPIO.setup` line and change the last parameter from `GPIO.PUD_UP` to `GPIO.PUD_DOWN`. This sets the internal pull down resistor on GPIO 4 so that it will always read LOW. For example: 96 | 97 | `GPIO.setup(pin, GPIO.IN, GPIO.PUD_DOWN)` 98 | 99 | 1. Press `Ctrl - O` then Enter to save, followed by `Ctrl - X` to quit from nano. 100 | 1. The file doesn't need to be marked as executable with `chmod` since this property was copied from the original file. You can go ahead and run your code now, remember to use `sudo`: 101 | 102 | `sudo ./pulldown.py` 103 | 1. The text `LOW` should begin scrolling up the screen, when you hold the wires together (close the switch) for a few seconds you'll see the text `HIGH` because you're shorting the pin to 3.3 volts. Release the wires (open the switch) and it will return to `LOW` because of the internal pull *down* resistor. 104 | 105 | ``` 106 | LOW 107 | LOW 108 | LOW 109 | LOW 110 | HIGH 111 | HIGH 112 | HIGH 113 | HIGH 114 | LOW 115 | LOW 116 | LOW 117 | LOW 118 | ``` 119 | -------------------------------------------------------------------------------- /physical-computing/resistor.md: -------------------------------------------------------------------------------- 1 | # What is a resistor? 2 | 3 | Resistors are a way of limiting the amount of electricity going through a circuit; specifically, they limit the amount of **current** that is allowed to flow. The measure of resistance is called **Ohm (Ω)**, and the larger the resistance, the more it limits the current. 4 | 5 | ![](images/resistor-330r.png) 6 | 7 | The value of a resistor is marked with coloured bands along the length of the resistor body. A commonly used resistor in LED projects has the resistance value of a 330Ω. You can identify the 330Ω resistors by the colour bands along the body. The colour coding will depend on how many bands are on the resistors supplied: If there are four colour bands, they will be Orange, Orange, Brown, and then Gold. If there are five bands, then the colours will be Orange, Orange, Black, Black, Brown. 8 | 9 | You have to use resistors to connect LEDs up to the GPIO pins of the Raspberry Pi. The Raspberry Pi can only supply a small current (about 60mA). The LEDs will want to draw more, and if allowed to they will burn out the Raspberry Pi. Therefore putting the resistors in the circuit will ensure that only this small current will flow and the Pi will not be damaged. It does not matter which way round you connect the resistors. Current flows in both ways through them. 10 | -------------------------------------------------------------------------------- /physical-computing/test-led-python.md: -------------------------------------------------------------------------------- 1 | # Test your LED with Python 2 | 3 | 1. With your circuit complete, you are now ready to write some code to switch the LEDs on. Boot your Raspberry Pi, login and type `startx`. 4 | 5 | 1. Click on the **Terminal** application icon on the taskbar or click on the **Menu** followed by **Accessories** and then select **Terminal** with your mouse pointer. The icon for **Terminal** looks like this: 6 | 7 | ![](images/terminal-icon.png) 8 | 9 | Once loaded type `sudo idle3 &` and press enter on the keyboard. This will load the Python 3 programming environment called `IDLE3` as the super user which allows you to create a program that affects the GPIO pins. Once loaded click on **file** and **new window**. 10 | 11 | 1. Save the file by clicking on **file** and **save as**. Name your file `led-on-off.py`. 12 | 13 | 1. Next type the following code: 14 | 15 | ```python 16 | import time 17 | import RPi.GPIO as GPIO 18 | GPIO.setmode(GPIO.BCM) 19 | 20 | GPIO.setwarnings(False) 21 | GPIO.setup(18,GPIO.OUT) 22 | ``` 23 | *The first two lines tells the Python interpreter (the thing that runs the Python code) that it will be using a ‘library’. You will need the `time` library in order to add timings to your program and the `RPi.GPIO` library that will tell the Pi how to work with the Raspberry Pi’s GPIO pins. A ‘library’ gives a programming language extra commands that can be used to do something different that it previously did not know how to do. This is like adding a new channel to your TV so you can watch something different. Each pin on the Pi has several different names, so you need to tell the program which naming convention is to be used in the second line of the code. The final line tells Python not to print GPIO warning messages to the screen.* 24 | 25 | 1. Underneath type: 26 | 27 | ```python 28 | print("Light on") 29 | GPIO.output(18,GPIO.HIGH) 30 | ``` 31 | *The `print` function prints some information to the terminal. This is handy as it tells you what is happening, so that even if you LED doesn't come on you know that your program is working. If that happens then there might be something wrong with the wiring of your circuit and you should go back through the steps above to check.* 32 | 33 | *The next line turns the GPIO pin 18 ‘on’. What this actually means is that this pins is made to provide power of 3.3volts. This is enough to turn the LED in your circuit on.* 34 | 35 | 1. The code so far will turn on the LED, let's add some code to turn it off after a period of time. Below type: 36 | 37 | ```python 38 | time.sleep(3) 39 | print("Light off") 40 | GPIO.output(18,GPIO.LOW) 41 | ``` 42 | *The first line adds a pause or sleep. It tells the program to sleep for 3 seconds before moving onto the next line in the sequence of code. During this time your LED will be on because you have not told it to do anything else yet. To turn the LED off, you add a line similar to the one that turned GPIO pin 18 on by making it high, instead you replace GPIO.HIGH with GPIO.LOW. This will turn the pins off so that they no longer supply any voltage.* 43 | 44 | 1. The final part to add to your program is: 45 | 46 | ```python 47 | GPIO.cleanup() 48 | ``` 49 | 50 | *The GPIO.cleanup() command at the end is necessary to reset the status of any GPIO pins when you exit the program. If you don’t use this, then the GPIO pins will remain at whatever state they were last set to.* 51 | 52 | 1. Save your code by clicking on **file** and **save**. 53 | 54 | 1. It is now the moment of truth! Click on **run** and **run module** to execute (or run) your code. 55 | 56 | -------------------------------------------------------------------------------- /physical-computing/test-led-scratch.md: -------------------------------------------------------------------------------- 1 | # Test a connected LED with Scratch 2 | 3 | 1. Locate the program **Scratch** by clicking on **Menu** followed by **Programming** and selecting **Scratch**. 4 | 5 | ![](images/scratch-icon.png) 6 | 7 | *Our version of Scratch on Raspbian is extra special. It allows you to access and control the GPIO pins.* 8 | 9 | 1. If prompted click **OK** when the remote sensor connections are enabled. 10 | 11 | ![](images/Scratch-interface.png "The Scratch Interface") 12 | 13 | 1. Click on **control** in the top left display. Drag the **when Sprite1 clicked** block onto the scripts area. 14 | 15 | 1. Click on the **control** in the blocks palette and drag a **broadcast** block to your scripts area and attach it to the play sound block. Click on the drop down menu on the broadcast block and select **new**. 16 | 17 | In the message name box type **pin11on** This instruction will tell the Raspberry Pi to light the LED. 18 | 19 | ![](images/pin11on.png) 20 | 21 | 1. Drag a **wait 1 second** block onto the scripts area and connect it to the broadcast block. 22 | 23 | 1. Drag another **broadcast** block onto your scripts area and connect it to the wait 1 second block. Click on the drop down menu on the broadcast block and select **new**. 24 | 25 | In the message name box type **pin11off** This will switch off the light on the cardboard robot's antenna. 26 | 27 | 1. Now add another **wait 1 second** block to the script. 28 | 29 | 1. Save your work so far by clicking on **File** and **Save As**. Name your file **Test LED** and click **OK**. 30 | 31 | 1. Test your program again by clicking on the sprite. You should see the LED come on for 1 second and turn off for one second. 32 | 33 | ![](images/pin11off.png "Turn pin 11 off") 34 | -------------------------------------------------------------------------------- /physical-computing/test-pir-python.md: -------------------------------------------------------------------------------- 1 | ## Test the PIR motion sensor in Python 2 | 3 | We're going to use the Python programming language to write some code that will detect movement and print out some text; we can extend the program to involve the camera board later on. When movement is detected the PIR motion sensor applies power to its OUT pin, which we have connected to GPIO pin 4 on the Pi. So in our code we just need to continually check pin 4 to see if it has power or not. 4 | 5 | If a pin has power we call it HIGH and if not we call it LOW. 6 | 7 | The program is pretty simple. We will first set up the Raspberry Pi GPIO pins to allow us to use pin 4 as an input; it can then detect when the PIR module sends power. We need to continually check the pin for any changes, so a `while True` loop is used for this. This is an infinite loop so the program will run continuously unless we stop it manually with `Ctrl + C`. 8 | 9 | We then use two Boolean (True or False) variables for the previous and current states of the pin, the previous state being what the current state was the preceding time around the loop. Inside the loop we compare the previous state to the current state to detect when they're different. We don't want to keep displaying a message if there has been no change. 10 | 11 | Firstly create a blank Python file with the following command: 12 | 13 | ```bash 14 | nano pirtest.py 15 | ``` 16 | 17 | Enter or copy and paste the code below: 18 | 19 | ```python 20 | import RPi.GPIO as GPIO 21 | import time 22 | 23 | sensor = 4 24 | 25 | GPIO.setmode(GPIO.BCM) 26 | GPIO.setup(sensor, GPIO.IN, GPIO.PUD_DOWN) 27 | 28 | previous_state = False 29 | current_state = False 30 | 31 | while True: 32 | time.sleep(0.1) 33 | previous_state = current_state 34 | current_state = GPIO.input(sensor) 35 | if current_state != previous_state: 36 | new_state = "HIGH" if current_state else "LOW" 37 | print("GPIO pin %s is %s" % (sensor, new_state)) 38 | ``` 39 | 40 | Press `Ctrl + O` to save and `Ctrl + X` to quit. 41 | 42 | Now run the Python file: 43 | 44 | ```bash 45 | sudo python3 pirtest.py 46 | ``` 47 | 48 | If you get an error saying `RuntimeError: No access to /dev/mem` it means you forgot to use `sudo`. You must run programs that access the GPIO as root and `sudo` does this for you; to help remember you can think of it as 'super-user-do'. 49 | 50 | If you start moving or waving the sensor pin will go HIGH. Keep on waving and it will stay HIGH, and only go back to LOW if you keep still again. If you see the sensor behave like this, then everything is working correctly. If not, something is wrong and you need to go back and troubleshoot. 51 | 52 | ``` 53 | GPIO pin 4 is HIGH 54 | GPIO pin 4 is LOW 55 | GPIO pin 4 is HIGH 56 | ``` 57 | 58 | Press `Ctrl + C` when you want to exit. 59 | 60 | ![](images/pir_potentiometers.png) 61 | 62 | On the PIR module you should see two orange components with sockets that fit a Phillips screwdriver (see above). These are called *potentiometers*, and they allow you to adjust the sensitivity of the sensor and the detection time. I would suggest setting the sensitivity to max and the time to min, but the choice is yours. 63 | -------------------------------------------------------------------------------- /physical-computing/test-pir-scratch.md: -------------------------------------------------------------------------------- 1 | ## Test a PIR Montion Sensor in Scratch 2 | 3 | Because we are using the GPIO pins, we need to run a special version of Scratch called 'Scratch GPIO 5'. Double-click this icon on the desktop to run it. 4 | 5 | Scratch uses the 'Sensing' blocks to check if there is any input on the GPIO pins. If there is an input, the value of the pin changes from `0` to `1`. As you connected the PIR sensor to pin 7 of the Pi, we need to monitor that. 6 | 7 | - Click on the drop-down menu on the `sensor value` block and choose `pin7`. 8 | - Tick the check-box to the left of the block to display the pin value on screen. 9 | 10 | ![Scratch sensing blocks](images/sensing-blocks.png) 11 | 12 | Test the PIR sensor by waving your hand in front of it. When it detects movement, the value on the screen should change from `0` to `1`. 13 | 14 | If the value doesn't change, check that the correct pins are connected. 15 | -------------------------------------------------------------------------------- /physical-computing/wiring-diagrams.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /pi/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Raspberry Pi Guide 2 | 3 | Got a Raspberry Pi? Great, let's get started by making sure you have all the cables and accessories before plugging them all in and logging in for the first time. 4 | 5 | ![](images/Raspberry_Pi_B+.png) 6 | 7 | ## Getting Started with Raspberry Pi 8 | 9 | 1. [Download and install Software](writing-sd-card-image.md) 10 | 1. [Plug in the hardware](quick-pi-setup.md) 11 | 1. [Boot and log in to your Pi](booting-logging-in.md) 12 | 1. [Updating your SD Card](update-sd-card.md) 13 | 1. [Checking free space on SD card](checking-sd-space.md) 14 | 1. [Connecting to Wifi](wifi.md) 15 | 1. [Installing Applications](install-apps.md) 16 | 17 | -------------------------------------------------------------------------------- /pi/booting-logging-in.md: -------------------------------------------------------------------------------- 1 | # Booting and Logging into your Raspberry Pi 2 | 3 | The Raspberry Pi does not have an on or off switch. To power on your Pi: 4 | 5 | 1. Make sure that you have plugged in all the cables and accessories you require, and have loaded software onto an SD card and inserted it. 6 | 1. Then plug in the power cable and you will see the lights on the Raspberry Pi appear. You should then see text appear on your display. 7 | 8 | *Note that if you do not see any text on your screen, it may be because you did not turn it on before powering up your Raspberry Pi.* 9 | 10 | 1. Once your Raspberry Pi has completed the boot process, a login prompt will appear. 11 | 12 | The default login for Raspbian is username `pi` with the password `raspberry`. 13 | *Note you will not see any writing appear when you type the password. This is a security feature in Linux.* 14 | 15 | 1. After you have successfully logged in, you will see the command line prompt 16 | 17 | ```bash 18 | pi@raspberrypi~$ 19 | ``` 20 | This lets you know that you are logged into your Pi. From here you can interact with your computer using only text commands. See [The Command Line](command-line-guide.md) guide to learn more. 21 | 22 | 1. To load the graphical user interface, type `startx` and press `Enter` on your keyboard. 23 | -------------------------------------------------------------------------------- /pi/checking-sd-space.md: -------------------------------------------------------------------------------- 1 | # Checking space on an SD card 2 | 3 | When running `sudo apt-get upgrade`, it will show how much data will be downloaded and how much space it will take up on the SD card. It's worth checking with `df -h` that you have enough disk space free, as unfortunately apt will not do this for you. Also be aware that downloaded package files (.deb files) are kept in `/var/cache/apt/archives`. You can remove these in order to free up space with `sudo apt-get clean`. 4 | -------------------------------------------------------------------------------- /pi/images/Ethernet_Cable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/pi/images/Ethernet_Cable.png -------------------------------------------------------------------------------- /pi/images/HDMI_Lead.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/pi/images/HDMI_Lead.png -------------------------------------------------------------------------------- /pi/images/Headphones.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/pi/images/Headphones.png -------------------------------------------------------------------------------- /pi/images/Monitor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/pi/images/Monitor.png -------------------------------------------------------------------------------- /pi/images/NOOBS_Card.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/pi/images/NOOBS_Card.png -------------------------------------------------------------------------------- /pi/images/NOOBS_Card_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/pi/images/NOOBS_Card_small.png -------------------------------------------------------------------------------- /pi/images/Raspberry_Pi_B+.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/pi/images/Raspberry_Pi_B+.png -------------------------------------------------------------------------------- /pi/images/TV.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/pi/images/TV.png -------------------------------------------------------------------------------- /pi/images/USB_Keyboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/pi/images/USB_Keyboard.png -------------------------------------------------------------------------------- /pi/images/USB_Mouse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/pi/images/USB_Mouse.png -------------------------------------------------------------------------------- /pi/images/USB_Power_Supply.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/pi/images/USB_Power_Supply.png -------------------------------------------------------------------------------- /pi/images/Video_Composite_Lead.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/pi/images/Video_Composite_Lead.png -------------------------------------------------------------------------------- /pi/install-apps.md: -------------------------------------------------------------------------------- 1 | # Downloading and Installing Applications on your Raspberry Pi 2 | 3 | You can use text commands to download and install extra applications that you may wish to use. In the 'What you will need' section of a Raspberry Pi Resource, for example, you may see listed a piece of software that you will need in order to complete the activity or project. To download extra software applications that you want to use on your Raspberry Pi and install them, you will need to be connected to the internet with ethernet or wifi. 4 | 5 | 1. From a terminal window, or on the command line simply type `sudo apt-get install ` and press **Enter** on the keyboard. 6 | 1. After searching for the package and downloading it, you will be asked if you want to continue with the installation. Press **Y** or **Enter** on the keyboard to continue. 7 | -------------------------------------------------------------------------------- /pi/quick-pi-setup.md: -------------------------------------------------------------------------------- 1 | # Plugging in your Pi 2 | 3 | Before you plug anything into your Raspberry Pi, make sure that you have all the equipment listed here: 4 | 5 | ### Required: 6 | - **SD Card** We recommend an 8GB class 4 SD card – ideally preinstalled with NOOBS. You can buy a card with NOOBS pre-installed, or you can download it for free from our downloads page. 7 | 8 | ![](images/NOOBS_Card_small.png) 9 | 10 | - **Display** Any HDMI/DVI monitor or TV should work as a display for the Pi. 11 | 12 | ![](images/Monitor.png) 13 | 14 | - **Display Cables** For best results, use one with HDMI input, but other connections are available for older devices. 15 | ![](images/HDMI_Lead.png) 16 | 17 | - **Keyboard and mouse** Any standard USB keyboard and mouse will work with your Raspberry Pi. 18 | 19 | ![](images/USB_Keyboard.png) 20 | 21 | ![](images/USB_Mouse.png) 22 | 23 | - **Power supply** Use a 5V micro USB power supply to power your Raspberry Pi. Be careful that whatever power supply you use outputs at least 5V; insufficient power will cause your Pi to behave in strange ways. 24 | 25 | ![](images/USB_Power_Supply.png) 26 | 27 | 28 | ### Not essential but helpful to have: 29 | 30 | - **Internet connection** To update or download software, we recommend that you connect your Raspberry Pi to the internet either via and ethernet cable or a wifi adapter. Use a standard Ethernet cable for internet access. 31 | 32 | ![](images/Ethernet_Cable.png) 33 | 34 | - **Headphones or speakers** Headphones, earphones or speakers with a 3.5mm jack will work with your Raspberry Pi. 35 | 36 | ![](images/Headphones.png) 37 | 38 | ![](images/Speaker.png) 39 | 40 | ## Plugging in your Raspberry Pi 41 | 42 | 1. Begin by slotting your SD card into the SD card slot on the Raspberry Pi, which will only fit one way. 43 | 1. Next, plug in your USB keyboard and Mouse into the USB slots on the Raspberry Pi. 44 | 1. Make sure that your monitor or TV is turned on, and that you have selected the right input (e.g. HDMI 1, DVI, etc) 45 | 1. Then connect your HDMI cable from your Raspberry Pi to your monitor or TV. 46 | 1. If you intend to connect your Raspberry Pi to the internet, plug in an ethernet cable into the ethernet port next to the USB ports, otherwise skip this step. 47 | 1. When you are happy that you have plugged in all the cables and SD card required, finally plug in the micro usb power supply. This action will turn on and boot your Raspberry Pi. 48 | 1. If this is the first time your Raspberry Pi and NOOBS SD card have been used, then you will have to select an operating system and configure it. Follow the [NOOBS guide](writing-sd-card-image.md) to do this. 49 | 50 | [![Setting Up Raspberry Pi screenshot](https://i.vimeocdn.com/video/482234224.webp?mw=1920&mh=108)](https://vimeo.com/91631396) 51 | 52 | ## What's next? 53 | 54 | - [Log into your Raspberry Pi](botting-logging-in.md) 55 | 56 | 57 | -------------------------------------------------------------------------------- /pi/update-sd-card.md: -------------------------------------------------------------------------------- 1 | # Updating and Upgrading your SD Card 2 | 3 | Keeping the software on your sd card up to date is often a good starting point for any project and is very simple to do. Your Raspberry Pi will need to be connected to the internet via an ethernet cable or wifi in order for these steps to work. 4 | 5 | ## Update 6 | 7 | You will need to type a command into a terminal window or on the command line once you have logged into your Pi. 8 | 9 | 1. Open a **Terminal** window by clicking on **Main Menu**, **Accessories** and **Terminal**. Alternatively you can click on the terminal icon in the taskbar. 10 | 1. Next type the following: 11 | 12 | ```bash 13 | sudo apt-get update 14 | ``` 15 | 1. Then press **Enter** on the keyboard. 16 | 17 | You will see... 18 | 19 | ## Upgrade 20 | 21 | Once the update process is complete, and any information abou new versions of applications are downloaded, you will need to install the upgrades. 22 | 23 | 1. In a terminal window or on the command line type: 24 | 25 | ```bash 26 | sudo apt-get upgrade 27 | ``` 28 | 1. Then press **Y** or **Enter** on the keyboard when asked and your upgrades will be installed. 29 | 30 | -------------------------------------------------------------------------------- /pi/wifi.md: -------------------------------------------------------------------------------- 1 | ## Connecting to Wifi 2 | 3 | Wifi connections can be made via the network icon at the right-hand end of the menu bar. If a wi-fi dongle is plugged in, left-clicking this icon will bring up a list of available wi-fi networks, as shown. (If no networks are found, it will show the message `"No APs found - scanning..."` - just wait a few seconds without closing the menu, and it should find your network.) 4 | 5 | The icons on the right show whether a network is secured or not, and its signal strength. Click the network that you want to connect to; if it is secured, a dialog box is shown prompting you to enter the network key. 6 | 7 | Enter the key and press **OK**, then wait a couple of seconds. The network icon will flash briefly to show that a connection is being made; once it is ready, the icon stops flashing and shows the signal strength. 8 | -------------------------------------------------------------------------------- /pi/writing-sd-card-image.md: -------------------------------------------------------------------------------- 1 | # How to get and install NOOBS 2 | 3 | To get started with Raspberry Pi you need an operating system. NOOBS (New Out Of the Box Software) is an easy operating system install manager for the Raspberry Pi. 4 | 5 | ## Buy a preinstalled SD Card 6 | 7 | The easiest way to get NOOBS is to buy an SD card with NOOBS already installed, available at the [Swag Store](http://swag.raspberrypi.org/products/noobs-8gb-sd-card). Alternatively, if you have an SD card (8GB recommended), then you can download NOOBS for free and install it on your card. 8 | 9 | ## Download 10 | 11 | 1. Using a computer with an SD card reader, visit the offical Raspberry Pi [Downloads page](http://www.raspberrypi.org/downloads/). 12 | 1. Click on the Download ZIP button under ‘NOOBS (offline and network install)’, and select a folder to save it to. 13 | 1. Extract the files from the zip. 14 | 15 | ## Format your SD Card 16 | 17 | It is best to format your SD card before copying the NOOBS files onto it. To do this: 18 | 19 | 1. Visit the [SD Association’s website](http://www.sdcard.org/) and download [SD Formatter 4.0](https://www.sdcard.org/downloads/formatter_4/index.html) for either Windows or Mac. 20 | 1. Follow the instructions to install the software. 21 | 1. Insert your SD card into the computer or laptop’s SD card reader and make a note of the drive letter allocated to it, e.g. `G:/` 22 | 1. In SD Formatter, select the drive letter for your SD card and format it. 23 | 24 | ## Drag and drop NOOBS files 25 | 26 | 1. Once your SD card has been formatted, drag all the files in the extracted NOOBS folder and drop them onto the SD card drive. 27 | 1. The necessary files will then be transferred to your SD card. 28 | 1. When this process has finished, safely remove the SD card and insert it into your Raspberry Pi. 29 | 30 | ## First time you power on 31 | 32 | 1. Plug in your keyboard, mouse and monitor cables. 33 | 1. Now plug in the USB power cable to your Pi. 34 | 1. Your Raspberry Pi will boot, and a window will appear with a list of different operating systems that you can install. We recommend that you use Raspbian – tick the box next to Raspbian and click on `Install`. 35 | 1. Raspbian will then run through its installation process. *Note this can take a while.* 36 | 1. When the install process has completed, the Raspberry Pi configuration menu (`raspi-config`) will load. Here you are able to set the time and date for your region and enable a Raspberry Pi camera board, or even create users. You can exit this menu by using `Tab` on your keyboard to move to `Finish`. 37 | -------------------------------------------------------------------------------- /sense-hat/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | All contributions are assumed to be licensed under the same licence as the source, i.e. [CC BY-SA](http://creativecommons.org/licenses/by-sa/4.0/). This licence must remain in all derivatives of this work. 4 | 5 | ## Issues 6 | 7 | If you find a mistake, bug or other problem, please [open an issue](https://github.com/raspberrypilearning/astro-pi-guide) in this repository. 8 | 9 | ## Pull Requests 10 | 11 | If you fix a mistake, bug or problem or have something to contribute, please create a pull request for each modification. Please consider grouping modifications sensibly, i.e. don't bundle typo fixes in the same pull request as code changes, instead file them separately. 12 | 13 | Please note that sometimes things are done for pedagogical reasons so changes which make sense from a software engineering perspective (reducing duplication or making use of more advanced programming language features) may not be suitable to maintain the intended educational value. 14 | 15 | ## Derivatives 16 | 17 | The licence must remain in all derivatives of this work. 18 | 19 | ## Licence 20 | 21 | Unless otherwise specified, everything in this repository is covered by the following licence: 22 | 23 | [![Creative Commons License](http://i.creativecommons.org/l/by-sa/4.0/88x31.png)](http://creativecommons.org/licenses/by-sa/4.0/) 24 | 25 | ***Astro Pi Guide*** by the [Raspberry Pi Foundation](http://www.raspberrypi.org) is licenced under a [Creative Commons Attribution 4.0 International Licence](http://creativecommons.org/licenses/by-sa/4.0/). 26 | 27 | Based on a work at https://github.com/raspberrypilearning/astro-pi-guide 28 | -------------------------------------------------------------------------------- /sense-hat/LICENCE.md: -------------------------------------------------------------------------------- 1 | # Licence 2 | 3 | Unless otherwise specified, everything in this repository is covered by the following licence: 4 | 5 | [![Creative Commons License](http://i.creativecommons.org/l/by-sa/4.0/88x31.png)](http://creativecommons.org/licenses/by-sa/4.0/) 6 | 7 | ***Astro Pi Guide*** by the [Raspberry Pi Foundation](http://www.raspberrypi.org) is licenced under a [Creative Commons Attribution 4.0 International Licence](http://creativecommons.org/licenses/by-sa/4.0/). 8 | 9 | Based on a work at https://github.com/raspberrypilearning/astro-pi-guide 10 | -------------------------------------------------------------------------------- /sense-hat/README.md: -------------------------------------------------------------------------------- 1 | # A Guide to Astro Pi 2 | 3 | ![Astro Pi Cover Art](images/cover.png) 4 | 5 | This collection of guides and worksheets has been designed to provide you with a broad understanding of the Astro Pi HAT and its capabilities. They could be used by teachers and students who have just entered the Astro Pi [Secondary School competition](http://astro-pi.org/secondary-school-competition/), or by anyone wanting to make the most of their Astro Pi HAT. It will introduce you to what the board does, how to set it up, how to write your first program, and how to use the HAT's many features. 6 | 7 | ## Getting Started 8 | 9 | - [Astro Pi: what is it?](board.md) 10 | - [Assemble the Astro Pi](assemble.md) 11 | - [Software setup](software.md) 12 | - [Astro Pi: first program](program.md) 13 | - [Astro Pi Python Cheatsheet](files/AstroPi-Cheatsheet.pdf) 14 | - [Getting started with Astro Pi learn resource](http://raspberrypi.org/learning/getting-started-with-astro-pi) 15 | 16 | ## Sensors 17 | 18 | - [Temperature](sensors/temperature.md) 19 | - [Humidity](sensors/humidity.md) 20 | - [Pressure](sensors/pressure.md) 21 | - [Movement](sensors/movement.md) 22 | 23 | ## Inputs & Outputs 24 | 25 | - [Joystick](inputs-outputs/joystick.md) 26 | - [LED Matrix](inputs-outputs/led-matrix.md) 27 | 28 | ## Learn more about Astro Pi 29 | 30 | - [The Official Astro Pi Website](http://astro-pi.org/) 31 | - Martin O'Hanlon has built a [virtual Astro Pi](http://www.stuffaboutcode.com/2015/05/interactive-minecraft-astro-pi.html) board in Minecraft which you can interact with to explore the functionality of the board. 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /sense-hat/assemble.md: -------------------------------------------------------------------------------- 1 | # Assemble the Astro Pi 2 | 3 | 1. If you have not yet installed the Astro Pi HAT, now is the time to do so. Do this with the Raspberry Pi shut down, disconnected from the mains, and with all other cables disconnected. 4 | 5 | 1. The Astro Pi HAT comes in a silver anti-static bag, along with the following fixtures and fittings: 6 | 7 | - 1 x GPIO pin extension header 8 | - 4 x Hexagon stand-offs (female-to-female) 9 | - 8 x M2.5 screws 10 | 11 | Check that these are all present before proceeding. 12 | 13 | 1. This diagram shows how it all fits together. 14 | 15 | ![](images/Astro_Pi_Diagram.jpg) 16 | 17 | 1. First, put the GPIO extension header block onto the Raspberry Pi GPIO pins. 18 | 19 | 1. Screw the hexagon stand-offs to the Raspberry Pi itself, by threading the screws through from the bottom and turning the hexagon stand-offs between finger and thumb. 20 | 21 | 1. Next, insert the Astro Pi HAT into the GPIO pin extension header. The corner holes should line up with the hexagon stand-offs. 22 | 23 | 1. Lastly, put the remaining screws through from the top. 24 | 25 | 1. Use a small Phillips screwdriver to tighten each corner stand-off individually. They don't need to be especially tight, just enough to ensure that the HAT doesn't become loose. 26 | 27 | ## What's Next? 28 | 29 | Now that you have assembled your Astro Pi board, you will need to complete the [Software setup](software.md). 30 | -------------------------------------------------------------------------------- /sense-hat/board.md: -------------------------------------------------------------------------------- 1 | # Astro Pi: what is it? 2 | 3 | The Astro Pi is a HAT board for the Raspberry Pi which has the ability to sense a wide variety of conditions and provide output via the built-in LED matrix. Two Astro Pis will be travelling to the International Space Station (ISS) with British ESA astronaut Tim Peake. You can find out more about the mission and the board by watching the official Astro Pi competition video: 4 | 5 | [![Astro Pi Competition](https://i.vimeocdn.com/video/504039170_640.webp)](https://vimeo.com/117274487) 6 | 7 | Here is NASA astronaut Reid Wiseman giving a fly-through tour of the ISS: 8 | 9 | [![Fly-through of the weather station](http://img.youtube.com/vi/kVK20xyfPrU/0.jpg)](https://www.youtube.com/watch?v=kVK20xyfPrU) 10 | 11 | ## What's on the board? 12 | 13 | Let's take a tour of the main features of the Astro Pi sensor board: 14 | 15 | ![Astro Pi Board Features](images/astro_pi_features.jpg) 16 | 17 | The main features are highlighted in red. 18 | 19 | 1. The LED matrix on the left has 64 [light emitting diodes](http://en.wikipedia.org/wiki/Light-emitting_diode) (LEDs) arranged in an 8 x 8 grid. On board the ISS the Astro Pi cannot be connected to a screen as the astronauts only have laptops, so these LEDs act as its display. They can be used to display shapes, icons and messages to the crew of the ISS. 20 | 1. Next is the [inertial measurement unit](http://en.wikipedia.org/wiki/Inertial_measurement_unit) (IMU). All spacecraft have these since they're very important for space flight. It's the small microchip just above the text `ACCEL/GYRO/MAG` on the Astro Pi. It's actually three sensors in one: 21 | - An accelerometer to measure the force of acceleration (like in a Wiimote) 22 | - A gyroscope to measure orientation (so you know which way you're pointing) 23 | - A magnetometer to measure the Earth's magnetic field (like a compass) 24 | So this is basically a movement sensor and will allow you to measure how you're moving the Astro Pi in your hand or, in space, how the ISS itself is moving. 25 | 1. Next is a [humidity](http://en.wikipedia.org/wiki/Humidity) sensor. This will allow you to measure air moisture. It's the small chip just below the text `HUMIDITY`. You can also use it to measure ambient temperature. 26 | 1. There is also a [pressure](http://en.wikipedia.org/wiki/Atmospheric_pressure) sensor for measuring air pressure, something which is certainly important in space. It's the chip to the right of the text `PRESSURE`. 27 | 1. Last but not least is the joystick. The Astro Pi cannot be connected to a USB keyboard or mouse in space, so it has its own five button joystick. This is the silver rectangle in the bottom right corner with the small stick poking out of the top. It can move up, down, left, right, and allow middle-clicks. 28 | 29 | ## What's Next? 30 | 31 | Now that you're familar with the board, you should [assemble](assemble.md) it and connect it to your Raspberry Pi. 32 | -------------------------------------------------------------------------------- /sense-hat/files/AstroPi-Cheatsheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/sense-hat/files/AstroPi-Cheatsheet.pdf -------------------------------------------------------------------------------- /sense-hat/hardware.md: -------------------------------------------------------------------------------- 1 | # Hardware Requirements 2 | 3 | You will also need an Astro Pi board, to find out how to get one visit [astro-pi.org](http://astro-pi.org/hardware/) 4 | -------------------------------------------------------------------------------- /sense-hat/hardware.yml: -------------------------------------------------------------------------------- 1 | - name: Astro Pi HAT 2 | img: astro-pi 3 | url: http://astro-pi.org/hardware/ 4 | -------------------------------------------------------------------------------- /sense-hat/images/Astro_Pi_Diagram.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/sense-hat/images/Astro_Pi_Diagram.jpg -------------------------------------------------------------------------------- /sense-hat/images/Astro_Pi_Logo_WEB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/sense-hat/images/Astro_Pi_Logo_WEB.png -------------------------------------------------------------------------------- /sense-hat/images/astro_pi_features.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/sense-hat/images/astro_pi_features.jpg -------------------------------------------------------------------------------- /sense-hat/images/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/sense-hat/images/cover.png -------------------------------------------------------------------------------- /sense-hat/inputs-outputs/images/additive_color_mixing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/sense-hat/inputs-outputs/images/additive_color_mixing.png -------------------------------------------------------------------------------- /sense-hat/inputs-outputs/images/closeup_of_pixels.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/sense-hat/inputs-outputs/images/closeup_of_pixels.jpg -------------------------------------------------------------------------------- /sense-hat/inputs-outputs/images/coordinates.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/sense-hat/inputs-outputs/images/coordinates.png -------------------------------------------------------------------------------- /sense-hat/inputs-outputs/images/cursor_keys.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/sense-hat/inputs-outputs/images/cursor_keys.jpg -------------------------------------------------------------------------------- /sense-hat/inputs-outputs/images/pointer_close.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/sense-hat/inputs-outputs/images/pointer_close.jpg -------------------------------------------------------------------------------- /sense-hat/inputs-outputs/joystick.md: -------------------------------------------------------------------------------- 1 | # The Joystick 2 | 3 | The Astro Pi joystick is mapped to the four keyboard cursor keys, with the mouse middle-click being mapped to the Return key. This means that moving the joystick has exactly the same effect as pressing those keys on the keyboard. Remember that the down direction is with the HDMI port facing downwards. 4 | 5 | ![](images/cursor_keys.jpg) 6 | 7 | ## Keyboard mapping 8 | 9 | 1. Open **Python 3** from a terminal window as `sudo` by typing: 10 | 11 | ```bash 12 | sudo idel3 & 13 | ``` 14 | 15 | 1. A Python Shell window will now appear. 16 | 1. Select `File > New Window`. 17 | 1. Type in the following code: 18 | 19 | ```python 20 | import pygame 21 | 22 | from pygame.locals import * 23 | from astro_pi import AstroPi 24 | 25 | pygame.init() 26 | pygame.display.set_mode((640, 480)) 27 | ap = AstroPi() 28 | ap.clear() 29 | 30 | running = True 31 | 32 | while running: 33 | for event in pygame.event.get(): 34 | print(event) 35 | if event.type == QUIT: 36 | running = False 37 | print("BYE") 38 | ``` 39 | 40 | 1. Select `File > Save` and choose a file name for your program. 41 | 1. Then select `Run > Run module`. 42 | 43 | Note that we are using the [pygame](http://www.pygame.org/docs/) Python module to detect the key presses. 44 | 45 | 1. A blank window will appear. Use the mouse to move it to one side of your screen so that the Python Shell window is also visible. 46 | 1. Keep the blank window selected but move the mouse over it, press and release some keys on the keyboard and waggle the Astro Pi joystick. Try pressing and holding a key for a moment and then releasing it a few seconds later. You should notice that two events occur when you do this: one for the key going down, and another for the key being released. For this program you will only use the **KEY DOWN** event. 47 | 1. Click the `x` in the corner of the blank pygame window. You should see the `BYE` message appear in the *Python Shell* window but the blank window does not close. 48 | 49 | We're consuming the pygame event queue using the `for event in pygame.event.get():` syntax. This will loop through all keyboard and mouse events that occur. Inside the loop, we display what the event was by using `print(event)` and then test to see if the event type is `QUIT`. If it is, we set `running` to `False` which causes the `while` loop to end and the program to finish. The program should print a line of text in the Python Shell window whenever we move the mouse, click the mouse, and press or release a keyboard key. 50 | 51 | ## Detecting movement of joystick with code 52 | 53 | Think about how a joystick might work. You can use the LED matrix to help you think about it. Let's make a pixel white and use the joystick to move the pixel around the 8x8 matrix. To do this you can use an event to detect a key press. For example, if a key is pressed DOWN what steps need to happen to move the pixel? 54 | 55 | - Turn OFF the LED using current `x` and `y` 56 | - If DOWN then add 1 to `y` 57 | - If UP then subtract 1 from `y` 58 | - If RIGHT then add 1 to `x` 59 | - If LEFT then subtract 1 from `x` 60 | - Turn ON the LED using updated `x` and `y` 61 | 62 | 1. Start by just adding the code for the DOWN key. Delete the `print(event)` command that you used in the previous section and insert the code below at the same indentation level: 63 | 64 | ```python 65 | if event.type == KEYDOWN: 66 | ap.set_pixel(x, y, 0, 0, 0) # Black 0,0,0 means OFF 67 | 68 | if event.key == K_DOWN: 69 | y = y + 1 70 | 71 | ap.set_pixel(x, y, 255, 255, 255) 72 | ``` 73 | 74 | 1. Save and run the code. You should be able to move the pixel point down using the `DOWN` key or the joystick. If you keep going, you'll eventually see this error: 75 | 76 | `ValueError: Y position must be between 0 and 7` 77 | 78 | 1. Our `y` value can only be between 0-7, otherwise it's off the edge of the matrix and into empty space! So that's why the error happens; the Astro Pi doesn't understand values outside this range. Our code just keeps adding 1 to `y` every time the DOWN key is pressed, so we need to stop `y` going above 7. 79 | 80 | We can achieve this by adding the syntax `and y < 7` (and `y` is less than 7) to the key direction test: 81 | 82 | ```python 83 | if event.key == K_DOWN and y < 7: 84 | y = y + 1 85 | ``` 86 | 87 | 1. Save and run the code again; this time, the code should not allow the point to go beyond the edge of the screen. 88 | 89 | 1. Now that this works, you will need to add the other directions for the joystick. Where you have `if event.key == K_DOWN:` in your code, you can also use: 90 | 91 | - `K_UP` 92 | - `K_LEFT` 93 | - `K_RIGHT` 94 | - `K_RETURN` 95 | 96 | 1. We can add a section for each direction to complete your code: 97 | 98 | ```python 99 | import pygame 100 | 101 | from pygame.locals import * 102 | from astro_pi import AstroPi 103 | 104 | pygame.init() 105 | pygame.display.set_mode((640, 480)) 106 | 107 | ap = AstroPi() 108 | ap.clear() 109 | 110 | running = True 111 | 112 | x = 0 113 | y = 0 114 | ap.set_pixel(x, y, 255, 255, 255) 115 | 116 | while running: 117 | for event in pygame.event.get(): 118 | if event.type == KEYDOWN: 119 | ap.set_pixel(x, y, 0, 0, 0) # Black 0,0,0 means OFF 120 | 121 | if event.key == K_DOWN and y < 7: 122 | y = y + 1 123 | elif event.key == K_UP and y > 0: 124 | y = y - 1 125 | elif event.key == K_RIGHT and x < 7: 126 | x = x + 1 127 | elif event.key == K_LEFT and x > 0: 128 | x = x - 1 129 | 130 | ap.set_pixel(x, y, 255, 255, 255) 131 | if event.type == QUIT: 132 | running = False 133 | print("BYE") 134 | ``` 135 | 136 | 1. When you run your code, you should now be able to move the pixel point anywhere on the matrix. 137 | -------------------------------------------------------------------------------- /sense-hat/inputs-outputs/led-matrix.md: -------------------------------------------------------------------------------- 1 | # LED Matrix 2 | 3 | The Astro Pi HAT LED matrix contains 64 multi-colour LEDs. Each of the 64 LEDs actually have three smaller LEDs inside them, one for each primary colour, just like a pixel on a TV. 4 | 5 | ## Simple colour mixing 6 | 7 | ![](images/additive_color_mixing.png) 8 | 9 | In additive colour mixing there are three primary colours: red, green, and blue. In the image above, there are three spotlights of equal brightness, one for each primary colour. In the absence of any colour the result is black. If all three primary colours are mixed, the result is white. When red and green combine, the result is yellow. When red and blue combine, the result is magenta. When blue and green combine, the result is cyan. It's possible to make even more colours than this by varying the brightness of the primary colours used. 10 | 11 | 1. Open **Python 3** from a terminal window as `sudo` by typing: 12 | 13 | ```bash 14 | sudo idel3 & 15 | ``` 16 | 17 | 1. Type in the following code: 18 | 19 | ```python 20 | from astro_pi import AstroPi 21 | ap = AstroPi() 22 | r = 255 23 | g = 255 24 | b = 255 25 | ap.clear((r, g, b)) 26 | ``` 27 | 28 | 1. Select `File > Save` and choose a file name for your program. 29 | 1. Then select `Run > Run module`. 30 | 1. The LED matrix will then go bright white. 31 | 1. The variables `r`, `g` and `b` represent the primary colours red, green, and blue. The numbers they contain specify how bright each colour should be; they can be between 0 and 255. In the above code the maximum value for each colour has been used, so the result is white. 32 | 1. Change the values to specify 255 red but 0 green and blue, then run the code again. 33 | 1. What other colours can you make? 34 | 35 | ## Changing foreground and background colours 36 | 37 | This colour mixing system is used throughout the Astro Pi programming module. You can use colour mixing to great effect by programming scrolling text. In this example, you can set the colour of the text that will appear on the matrix. 38 | 39 | 1. Type the following code into a new file: 40 | 41 | ```python 42 | from astro_pi import AstroPi 43 | ap = AstroPi() 44 | ap.show_message("Hello my name is Tim Peake", text_colour=(255, 0, 0)) 45 | ``` 46 | 47 | Note the syntax `, text_colour=(255, 0, 0)`. Don't forget the comma! 48 | 49 | 1. You can also modify the background colour for the message like so: 50 | 51 | ```python 52 | from astro_pi import AstroPi 53 | ap = AstroPi() 54 | ap.show_message("Hello my name is Tim Peake", text_colour=(255, 0, 0), back_colour=(255,255,255)) 55 | ``` 56 | 57 | *Note: The comma is important, don't forget it!* 58 | 59 | ## Pixels 60 | 61 | This image shows the pixels on a laptop LCD screen. You can see that the pixels are turned on and off to form the pattern of letters and numbers. 62 | 63 | ![](images/closeup_of_pixels.jpg) 64 | 65 | This is how all computer and smartphone screens work. If you want to make recognisable shapes on the LED matrix this is what you also need to do. You only have a resolution of 8 by 8 pixels to work with on the Astro Pi HAT LED matrix though, so you must make shapes and icons that will look quite blocky. This can be a nice challenge! 66 | 67 | 1. Select `File > New Window`. 68 | 1. Type in the following code: 69 | 70 | ```python 71 | from astro_pi import AstroPi 72 | ap = AstroPi() 73 | ap.clear() 74 | x = 0 75 | y = 0 76 | ap.set_pixel(x, y, 255, 255, 255) 77 | ``` 78 | 79 | 1. Select `File > Save` and choose a file name for your program. 80 | 1. Then select `Run > Run module`. 81 | 1. This will turn one LED in the corner white. 82 | 1. Remember that you can change the colour if you wish. 83 | 84 | ## Using coordinates to set pixels 85 | 86 | The `x` and `y` variables can be used to control which individual LED the `set_pixel` command should change. **X** is horizontal and ranges from `0` on the *left* to `7` on the *right*. **Y** is vertical and ranges from `0` at the *top* to `7` on the *bottom*. Therefore, an `x, y` coordinate of `0, 0` is the *top left* and an `x, y` coordinate of `7, 7` is the *bottom right*. 87 | 88 | ![](images/coordinates.png) 89 | 90 | You can get a different colour in each corner of the LED matrix. You will need to use the `set_pixel` command multiple times in your code like this: 91 | 92 | ```python 93 | from astro_pi import AstroPi 94 | ap = AstroPi() 95 | ap.clear() 96 | ap.set_pixel(0, 0, 255, 0, 0) 97 | ap.set_pixel(0, 7, 0, 255, 0) 98 | ap.set_pixel(7, 0, 0, 0, 255) 99 | ap.set_pixel(7, 7, 255, 0, 255) 100 | ``` 101 | 102 | ## Drawing shapes and patterns on the LED matrix 103 | 104 | You may be tempted to try and draw shapes or patterns using the `set_pixel` command over and over in your code. There is a `set_pixels` command though, and with it you can change all 64 LEDs using one line of code! For example, you could draw a Minecraft creeper face on the LED Matrix: 105 | 106 | ```python 107 | from astro_pi import AstroPi 108 | 109 | ap = AstroPi() 110 | 111 | O = (0, 255, 0) # Green 112 | X = (0, 0, 0) # Black 113 | 114 | creeper_pixels = [ 115 | O, O, O, O, O, O, O, O, 116 | O, O, O, O, O, O, O, O, 117 | O, X, X, O, O, X, X, O, 118 | O, X, X, O, O, X, X, O, 119 | O, O, O, X, X, O, O, O, 120 | O, O, X, X, X, X, O, O, 121 | O, O, X, X, X, X, O, O, 122 | O, O, X, O, O, X, O, O 123 | ] 124 | 125 | ap.set_pixels(creeper_pixels) 126 | ``` 127 | 128 | You can even use more than two colours, like in this example of Steve from Minecraft: 129 | 130 | ```python 131 | from astro_pi import AstroPi 132 | 133 | ap = AstroPi() 134 | 135 | B = (102, 51, 0) 136 | b = (0, 0, 255) 137 | S = (205,133,63) 138 | W = (255, 255, 255) 139 | 140 | steve_pixels = [ 141 | B, B, B, B, B, B, B, B, 142 | B, B, B, B, B, B, B, B, 143 | B, S, S, S, S, S, S, B, 144 | S, S, S, S, S, S, S, S, 145 | S, W, b, S, S, b, W, S, 146 | S, S, S, B, B, S, S, S, 147 | S, S, B, S, S, B, S, S, 148 | S, S, B, B, B, B, S, S 149 | ] 150 | 151 | ap.set_pixels(steve_pixels) 152 | ``` 153 | 154 | ## Loading images from files 155 | 156 | Instead of setting the LED matrix, you may wish to use images which are loaded from files. This is a convenient option if you want to have lots of stock images, for example international flags. 157 | 158 | 1. Use any graphics editing tool (on Windows, OS X or Linux) to create the files. As long as they are saved onto the Astro Pi SD card as `JPEG` or `PNG`, and are 8 x 8 pixels in size, then they can be loaded directly to the LED matrix with a single command. 159 | 1. Open the *File Manager* on the Raspberry Pi using `Menu > Accessories > File Manager`. 160 | 1. Browse into the `astro-pi-hat` folder followed by `examples`. There should be a file named `space_invader.png` which you can double-click. 161 | 1. Load the image onto the Astro Pi LED matrix by using the `load_image` function, which needs the file system path to the file you want to load. So for `space_invader.png` the full path is `/home/pi/astro-pi-hat/examples/space_invader.png`. 162 | 163 | Here is the code: 164 | 165 | ```python 166 | from astro_pi import AstroPi 167 | 168 | ap = AstroPi() 169 | ap.load_image("/home/pi/astro-pi-hat/examples/space_invader.png") 170 | ``` 171 | -------------------------------------------------------------------------------- /sense-hat/meta.yml: -------------------------------------------------------------------------------- 1 | title: A Guide to Astro Pi 2 | category: teach 3 | -------------------------------------------------------------------------------- /sense-hat/overview.md: -------------------------------------------------------------------------------- 1 | This collection of guides and worksheets has been designed to provide you with a broad understanding of the Astro Pi HAT and its capabilities. They could be used by teachers and students who have just entered the Astro Pi Secondary School competition, or by anyone wanting to make the most of their Astro Pi HAT. It will introduce you to what the board does, how to set it up, how to write your first program, and how to use the HAT's many features. 2 | -------------------------------------------------------------------------------- /sense-hat/program.md: -------------------------------------------------------------------------------- 1 | # Astro Pi: first program 2 | 3 | Connect the Raspberry Pi peripherals (keyboard, mouse, monitor, and power), and log in using the following login information: 4 | 5 | ```bash 6 | login: pi 7 | password: raspberry 8 | ``` 9 | 10 | You will not see any text when typing the password; this is a security feature. 11 | 12 | Load the graphical user interface by typing `startx`. Now, open Python 3 using `Menu > Programming > Python 3`. This will cause a Python Shell window to appear. Select `File > New Window`, and type in the following code: 13 | 14 | ```python 15 | from astro_pi import AstroPi 16 | ap = AstroPi() 17 | ap.show_message("Hello my name is Tim Peake") 18 | ``` 19 | 20 | Select `File > Save` and choose a file name for your program, then select `Run > Run module`. Your message should then scroll across the LED matrix in white text. 21 | 22 | Why not try changing the message between the double quotation marks and running your code again? 23 | -------------------------------------------------------------------------------- /sense-hat/sensors/humidity.md: -------------------------------------------------------------------------------- 1 | # Humidity 2 | 3 | The Astro Pi HAT features a number of sensors, one of which is a humidity sensor that measures the amount of water in the air. 4 | 5 | ## What does humidity mean? 6 | 7 | - Humidity is the amount of water vapour in the air. 8 | - Water vapour is the gaseous state of water. 9 | 10 | The amount of water vapour suspended in the air is dependent on temperature. 11 | 12 | - The higher the temperature, the more water vapour can be suspended in the air. 13 | - The lower the temperature, the less water vapour can be suspended. 14 | 15 | ![](images/condensation.jpg) 16 | 17 | When you take a cold can or bottle out of the fridge you see water appearing on it. This happens because the cold bottle is cooling the air around it, causing the air to be less capable of suspending water vapour. This then causes the water vapour that can't be suspended to turn back into liquid water. This is called *condensation*. So, given this information, we next need to understand that there are two ways that we can measure humidity: 18 | 19 | - *Absolute* humidity is the total mass of water vapour suspended in a given volume of air. Temperature is not taken into consideration. It's usually expressed as grams of water per cubic metre of air. 20 | - *Relative* humidity, however, is expressed as a percentage. For any given air temperature there is a maximum amount of water vapour that it can suspend. Relative humidity is the percentage of actual water vapour present, compared to the maximum possible amount. 21 | 22 | A known amount of water vapour will result in different relative humidity readings, depending on the temperature of the air and the ability of the air to suspend it. So a low air temperature might give a high relative humidity reading because the air can't suspend much more water vapour. Increasing the temperature of the air and keeping the same amount of water vapour will cause the relative humidity reading to drop, because the maximum amount of water vapour that *could* be suspended has increased. 23 | 24 | The Astro Pi gives you the humidity measurement as *relative humidity*. This is why the humidity sensor also has a temperature sensor built in! 25 | 26 | ## what is the current humidity? 27 | 28 | 1. Open **Python 3** from a terminal window as `sudo` by typing: 29 | 30 | ```bash 31 | sudo idel3 & 32 | ``` 33 | 34 | 1. Select `File > New Window` and enter the following code: 35 | 36 | ```python 37 | from astro_pi import AstroPi 38 | 39 | ap = AstroPi() 40 | ap.clear() 41 | 42 | humidity = ap.get_humidity() 43 | print(humidity) 44 | ``` 45 | 46 | 1. Select `File > Save` and choose a file name for your program. 47 | 1. Select `Run > Run module`. 48 | 1. If you see the error `Humidity Init Failed, please run as root / use sudo` on the last line in red, it means you haven't followed the instructions above. Close everything and go back to step 1. 49 | 1. You should see something like this: 50 | 51 | ```bash 52 | Humidity sensor Init Succeeded 53 | 34.6234588623 54 | ``` 55 | 56 | 1. Just before the `print(humidity)` line add this line below: 57 | 58 | ```python 59 | humidity = round(humidity, 1) 60 | ``` 61 | 62 | 1. You should now see something like this, without all the numbers after the decimal point: 63 | 64 | ```bash 65 | Humidity sensor Init Succeeded 66 | 34.6 67 | ``` 68 | 69 | ## Monitoring humidity over time 70 | 71 | 1. It would be good to monitor the humidity as it changes, so let's put your code into a `while` loop and run it again: 72 | 73 | ```python 74 | while True: 75 | humidity = ap.get_humidity() 76 | humidity = round(humidity, 1) 77 | print(humidity) 78 | ``` 79 | 80 | 1. Exhale slowly onto the sensors. The water vapour in your breath should cause the readings to jump up. 81 | 1. Keep watching and it should slowly fall back to the background humidity of the room. 82 | 1. Press `Ctrl - C` to stop the program. 83 | 84 | ## Display the humidity on the LED matrix 85 | 86 | Think about how you might use the matrix to display the humidity. One way is to divide 64 (the number of LEDs in the matrix) by 100, then multiply that by the percentage of relative humidity, which gives you the number of LEDs you should turn on. 100%, for example, would be all 64 LEDs turned on. To do this, you need to build up a pixel list of the right number of light vs. dark pixels, and then call the `set_pixels` function. 87 | 88 | Here is some example code- notice that you have to clamp the humidity measurement to 100: 89 | 90 | ```python 91 | from astro_pi import AstroPi 92 | 93 | ap = AstroPi() 94 | ap.clear() 95 | 96 | on_pixel = [255, 0, 0] 97 | off_pixel = [0, 0, 0] 98 | 99 | while True: 100 | humidity = ap.get_humidity() 101 | humidity = round(humidity, 1) 102 | 103 | if humidity > 100: 104 | humidity = 100.0 105 | 106 | pixels = [] 107 | on_count = int((64 / 100.0) * humidity) 108 | off_count = 64 - on_count 109 | 110 | pixels.extend([on_pixel] * on_count) 111 | pixels.extend([off_pixel] * off_count) 112 | 113 | ap.set_pixels(pixels) 114 | ``` 115 | 116 | *Note: Please note that it is possible to get a value higher than 100 from the humidity sensor.* 117 | -------------------------------------------------------------------------------- /sense-hat/sensors/images/Astro_Pi_Diagrams-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/sense-hat/sensors/images/Astro_Pi_Diagrams-01.png -------------------------------------------------------------------------------- /sense-hat/sensors/images/Astro_Pi_Diagrams-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/sense-hat/sensors/images/Astro_Pi_Diagrams-02.png -------------------------------------------------------------------------------- /sense-hat/sensors/images/Astro_Pi_Diagrams-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/sense-hat/sensors/images/Astro_Pi_Diagrams-03.png -------------------------------------------------------------------------------- /sense-hat/sensors/images/Astro_Pi_Diagrams-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/sense-hat/sensors/images/Astro_Pi_Diagrams-04.png -------------------------------------------------------------------------------- /sense-hat/sensors/images/apollo_imu.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/sense-hat/sensors/images/apollo_imu.jpg -------------------------------------------------------------------------------- /sense-hat/sensors/images/apollo_soyuz.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/sense-hat/sensors/images/apollo_soyuz.jpg -------------------------------------------------------------------------------- /sense-hat/sensors/images/bottle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/sense-hat/sensors/images/bottle.jpg -------------------------------------------------------------------------------- /sense-hat/sensors/images/condensation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/sense-hat/sensors/images/condensation.jpg -------------------------------------------------------------------------------- /sense-hat/sensors/images/orientation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/sense-hat/sensors/images/orientation.png -------------------------------------------------------------------------------- /sense-hat/sensors/images/thermometer.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/sense-hat/sensors/images/thermometer.jpg -------------------------------------------------------------------------------- /sense-hat/sensors/movement.md: -------------------------------------------------------------------------------- 1 | # Movement 2 | 3 | The Astro Pi has a movement sensor called an IMU, which can measure the kind of movement it is experiencing. 4 | 5 | ## What is an IMU? 6 | 7 | IMU stand for *inertial measurement unit*. It's actually three sensors in one: 8 | 9 | - A gyroscope (measures momentum and rotation) 10 | - An accelerometer (measures acceleration forces and can be used to find the direction of gravity) 11 | - A magnetometer (measures the Earth's own magnetic field, so it's a bit like a compass) 12 | 13 | ![](images/apollo_imu.jpg) 14 | 15 | Why is a movement sensor important, though? When you're up in space there is one question of absolute importance that you must *always* know the answer to: 16 | 17 | - **Which way am I pointing?** 18 | 19 | If you don't know your orientation you are in big trouble, so an IMU sensor like this one is used on all manned and unmanned spacecraft to track movements and maintain an understanding of orientation. Even the earliest spacecraft had them. Ask your grandparents if they remember the [Apollo missions](http://en.wikipedia.org/wiki/Apollo_program) that landed humans on the surface of the moon. 20 | 21 | Above is a picture of the IMU sensor from the Apollo command module. You'll notice how big it is compared to the tiny black cube on the Astro Pi; that's the difference between 1975 and 2015 technology. Incidentally, the Astro Pi IMU is probably not as accurate as the Apollo one, however it *is* a million times cheaper! 22 | 23 | ## How is orientation represented? 24 | 25 | We all know the Earth rotates around an axis that runs between the North and South Poles. All objects in space or otherwise have *three* axes around which they can rotate. If you know how much rotation has happened on each axis, then you know which way the object is pointing. 26 | 27 | The three axes are: 28 | 29 | - **Pitch** (like a plane taking off) 30 | - **Roll** (the plane doing a victory roll) 31 | - **Yaw** (imagine steering the plane like a car) 32 | 33 | Watch this short [video](https://www.youtube.com/watch?v=pQ24NtnaLl8) that shows where these axes are in relation to a plane. Try to imagine the plane pointing in any random direction. To get the plane into that position, you can rotate it by a known amount around each axis to get it to the orientation that you imagined. 34 | 35 | ![](images/orientation.png) 36 | 37 | The image above shows where these axes are in relation to the Astro Pi. 38 | 39 | Let's download and run a 3D demo program to explore this. 40 | 41 | ## Apollo Soyuz Demo 42 | 43 | The image below shows the Apollo Soyuz module that was used to take humans to the surface of the moon during the 1970s. The 3D demo we're going to play with shows this same spacecraft (but with less detail). 44 | 45 | ![](images/apollo_soyuz.jpg) 46 | 47 | You will need to have your Astro Pi connected to the internet in order to download the required software. 48 | 49 | Enter the commands below into a terminal window: 50 | 51 | ```bash 52 | sudo apt-get install python3-pip 53 | sudo pip-3.2 install pi3d 54 | git clone git://github.com/astro-pi/apollo-soyuz 55 | cd apollo-soyuz 56 | sudo ./soyuz.py 57 | ``` 58 | 59 | Pi 1 users will have to wait 3 to 4 minutes for this to load. For Pi 2 users it's about 30 seconds. When you see the spacecraft appear on the screen start moving the Astro Pi around with your hands. The the main booster is where the SD card slot is on your Astro Pi. 60 | 61 | See if you can get the spacecraft to do the pitch, roll and yaw movements. Refer back to the [video](https://www.youtube.com/watch?v=pQ24NtnaLl8) if you need to remind yourself which is which. 62 | 63 | The code behind this demo is basically calling the Astro Pi `get_orientation` function which accesses the IMU sensor. This then returns three angles between 0 and 360 degrees. One for each axis (pitch, roll and yaw). The spacecraft model is then rotated by those angles so that it points in the same direction. This is all repeating over and over very quickly to maintain the orientation of the model with what the IMU is reporting. 64 | 65 | Press `Esc` to exit the demo. Let's try a simpler version of this ourselves in code. 66 | 67 | ## Which way am I pointing? 68 | 69 | 1. Open **Python 3** from a terminal window as `sudo` by typing: 70 | 71 | ```bash 72 | sudo idel3 & 73 | ``` 74 | 75 | 1. Select `File > New Window` and enter the following code: 76 | 77 | ```python 78 | from astro_pi import AstroPi 79 | ap = AstroPi() 80 | ap.clear() 81 | 82 | o = ap.get_orientation() 83 | pitch = o["pitch"] 84 | roll = o["roll"] 85 | yaw = o["yaw"] 86 | print("pitch %s roll %s yaw %s" % (pitch, yaw, roll)) 87 | ``` 88 | 89 | 1. Select `File > Save` and choose a file name for your program. 90 | 1. Select `Run > Run module`. 91 | 1. If you see the error `IMU Init Failed, please run as root / use sudo` on the last line in red, it means you haven't followed the instructions above. Close everything and go back to step 1. 92 | 1. You should now see something like this: 93 | 94 | ``` 95 | IMU Init Succeeded 96 | pitch 356.35723002363454 roll 303.4986602798494 yaw 339.19880231669873 97 | ``` 98 | 99 | 1. We don't need all the numbers after the decimal point so let's round them off. Just before the `print("pitch %s roll %s yaw %s" % (pitch, yaw, roll))` line, add these lines below: 100 | 101 | ```python 102 | pitch = round(pitch, 1) 103 | roll = round(roll, 1) 104 | yaw = round(yaw, 1) 105 | ``` 106 | 107 | ## Monitor movement over time 108 | 109 | 1. It would be good to monitor the axis values changing during movements, so let's put your code into a `while` loop and run it again: 110 | 111 | ```python 112 | while True: 113 | o = ap.get_orientation() 114 | pitch = o["pitch"] 115 | roll = o["roll"] 116 | yaw = o["yaw"] 117 | 118 | pitch = round(pitch, 1) 119 | roll = round(roll, 1) 120 | yaw = round(yaw, 1) 121 | 122 | print("pitch %s roll %s yaw %s" % (pitch, yaw, roll)) 123 | ``` 124 | 125 | 1. Move the Astro Pi around in your hand and you should see the numbers changing. See if you can just make one axis change by moving only in the pitch direction for example. Do this for all three axes. Press `Ctrl - C` to stop the program. 126 | 127 | ## Display orientation on the LED matrix 128 | 129 | 1. Displaying something which is 3D in a 2D way is always a challenge, especially when your screen is only 8 x 8 pixels in size. One way which might work well is to have one LED for each axis and then make them move in different ways. For example: 130 | 131 | - The pitch LED could go up and down 132 | - The roll LED could go side to side 133 | - The yaw LED could chase around the edge 134 | 135 | 1. Here is a clever trick you can do. The table below shows the sequential LED numbers laid out in horizontal rows. 136 | 137 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 138 | --- | --- | --- | --- | --- | --- | --- | --- 139 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 140 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 141 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 142 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 143 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 144 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 145 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 146 | 147 | For any of those numbers you can convert them into their X Y coordinate using the code below. 148 | 149 | ```python 150 | y = number // 8 151 | x = number % 8 152 | ``` 153 | 154 | For the `y` value you floor divide `//` the number by 8. This is Integer division and ignores the remainder. Then for the `x` value you do the modulus `%` of 8 which gives you *only* the remainder. 155 | 156 | For example (using the number 60 which is on the bottom row): 157 | - `60 // 8 = 7` 158 | - `60 % 8 = 4` 159 | 160 | 1. Try this code: 161 | 162 | ```python 163 | number = 60 164 | 165 | y = number // 8 166 | x = number % 8 167 | 168 | ap.set_pixel(x, y, 255, 255, 255) 169 | ``` 170 | 171 | 1. The clever trick is to make a list containing the LED numbers for the path you want it to move back and forth through. So say you want to make an LED chase around the edge you would read the numbers accross the top of the table, down the right hand side, backwards along to bottom and up the left side. So it would be: 172 | 173 | ```python 174 | edge = [0, 1, 2, 3, 4, 5, 6, 7, 15, 23, 31, 39, 47, 55, 63, 62, 61, 60, 59, 58, 57, 56, 48, 40, 32, 24, 16, 8] 175 | ``` 176 | 177 | We can then find the length of the list using the `len` function: 178 | 179 | ```python 180 | length = len(edge) 181 | ``` 182 | 183 | So the length is 28. If we divide 28 by 360 we have a ratio between say the yaw measurement and the positions in our list (how far around the edge we are). We can then get the sequential pixel number *out of the list* at the calculated position, work out it's coordinate and then switch the LED on! Like this: 184 | 185 | ```python 186 | from astro_pi import AstroPi 187 | ap = AstroPi() 188 | ap.clear() 189 | 190 | edge = [0, 1, 2, 3, 4, 5, 6, 7, 15, 23, 31, 39, 47, 55, 63, 62, 61, 60, 59, 58, 57, 56, 48, 40, 32, 24, 16, 8] 191 | length = len(edge) 192 | ratio = length / 360.0 193 | 194 | while True: 195 | o = ap.get_orientation() 196 | pitch = o["pitch"] 197 | roll = o["roll"] 198 | yaw = o["yaw"] 199 | 200 | yaw_list_position = int(yaw * ratio) 201 | 202 | yaw_pixel_number = edge[yaw_list_position] 203 | 204 | y = yaw_pixel_number // 8 205 | x = yaw_pixel_number % 8 206 | 207 | ap.set_pixel(x, y, 255, 255, 255) 208 | ``` 209 | 210 | 1. What you'll notice is that the above code only turns LEDs on, you'll need to figure out how to turn them off yourself. Try having a variable for the previous `x` and `y` from the last time around the loop and if this is different from the new `x` and `y` you use `set_pixel` to set the LED to black. 211 | -------------------------------------------------------------------------------- /sense-hat/sensors/pressure.md: -------------------------------------------------------------------------------- 1 | # Pressure 2 | 3 | The Astro Pi HAT features a number of sensors, including a pressure sensor. 4 | 5 | ## What is pressure and how can it be measured? 6 | 7 | Pressure, generally speaking, is the force applied to a surface per unit of area. Imagine a brick sitting on a table. The force of its weight is being applied through the area of one of its faces. If you were then to balance the brick on a needle the force of its weight is concentrated on the area of the needle's tip, so the pressure being applied to the table is much higher. 8 | 9 | Atmospheric pressure (also known as barometric pressure) is the pressure exerted by the weight of air in the Earth's atmosphere. Air pressure is pushing on every part of your body all the time. The pressure inside your body is the same as outside, though, so you don't feel anything. The unit of measurement is usually bars or millibars. One bar is about equal to the atmospheric pressure on Earth at sea level, which is 1000 millibars. 10 | 11 | # Facts about pressure: 12 | 13 | - Atmospheric pressure decreases smoothly from the Earth's surface (sea level) up to the edge of space. 14 | 15 | ![](images/bottle.jpg) 16 | 17 | - The plastic bottle above was sealed at approximately 4300 metres altitude, and was crushed by the increase in atmospheric pressure at 2700 metres and then 300 metres as it was brought down towards sea level. 18 | - Animal and plant life need atmospheric pressure in order to survive. The air above 8000 metres altitude is dangerous to humans and has been named the [Death Zone](http://simple.wikipedia.org/wiki/Death_zone) by mountain climbers. The summit of Mount Everest is in this zone. 19 | - The [Armstrong line](http://en.wikipedia.org/wiki/Armstrong_limit) is the altitude beyond which humans absolutely cannot survive in an unpressurised environment. This is between 18900 and 19350 metres, where water boils at the normal temperature of the human body. 20 | - The ISS maintains an orbit with an altitude of about 400 km (400000 metres), which is way past the Armstrong line and right out in the vastness of space without any atmosphere (zero millibars). However, the air pressure inside the ISS is maintained at about 1013 millibars, which is nice and comfortable for the crew. 21 | 22 | ## What is the pressure? 23 | 24 | 1. Open **Python 3** from a terminal window as `sudo` by typing: 25 | 26 | ```bash 27 | sudo idel3 & 28 | ``` 29 | 30 | 1. A Python Shell window will now appear. The terminal window can now be closed. 31 | 1. Select `File > New Window`. 32 | 1. Enter the following code: 33 | 34 | ```python 35 | from astro_pi import AstroPi 36 | 37 | ap = AstroPi() 38 | ap.clear() 39 | 40 | pressure = ap.get_pressure() 41 | print(pressure) 42 | ``` 43 | 44 | 1. Select `File > Save` and choose a file name for your program. 45 | 1. Select `Run > Run module`. 46 | 1. If you see the error `Pressure Init Failed, please run as root / use sudo` on the last line in red, it means you haven't followed the instructions above. Close everything and go back to step 1. 47 | 1. You should see something like this: 48 | 49 | ```bash 50 | Pressure sensor Init Succeeded 51 | 1013.40380859 52 | ``` 53 | 54 | If you get `0` just run the code again. This sometimes happens when you use the pressure sensor for the first time. 55 | 56 | 1. Just before the `print(pressure)` line, add this line below: 57 | 58 | ```python 59 | pressure = round(pressure, 1) 60 | ``` 61 | 62 | ## Monitoring the pressure 63 | 64 | 1. It would be good to monitor the pressure as it changes, so let's put your code into a `while` loop and run it again: 65 | 66 | ```python 67 | while True: 68 | pressure = ap.get_pressure() 69 | pressure = round(pressure, 1) 70 | print(pressure) 71 | ``` 72 | 73 | 1. Unfortunately, it's not as easy to make it change as holding your thumb on the sensor or breathing on it, so use the plastic bottle experiment below to test your code. 74 | 75 | ## The plastic bottle experiment 76 | 77 | The experiment involves sealing an Astro Pi inside a plastic bottle along with a mobile phone top up battery, and then blowing into the bottle to increase the air pressure. Someone with a good pair of lungs should easily be able to increase the pressure to about 1100 millibars inside the bottle. You'll first need to program the visual display. 78 | 79 | 1. Watch [Dave Honess's video](https://www.youtube.com/watch?v=CHUukiKF3ew) about the plastic bottle experiment. 80 | 1. Take an empty two litre plastic bottle, discard the lid, and cut it in half across the middle as shown: 81 | 82 | ![](images/Astro_Pi_Diagrams-01.png) 83 | 84 | Dry the inside of the bottle using a tissue or a dishcloth. Do not be tempted to use a heat gun or a hair dryer as they will warp the plastic. 85 | 86 | 1. Do a fit test. Try to fit the upper half inside the bottom half to join it back together. If you blow into the bottle now you'll feel the air coming back at you through the gaps in the side; later you'll use tape to seal them. 87 | 1. Shut down the Astro Pi, leaving all the peripherals connected. 88 | 1. Disconnect the power supply and replace it with the mobile top up battery. 89 | 1. The Astro Pi should boot up as usual, allowing you to load up and run the code. 90 | 1. Disconnect all the peripherals apart from the battery once the code is running, and put everything into the bottle. Make sure the top half goes inside the bottom half, so you'll feel the air coming back at you when you blow. 91 | 92 | ![](images/Astro_Pi_Diagrams-02.png) 93 | 94 | 1. Use the tape to seal the join between the two halves of the bottle: 95 | 96 | ![](images/Astro_Pi_Diagrams-03.png) 97 | 98 | 1. Blow into the bottle. You should feel air coming back at you if you've got any leaks so just use more tape to patch these. 99 | 100 | ![](images/Astro_Pi_Diagrams-04.png) 101 | 102 | 1. Be aware that the moisture in your breath will steam up the inside of the bottle, so stop before you make the Astro Pi damp. 103 | 1. Remove the tape and separate the two halves of the bottle if you need to change the code. Just reconnecting the peripherals to do a quick edit should work fine. 104 | 105 | 106 | ## Display the pressure on the LED matrix 107 | 108 | Below is the code that was used in the video. It can cope with 1000 to 1100 millibars, so that’s 100 millibars of range. We know that the LED matrix colours have a range of 0 to 255, so the first thing it does is create a ratio between the pressure range and the colour range. The plan is then to multiply the measured pressure by that ratio to get the colour. You have to subtract 1000 from the measured pressure to make this work, so you're multiplying a number between 0 and 100 by the ratio. It then clamps the colour to a maximum of 255, in case there is someone with very strong lungs who can drive the pressure higher than 1100 millibars. 109 | 110 | ```python 111 | from astro_pi import AstroPi 112 | 113 | ap = AstroPi() 114 | ap.clear() 115 | 116 | ratio = 255 / 100.0 117 | 118 | while True: 119 | pressure = ap.get_pressure() 120 | pressure = round(pressure, 1) - 1000 121 | blue = int(ratio * pressure) 122 | if blue > 255: 123 | blue = 255 124 | ap.clear((0, 0, blue)) 125 | -------------------------------------------------------------------------------- /sense-hat/sensors/temperature.md: -------------------------------------------------------------------------------- 1 | # Temperature 2 | 3 | The Astro Pi HAT features a number of sensors, including a temperature sensor. 4 | 5 | ![](images/thermometer.jpg) 6 | 7 | The image above shows a clinical thermometer. You may have been asked to place one in your mouth when you've been ill. Notice that the numbers start at 35, so it's only used for measuring human body temperature. The Astro Pi temperature sensors can measure temperatures from as low as -40 degrees Celsius up to +120 degrees Celsius though, so they are much more versatile than a clinical thermometer. The Astro Pi has two temperature sensors. One is built into the humidity sensor and the other is built into the pressure sensor. You can choose which one to use, or you could use both and average the result. 8 | 9 | ## What is the temperature? 10 | 11 | 1. Open **Python 3** from a terminal window as `sudo` by typing: 12 | 13 | ```bash 14 | sudo idel3 & 15 | ``` 16 | 17 | 1. Enter the following code into a new window: 18 | 19 | ```python 20 | from astro_pi import AstroPi 21 | 22 | ap = AstroPi() 23 | ap.clear() 24 | 25 | temp = ap.get_temperature() 26 | print(temp) 27 | ``` 28 | 29 | 1. Select `File > Save` and choose a file name for your program. 30 | 1. Select `Run > Run module`. 31 | 1. If you see the error `Humidity Init Failed, please run as root / use sudo` (look on the last line of the message in red), it means you haven't followed the instructions above. Close everything and go back to step 1. 32 | 1. You should see something like this: 33 | 34 | ```bash 35 | Humidity sensor Init Succeeded 36 | 28.6293258667 37 | ``` 38 | 39 | 1. Just before the `print(temp)` line add this line below: 40 | 41 | ```python 42 | temp = round(temp, 1) 43 | ``` 44 | 45 | 1. You should now see something like this (without all the numbers after the decimal point): 46 | 47 | ```bash 48 | Humidity sensor Init Succeeded 49 | 28.6 50 | ``` 51 | 52 | 1. Try the following functions instead of `get_temperature`. 53 | 54 | - `get_temperature_from_humidity` (uses the humidity sensor, `get_temperature` is a short version of this) 55 | - `get_temperature_from_pressure` (uses the pressure sensor) 56 | 57 | For example: 58 | 59 | ```python 60 | from astro_pi import AstroPi 61 | 62 | ap = AstroPi() 63 | ap.clear() 64 | 65 | temp = ap.get_temperature_from_pressure() 66 | temp = round(temp, 1) 67 | print(temp) 68 | ``` 69 | 70 | Your code takes one measurement and then exits. 71 | 72 | ## Monitoring the temperature 73 | 74 | 1. It would be good to monitor the temperature as it changes, so let's put our code into a `while` loop and run it again. 75 | 76 | ```python 77 | while True: 78 | temp = ap.get_temperature() 79 | temp = round(temp, 1) 80 | print(temp) 81 | ``` 82 | When you run the code the temperature values will scroll up the screen with the latest ones at the bottom. 83 | 84 | 1. Put your thumb over the sensor and hold it there. You should see the measurement start to rise. 85 | 1. Blow on it (or give the sensors a short blast from an air duster, if available). The measurement should fall. 86 | 1. Press `Ctrl - C` to stop the program. 87 | 88 | ## Display the temperature on the LED Matrix 89 | 90 | Think about how you could show the temperature information on the LED matrix in some way (see the [LED Matrix guide](../inputs-outputs/led-matrix.md) for more information). The obvious choice would be to use the `show_message` function, but, while this would work, there are probably better ways to do it. For example, you could: 91 | - Use the `clear` function to display some predefined colours based on ranges that the temperature falls in. For example 0 to 5 degrees could be blue? 92 | - Use the `clear` function to display a single colour but change the brightness of red (0 to 255) based on the measured temperature? 93 | - Use the `set_pixel` function to display a bar that moves up and down similar to a thermometer. 94 | 95 | Below is some starter code for the final suggestion above. This code will display a bar that has a range of 8 degrees Celsius (one degree per horizontal row of LEDs). The maximum it can display is `31` (hard coded; feel free to edit this) and so the minimum is `31 - 8` which is `23`. If the measured temperature goes outside of that range then errors can occur. You can add code to clamp the measured temperature to prevent these errors if you like. 96 | 97 | ```python 98 | from astro_pi import AstroPi 99 | 100 | ap = AstroPi() 101 | ap.clear() 102 | 103 | tmax = 31 104 | tmin = tmax - 8 105 | 106 | while True: 107 | temp = ap.get_temperature() 108 | print(temp) 109 | temp = int(temp) - tmin 110 | for x in range(0, 8): 111 | for y in range(0, temp): 112 | ap.set_pixel(x, y, 255, 0, 0) 113 | for y in range(temp, 8): 114 | ap.set_pixel(x, y, 0, 0, 0) 115 | ``` 116 | 117 | It works by subtracting the minimum value from the measured value which should give a number between 0 and 8. We then use two nested `for` loops. The outer loop is for the `x` axis and the two inner loops are for the `y` axis. We use two loops here because we want to turn all the LEDs below the measurement red with `set_pixel` and those above it off. That way the bar will appear to move up and down the `y` axis following the measured temperature. 118 | 119 | Remember that you can use `ap.set_rotation(n)` (where `n` is 0, 90, 180 or 270) at the start of the program just after `ap.clear()` if you want to change the orientation of the bar. 120 | 121 | -------------------------------------------------------------------------------- /sense-hat/software.md: -------------------------------------------------------------------------------- 1 | # Astro Pi: software setup 2 | 3 | This guide assumes you have an SD card loaded with NOOBS/Raspbian. If not, see [the Downloads section](http://www.raspberrypi.org/downloads/) to download NOOBS/Raspbian and use the [NOOBS setup guide](http://www.raspberrypi.org/help/noobs-setup/) for help with installation. 4 | 5 | [Connect](assemble.md) your Astro Pi HAT and boot it up. 6 | 7 | ## Astro Pi driver installation 8 | 9 | Ensure your Pi is connected to the internet, then run the following command (from the command prompt or a Terminal window) to download and start the Astro Pi installation script: 10 | 11 | ```bash 12 | wget -O - http://www.raspberrypi.org/files/astro-pi/astro-pi-install.sh --no-check-certificate | bash 13 | ``` 14 | 15 | This will take about 5 minutes on a Pi 2 and about 15 to 20 minutes on a Pi 1. 16 | When it's finished you'll see the following message: 17 | 18 | ``` 19 | You must reboot to complete the Astro Pi installation 20 | Type: 21 | sudo reboot 22 | and press Enter when ready 23 | ``` 24 | 25 | Reboot the Pi to complete the installation: 26 | 27 | ```bash 28 | sudo reboot 29 | ``` 30 | 31 | The rainbow pattern on the LED matrix should now turn off during boot up. 32 | 33 | ## What's Next? 34 | 35 | Now you are ready to write your first [program](program.md) for the Astro Pi board. 36 | -------------------------------------------------------------------------------- /vnc/README.md: -------------------------------------------------------------------------------- 1 | # Using VNC to view your Raspberry Pi on a different computer 2 | 3 | ## What is VNC? 4 | 5 | Virtual Network computing or VNC for short, is a type of software that allows you to view a graphical desktop from another computer on your own across a shared network. 6 | 7 | This is a really useful for Pi users who may not have a spare display. 8 | 9 | - [Setting up and using VNC](vnc-classroom-guide.md) 10 | - [Using VNC through a browser](vnc-browser-guide.md) 11 | -------------------------------------------------------------------------------- /vnc/images/vnc_firefox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/vnc/images/vnc_firefox.png -------------------------------------------------------------------------------- /vnc/images/vnc_ie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raspberrypilearning/guides/72145a9af5018110002e6a46109b32515a82ecce/vnc/images/vnc_ie.png -------------------------------------------------------------------------------- /vnc/vnc-browser-guide.md: -------------------------------------------------------------------------------- 1 | # Remote desktop to a Raspberry Pi through your web browser 2 | 3 | This guide is a slight variant on using remote desktop, such as VNC, to connect to a Raspberry Pi. 4 | 5 | The basic premise is to use another computer as the input console for the Raspberry Pi without needing to get a separate screen, keyboard, and mouse on the Pi. This is ideal if, for example, you've got a room full of laptops, Chromebooks or iMacs. 6 | 7 | This differs from the previous method in that you don't need to install any software on the host computer/laptop. You can set the Raspberry Pi up so that it provides everything the host computer needs through the web browser. It makes it as easy as typing an address in. 8 | 9 | Here is an example of the end product on Windows / IE: 10 | 11 | ![](images/vnc_ie.png) 12 | 13 | ## What will it work on? 14 | 15 | This system will work on any HTML5-compliant web browser, in particular these browser versions or later: 16 | 17 | - Chrome 8 18 | - Firefox 4 19 | - Safari 5 20 | - iOS Safari 4.2 21 | - Opera 11 22 | - IE 9 23 | 24 | ## Step 1: Setting up the server on a Raspberry Pi 25 | 26 | 1. Start with a fresh install of Raspbian and log in as the default `pi` user. You can use the command line interface for this guide. 27 | 1. Install the following packages (TightVNC server and screen). Run these commands from the terminal: 28 | 29 | ``` 30 | sudo apt-get update 31 | sudo apt-get install tightvncserver screen -y 32 | ``` 33 | 34 | 1. Next run TightVNC server, which will prompt you to enter a password and an optional view-only password, by typing `tightvncserver` and pressing **Enter** on the keyboard. 35 | 36 | 1. Now let's get the HTML5 VNC client. Enter the following commands and press **Enter** at the end of each line: 37 | 38 | ``` 39 | cd /usr/local/share/ 40 | sudo git clone git://github.com/kanaka/noVNC 41 | ``` 42 | 43 | 1. We just need to make a small adjustment to some of the files here. The folder we've just downloaded will be served out as a HTTP root for the Pi, so we just need to ensure there is an index page. This will allow the host computer to access the VNC client software. 44 | 45 | ``` 46 | cd noVNC 47 | sudo cp vnc_auto.html index.html 48 | ``` 49 | 50 | 1. Next we need to set everything to start automatically, since you're probably going to want to use the Raspberry Pi in headless mode (without a keyboard, mouse or monitor). To do this we just need to download a few scripts for `init.d`. Enter the following commands: 51 | 52 | ``` 53 | cd /etc/init.d/ 54 | sudo wget https://raw.githubusercontent.com/raspberrypilearning/teachers-classroom-guide/master/vncboot --no-check-certificate 55 | sudo nano vncboot 56 | ``` 57 | 58 | *Note the line that says `-geometry 1280x800`. This sets the screen resolution for the remote desktop, so you may wish to alter this to suit the screen size of the host computer. Ideally this should be set slightly lower to avoid having scrollbars.* 59 | 60 | 1. Press **Ctrl** and **O** followed by **Enter** to save, then **Ctrl** and **X** to quit editing. 61 | 62 | 1. The script you have just created basically makes VNC part of the background services that Linux is controlling. We next need to register the script. Enter the following commands: 63 | 64 | ``` 65 | sudo chmod 755 vncboot 66 | sudo update-rc.d vncboot defaults 67 | ``` 68 | 69 | Ignore any messages about missing LSB tags and overrides. That's the server part done. Next we need to setup a similar script for the HTML5 client. 70 | 71 | ## Step 2: Setting up the client 72 | 73 | With the server side completed, you now need to download a similar script for the HTML5 client. 74 | 75 | 1. Enter the following command: 76 | 77 | ``` 78 | sudo wget https://raw.githubusercontent.com/raspberrypilearning/teachers-classroom-guide/master/vncproxy --no-check-certificate 79 | ``` 80 | 81 | 1. Then register this script with Linux by typing: 82 | 83 | ``` 84 | sudo chmod 755 vncproxy 85 | sudo update-rc.d vncproxy defaults 98 86 | ``` 87 | 88 | Ignore any messages about missing LSB tags and overrides. 89 | 90 | 1. Now reboot your Raspberry Pi by typing `sudo reboot` and both services will start up automatically. When the Pi has rebooted, you should now be able to enter the IP address of the Raspberry Pi into the web browser of the host computer. You will be prompted for the password that you specified when setting up the VNC server. 91 | 92 | *Note: an error has occasionally been observed on the first time that you try to connect; this is possibly caused by the proxy starting before the VNC server socket is open. If you see this the top bar goes red. Just hit refresh (F5), enter the password again and it should work.* 93 | 94 | ## Step 3: Master and slave mode 95 | 96 | There is another trick you can do here if you want to refine the setup further. 97 | 98 | Using the following instructions, each Raspberry Pi will be directly connecting to the host computer using a single Ethernet cable, thus making a completely isolated point-to-point network between the two; this way, your network administrators shouldn't have any cause to complain. Note that you don't need a crossover cable for this; a standard cable will work, because the Pi Ethernet port auto-switches the transmit and receive pins. 99 | 100 | Firstly we'll need to install some more software on the Pi. We’re going to make the Pi Ethernet port behave in a similar way to a home router. This means assigning a static IP address to it and installing a DHCP service (dnsmasq) that will respond to address requests from the host computer. 101 | 102 | 1. Enter these commands: 103 | 104 | ``` 105 | sudo apt-get install dnsmasq -y 106 | ``` 107 | 108 | 1. It’s a good idea to use an IP address range that is very different to your main network, so let’s use `10.0.0.X`. To configure this we must edit the network interfaces file. Enter the following command: 109 | 110 | ``` 111 | sudo nano /etc/network/interfaces 112 | ``` 113 | 114 | 1. Find the following line `iface eth0 inet dhcp`, add a hash symbol at the start of the line to disable it, and then add the other four lines shown below. 115 | 116 | ``` 117 | # iface eth0 inet dhcp 118 | auto eth0 119 | iface eth0 inet static 120 | address 10.0.0.1 121 | netmask 255.255.255.0 122 | ``` 123 | 124 | 1. Press **Ctrl** and **O** followed by **Enter** to save, then **Ctrl** and **X** to quit editing. The Raspberry Pi will now have a static address of `10.0.0.1`. 125 | 126 | 1. Next configure `dnsmasq` (that you installed earlier) to give out IP addresses. We are going to explicitly specify a configuration file for the `dnsmasq` service, so let’s first make a backup of the default config file and then save our one in its place: 127 | 128 | ``` 129 | cd /etc 130 | sudo mv dnsmasq.conf dnsmasq.default 131 | sudo nano dnsmasq.conf 132 | ``` 133 | 134 | 1. You should now be editing a blank file. Type the following into it: 135 | 136 | ``` 137 | interface=eth0 138 | dhcp-range=10.0.0.2,10.0.0.250,255.255.255.0,12h 139 | dhcp-option=3,10.0.0.1 140 | dhcp-option=6,10.0.0.1 141 | ``` 142 | 143 | The first line tells `dnsmasq` to listen for DHCP requests on the Ethernet port of the Pi. The second line is specifying the range of IP addresses that can be given out. The third and fourth lines tell the host computer what its default gateway and DNS server settings are. 144 | 145 | 1. Next make a small edit to the hosts file. This will allow the user to type in 'pi' into the browser instead of `10.0.0.1`. Enter the following to edit the hosts file: `sudo nano /etc/hosts`. 146 | 147 | 1. Find the line that says `127.0.0.1 raspberrypi` and add the following line: 148 | 149 | `10.0.0.1 pi` 150 | 151 | 1. Press **Ctrl** and **O** followed by **Enter** to save, then **Ctrl** and **X** to quit editing. Next, disconnect the Pi from the LAN and reboot by typing `sudo reboot`. 152 | 153 | 1. You can go ahead and plug in the single Ethernet cable directly from the Pi to the host computer. 154 | The host computer should then be given an IP address which will be 10.0.0.X, where X is a random number between 2 and 250. 155 | 156 | One thing to try is to open up a command prompt on the host computer (a terminal on OSX and Linux), and enter the following command: 157 | 158 | ``` 159 | ping 10.0.0.1 160 | ``` 161 | 162 | If you see `reply, reply, reply` then it's working. If you see request timed out, then something is wrong and you'll need to go back and double-check everything. 163 | 164 | You should now be able to open up a web browser on the host computer and enter `pi` into the address bar to get to the VNC client page. 165 | 166 | *Note: Windows users:* This may not work properly on Windows (you'll still need to use `10.0.0.1`), but if you install a package called `winbind` you'll be able to type the Raspberry Pi hostname into the browser. Usually the hostname is `raspberrypi`. The `winbind` package can be installed with the command below: 167 | 168 | `sudo apt-get install winbind` 169 | 170 | However, it should be fine on OSX, Ubuntu, and any other flavour of Linux. 171 | 172 | ![](images/vnc_firefox.png) 173 | 174 | You will be prompted for the password that you specified when setting up the VNC server. 175 | 176 | *Note: an error has occasionally been observed on the first time that you try to connect; this is possibly caused by the proxy starting before the VNC server socket is open. If you see this the top bar goes red. Just hit refresh (F5), enter the password again and it should work.* 177 | -------------------------------------------------------------------------------- /vnc/vnc-classroom-guide.md: -------------------------------------------------------------------------------- 1 | # Remote Desktop to a Raspberry Pi from a networked computer 2 | 3 | ## Step 1: Set up and install VNC server on Raspberry Pi 4 | 5 | Install the VNC server software on Pi and the VNC viewer software on the host computer (which will show the Pi desktop). 6 | 1. On your Raspberry Pi install the TightVNC package: 7 | 8 | ``` 9 | sudo apt-get install tightvncserver 10 | ``` 11 | 1. Next, run TightVNC Server which will prompt you to enter a password and an optional view-only password: 12 | 13 | ``` 14 | tightvncserver 15 | ``` 16 | 17 | 1. Start a VNC server from the terminal. This example starts a session on VNC display zero (```:0```) with full HD resolution: 18 | 19 | ``` 20 | vncserver :0 -geometry 1024x768 -depth 24 21 | ``` 22 | 23 | ## Step 2: Install a VNC client on a computer 24 | 25 | 1. Now, on your computer, install and run the VNC client: 26 | 27 | - On a Linux machine install the package `xtightvncviewer`: 28 | 29 | `sudo apt-get install xtightvncviewer` 30 | 31 | - Otherwise, TightVNC is downloadable from [tightvnc.com](http://www.tightvnc.com/download.php) 32 | 33 | 34 | 35 | ## Step 3: If necessary, configure the Pi to give out an IP address 36 | 37 | This is the method you'll want to use if your network administrator refuses to allow a Raspberry Pi to be connected to the main school network. This way each Raspberry Pi will be directly connecting to a host computer using a single Ethernet cable, thus making a completely isolated point-to-point network between the two. 38 | 39 | *Note: you don't need a crossover cable for this; a standard cable will work because the Pi Ethernet port auto-switches the transmit and receive pins.* 40 | 41 | Firstly we'll need to install some software on the Pi, so for this first part you'll need to connect it to a LAN for internet access. We’re going to make the Pi Ethernet port behave in a similar way to a home router. This means assigning a static IP address to it and installing a DHCP service (`dnsmasq`) that will respond to address requests from the host computer. 42 | 43 | 1. From the command line or an LXTerminal window type: 44 | 45 | ``` 46 | sudo apt-get update 47 | sudo apt-get install dnsmasq 48 | ``` 49 | 50 | 1. It’s a good idea to use an IP address range that is very different to your main network, so let’s use 10.0.0.X. To configure this we must edit the network interfaces file. Enter the following command: 51 | 52 | ``` 53 | sudo nano /etc/network/interfaces 54 | ``` 55 | 1. Find the line `iface eth0 inet dhcp` and add a hash symbol at the start of the line to disable it. Then add the other four lines shown below: 56 | 57 | ``` 58 | # iface eth0 inet dhcp 59 | auto eth0 60 | iface eth0 inet static 61 | address 10.0.0.1 62 | netmask 255.255.255.0 63 | ``` 64 | 65 | 1. Press **Ctrl** and **X** followed by **Y** then **Enter** to save and quit out of nano. The Raspberry Pi will now have a static address of `10.0.0.1`. 66 | 67 | ## Step 4: Configure **dnsmasq** to give out IP addresses 68 | 69 | To do this first make a backup of the default config file and then save my one in its place: 70 | 71 | 1. Type `cd /etc` on the command line to change directories then press **Enter**. 72 | 1. Next type `sudo mv dnsmasq.conf dnsmasq.default` and press **Enter**. 73 | 1. Then type `sudo nano dnsmasq.conf` and press **Enter**. You should now be editing a blank file. Type the following into it: 74 | 75 | ``` 76 | interface=eth0 77 | dhcp-range=10.0.0.2,10.0.0.250,255.255.255.0,12h 78 | dhcp-option=3,10.0.0.1 79 | ``` 80 | The first line tells `dnsmasq` to listen for DHCP requests on the Ethernet port of the Pi. The second line is specifying the range of IP addresses that can be given out. The third line provides the default gateway for the host computer (which won't actually be used here). 81 | 82 | 1. Disconnect the Pi from the LAN and reboot by typing `sudo reboot`. 83 | 84 | ## Step 5: Test the connection 85 | 86 | 1. After the Pi boots back up, give it a minute or so, and you can go ahead and plug in the single Ethernet cable directly from the Pi to the host computer. The host computer should then be given an IP address which will be `10.0.0.X`, where X is a random number between 2 and 250. 87 | 1. Test that there is a working connection by opening up a command prompt on the host computer (a Terminal on OSX and Linux), and enter the following command `ping 10.0.0.1`. 88 | 89 | If you see `reply, reply, reply `then it's working. If you see request timed out, then something is wrong and you'll need to go back and double-check everything. 90 | 91 | 1. You can now open up your VNC viewer on the host PC and connect it to the Pi. When prompted for the remote host enter `10.0.0.1:1` and click **connect**. It could also be `10.0.0.1:0` depending on how you set it up in step 1. 92 | 93 | You'll be prompted for the password that you chose during step 1; after that you'll see the Pi desktop and will be able to get going with Scratch or whatever program you need. Remember that 3D games like Minecraft are not going to work using this method, as those draw their image directly to the local screen memory and will be ignored by VNC. You'll just see an empty window. 94 | -------------------------------------------------------------------------------- /vnc/zeroconf.md: -------------------------------------------------------------------------------- 1 | Guide on how to address your pi by name rather than IP 2 | -------------------------------------------------------------------------------- /wifi/README.md: -------------------------------------------------------------------------------- 1 | # Connecting a Raspberry Pi to Wifi 2 | 3 | - [Connecting to wifi](wifi.md) 4 | - [Connecting to wifi from the command line](wifi-cli.md) 5 | -------------------------------------------------------------------------------- /wifi/wifi-cli.md: -------------------------------------------------------------------------------- 1 | # Setting WiFi up via the command line 2 | 3 | 4 | This method is suitable if you do not have access to the graphical user interface normally used to set up WiFi on the Raspberry Pi. It is especailly suited for use with a serial console cable if you don't have access to a screen or wired Ethernet network. Also note that no additional software is required; everything you need is already included on the Raspberry Pi. 5 | 6 | ##Getting WiFi network details 7 | 8 | To scan for WiFi networks, use the command `sudo iwlist wlan0 scan`. This will list all available WiFi networks along with other useful information. Look out for: 9 | 10 | 1. `ESSID:"testing"`. This is the name of the WiFi network. 11 | 1. `IE: IEEE 802.11i/WPA2 Version 1`. This is the authentication used; in this case it is WPA2, the newer and more secure wireless standard which replaces WPA1. This guide should work for WPA or WPA2, but may not work for WPA2 enterprise; for WEP hex keys see the last example [here](http://netbsd.gw.com/cgi-bin/man-cgi?wpa_supplicant.conf+5+NetBSD-current). 12 | You will also need the password for the WiFi network. For most home routers this is located on a sticker on the back of the router. The ESSID (ssid) for the network in this case is `testing` and the password (psk) `testingPassword`. 13 | 14 | ##Adding the network details to the Raspberry Pi 15 | 16 | Open the `wpa-supplicant` configuration file in nano: 17 | 18 | `sudo nano /etc/wpa_supplicant/wpa_supplicant.conf` 19 | 20 | Go to the bottom of the file and add the following: 21 | 22 | ``` 23 | network={ 24 | ssid="The_ESSID_from_earlier" 25 | psk="Your_wifi_password" 26 | } 27 | ``` 28 | 29 | In the case of the example network, we would enter: 30 | 31 | ``` 32 | network={ 33 | ssid="testing" 34 | psk="testingPassword" 35 | } 36 | ``` 37 | 38 | Now save the file by pressing **ctrl+x** then **y**, then finally press **enter**. 39 | 40 | At this point, `wpa-supplicant` will normally notice a change has occurred within a few seconds, and it will try and connect to the network. If it does not, either manually restart the interface with `sudo ifdown wlan0` and `sudo ifup wlan0`, or reboot your Raspberry Pi with `sudo reboot`. 41 | 42 | You can verify if it has successfully connected using `ifconfig wlan0`. If the `inet addr` field has an address beside it, the Pi has connected to the network. If not, check your password and ESSID are correct. 43 | -------------------------------------------------------------------------------- /wifi/wifi.md: -------------------------------------------------------------------------------- 1 | ## Connecting to Wifi 2 | 3 | Wifi connections can be made via the network icon at the right-hand end of the menu bar. If a wi-fi dongle is plugged in, left-clicking this icon will bring up a list of available wi-fi networks, as shown. (If no networks are found, it will show the message `"No APs found - scanning..."` - just wait a few seconds without closing the menu, and it should find your network.) 4 | 5 | The icons on the right show whether a network is secured or not, and its signal strength. Click the network that you want to connect to; if it is secured, a dialog box is shown prompting you to enter the network key. 6 | 7 | Enter the key and press **OK**, then wait a couple of seconds. The network icon will flash briefly to show that a connection is being made; once it is ready, the icon stops flashing and shows the signal strength. 8 | --------------------------------------------------------------------------------