Changes from NuScratch15012016 to NuScratch02052016
The major change is in swapping from use of wiringPi to pigpio. This made it easier to extend the GPIOServer to support model servos and the SR04 series ultrasonic sensors so popular with robotics tinkerers. We are using the pigpiod daemon rather than a direct bind to the pigpio library, which has the advantage that other applications can use the same facility and at some point we ought to be able to co-ordinate the pin usage so that applicationA doesn’t think it has gpio21 as an input whilst applicationB is determinedly using it as a pwm output. It also has the ability to accept input from other Pi’s that the one it runs on, which isn’t currently used from Scratch but might be an interesting future feature.
All the low-level device code had to be touched to make this change and despite testing there may be some bugs. One bug already known is that the value range for the pwm outputs is set to 0-255 instead of the 0-1023 that ought to pertain; we’ll fix that for the next release of NuScratch.
Other GPIOServer changes
The new servo support uses two new broadcasts:
‘servoXX%YYY’ to set the servo output on gpio XX to YYY % of movement; 0% is the centre so remember to use ’servoXX%-100’ to go to extreme low-value. You can also use ‘servoXXpercentYYY’ if you prefer to spell it out.
‘servoXXstop’ will close down the the thread that runs the servo attached to gpio XX. It’s a good idea to do this to release resources.
You can see the basic use of these in the new example project ‘gpio-servoDemo’ which will be found in Examples-> Sensors and Motors.
I have limited the pulse width range to 1000-2000 milliseconds with 1500 as a centre position in order to protect the hardware. I know that some servos will accept a wider range but they’re uncommon in my 45 years of model flying.
The ultrasonic support is currently quite basic and only handles a single sensor. There are two broadcasts of interest:
‘ultrasonictriggerXXechoYY’ sets the two pins used by the SR04. You won’t be startled to hear that the gpio XX is the one attached to the trigger pin of the sensor and YY is the one for the echo pin. Remember to do the correct wiring for these sensors since they use 5v and the echo pin voltage must be scaled down to ~ 3v to protect your Pi.
‘ultrasonicclose’ shuts down the thread that monitors the SR04.
The result from the ultrasonic sensor are provided as a sensor variable ‘ultrasonicdistance’ giving you the distance measured in centimetres. The example project ‘gpio-ultrasonicDemo’ (also on Examples -> Sensors and Motors) illustrates how this can be used to set the position of a sprite.
Camera use: some reports of the broadcast ‘photo’ not working intermittently lead to a revised way of getting the camera to take a snapshot. This seems to be much more reliable but there are still cases where the camera OS level drivers simply can’t provide a picture in a timely manner, so just occasionally it may still fail.
To make using the camera a bit more flexible there is a new broadcast to allow requesting a specific sized image. ‘[email protected]
’ will request an image XXX pixels wide and YYY pixels high. There are some cases the camera simply won’t accept - for example ‘[email protected]
' sometimes looks strange, and ‘[email protected]
’ simply won’t work, and asking for a [email protected]
image will strictly speaking work but you might get very bored waiting for it to transfer and appear in Scratch.
I also added ‘photobig’ (or ‘photolarge’ whichever you prefer) to grab an image the size of the stage.
There is a new and slightly faster Squeak virtual machine.
The entire code for displaying the stage and sprites has been reworked to clean up a lot of ancient ugliness. The major visual effect is that dragging a sprite in the small stage now works correctly (and in fact more correctly than the original Scratch release) for precise positioning of the dropped sprite and the size of the sprite whilst being dragged. It also works for odd scales rather than just half or double, so maybe we can extend the stage sizes some day.
Font sizes for Scratch can now be set by editing your ‘.scratch.ini’ file (remember the first dot!) and adding a line
or a similar number; much outside the range 0.7 - 2 will tend to make things look ugly because it stretches the layout beyond it’s decent limits.
The Japanese translation files have been extended and improved a little. If you are multi-lingual and spot problems in any of the translations, do please let us know and maybe volunteer to help edit the relevant files!
As Simon mentioned the changes to support Bluetooth audio have caused problems with ALSA that are not yet solved for Scratch.
Anyone using xrdp (and possibly other remote desktop facilities) will still need to use ‘sudo’ even though we no longer need it for gpio access. This is due to some issue with xrdp and so far no one has any information about how it might be solved. For now, the solution is to edit /usr/bin/scratch and make sure that the line starting with
WRAPPER=“sudo -E "