Scratch GPIO Development

This blog entry is for me to provide feedback on what’s happening in developing my Scratch GPIO hander set-up.

This code WILL PROBABLY NOT be compatible with the 1.x release and is intended for experimenters and helpers.

Its for both coders with suggestions and importantly users (particularly teachers/educators/parents with kids) to provide input into what the handler does and the syntax used to do it.

My development code is available on Git Hub https://github.com/cymplecy/scratch_gpio

I’d welcome collaborators who share my vision to enable 10 year olds and younger to make things flash/beep/turn/step using a Raspberry Pi and some cheap components. This project is NEVER going to be an I2C bus controller 🙂  (But as Sean says – never say never again!)

I’ve created a ScratchGPIO login on the Scratch Site so that we can all start to upload and share Scratch GPIO code – I want to share the password with any educator who’d can contribute examples and lessons – just contact me for it 🙂

Changes made from 1.x codebase
All pins now default to inputs until addressed as outputs and then they are switched dynamically between digital, PWM or Stepper Motor mode as needed

Any pin can now be used for DC motor or variable brightnes LED using PWM as I now use the a threaded libary PyzPWM

(Although I expect to start using the PWM within RPi.GPIO now that Ben Croston has added it in 🙂 )

PWM output is controlled by variables starting with “Power” e.g Set power11 to 50  will set pin 11 to a 50% duty cycle and effectively give an average 1.65V instead of 3.3V  (MotorA/B on pins11/12 retained for simpler syntax for younger pupils)

“Power” is more generic and can be applied even when just varying a LEDS brightness (prompting for this change came from Aaron Shaw’s RGB LED MagPi article http://issuu.com/themagpi/docs/issue10final Page 26)

PinPattern usage has been removed at this time as not compatible with the concept of any pin being input or output – needs thinking about how to re-introduce.

Single Pin Ultrasonics – if you connect an Ultrasonic Module as per this diagram, then we only need one GPIO pin to trigger it and receive the returned pulse

ultrasonic1pin

So now you simply use it (assuming connected to pin 23)  use broadcast sonar23 and then just use the sensor item sonar23 to get the distance measured in cm

Stepper motors
Currently got 5 wire unipolar steppers addressed using “StepperX” broadcast to tell Scratch that we’ve connected them . “StepperA” means one connected to Pins 11,12,13 and 15, “StepperB” means one connected to Pins 16,18,22 and 7.  They are then controlled using normal MotorA or MotorB variables to control their speed but since they are bi-directional, you can use values of -100 to 100.

Also I have syntax for saying stepping a finite number of steps.  You need to broadcast a “StepperA” or “StepperB” to initialise as above but then change (not set) variables PositionA or  PositionB for the numbers of steps you wish each stepper to turn ( using change and not set overcomes a bug/feature of Scratch itself)

Tasks currently in progress

Begining to document

Tasks to be done next but not yet in progress

Add back in PinPattern in some fashion to allow multiple pinout changes in one command

Make sure AllOn /Alloff can still be used

Add global Invert broadcast that inverts all high/on/1 commands to pin being set to 0V and all low/off/0 to set a pin to 3.3V (Needed if dealing with components that need to be dragged to 0V to turn them on)

Add in code to deal with H bridge DC motors  (I’d need to build a bot with one first 🙂 )

Tasks just a gleam in my eye
Add in Servo control (so I can make robot arms wave around)

Plugin in modules for specific hardware (e.g Raspberry Ladder Board, PiBorg, H-Bridge Motors,BerryBoard) etc

Manchester Jamboree – Intro to Robotics Session

On the 9th March, the first every Jamboree was held in Manchester and myself Jason Barnett (@boeeerb) http://www.boeeerb.co.uk/ and Ben Smith (@ManchesterBudo) ran a 45 minute session showing people how to easily interface a Raspberry Pi to a £5 breadboard setup with some LEDs and a switch.

CPC Components kindly provided all the hardware for the day and we had 16 RPi setup and managed to cram 32 people into the session.

We showed them (and they all then did) how to make a simple set of Traffic Lights and have them go through the Green-Amber-Red-Red and Amber -Green sequqnce and how the RPi could detect if a switch was open or shut.

All of this was done with a normal RPi running my Scratch GPIO package. https://cymplecy.wordpress.com/2012/08/26/scratch-controlling-the-gpio-on-a-raspberrypi/

We explained how as well as switching things off and on, you can use an RPi to vary the speed of a motor by simply adding in a 37p IC (ULN2003) and Jason showed everyone what you can acheive with a bit more time and effort 🙂


The link to our presentation is here https://docs.google.com/presentation/d/1JqwOkrtjOu6y-uS2w3M1IPbosq6vlAEgl_M7CJqMcJ4/

Please tweet any of us of leave comments here
@cycmplecy (me) @boeeerb (Jason-Master Roboteer) @ManchesterBudo (Proper Teacher)

My email is simplecy at googlemail dot com