At this post here, a demo of how to blink a Led with scratch on Raspberry will be explained. Although this post is for beginners, it is suggested to have a previous experience with programming in general and programming by python and Scratch in specific.
Learn Python – Code Academy
Step 01 – Boot you Raspberry Pi
- Login to your raspberry board using the following defaults:
- Username: pi
- Password: Raspberry
- At the command prompt write startx. This action will start the XWindows on the Raspbian.
Step 02 – Install GPIO
- Open a terminal and write there: sudo apt-get install python-dev python-rpi.gpio.
Step 03 – Write a demo program with python to test the GPIO functionality
- At terminal write: sudo nano /home/pi/Desktop/RPiLED.py, this will open a text editor and will create a file RPiLED.py.
- At Nano editor write the following python code:
import RPi.GPIO as GPIO import time
for i in range(0,50):
Exit the nano editor by pressing CTRL+X, Y, and Enter. Right now, running RPiLED.py will cause the LED to blink 50 times.
Step 04 – Install Scratch GPIO
sudo bash install_scratchgpio5.sh
Step 05 – Load Scratch and write a demo program that Blinks a Led
- Create the following program at Scratch and run it, notice the broadcast command:
Available GPIO Commands and Pins
GPIO Pins controlled by Scratch GPIO:
The current scratch_gpio_handler.py has the GPIO pins fixed to the following inputs and outputs. The pin numbers given, are the pins as counted on the P1 GPIO header itself.
||Turns pin X ON
||Turns pin X OFF
||Turns all pins ON
||Turns all pins OFF
||Sets each pin ON or OFF depending on 1 or 0 [21,18,16,15,13,12,11]
You will need to see SimpleSi’s blog post for more information.
||Runs motor X (A = pin11, B = pin12)
||Trigger input on pin23, X = echo output on an input pin
To use the input pins, see the blog pages for more information.