MiniPiiO Protoboard for Raspberry Pi

Courtesy of Gordon Henderson

When I was up at MakerFaireUK at Newcastle, I found this great product by one of the Newcastle Makerspace people called Tony Dixon of http://www.dtronixs.com.

Gordon already reviewed this last year but I missed it.  I think is a brilliant concept and I hope that Tony gets production ramped up (or farmed out to a UK supplier) so we can all get hold of them. (At a good price of course :) )  And I think that a bigger version that goes the whole length of the Raspberry Pi or just another little one tagged on would be great

Posted in Uncategorized | 2 Comments

Scratch GPIO V2 – Add on Modules/Boards

Part 4 (Previous Post – Stepper Motors)

Ultrasonic Sensor Boards
ultrasonic1pinSingle Pin Ultrasonics – if you connect a cheap 4 pin Ultrasonic Module as per this diagram, then you only need one spare GPIO pin to trigger it and receive the returned pulse

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.  Any pin can be used for this purpose and if you had several of them you could broadcast each of them in turn.

Gordon’s Ladder Board
This cheap and useful educational board (link) is an ideal introduction to getting kids to turns things on and off and saves having to wire up a breadboard to get going.  It does need someone to solder it together and if you don’t have that skill or tools – jsut give a shout out at a RaspberryJam and I’m sure someone will help you out :)

ld1If you’ve got one of these then just add this broadcast into your Green Flag event.  This tells the system that your using one and then you can use broadcasts such as:

ld2This script will simply turn all the LEDs out and then just switch on every other one.

ld3To vary the brightness of a LED, you can use a Power variable like this example:

 

The state of the switches can be accessed through the sensing blocks.ld4 Scroll down to the bottom and click on the arrow next to slider and you should see switch1 – 4 (they will only appear after you have  run a Green Flag event as above)

 

 

 

Posted in Uncategorized | 6 Comments

Scratch GPIO Version 2 – Using Stepper Motors

Part 3  (Previous Part- Using Motors)

Stepper Motor Control

WARNING: NO MOTOR SHOULD EVER BE CONNECTED DIRECTLY TO A RASPBERRY PI

However, if you would like to build a neat little vehicular robot then you can do so by connecting up a pair of cheap Stepper Motors through a couple of very cheap ULN2003s.

The cheap 5V steppers that are widely available (BY28) don’t turn very fast (maximum about 12 RPM) which actually makes them idea as beginners motors as your vehicle won’t run away during testing :)

These motors have 5 connections 1 for power and the rest to control the stepping.  (Their technical name is 5 Wire Unipolar Stepper Motor)

To use them in Scratch, you need to connect them up as followsStepper Motors_bb

StepperA must be connected (via a ULN2003 buffer of course) to pins 11,12,13 and 15 – Stepper B must be connected to pins 16,18,22 and 7.

With the cheap BY28 series – this means Orange,Yellow,Pink,Blue to 11,12,13 and 15 with the Red going to the 5V Pin2 or a separate motor 4.5-6V battery

stepabIn your Scratch program, you need to say that you are using Stepper motors instead of ordinary motors this is simply done by broadcasting StepperA and/or StepperB in your Green Flag code block.

You can then simply using variables MotorA and MotorB as before but this time they will each control 4 pins at a time.

The advantage of using stepper motors is that they can be just as easily stepped backwards as forwards.  So to make MotorA go backwards at full speed simply use

sma-100

Position Control
As well as treating the stepper as a continously rotating motor, you can simply tell the stepper to change its “position” by a number of steps.

e.g. To turn 500 steps (approx 180 degrees on my motors) use posa

Note the use of change and not set

Advanced Stepper Control

Stepper motors need a delay between each step – this is currently set to 0.003 secs.   You can control this value by using a variable called StepDelay.

You can also change the type of stepping mode from 2Coil (default value that gives maximum turning force) to 1Coil or HalfStep

Posted in Uncategorized | 3 Comments

Scratch GPIO Version 2 – Using Motors

Part 2 of 3 (Previous Part)

Motor Control
Note:
Connecting a motor directly to a GPIO pin WILL BREAK YOUR RASPBERRY PI!!! So don’t do it!

David Ferguson supplied the diagram below which shows a very cheap way of getting 2 motors connected safely to your Raspberry Pi. The chip used is a very cheap one(37 pence)  called a ULN2003. motor_pinout Wire pin11 of RPi to Pin1 on ULN2003 and then RPi pin12 to ULN2003 pin2 and finally RPi Pin6 (Gnd) connects to ULN Pin8

Then ULN2003 pin16 goes to one motor, ULN2003 pin15 goes to other motor.

The other connections on each motor are both connected to ULN Pin 9.

Finally connect a separate motor power supply (I use a 4xAA battery pack to give 6V) and CAREFULLY connect +ve to the ULN2003 Pin 9 and -ve to ULN2003 pin 8)

Once you’ve got your motor(s) SAFELY connected up, to control a motor, it is usually required to be able to not just switch it on or off but to vary its speed.

To do this in Scratch you can create 2 special variables called MotorA and MotorB and then assign these values from 0 (off) to 100 (fully on)

MotorA controls pin11 and MotorB controls pin12.

e.g To make MotorA go at half speed use  ma50

To make MotorA switch off use ma0

Although MotorA controls pin 11 and MotorB controls pin12,  you could have used variables called Motor11 and Motor12.  In fact all the pins on the Raspberry Pi can be controlled in this way – to use a motor on pin 13 you would simply crate a variable called Motor13 and set that from 0-100 to control the speed

(Remember – pins on the Raspberry Pi must NEVER be connected directly to motors – always go through some sort of buffer electronics)

Power
As well as using the term “Motor” you can use the word “Power” instead.  Using “Power” makes more sense if you are just controlling the brightness of an LED. To make an LED go from off to full brightness try this

spower11

Part 3 – using Stepper Motors

Posted in Uncategorized | 2 Comments

Scratch GPIO Version 2 – Introduction for Beginners

Last change:  30Apr13 1715  Version Release 2.1

Scratch Controlling the GPIO Pins on a Raspberry Pi
(Version 2.1)

This post is intended to make it as Simple as Pi to get up and running and make your Raspberry Pi control some lights and small motors and to respond to switches and sensors.

Minimum Requirements – a Raspberry Pi with Raspbian installed (a working internet connection is very handy but not required)  a breadboard, some Light Emitting Diodes (LEDs), some resistors and some wire connectors. Total cost £5-£10.

Blue italics are extra information for those who like to understand things a bit more - Pink italics are for the more advanced users and  can be completely ignored by normal users

How to get a Raspberry Pi to control the GPIO Pins using Scratch
—————————————————————
Your Raspberry Pi needs to be connected to the internet to install the software but not needed to run ScratchGPIO2.

Copy the text below ( left click just before the s of sudo and drag right until all the text in the line, up to and including gpio.sh, 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 run it to download the installer.

sudo wget https://dl.dropbox.com/s/oql4qzm8jlnsbeb/install_scratch_gpio2.sh -O /boot/install_scratch_gpio2.sh

using Raspberry Pi as a normal user, then just type (or copy and paste as before)

sudo /boot/install_scratch_gpio2.sh

(If logged in as a different user, then  type sudo /boot/install_scratch_gpio2.sh yourusername)

This will install all the necessary extra software and some simple examples.

(If you do not have internet on your Pi then, put your SD card into a card reader and try using your browser to right-click and save the script direct to your SD card and then put it back into you Pi and run the second instruction)

Connecting Components Up
———————————————————————
EXTREME care should be taken when connecting hardware to the GPIO pins. You can cause your Pi to die by connecting the wrong things together – only do this if your confident of your ability to follow instructions correctly :)
AT A MINIMUM - get a breadboard and use some female-male 0.1 leads (available from lots of on-line suppliers or your local Maplin shop)

Check out GPIO pin guides to make sure you know what pins are what.

Wire up Pin 1 (3.3V) to (at least) a 330ohm resistor – connect that resistor to the long lead of an LED and then connect other end of LED to Pin 6 (0V).

It should light up. If it doesn’t try reversing your LED.

Now move the lead from Pin 6 to Pin 11.

Run the special Scratch icon (Scratch GPIO) on your desktop.
(It is actually a completely normal version of Scratch, it just runs a little Python background program as well that handles communications between Scratch and the GPIO and automatically enables Scratch’s Remote Sensor Connections(RSC))

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.

blink11Your LED should now blink on for 1 second and off for 2 seconds – see trouble shooting if this doesn’t happen.

What more can I do with Scratch and the GPIO
As it comes, you can control six pins as outputs (Pins 11,12,13,15,16 and 18) and treat all the rest as simple inputs (22,7,3,5,24,26,19,21,23,8 and 10)

(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

pinson

along with the corresponding pin off messages.

pinsoff

You can also say allonoff

And you can replace the word  on with high and replace off with low if you want to talk in pure logic levels.

You can combine message together to make a single broadcast so to turn Pin11 and Pin13 on and all others off you can sayjoined

oroff11on13on

Alternatively you can use the pinpattern broadcast to achieve the same result e.g:bpinpattern2This will also set just pins 11 and 13 on.

Inputs
To check an input, you should go into the Sensing block and click on the word “slider” at the bottom and you’ll notice that you have pins 22,7,3,5,24,26,19,21,23,8 and 10.

inputs

If you connect a switch to one of these pins (through a resistor don’t forget) to OV, then you can detect when the switch is open or closed. The inputs will normally read 1 and go to 0 when they are connected (through a resistor) to ground. Click on the checkbox next to pin7 and try it out.

Using variables instead of broadcasts

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

For example: create a global variable called pin11

To make pin11 go on or off  use

vonoff

On can be replaced with high or 1 and off can be replaced with low or 0 so that you can use whatever logic scheme you’d like.

To set all outputs to on or off usevallonoff

To use a “bit-pattern” to set/unset multiple outputs simultaneously usevpp

(this will set Pin 11 , Pin 13,  Pin 16  and Pin 18 on and Pins 12 and 15  off)

Note – currently there is an unfortunate “bug” in Scratch in that it remembers variable states and only sends changes out.    Even when you press the Green Flag, it will not send the state of all the variables out, it will only send them when a variable changes. I recommend (nay insist even!) setting any gpio variables to an invalid value – say a full-stop and then to their initial state in a Green Flag start-up script.

vbug3

Need more Pins as outputs?
If you need more than 6 pins to be outputs  then, for example, you can use

broadcast config22out

to change pin22 from being an input to being an output.  All the pins can be re-configured this way.

I for some reason,  you need more input pins you can use
broadcast config11in

to change pin 11 from an output to an input

Part 2 – using Motors and varying brightness of LEDs

Troubleshooting
To test if the software necessary to control the GPIO is correctly installed open a LXTerminal session and type

sudo python blink11.py

If this doesn’t give an error but doesn’t make a LED on Pin 11 blink then we have real problems Houston :(

Try connecting the lead going to Pin 11 back to Pin 1 to make sure the LED lights up then just in case you have a loose connection.

Posted in Uncategorized | 61 Comments

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

Posted in Uncategorized | 29 Comments

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. http://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

Posted in Uncategorized | 3 Comments