I've been experimenting with servo control from Scratch. WiringPi isn't a suitable way to do it (at least, not its current incarnation) but ServoBlaster appears to be a good bet.
I've added "servoXpositionY" and "servoXpercentageY" commands and it seems to work perfectly well. What isn't so nice is the way one has to configure it, start it, stop it, and cope with the way it grabs gpio pins possibly clashing with the rest of your scripts. The default config takes over 8 pins, for example, and trying to do anything else with them from within Scratch can lead to assorted problems.
I'd be interested to hear of any ideas people have on how to deal with this - or even if I should worry about it. If it all works out ok it should make the next release.
-
- Posts: 1365
- Joined: Mon Oct 29, 2012 8:12 pm
- Location: Vancouver Island
- Contact: Website
Scratch servo control
Making Smalltalk on ARM since 1986; making your Scratch better since 2012
Re: Scratch servo control
Great work, Tim !! I'm afraid you're well above my skill level, so I'm not sure what you mean by the servo taking over 8 pins - how, why, huh !? So, nothing useful to add, just thought I'd pop up to show my appreciation, especially as I've been giving you a hard time about servos and Scratch.
Thanks.
Thanks.
- mikronauts
- Posts: 2822
- Joined: Sat Jan 05, 2013 7:28 pm
- Contact: Website
Re: Scratch servo control
Tim,
Joan's pigpio works very well with servos and pwm, I use it for my Pi Droid Alpha product.
http://abyz.co.uk/rpi/pigpio/
http://www.mikronauts.com/raspberry-pi/pi-droid-alpha/
Joan's pigpio works very well with servos and pwm, I use it for my Pi Droid Alpha product.
http://abyz.co.uk/rpi/pigpio/
http://www.mikronauts.com/raspberry-pi/pi-droid-alpha/
timrowledge wrote:I've been experimenting with servo control from Scratch. WiringPi isn't a suitable way to do it (at least, not its current incarnation) but ServoBlaster appears to be a good bet.
I've added "servoXpositionY" and "servoXpercentageY" commands and it seems to work perfectly well. What isn't so nice is the way one has to configure it, start it, stop it, and cope with the way it grabs gpio pins possibly clashing with the rest of your scripts. The default config takes over 8 pins, for example, and trying to do anything else with them from within Scratch can lead to assorted problems.
I'd be interested to hear of any ideas people have on how to deal with this - or even if I should worry about it. If it all works out ok it should make the next release.
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi
-
- Posts: 1365
- Joined: Mon Oct 29, 2012 8:12 pm
- Location: Vancouver Island
- Contact: Website
Re: Scratch servo control
Yup, that looks very interesting. Thanks for pointing me to it!mikronauts wrote:Tim,
Joan's pigpio works very well with servos and pwm, I use it for my Pi Droid Alpha product.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012
Re: Scratch servo control
It would be nice if you could use the gpiozero library, which has a pigpio extension
That would possibly make a smoother transition moving from scratch to python.
gpiozero
Chris
That would possibly make a smoother transition moving from scratch to python.
gpiozero
Chris
-
- Posts: 1365
- Joined: Mon Oct 29, 2012 8:12 pm
- Location: Vancouver Island
- Contact: Website
Re: Scratch servo control
As far as I can tell gpiozero is completely written in Python which makes it completely unusable by anyone else. Not such a good idea really.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012
Re: Scratch servo control
Thanks for checking it out.
Chris
Chris
-
- Posts: 1365
- Joined: Mon Oct 29, 2012 8:12 pm
- Location: Vancouver Island
- Contact: Website
Re: Scratch servo control
Just as an update - pigpen is working out very well for servo control. What, 'pigpen'? Damn You Autocorrect! That should, obviously, be 'pigpio'
Making Smalltalk on ARM since 1986; making your Scratch better since 2012
- mikronauts
- Posts: 2822
- Joined: Sat Jan 05, 2013 7:28 pm
- Contact: Website
Re: Scratch servo control
Please shoot me an email (or PM) once you release it... I'd like to see how easy it would be for my nephew's to program a PiDroidAlpha+RaspberryPi based robot.
http://www.mikronauts.com/raspberry-pi/pi-droid-alpha/
http://www.mikronauts.com/raspberry-pi/pi-droid-alpha/
timrowledge wrote:Just as an update - pigpen is working out very well for servo control. What, 'pigpen'? Damn You Autocorrect! That should, obviously, be 'pigpio'
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi
Re: Scratch servo control
External programs can fill the gap till a perfect solution in scratch gpioserver is available.
scratchClient supports servo control with 'build in' DMA support, using a pi2- modification of RPIO.PWM. This lib is included in distribution.
Or use an arduino nano as an adapter board, featuring servo control, io and adc:
http://heppg.de/ikg/wordpress/?p=532
Regards,
Gerhard
scratchClient supports servo control with 'build in' DMA support, using a pi2- modification of RPIO.PWM. This lib is included in distribution.
Or use an arduino nano as an adapter board, featuring servo control, io and adc:
http://heppg.de/ikg/wordpress/?p=532
Regards,
Gerhard
Re: Scratch servo control
I am some way behind the progress made by others on this thread. I am trying to control a servo using scratch running on a raspberry pi. I can see how to control the pwm using the GPIO server. Is there a way to control the duty cycle, or do i need some additional code to support Scratch to o this? Is the current GPIO server on Scratch capable of controlling a servo directly?
thanks
john
thanks
john
-
- Posts: 1365
- Joined: Mon Oct 29, 2012 8:12 pm
- Location: Vancouver Island
- Contact: Website
Re: Scratch servo control
No, you cannot currently drive servos from the built in gpio server. Next release, maybe, depending on how much time I get to spend on it.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012
Re: Scratch servo control
Hi,
I want to get some students (12 years) to work with scratch and a single servo. What is the status of this doing it with a micro servo directly connected to the gpio ports.
grt
I want to get some students (12 years) to work with scratch and a single servo. What is the status of this doing it with a micro servo directly connected to the gpio ports.
grt
Re: Scratch servo control
NuScratch (the 'built-in' Scratch) does now support servos, but in my experience it seems that the travel is limited to around 60 degrees.ikke4 wrote:Hi,
I want to get some students (12 years) to work with scratch and a single servo. What is the status of this doing it with a micro servo directly connected to the gpio ports.
grt
Have you tried ScratchGPIO: http://simplesi.net/scratchgpio/scratch ... rypi-gpio/
This has had servo support for ages now, and work well.
Re: Scratch servo control
Hello,
the servo angle is a device property, most servo have 60 degree. 90 degree or 180 degree or even 360 degree servo are on market.
The control signal are always the same (1ms to 2ms pulse, 50Hz).
Regards,
Gerhard
the servo angle is a device property, most servo have 60 degree. 90 degree or 180 degree or even 360 degree servo are on market.
The control signal are always the same (1ms to 2ms pulse, 50Hz).
Regards,
Gerhard
Re: Scratch servo control
My micro servos, which have a >180 degrees of travel using ScratchGPIO, only have a 50-ish degree of travel under NuScratchghp wrote:Hello,
the servo angle is a device property, most servo have 60 degree. 90 degree or 180 degree or even 360 degree servo are on market.
The control signal are always the same (1ms to 2ms pulse, 50Hz).
Regards,
Gerhard

Re: Scratch servo control
Hello,
was curious to see what happens. With "servo17%0", I get 1.5 ms pulse width. With "servo17%100", there are 2ms pulses. So I checked -100 with "servo17%-100" and got (drum fill) 1ms.
In scratchClient, I use ranges from 0..100 for outputs. Here in scratch gpioserver, servo use -100 to 100.
Regards,
Gerhard
was curious to see what happens. With "servo17%0", I get 1.5 ms pulse width. With "servo17%100", there are 2ms pulses. So I checked -100 with "servo17%-100" and got (drum fill) 1ms.
In scratchClient, I use ranges from 0..100 for outputs. Here in scratch gpioserver, servo use -100 to 100.
Regards,
Gerhard
Re: Scratch servo control
Ok, so how many degrees of rotation does that give you from -100 to 100 ?ghp wrote:Hello,
was curious to see what happens. With "servo17%0", I get 1.5 ms pulse width. With "servo17%100", there are 2ms pulses. So I checked -100 with "servo17%-100" and got (drum fill) 1ms.
In scratchClient, I use ranges from 0..100 for outputs. Here in scratch gpioserver, servo use -100 to 100.
Regards,
Gerhard
BTW, I'm using cheap 9g MIcro-servos.
Re: Scratch servo control
Hello,
I just connected my good old oscilloscope and checked the signal. When you had only half the rotation expected with values[0..100] or [1.5..2ms], then you will get full rotation angle with values [-100..100] or [1..2ms].
I heard that some servo allow for some 'overdrive'. Pulses smaller than 1ms or larger 2ms could extend the angle range, just to the control electronics' limits. You could use a 0 to 100% pwm signal with 50Hz and check values lower than 5% or larger 10%. Could damage a servo, possibly.
You could work around limited angle by using a different lever. Which rises the question of 'torque', but this could be beyond the scope of a scratch forum ?
Regards,
Gerhard
I just connected my good old oscilloscope and checked the signal. When you had only half the rotation expected with values[0..100] or [1.5..2ms], then you will get full rotation angle with values [-100..100] or [1..2ms].
I heard that some servo allow for some 'overdrive'. Pulses smaller than 1ms or larger 2ms could extend the angle range, just to the control electronics' limits. You could use a 0 to 100% pwm signal with 50Hz and check values lower than 5% or larger 10%. Could damage a servo, possibly.
You could work around limited angle by using a different lever. Which rises the question of 'torque', but this could be beyond the scope of a scratch forum ?
Regards,
Gerhard
Re: Scratch servo control
The 9g servos I have accept pulses in the range roughly 600µs to 2400µs to turn through their just over 180 degrees.
-
- Posts: 1365
- Joined: Mon Oct 29, 2012 8:12 pm
- Location: Vancouver Island
- Contact: Website
Re: Scratch servo control
Apologies for the delayed response; busy-busy!
I've been flying radio controlled model planes for... 43 years now, gulp... a while, and have always understood the proper signal to range from 1000 to 2000 microseconds with the centre at 1500. If anyone can find me a good authoritative reference explaining why this range should be expanded I'll be happy to revise the code.
I've been flying radio controlled model planes for... 43 years now, gulp... a while, and have always understood the proper signal to range from 1000 to 2000 microseconds with the centre at 1500. If anyone can find me a good authoritative reference explaining why this range should be expanded I'll be happy to revise the code.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012
Re: Scratch servo control
That depends on what you think is authoritative.
There are plenty of on-line mentions of ranges between 500µs and 2500µs.
E.g. http://www.robotshop.com/forum/servo-range-t8519
I think the Arduino libraries also allow 500-2500 limits.
The pigpio limits are 500-2500. I don't remember why I chose those limits but there would have been a justifiable reason at the time.
Later on I'll try some 9g servos and see what they accept.
There are plenty of on-line mentions of ranges between 500µs and 2500µs.
E.g. http://www.robotshop.com/forum/servo-range-t8519
I think the Arduino libraries also allow 500-2500 limits.
The pigpio limits are 500-2500. I don't remember why I chose those limits but there would have been a justifiable reason at the time.
Later on I'll try some 9g servos and see what they accept.
Re: Scratch servo control
Just tried a 9g servo.
It is happy with values between 500 and 2500 µs. For those limits it turns about 190 degrees.
Video at http://abyz.co.uk/videos/servo.mp4 (my browser complains that the video is corrupt, you may need to download to view, e.g. wget http://abyz.co.uk/videos/servo.mp4).
It is happy with values between 500 and 2500 µs. For those limits it turns about 190 degrees.
Video at http://abyz.co.uk/videos/servo.mp4 (my browser complains that the video is corrupt, you may need to download to view, e.g. wget http://abyz.co.uk/videos/servo.mp4).
Code: Select all
#!/usr/bin/env python
import time
import pigpio
import i2c_lcd
SERVO=4
SERVO_MIN=500
SERVO_MAX=2500
SERVO_INC=100
SERVO_LOW=1400
SERVO_HIGH=1600
servo_low=SERVO_LOW
servo_high=SERVO_HIGH
pi = pigpio.pi()
if not pi.connected:
exit(0)
lcd = i2c_lcd.lcd(pi, width=20)
count = 1
try:
while True:
lcd.put_line(0, "Servo range test")
lcd.put_line(1, "Low={}".format(servo_low))
lcd.put_line(2, "High={}".format(servo_high))
lcd.put_line(3, time.asctime())
for i in range(3):
pi.set_servo_pulsewidth(SERVO, servo_low)
time.sleep(1)
pi.set_servo_pulsewidth(SERVO, servo_high)
time.sleep(1)
servo_low -= SERVO_INC
servo_high += SERVO_INC
if servo_low < SERVO_MIN:
servo_low = SERVO_LOW
if servo_high > SERVO_MAX:
servo_high = SERVO_HIGH
except KeyboardInterrupt:
pass
print("exiting")
lcd.close()
pi.stop()
Re: Scratch servo control
Deja vu...timrowledge wrote:Apologies for the delayed response; busy-busy!
I've been flying radio controlled model planes for... 43 years now, gulp... a while, and have always understood the proper signal to range from 1000 to 2000 microseconds with the centre at 1500. If anyone can find me a good authoritative reference explaining why this range should be expanded I'll be happy to revise the code.
viewtopic.php?f=77&t=148071
The point is, respectfully, we're not flying model planes. We're teaching 8-year-olds to wave a flag, and 10-year-olds to build a robot arm, using cheap 9g micro-servos.
Re: Scratch servo control
Hello Forris,
I think that it is not a question of what is done with the servo, but what 'the standard' is. When I started to use servo, I looked in the net and found almost always the pulse width [1..2 ms].
scratch is by its nature a general purpose system. To implement all possible deviations for special devices or some vendors would make the commands quite complicated. Especially for kids, the target audience of scratch.
For scratchClient, the framework for hardware connections I maintain, I have started to implement optional parameter for the servo adapters which allow to set millisecond.min and millisecond.max in the configuration files. This will allow operation of servo outside the specs, but also the limitation of sweep range because connected hardware could need it. The config files used are prepared as part of the hardware setup by the teacher, so in school hours kids cannot collect frustration points by misspelling commands or alike. Will be completed the next weeks and the uploaded to the website.
Regards,
Gerhard
I think that it is not a question of what is done with the servo, but what 'the standard' is. When I started to use servo, I looked in the net and found almost always the pulse width [1..2 ms].
scratch is by its nature a general purpose system. To implement all possible deviations for special devices or some vendors would make the commands quite complicated. Especially for kids, the target audience of scratch.
For scratchClient, the framework for hardware connections I maintain, I have started to implement optional parameter for the servo adapters which allow to set millisecond.min and millisecond.max in the configuration files. This will allow operation of servo outside the specs, but also the limitation of sweep range because connected hardware could need it. The config files used are prepared as part of the hardware setup by the teacher, so in school hours kids cannot collect frustration points by misspelling commands or alike. Will be completed the next weeks and the uploaded to the website.
Regards,
Gerhard