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
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
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