simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Scratch controlling the real world with a RaspberryPi

Mon Sep 03, 2012 10:28 am

WARNING - because your end up attaching things to your RaspberryPi there is a real possibility that a wiring error could damage your PI! - but if you follow the instructions then you will fine

Normally. to get Scratch controlling real-world devices, you normally have to spend money on someething ike a Lego WeDo kit (£70) or use a modified version of Scratch to control an Arduino.

My project lets you use the normal Scratch that comes with your RaspberryPi and basically just connect some LEDs and switches or light sensors etc on a low cost breadboard so that you can start experimenting for just a few pounds.

I've got an article http://cymplecy.wordpress.com/2012/08/2 ... spberrypi/ that has all the info needed and the extra little bit of software required to interface between Scratch and the input/output pins on your RaspberryPi.

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Scratch controlling the real world with a RaspberryPi

Tue Sep 04, 2012 9:06 pm

Updated now to version 1.1 which will work even on bright clean 2012-08-16 images :)

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Scratch controlling the real world with a RaspberryPi

Sun Sep 09, 2012 9:20 pm

Updated to 1.1a - fixed the "need to run it twice" bug that makes you think you can't double-click properly.
Should launch fine now even from a reboot :)

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

dmurday
Posts: 14
Joined: Sat Aug 25, 2012 10:35 am

Re: Scratch controlling the real world with a RaspberryPi

Fri Sep 14, 2012 10:54 am

This is great and it works fine.

On scratch opening I get a message "Could not read: /home/pi/Scratch/rsc.sb" - is this something you are aware of?

However, it all works fine after that.

Regards,

David

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Scratch controlling the real world with a RaspberryPi

Fri Sep 14, 2012 9:43 pm

On scratch opening I get a message "Could not read: /home/pi/Scratch/rsc.sb" - is this something you are aware of?
Well spotted :)
In the original distribution Scratch projects were saved in /home/pi/Scratch and not "/home/pi/Documents/Scratch Projects" as is the setting in the latest Distribution.

I've altered the script that the ScratchGPIO desktop shortcut calls - if you get a chance - please download V1.1b and see if that cures it for you :)

regards

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Scratch controlling the real world with a RaspberryPi

Fri Sep 14, 2012 10:30 pm

V1.1c up which fixes a permissions problem that only occurs if you ran ScratchGPIO before running Scratch for the 1st time on a brand new image - wouldn't affect most people :)

Simon

PS Software maint is far far far harder that creating it in the first place :)
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Scratch controlling the real world with a RaspberryPi

Sun Sep 23, 2012 1:26 pm

Following on with some real customer testing (William at Wigan RaspberryJam) with a bunch of teachers (and me :) ) watching it became apparent that we should use

Code: Select all

Broadcast Pin11on
and
Broadcast Pin11off
type statements instead of

Code: Select all

Broadcast Pin11high
and
Broadcast Pin11low
Also, for teachers/scratchers who want to use variables I'm going to make the handler respond to variables being set to on and off as well as 1 and 0.

I'm also hoping to have the handler work transparently with whatever revision board is available once the clever people who write the GPIO c programs have weaved their magic :)

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Scratch controlling the real world with a RaspberryPi

Sun Sep 23, 2012 11:34 pm

From my blog
Updated to V1.2 – Pin 13 should now work again on Revision 2 boards and the default broadcast sysntax is now to use things like pin11on and pin12off instead of using high and low although the old syntax will still work in this version. Also the gpio variable usuage can use on/off and high/low as well as 1/0 as before. If you have a revision 2 board and Pin13 doesn’t work – please lete me know
Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Scratch controlling the real world with a RaspberryPi

Sat Oct 13, 2012 10:09 pm

OK - now updated to V1.3 with some fairly major improvements and changes

You can now use pins 11,12,13,15,16,18,21,23 as outputs and 7,8,10,19,22,24,26 as inputs so that should let people with mega-ideas get on with things :)

Also, I've implented a simple software PWM control over Pins11 and 12 accessible through using Scratch global variables MotorA and MotorB. This allows an RPi mounted on a robot to be programmed to control two motors :)

Finally, the option of using Broadom GPIO numbering scheme has been removed - I think when people are wiring up pins to breadboard, they are counting pins numbers and not looking them up on a datasheet somewhere. You can still use variables instead of broadcasts but you need to create pin11, pin12, pin13 etc variables instead of gpioXX variables.

See blog docs for full syntax options
http://cymplecy.wordpress.com/2012/08/2 ... spberrypi/
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Scratch controlling the real world with a RaspberryPi

Sun Oct 14, 2012 8:54 pm

Bug fix version 1.3a now up - slight issue with the inputs now fixed
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

sdmeijer
Posts: 25
Joined: Thu Jun 21, 2012 6:13 pm

Re: Scratch controlling the real world with a RaspberryPi

Mon Oct 29, 2012 9:27 pm

simplesi wrote:If you have a revision 2 board and Pin13 doesn’t work – please let me know
I can't get Pin13 working on a Rev2-board. I've updated your script this evening.
N.B. I also posted this on your website.

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Scratch controlling the real world with a RaspberryPi

Tue Oct 30, 2012 9:49 am

Sorry - been away for a few days.

Quick fix should be to just run LX terminal and type

Code: Select all

sudo apt-get update
and when that finishes

Code: Select all

sudo apt-get install python-rpi.gpio
to update to the latest GPIO python library

Let me know if that fixes things please :)

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

sdmeijer
Posts: 25
Joined: Thu Jun 21, 2012 6:13 pm

Re: Scratch controlling the real world with a RaspberryPi

Tue Oct 30, 2012 10:47 am

simplesi wrote:Let me know if that fixes things please :)
That fixed it, thanks!

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Scratch controlling the real world with a RaspberryPi

Tue Oct 30, 2012 2:45 pm

Ta - I used to include the RPi.GPIO library but once it started being included in the default Raspbian image, I removed it. You probably had an older base image (or something else downgraded your version).

I'm trying to make sure I can cope with such a situation automatically in future - thanks for your feedback.

If you have any suggestions or find other problems - let me me know.

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

davidmam
Posts: 101
Joined: Tue Dec 06, 2011 4:13 pm

Re: Scratch controlling the real world with a RaspberryPi

Sun Nov 25, 2012 7:38 pm

Thanks for your hard work on this. My son (10) tried Scratch with GPIO for the first time and loved it. He did most of the work once he had worked out what the various bits did.

Short video here:

http://www.flickr.com/photos/davidmam/8 ... hotostream

bantammenace2012
Posts: 122
Joined: Mon May 28, 2012 12:18 pm

Re: Scratch controlling the real world with a RaspberryPi

Thu Nov 29, 2012 6:17 pm

I have a RPi with (2012-09-18)-wheezy-raspbian on it.
I know next to nothing about Linux.
I know even less about GPIO.
The last time I did anything remotely resembling electronics was at school 34 years ago. Coincidentally the same year as I passed my Computer Studies O-level.
I have a 10 year old child.
I have a Lego WeDo USB hub and two Lego WeDo motors that attach to the hub.
I don't have a blog, a web page or a twitter account. I don't know how to make a video or upload it to YouTube. I don't have a soldering iron either.
Not very promising is it ?
But I think I have something that may be of use to others who are following this thread,
I wanted to use Scratch on the RPi to drive the 2 WeDo motors independently, so here's what I did.
I read the forums, looked at YouTube and Googled.
I downloaded this image created by Kazuhiro Abe and followed the steps he kindly sent me
http://squeakland.jp/abee/tmp/Controlli ... i.image.gz
My apologies if these links don't appear as they should but I don't know how get them looking as one would expect.
For anyone whose interested here they are the steps:
1. I copied the file above onto my windows PC
2. I started my RPi making sure it was connected to the internet, in my case via ethernet cable. I made a note of the ip address of my RPi as it came up on the screen.
3. I used WinSCP to connect to my RPi and to copy the file into the /home/pi directory (?)
The last part of
http://www.youtube.com/watch?feature=pl ... n-9FDo_J3M
covers how to do this.
4. Startx on the RPi, open the file manager accessory. Extract the contents of the ControllingTwoMotorsForRasPi.image.gz file to /home/pi
The file is called ControllingTwoMotorsForRasPi.image
5. Browse to /usr/bin and copy the file called scratch
6. browse back to /home/pi and paste the file
7. Rename the file to ControllingTwoMotorsForRasPi
8. Open the file and do the following edit
before:
IMAGE="/usr/share/scratch/Scratch.image"

after
IMAGE="/home/pi/ControllingTwoMotorsForRasPi.image
save it
9. Still in LXDE open the terminal and enter the following
/home/pi/ControllingTwoMotorsForRasPi
10. If this works for you as it does for me then when you enable the motor blocks in Scratch you will see the ability to control motors A and B. It works for me. Does it work for you ?

I am aiming to do something very similar to what Simplesi is doing but I'm even more simple than he is. By adding a battery pack I aim to have the RPi on-board a two motor tracked vehicle and to drive/steer it remotely by VNC or some such method.

Perhaps this image will be of use to those who are, or who are intending to working directly from the GPIO with Scratch ?

When I learn something about GPIO and soldering I think ill get hold of a NanoBoardAg.. Apparently it can drive 2 motors. When I do I'll be able to replace the WeDo motors with something a bit beefier.

https://docs.google.com/presentation/pu ... 943e9a_0_0

kind regards
evensimplersi

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Scratch controlling the real world with a RaspberryPi

Fri Nov 30, 2012 9:52 pm

Check here http://www.raspberrypi.org/phpBB3/viewt ... 37&t=19179 for stuff on how I'm using my setup for Robotics :)

Simon

PS - I will pursue anyone thru all the courts in the world to preserve my right to be called the simplest si in the world :)
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Scratch controlling the real world with a RaspberryPi

Wed Mar 13, 2013 10:21 pm

The scratch_gpio_handler has worked fine for the past few months but now its time to make a 2.0 version with proper configuration files so that pins can be setup in different ways for different project types (LEDS/switches vs bi-directional robots for instance)

Also, having used the project as the basis of an PC/Mac Scratch/Pyfirmata/Arduino handler, I understand threads in Python a bit better (just a little bit better :) ) and need to add in things like PWM on all pins, stepper motor control and servo control (if possible in Python on RPi)

So I've uploaded the current version that I use (which has had few changes compared to previous published one) onto github
https://github.com/cymplecy/scratch_gpio

Any ideas greatly welcome e.g suggestons on pin usage (input on odd, output on even pins maybe??) What should go in a config file - what format the config file should be, GUI config editor would be nice :)

regards

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

User avatar
alexeames
Forum Moderator
Forum Moderator
Posts: 2876
Joined: Sat Mar 03, 2012 11:57 am
Location: UK
Contact: Website

Re: Scratch controlling the real world with a RaspberryPi

Wed Mar 13, 2013 11:09 pm

simplesi wrote:stepper motor control and servo control (if possible in Python on RPi)
Stepper motor control is quite easy if you write a script to pulse four ports in python and use a Darlington array like ULN2803 or ULN2003.

Servo control is possible using GPIO port 18. I just gave Eben a flag-waving "direct drive" servo at the Oxford Geek night tonight. I detailed how I did it here...

http://raspi.tv/2013/how-to-make-your-o ... aving-demo

It does require some kernel modules, which can be added to Raspbian, but I used Adafruit's Occidentalis (all the required stuff is linked in the blog article).

It's not as smooth as with a microcontroller, but it is directly controlled by the Pi. :D
Alex Eames RasPi.TV, RasP.iO

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Scratch controlling the real world with a RaspberryPi

Wed Mar 13, 2013 11:47 pm

Re- servo That'll be great to add in if its added into standard Raspbian (this project is for non-apt-getters :) )

I've got stepper motors working on my Scratch/Pyfirmata/Arduino code base http://cymplecy.wordpress.com/2013/01/1 ... mparduino/ and it should be easy to import it back into the RPi code (I've servo's working on that one as well but as we know, its easy to do real-world stuff on an Arduino :) )

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

Return to “Scratch”