Scratch Controlling the GPIO Pins on a Raspberry Pi
Part 4 of 4
Ultrasonic Sensor Boards Single 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 followed by a wait 1 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.
Alternatively, you can use this syntax which will tell your Raspberry Pi to continuously do a distance check every 1 second and update sensor item Ultra8 with the results without any further need to do another broadcast
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
If you’ve got one of these then just create a variable called AddOn and set it to Ladder as the first line in your Green Flag event. This tells the system that your using one and then you can use broadcasts such as:
The state of the switches can be accessed through the sensing blocks. 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)
This board makes it very easy to control Motors and Servos without any extra hardware as well as giving you the ability to switch your Raspberry Pi on and off and power it from AA batteries.
See http://cymplecy.wordpress.com/2013/08/12/scratch-gpio-piglow-support/ for full support info
This really cheap and useful board is an alternative to @drogon LadderBoard.
It has 6 LEDs, a switch and a buzzer
To use it just set the AddOn variable to Berry and then you have easy methods of accessing it
[Led1..6] [On/Off/High/Low] e.g broadcast Led1On will make first red led light up
[All] [On/Off/High/Low] e.g broadcast AllOn will make all LEDs and the buzzer come on.
[Buzzer] ]On/Off/High/Low] e.g broadcast BuzzerOn
You can use variables instead e.g Set Led1 On will turn on 1st LED
And also use Power1..6 (values 0-100) variables to vary the brightness as
There is only one sensor value returned and that is called switch (1 if not pressed – 0 if pressed)
This board is a complete robotics controller for your Raspberry Pi based mobile robot.