After-school Robot Primary Club

It would be nice if these additions appeared as native blocks in scratch

Because the RPi is unique, then GPIO i/o blocks are not going to appear in mainline Scratch.

It is possible to make a special RPi vesion (the pi-face people have done that I believe) but then you are into supporting your own version of Scratch and you can't load/save projects to the Scratch website and it would be confusing for the younger customer

However, once 2.0 comes out AND assuming their is goign to be a standalone version AND it works on the RPi then we can make our own blocks up and we are off to the races that way

Simon

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

Sorry to be copying your plans but I was thinking of trying the IR line following sensors. Am I correct in thinking each unit just senses black or white and hence gives either a hi or lo signal?

Also just trying to work out how to hook up an ultrasound distance sensor to the pi. I have a really cheap sensor (about £1.50 from ebay) which should be possible to connect and then add to the scratch handler!

So the HC-SR04 is digital. I have the VCC connected to the 5V power from the pi. GND to GND. The trigger pin to a GPIO output and then echo pin connected to an input via a 300ohm resister and a 3.3V zenner diode (thanks Gordon!).

The Python code is crude but simple. I turn the trigger pin on very briefly (supposed to be 10uS). Then wait until the echo pin comes on I then time how long the pin remains on. The distance is the time of that echo signal in microseconds divided by 58. I appreciate the timing in python isn't going to be perfect but the results are pretty good. As I say I just need to add it to the scratch handler in a neat way!

Quick bit of code for you to paste in so you can see the fruits of your labour

I think I'll modify it and steal pin 23 as the trigger output and allow any of the current input pins 22,7,8,10,24,26,19 be used as echo receivers (I've seen one 'bot design with 1 sensor on front and 1 each side (for maze navigating) and I can easily see need for 1 at back as well)

But we could end up needing a configuration setting - might be best to do that via a simple .txt file to start with

But current code listens for a broadcast called "sonar" - if it receives it - it pulses Pin23 and its up to the Scratch programmer which pin they read the distance value from - so if echo output is connected to Pin19 - then the Scratch user just needs to monitor pin19 sensor value

Simon

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

I saw your post this morning and the code you haveincluded makes sense.

Did you actually have problems with it getting stuck in the while loops or was it just keep the code fool proof?

If I have followed your code correctly the timeout you have set of 10000 microseconds will mean that you can measure only up to 10000/58=172cm then the loop will give up. In theory the sensor can give a measurment upto 500cm. With he echo signal being even longer (~38ms) if there is nothing in its path.

If your code works fine then ignore me; otherwise I think you need to wait abit longer. I havent done the timings myself but I clearing it must take longer for the echo signal to arrive when the distance is longer so potentially you would need to wait 38+abit milliseconds at each loop before totally giving up!

Something I just though, which probably isn't an issue, is the frequency of the trigger signal - is there a trigger signal only when there is a Scratch broadcast? If it forms part of a loop in your script you need to be sure that there is at least a 50ms gap between the triggers. I'm not really sure of the timings in scratch but I think it is probably unlikely that you could make a loop that would send a out a broadcast faster than 50ms but if that is possible then the handler would need something to prevent that happening.

Had a great day out with a ScratchPiBot at Manchester RaspberryJam but not quite as sucessful back at the school this MondayFrom my blog

Week4Having successfully had a run out at Manchester Raspberry Jam, I thought it would be plain sailing but no I couldn't get a 2nd RaspberryPi to connect to the school WiFi so we had to make do with just the one (Which worked fine via VNC). The roboteers coded up 2 different methods of controlling the bot - Method 1 was to control both motor speeds using up/down arrow keys and then increasing one/decreasing the other using left/right keys to steer. Then they tried W/S for left motor Up/Down for right motor. Next time I aim for them to re-code up a control system and race against each other. We are both learning a lot

Although I cloned the SD card - I couldn't seem to get the second RPi to be visible over the school WiFi (I don't have much time to setup as I'm actually working fixing printers etc during the afternoon )

But we still made some progress and finally the kids got to write code and control the bot. One of them remarked on how slow Scratch seemed to be but was happy when I pointed out that we were VNCing into it and that the RPi is slower than the 2.8GHz dual-core Win7 machine being used as a dumb terminal

So I need to see make sure the VNC Settings are as fast as they can be- might reduce colour depth to see if that helps.

Also, the bot seemed to stop responding to Scratch commands but cured by exiting Scratch and relaunching my ScratchGPIO shortcut whick kills any running handler and launches a new one. I'll need to try and replicate this at home as and fix it as its a pain tin the neck

Simon

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

Since we now had 2 'bots, I switched from using main class PC to 2 netbooks - the netbook screens (1024x600) were too small (certainly for my eyesight as least) for remote VNCing so I'm going to use a couple of the older laptops next time.

The IR Sensor was showing good promise (sitting on a bench not moving of course )

The next club isn't for 2 weeks so DEFINTELY going to get a pair of sensors wired up for next outting - promise

Simon

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

I've had some M3 machine screws in 30mm and 40mm lengths from: http://www.modelfixings.co.uk/ who are fine for small orders (I needed them that long to build a bridge for a headless electric guitar - yet another unfinished project.)

Blutak might just do the job too. Maybe they just need lifting up a bit, as they're a different type of sensor. They look like they have lenses on them?