Discuss Scratch
- Discussion Forums
- » Connecting to the Physical World
- » Connect Scratch 2 to Raspberry Pi GPIO port
- procd
- Scratcher
100+ posts
Connect Scratch 2 to Raspberry Pi GPIO port
I've just uploaded a newer version, so download from the same link. This version is more configurable, so can change the raspberry pi's hostname/ip address and port etc.
Let me know how it goes and see what changes you think it may need.
Let me know how it goes and see what changes you think it may need.
- procd
- Scratcher
100+ posts
Connect Scratch 2 to Raspberry Pi GPIO port
Re pin numbering
I use physical pin numbering in my Scratch 1.4 stuff so that's what I prefer.
Easy edit, just change the Scratch names in the s2e file, so you can rename GPIOx to Piny etc.
Let me know how it goes. Just seen the Camjam on the raspberrypi website which looks handy. May have to order one!
- SimpleScratch
- Scratcher
500+ posts
Connect Scratch 2 to Raspberry Pi GPIO port
I must apologise for not testing this yet but real life getting in the way!
I'm off to cinema with daughter adn then there is Brazil vs Germany later!!
Simon
I'm off to cinema with daughter adn then there is Brazil vs Germany later!!
Simon
- procd
- Scratcher
100+ posts
Connect Scratch 2 to Raspberry Pi GPIO port
I must apologise for not testing this yet but real life getting in the way!
I'm off to cinema with daughter adn then there is Brazil vs Germany later!!
Simon
That's ok. I've ordered a camjam so will be able to test properly in a few days myself I hope!
- FCEFEAR
- Scratcher
3 posts
Connect Scratch 2 to Raspberry Pi GPIO port
Love this idea.
when green flag clicked
say [Felix was here] for (2) secs
- SimpleScratch
- Scratcher
500+ posts
Connect Scratch 2 to Raspberry Pi GPIO port
Well got everything plugged in but not quite there on getting pins to actually change state
Turns out that Webiopi is using broadcom pin numbering go for instance to change physical pin 7 from in to out I used
Set GPIO 4 function out
and that worked fine
But I'm at a loss as to how to make the pin change state as the parameter box seems to be the wrong type
regards
Simon
Turns out that Webiopi is using broadcom pin numbering go for instance to change physical pin 7 from in to out I used
Set GPIO 4 function out
and that worked fine
But I'm at a loss as to how to make the pin change state as the parameter box seems to be the wrong type
regards
Simon
- procd
- Scratcher
100+ posts
Connect Scratch 2 to Raspberry Pi GPIO port
It's a pointy box so takes a Boolean. To make it go high use
<[1] = [1]>and for false
<[1] = [0]>or maybe use
<key [space v] pressed?>
- SimpleScratch
- Scratcher
500+ posts
Connect Scratch 2 to Raspberry Pi GPIO port
I did try that but I it doesn't change the pin state on my setup
Simon
Simon
- SimpleScratch
- Scratcher
500+ posts
Connect Scratch 2 to Raspberry Pi GPIO port
I've gone backwards now - I can't change the pin from input to output anymore
Off to sleep now - will try again tomorrow
Off to sleep now - will try again tomorrow
Last edited by SimpleScratch (July 9, 2014 22:24:51)
- procd
- Scratcher
100+ posts
Connect Scratch 2 to Raspberry Pi GPIO port
That's annoying. I suppose first thing to try is use the browser and ensure that webiopi can change the pin states itself. if you run webiopi with the -d command then it goes into debug mode and you can it's messages. Annoyance with that is that Scratch's polling 30 times a second means that you just get screenfulls of GET/* messages. I'll probably have to add some instrumentation into the extension.
- SimpleScratch
- Scratcher
500+ posts
Connect Scratch 2 to Raspberry Pi GPIO port
mm - tried rebooting my this morning and its not working now so maybe I have other issues
- procd
- Scratcher
100+ posts
Connect Scratch 2 to Raspberry Pi GPIO port
One thing I did notice once but didn't investigate was that if I had the extension running to the Pi and then used the browser to access WebIOPi then the connection from the extension to the Pi was dropped. In other words use them sequentially and not in parallel. If youuse webiopi in debug mode then you'll know the extension is connected and Scratch is connected to the extension because of the continual polling and so constant stream of debug messages.
- SimpleScratch
- Scratcher
500+ posts
Connect Scratch 2 to Raspberry Pi GPIO port
Ta - I was using them in paralell - I've had to remake a new SD card as the old one decided that yesterday was a good day to die
Simon
Simon
- SimpleScratch
- Scratcher
500+ posts
Connect Scratch 2 to Raspberry Pi GPIO port
Ok back up but no luck at all this time
Would it possible to have some debug output from your .exe file to see what its receiving from Scratch 2 and then sending off to the Pi?
Maybe webiopi needs 1/0 values and not true/false?
Simon
Would it possible to have some debug output from your .exe file to see what its receiving from Scratch 2 and then sending off to the Pi?
Maybe webiopi needs 1/0 values and not true/false?
Simon
- procd
- Scratcher
100+ posts
Connect Scratch 2 to Raspberry Pi GPIO port
Had an email that the camjam has shipped so hopefully get that by the weekend. The extension should convert the true/false to 1/0 or whatever is necessary. I'll add some debug statements in.
- procd
- Scratcher
100+ posts
Connect Scratch 2 to Raspberry Pi GPIO port
Only build and uploaded didn't test. But if you download from the same link if the extension is run with a -d command line parameter (now where did I get that idea from ;-) it will enter a debug mode and print message to the console. It doesn't print poll messages as that would just get in the way. Hopefully that will help?
- SimpleScratch
- Scratcher
500+ posts
Connect Scratch 2 to Raspberry Pi GPIO port
Debug mode on
Connecting to Raspberry pi at raspberrypi:8000
Listening on port 8080
Press return to exit.
Scratch Request : /setGPIOFn/4/OUT
Scratch Request : /setGPIO/4/true
So the requests are being made to your help app but nothing going onwards to the Pi (or at least no debug info)
Simon
- SimpleScratch
- Scratcher
500+ posts
Connect Scratch 2 to Raspberry Pi GPIO port
Getting somewhere - restarted things and made sure green circle was lit on the extension in Scratch
So it looks like the wring GPIO number is being sent to the Pi
I put a LED on GPIO 23 (physical pin 16) - and it switches off and on at my command
Simon
Listening on port 8080
Press return to exit.
Scratch Request : /setGPIOFn/4/OUT
POSTing WebIOPi : /GPIO/23/function/OUT
WebIOPi response : OUT
Scratch Request : /setGPIO/4/true
POSTing WebIOPi : /GPIO/23/value/1
WebIOPi response : 1
So it looks like the wring GPIO number is being sent to the Pi
I put a LED on GPIO 23 (physical pin 16) - and it switches off and on at my command
Simon
- procd
- Scratcher
100+ posts
Connect Scratch 2 to Raspberry Pi GPIO port
Good news!
The conversion I do from RaspberryPi GPIO number to BCM GPIO numbering is;
The conversion I do from RaspberryPi GPIO number to BCM GPIO numbering is;
public string ConvertRPIToBCM(string gpio)
{
switch (gpio)
{
case "0":
return "17";
case "1":
return "18";
case "2":
return "21";
case "3":
return "22";
case "4":
return "23";
case "5":
return "24";
case "6":
return "25";
case "7":
return "4";
default:
return "";// should never get
}
}
- procd
- Scratcher
100+ posts
Connect Scratch 2 to Raspberry Pi GPIO port
Think they are the correct mappings. See this https://projects.drogon.net/raspberry-pi/wiringpi/pins/ for mapping to physical pin outs too.
- Discussion Forums
- » Connecting to the Physical World
- » Connect Scratch 2 to Raspberry Pi GPIO port