51
ScratchGPIO, Raspberry Pi & BerryClip KS2 Starter Guide to Physical Computing Sense and control the physical world using computer programs running on the Raspberry Pi. Here you will learn how easy it is to interact with the outside world, and how this opens up limitless possibilities for exploration. A wide range of sensors, motors, robots and USB devices can be connected. https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot /

ScratchGPIO, Raspberry Pi & BerryClip

Embed Size (px)

Citation preview

ScratchGPIO, Raspberry Pi & BerryClipKS2 Starter Guide to Physical ComputingSense and control the physical world using computer programs running on the Raspberry Pi. Here you will learn how easy it is to interact with the outside world, and how this opens up limitless possibilities for exploration. A wide range of sensors, motors, robots and USB devices can be connected.https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/

Getting Startedhttps://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/getting_started/

https://www.raspberrypi.org/guides/teachers/

https://www.raspberrypi.org/resources/teach/

Desirable features Interactive Design

Scratch and BerryCliphttp://www.rpischool.org.uk/?p=114

A simple way for primary school aged children to control lights, a buzzer and use a physical button with their scratch programs.

++BerryClip

Raspberry PiBerryClip plugs directly onto the Raspberry Pis GPIO header and provides 6 coloured LEDs, 1 Buzzer, 2 Switches and a 13 pin header. It can be controlled using any programming languagethat can manipulate the GPIO pins and this includes Python and C.GPIO

ScratchGPIO: How to install on your Raspberry PiA modified version of Scratch called ScratchGPIO is needed to be able to connect to the BerryClip.The following are instructions to install ScratchGPIO7 software on Raspberry Pi

With Raspberry Pi connected to InternetCopy the text below ( left click just before the s of sudo and drag right until all the text in the line as been selected) then right-click and select copy. Open up an LX Terminal window and select Edit and the Paste that into an LX Terminal window and press Enter it to download the installer.wget http://bit.ly/1wxrqdp-O isgh7.shOnce the installer has been downloaded then just type (or copy and paste the text below as before)sudo bash isgh7.shand press Enter(If logged in as a different user to standard pi, then typesudo bash isgh7.sh yourusername)This will install all the necessary extra software and some simple examples.

http://simplesi.net/scratchgpio/scratch-raspberrypi-gpio/

With Raspberry Pi not connected to Internet.

Power down you Pi and put the SD card into another computer and download this file

http://bit.ly/1wxrqdp

and copy it to your SD card.

Put the card back into your Pi and then open up an LX Terminal window and type the following

sudo bash /boot/install_scratchgpio7.sh

(If logged in as a different user to standard pi, then typesudo bash /boot/install_scratchgpio6.shyourusername) This will install all the necessary extra software and some simple examples.

The installer will create 2 desktop icons ScratchGPIO7 which is used for beginners using simple circuits and ScratchGPIO 7Plus which is used with a lot of add-on boards.

Continue onto1st Project

http://simplesi.net/scratchgpio/scratchgpio-1st-project/

ScratchGPIO6 was the previous version if you need a copy of it then clickhere

http://cymplecy.github.io/scratch_gpio/

Raspberry pi installationhttps://www.raspberrypi.org/documentation/installation/noobs.md

Use Broadcast to control lightsScratchGPIORun the special Scratch icon (ScratchGPIO) on your desktop.To test out control from Scratch, click on File then Open and then click on the My Projects button and select blink11 and click on OK. Once the project opens, just click on the OK to enable Remote Sensor Connections. To run the script just click on the Green Flag.

Your LED should now blink on for 1 second and off for 2 seconds(Play Video below to see)

Turn on all the BerryClip LED lights

The LEDs have a Hardware Reference: Use this reference in ScratchGPIO: or = LED on or = LED off(All the LEDs are on)(GPIO pin numbers/ordering do not follow anything that makes sense to most people so you just have to go with the seemingly random numbering arrangement)

As you can see in the blink11 script , you can simply use a broadcast message telling Pins to go on or off (Up to 3.3V and down to 0V) The valid messages are along with the corresponding pin off messages.

You can also say And you can replace the wordonwithhighand replaceoffwith lowif you want to talk in pure logic levels.

Play video:

Using variables instead of broadcasts

For more advanced Scratchers, you can use variables instead (or as well as broadcast messages)

A broadcast allows a signal to everything with the When I Receive to be broadcasted, and it allows different objects to do different things all at the same time.

A custom block is a Shortcut to a command. For example, pressing Ctrl+X cuts something much like a string of custom commands created by you using custom blocks.

Custom Block - Allows you to create a new block which you can use in the sprite in which it is defined

Broadcast - Sends an event so all the corresponding when I receive scripts will start running

Edit: OK a broadcast can be used to replace a custom block. The custom block makes things much easier by having parameters. The custom block also has run without screen refresh which broadcast cannot do.For example: create a global variable called pin11To make pin11 go on or off, set it to; 1 = on0= off

Variables to control the GPIOs (General Purpose In and Out)

Hardware ReferenceThe following list shows the mapping between the components, the header pins and the GPIO references :LED 1 - Pin 7 - GPIO4 LED 2 - Pin 11 - GPIO17 LED 3 - Pin 15 - GPIO22 LED 4 - Pin 19 - GPIO10 LED 5 - Pin 21 - GPIO9 LED 6 - Pin 23 - GPIO11 Buzzer - Pin 24 - GPIO8 Switch - Pin 26 - GPIO7

Make a variable for each of the LED lights.

For example: To control the first RED LED (LED 1) the Hardware Reference for LED-1 is Pin 7.

Go to Variables. Click on Make a variable call it pin7Drag the set pin7 to 0 block to the Sprite Script.Create variables like this for all the LEDs. Use the Hardware Reference as a guide.

To turn a LED on set it to 1To turn it off set it to 0

Make LED light patternOnce you know how to turn on an off the LEDs you can easily start to write your own sequences.

This piece of script when I press space will create a looping light cycle.

Try your own combinations of flashing lightsUse either Broadcast or Variable method to create your own light patterns, turning on and off the individual LEDs. Which method is easier?Use wait block to vary the length of time a light stays on. Use forever block to loop the pattern.Save your work.

Traffic lights sequence (Simple)

Lights go off in pairs in sequence like traffic lights

Traffic Lights Sequence

When flag is clicked it goes to green. Press Space to start sequence. Print PCB?

GPIO Example: control LEDs using keyboard

Ways to control LEDs using keyboard input with either broadcast or a variable.

GPIO Game BerryClip

A simple game that uses Scratch GPIO extensions to play. The 3 LEDs display health/ lives of the catUse buttons or arrows to move the cat up and down to avoid Rex. Be careful, he gets faster!

LED Health Bars -Raspberry Pi, BerryClip, ScratchGPIO

http://computers.tutsplus.com/tutorials/learn-how-to-use-raspberry-pi-gpio-pins-with-scratch--mac-59941

Random Crazy Lights GPIO

Disco lightshttp://pdwhomeautomation.blogspot.co.uk/2013/04/raspberry-pi-scratch-gpio-disco-lights.html

Allpins on/offTo set all outputs to on or off use

For a complete list of all commands that ScratchGPIO understands seehere.

Robot Antenna project Raspberry Pi, Scratch and Breadboard

https://www.raspberrypi.org/learning/getting-started-with-scratch/worksheet/

Robot on Scratch linked with Real robot

Pi, Breadboard, Scratch

Pi, Breadboard, Scratch

SWEET SHOP REACTION GAME https://www.raspberrypi.org/learning/reaction-game/

http://www.dmict.co.uk/programming-using-a-raspberry-pi-berryclip-and-scratchgpio/

The 3 projects are:1. Creating a scanning LED sequence (Think KITTs lights from the TV show Knight Rider).2. Creating a Morse code generator using the Berryclips buzzer.3. Creating a working die using the 6 LEDs that is triggered by the on-board switch.A guide for creating these mini-projects can by downloaded from the link below, the Scratch project files can be downloaded for modification frommy Scratch pageand demos of the 3 projects are embeded below.3 Raspberry Pi Berryclip mini-projects documentation

Simplesi website have the basicshttp://simplesi.net/scratchgpio/scratchgpio-1st-project/

Im using this website as reference but have changed it slightly as Im using the BerryClip and not a Breadboard.

1st BerryClip project Control the Traffic Lights Manually

Remote Sensor Connections (RSC

Scratch uses thisRSC feature to talk to external devices over a network. To enable this in scratch, go the sensor blocks, then right click on either of the last two blocks to find a menu item called Enable remote sensor connection. Your scratch program will remember this setting when you save your scratch file. RSC has two main types of communication:Broadcast messagesThese are simple messages that can be sent and received over RSC. e.g.led1onSensor-updatesThese are special messages that pass a value associated to a changing sensor input or variable. These sensor updates are only sent when a variable or sensors value has changed. The berryclip push button is a simple sensor, when pressed a value of 1 is sent, on releasing the button a value of 0 is sent.

You should at this point be using ScratchGPIO on your Raspberry Pi with the BerryClip attached to it.

Now you must enable ScratchGPIO to talk to the BerryClip;

In Scratch, go to the sensor block, then right click on either of the last two blocks to find a menu item called Enable remote sensor connection.

SCRATCH INTERFACE DEVICE (SID

use Scratch on a desktop/laptop PC and get it to remotely control the GPIO pins via a WiFi connection.

http://simplesi.net/sidrpi/

Berry Bookies A Horse Racing Game For The BerryClip

http://www.raspberrypi-spy.co.uk/2014/01/berry-bookies-a-horse-racing-game-for-the-berryclip/

Raspberry Pi and Berry Cliphttp://www.rpischool.org.uk/?p=114

BERRYCLIP PLUS INSTRUCTIONSThe BerryClip+ is an enhanced version of the popular BerryClip add-on board. It is a simple, cheap and easy to use addition to the Raspberry Pi. It plugs directly onto the Pis GPIO header and provides 6 coloured LEDs, 1 Buzzer, 2 Switches and a 13 pin header. It can be controlled using any programming languagethat can manipulate the GPIO pins and this includes Python and C.The 13 pin header allows additional components and sensors to be added.The kit includes the following parts : 1 PCB 1 26-way header 1 13-way header 2 Red LEDs 2 Yellow LEDs 2 Green LEDs 1 Buzzer 2 Switches 6 330 ohm resistors 2 1K ohm resistors 2 10K ohm resistors 1 Rubber bumper

Pin Pattern

To use a bit-pattern to set/unset multiple outputs simultaneously use (this will set Pin 11 , Pin 13, Pin 16 and Pin 18 on and Pins 12 and 15 off)

25 fun things to do with a Raspberry Pi

http://www.cnet.com/uk/how-to/25-fun-things-to-do-with-a-raspberry-pi/https://pihw.wordpress.com/lessons/rgb-led-lessons/rgb-led-lesson-2-scratch-gpio-getting-started/http://www.ncl.ac.uk/computing/outreach/resources/primary/primary-conf-2014/resources/w2.4.pdfhttp://www.adafruit.com/

VGA Adaptorhttp://www.bloglovin.com/blogs/raspberry-pi-spy-5426543?post=4101956151&group=0&frame_type=a&context=&context_ids=&blog=5426543&frame=1&click=0&user=0&viewer=true

Broadcast v custom block

Custom build an enclosure digital fabrication

https://github.com/diy-electronics/raspberrypi-b-plus-case

How To Create A Raspberry Pi Video Capture Unit Part 1

http://www.raspberrypi-spy.co.uk/2014/11/how-to-create-a-raspberry-pi-video-capture-unit-part-1/

http://uk.rs-online.com/web/b/raspberry-pi/?cm_mmc=UK-PPC-0914-_-google-_-2_UK_EN_LS_Raspberry_Pi_BMM-_-b7b28a6f-48dd-4d1c-91b5-51884f7b1082&gclid=CIbki8_YxsgCFQUewwodaHQHFA

http://www.bitsbox.co.uk/

Where to buy a BerryClipI bought my BerryClip + (the '+' version is red and has an extra switch button) from DAwn Robotics:

http://www.dawnrobotics.co.uk/brands/Raspberry-Pi-Spy.html

Also recommended outlets are:

https://www.modmypi.com/search/?search=berryclip

and:

https://www.m.nu/berryclip-addon-p-767.html

Berry Clip and more Pi Shoppinghttp://www.modmypi.com/raspberry-pi

Websites

http://www.raspberrypi-spy.co.uk/

Melting ice cube game

Programming for GCSE

Topic 17: Comparing Scratch and Python http://scratch.mit.edu/

William Marsh School of Electronic Engineering and Computer Science Queen Mary University of London

Aims

Compare Scratch and Python Show conceptual links Consider transition from Scratch to Python

Scratch has recently introduced Scratch 2.0 which is used online but is not yet (July 2013) available for offline use. These slides only cover Scratch 1.4

SYLLABUS AND TEACHING ISSUES

Scratch is usable as one language in GCSE

OCR GCSE Programming Language

There are no restrictions on the programming language chosen providing it has the features indicated within the specification. It is anticipated that the work for this unit will follow on from the programming elements in unit A451 and that the same programming language may, therefore, be appropriate. The tasks are set so that they can be completed in a wide range of languages including those frequently used to teach programming techniques including all forms of BASIC and C. There may be a question which states that the work must be completed within a specific package, if this is the case, that package will be available for free and legal download, for example SCRATCH from MIT and ALICE from Carnegie.

Teaching Issue

Scratch is fun, but how much is learnt? Problem solving Logical reasoning Programming concepts

How to make the links from Scratch to Python clear?

SCRATCH & PYTHON

x = 1 while x 22 :! print(var2, "is large")!else:! print("The sum is", var1 + var2)!

Introduce Assignment

Exploit different syntax to emphasise that assignment is not equality Python

Means the same as:

Total = Total + ItemCost * Number!

Problems for Scratch & Python

Many simple exercises can be set in Scratch and transliterated into

Python

var1 = int(input("First value? "))!var2 = int(input("Second value? "))!if var1 < var2:! print(var2, "is the larger")!else:! print(var1, "is the larger")!

SUMMARY

Summary

Scratch may be simple but all programming concepts present Teach Scratch or Python with same learning

outcomes Basic programming concepts Specification and design Decomposition Testing

Emphasise how ideas transfer

raspberrypi-b-plus-case-master/README.mdRaspberry Pi Model B+ Case==========================

This is a simple acrylic lasercut case for the Raspberry Pi Model B+.

![top](images/top.jpg)

Build Instructions------------------

![raspberrypi-b-plus-case](images/raspberrypi-b-plus-case.png)

green:vector engraving black:raster engraving red:cut

Detailed instructions coming soon.

BOM---

- 3mm acryl- 4x M2.5 10mm screws- 4x M2.5 screw nuts

Visicut color-mapping---------------------

If you use Visicut (https://github.com/t-oster/VisiCut) you can find a working color-mapping under [visicut/raspberrypi-b-plus-case.xml](visicut/raspberrypi-b-plus-case.xml)

License-------


raspberrypi-b-plus-case by https://github.com/diy-electronics/raspberrypi-b-plus-case is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Raspberry Pi is a trademark of the Raspberry Pi Foundation

Based on the [Adafruit Pi Box - Enclosure for Raspberry Pi Model A or B](https://www.adafruit.com/products/859)

raspberrypi-b-plus-case-master/concept/raspberrypi-b-plus-case-concept-connectors.svg image/svg+xml usb HDMI LAN USB USB Raspberry Pi Model B+ Case connectors by diy-electronics https://github.com/diy-electronics/raspberrypi-b-plus-case License: CC BY-SA 4.0 Raspberry Pi is a trademark of the Raspberry Pi Foundation

raspberrypi-b-plus-case-master/concept/raspberrypi-b-plus-case-concept.svg image/svg+xml Raspberry Pi Model B+ Case Concept design by diy-electronics https://github.com/diy-electronics/raspberrypi-b-plus-case License: CC BY-SA 4.0 vector engraving raster engraving cut reference line Raspberry Pi is a trademark of the Raspberry Pi Foundation Top Spacer Bottom

raspberrypi-b-plus-case-master/images/back.jpg

raspberrypi-b-plus-case-master/images/bottom.jpg

raspberrypi-b-plus-case-master/images/front.jpg

raspberrypi-b-plus-case-master/images/left.jpg

raspberrypi-b-plus-case-master/images/raspberrypi-b-plus-case.png

raspberrypi-b-plus-case-master/images/right.jpg

raspberrypi-b-plus-case-master/images/top.jpg

raspberrypi-b-plus-case-master/raspberrypi-b-plus-case.pdf

raspberrypi-b-plus-case-master/raspberrypi-b-plus-case.svg image/svg+xml

raspberrypi-b-plus-case-master/visicut/raspberrypi-b-plus-case.xml 4 1 false false Color 0 0 255 255 false 500.0 Engrave engrave false 0 99 1 false false Color 0 255 0 255 false 500.0 Engrave along lines mark NEAREST false false 1.0 1 false false Color 255 0 0 255 false 500.0 Cut through the material cut NEAREST false true 0.7 Cut red, engrave all other colors, ignore blue, mark green raspberrypi-b-plus-case