Page 6 of 9

Re: Driving multiple servos from the RaspberryPi

Posted: Tue Feb 05, 2013 2:01 am
by RomanG
Gert van Loo wrote: Also audio, it is something called 'stereo'.
stereo...eh...
Now I feel like an idiot ..... :oops:

Re: Driving multiple servos from the RaspberryPi

Posted: Tue Feb 05, 2013 3:10 am
by johnnyz77
Hi Richard,

Have done more testing and I have worked out that the problem is related to the power supply.
So nothing to do with your lib.
I was able to get the servos to work when power source and ground is the Pi.

I have a 4xAA battery case that gives my 6V and when this is used as power/ground, it doesn't work (and get issue as described above). Not quite sure why this is the case at the servos run between 4.8V-6V.

Any ideas on this?

Re: Driving multiple servos from the RaspberryPi

Posted: Tue Feb 05, 2013 4:55 am
by RomanG
johnnyz77,

Just to make sure, is your battery negative terminal also connected to the pi's ground (pin 6 on GPIO header)?
If not, then servo circuit may not "see" the signal from the pi correctly, as they do not have common reference.
If it is not connected, try to connect it and test again.

Just my 2 cents...

Roman

Re: Driving multiple servos from the RaspberryPi

Posted: Tue Feb 05, 2013 8:48 am
by joan
That is likely to be the problem. Generally you must ensure that the servos and the Pi have a common ground.

Re: Driving multiple servos from the RaspberryPi

Posted: Tue Feb 05, 2013 9:04 am
by johnnyz77
OK I will try that out! I was grounding to battery.


I'm setting up another Pi now and I just got this error when trying to send an instruction:

[email protected] /dev $ echo 1=120 > /dev/servoblaster
-bash: /dev/servoblaster: Permission denied


Any idea why this is happening???
Should I be able to see "servoblaster" if I go to "/dev" directory and "ls -l" ???
Cause I can't see it.
This was running OK on the other Pi but for some reason this Pi is giving me this head ache.

I have run update, created the 2 files, changed permission on "/lib/udev/servoblaster" and then run servoblaster.ko by this command:
sudo insmod servoblaster.ko


I then try to send it instruction and I get "permission denied".

Any ideas?

Re: Driving multiple servos from the RaspberryPi

Posted: Tue Feb 05, 2013 9:06 am
by joan
joan wrote:OK. In that case, damn, stamp foot, I have one more blunder in my code. But at least I now know where not to look! :D
Well perhaps

#define CLK_PCMCTL 26
#define CLK_PCMDIV 27

is where I've gone wrong.

I don't know what I was thinking but 0x26 is 38. :oops:

Re: Driving multiple servos from the RaspberryPi

Posted: Tue Feb 05, 2013 9:12 am
by johnnyz77
FYI:

[email protected] /dev $ ls -l /dev/servoblaster
ls: cannot access /dev/servoblaster: No such file or directory


I believe this is wrong.... File should be there?!

Re: Driving multiple servos from the RaspberryPi

Posted: Tue Feb 05, 2013 9:15 am
by joan
That was my mistake. Now I'll just need to unwind all the code which trys different start bit, number of samples, panic levels, interrupt combinations.

Re: Driving multiple servos from the RaspberryPi

Posted: Tue Feb 05, 2013 1:06 pm
by RomanG
johnnyz77 wrote:OK I will try that out! I was grounding to battery.
What exactly do you mean?
Was the battery negative terminal connected to the ground of the RPi (i.e. GPIO pin 6)?
Both, the servo ground as well as battery negative must be connected to common ground reference.
...
....
......
johnnyz77 wrote: I have run update, created the 2 files, changed permission on "/lib/udev/servoblaster" and then run servoblaster.ko by this command:
sudo insmod servoblaster.ko
Did you run first time

Code: Select all

sudo /lib/udev/servoblaster
manually? Or did you restart your RPi?

Was there any message after you run insmod command?
Did you check dmesg and syslog for any error messages related to servoblaster?

Cheers,
Roman

Re: Driving multiple servos from the RaspberryPi

Posted: Tue Feb 05, 2013 11:55 pm
by johnnyz77
I've just realised I have to run
sudo ./servod

for it to create the "/dev/servoblaster" file.

When I do this it all runs OK :)

I just dont remember doing this on the other Pi.
I would just run the servoblaster.ko file.

Re: Driving multiple servos from the RaspberryPi

Posted: Wed Feb 06, 2013 12:08 am
by johnnyz77
RomanG wrote:
johnnyz77 wrote:OK I will try that out! I was grounding to battery.
What exactly do you mean?
Was the battery negative terminal connected to the ground of the RPi (i.e. GPIO pin 6)?
Both, the servo ground as well as battery negative must be connected to common ground reference.
...
....
......
johnnyz77 wrote: I have run update, created the 2 files, changed permission on "/lib/udev/servoblaster" and then run servoblaster.ko by this command:
sudo insmod servoblaster.ko
Did you run first time

Code: Select all

sudo /lib/udev/servoblaster
manually? Or did you restart your RPi?

Was there any message after you run insmod command?
Did you check dmesg and syslog for any error messages related to servoblaster?

Cheers,
Roman


Roman, please ignore my comments about battery and ground etc.
I am a total newbie to electronics and am making lots of mistakes as I learn.
I thought battery negative line was = ground. But of course this is not the case!!

Re: Driving multiple servos from the RaspberryPi

Posted: Wed Feb 06, 2013 1:21 am
by RomanG
[quote]
Roman, please ignore my comments about battery and ground etc.
I am a total newbie to electronics and am making lots of mistakes as I learn.
I thought battery negative line was = ground. But of course this is not the case!!
[/quote]

Hi johnnyz77,
No worries, everyone was green at some point in time.
Actually, in this case, battery negative needs to be connected to RPi ground (GPIO pin 6) and servo ground wire (black or brown depending on servo manufacturer) needs to be connected to RPi ground as well. So all grounds need to have common reference.

Servoblaster can be now run in two modes, in kernel mode (older, more mature method) and in user mode as a daemon (new method).

When running in kernel mode, the servoblaster device in /dev directory needs to be created, this is done with help of the script /lib/udev/servoblaster as described in servoblaster.c source code. When you install servoblaster and want to run it in kernel mode, you need to create that script and run it manually or restart the RPi and then it is run automagically at startup. Then you can load the servoblaster module and start using the servoblaster. Without device file (in /dev directory) it would not work.

When running in user mode, you only run servod daemon (as sudo) and it will create /dev/servoblaster device and you can then use it right away.

Roman

Re: Driving multiple servos from the RaspberryPi

Posted: Wed Feb 06, 2013 5:01 pm
by davidbraith

Re: Driving multiple servos from the RaspberryPi

Posted: Thu Feb 07, 2013 6:24 pm
by Forris
Hi Richard,

I just wanted to say thanks for all the work you've done on this. After all the hassle I had a while ago inserting the servoblaster module, I downloaded your user space (whatever the hell that means :? ) version. Within 30 minutes I had a servo connected and a bit of Python script to move it backwards and forwards when a switch was pressed. After another few minutes with the Lego pile, I had a (primitive) working barrier for my sons police station.

So, thanks to you ( and the Pi ), I've written my first bit of real-world Python and my son is now showing an interest in my new toy.

Good work!!

Re: Driving multiple servos from the RaspberryPi

Posted: Thu Feb 07, 2013 6:59 pm
by rgh
Forris wrote:I've written my first bit of real-world Python and my son is now showing an interest in my new toy.
Excellent! That's what it is all about :)

Servo doesnt work when playing audio

Posted: Fri Feb 08, 2013 5:29 am
by johnnyz77
Hi Richard (or who ever else can help!)

I have been able to get the servos to work.

But there is a problem.
When I ask the Pi to play some audio, ie a WAV file, the servo goes into an uncontrollable state. It just buzzes/vibrates somewhat violently, and moves in small movements in one direction.
If I try and send it any commands during the time, it doesnt work at all. Seems the servo is in an invalid state.
Even when the audio finishes playing, sending an instruction for it to move doesnt work. It's gone.
I need to fire up servod again for it to start working properly.

Any ideas???

Re: Driving multiple servos from the RaspberryPi

Posted: Fri Feb 08, 2013 5:32 am
by johnnyz77
I should add, for clarity's sake, that what I want to do is have the servos move while the music is playing. Both the actions for audio (WAV file) to play and the instruction sent to servo to move is made from the same Java program.

Re: Driving multiple servos from the RaspberryPi

Posted: Fri Feb 08, 2013 5:36 am
by johnnyz77
One last thing.... even when I play an audio file from the command line ie
sudo aplay 12345.wav

the servos buzz/vibrate uncontrollably and go into an invalid state as described above.

FYI, the servos are being powered with their own power source: 4xAA batteries.

Your help/comments is greatly appreciated.

Re: Driving multiple servos from the RaspberryPi

Posted: Fri Feb 08, 2013 5:42 am
by johnnyz77
RomanG wrote:
Roman, please ignore my comments about battery and ground etc.
I am a total newbie to electronics and am making lots of mistakes as I learn.
I thought battery negative line was = ground. But of course this is not the case!!
Hi johnnyz77,
No worries, everyone was green at some point in time.
Actually, in this case, battery negative needs to be connected to RPi ground (GPIO pin 6) and servo ground wire (black or brown depending on servo manufacturer) needs to be connected to RPi ground as well. So all grounds need to have common reference.

Servoblaster can be now run in two modes, in kernel mode (older, more mature method) and in user mode as a daemon (new method).

When running in kernel mode, the servoblaster device in /dev directory needs to be created, this is done with help of the script /lib/udev/servoblaster as described in servoblaster.c source code. When you install servoblaster and want to run it in kernel mode, you need to create that script and run it manually or restart the RPi and then it is run automagically at startup. Then you can load the servoblaster module and start using the servoblaster. Without device file (in /dev directory) it would not work.

When running in user mode, you only run servod daemon (as sudo) and it will create /dev/servoblaster device and you can then use it right away.

Roman

Thanks for the clarification Roman!
Regarding the wiring of ground, I have The Pis ground (GPIO 6) going into a breadboard line, and I have all servo ground (black) and battery negative, going in to the same breadboard row. Is this the way to do it?

Re: Driving multiple servos from the RaspberryPi

Posted: Fri Feb 08, 2013 8:12 am
by rgh
johnnyz77 wrote:One last thing.... even when I play an audio file from the command line ie
sudo aplay 12345.wav

the servos buzz/vibrate uncontrollably and go into an invalid state as described above.
See this post... you need to try "sudo ./servod --pcm"
http://www.raspberrypi.org/phpBB3/viewt ... 00#p278587

Re: Driving multiple servos from the RaspberryPi

Posted: Fri Feb 08, 2013 12:45 pm
by RomanG
johnnyz77 wrote: Thanks for the clarification Roman!
Regarding the wiring of ground, I have The Pis ground (GPIO 6) going into a breadboard line, and I have all servo ground (black) and battery negative, going in to the same breadboard row. Is this the way to do it?
Perfect, that should work fine.

Roman

Re: Driving multiple servos from the RaspberryPi

Posted: Fri Feb 08, 2013 8:05 pm
by johnnyz77
Hi Richard

I tried that adding --pcm, but it didnt work.

This is the console when I run the command:

[email protected] ~ $ sudo /home/pi/tmp/servo/ServoBlaster/servod --pcm
Number of servos: 8
Servo cycle time: 20000us
Pulse width units: 10us
Maximum width value: 249 (2490us)

I didnt see the "using PCM hardware...." line as per the README.

Also, and most importantly, when I run and play audio, I still get the same issue/conflict where servo buzzes uncontrollably and seems to goes into invalid state.

Any ideas?

Re: Driving multiple servos from the RaspberryPi

Posted: Fri Feb 08, 2013 8:15 pm
by johnnyz77
Hi Richard
Just realised I didnt have the latest servod. I now got it, and it works a treat.
Thanks for your help.
John

Re: Driving multiple servos from the RaspberryPi

Posted: Sun Feb 10, 2013 7:41 am
by Forris
Ok, now I've got it all working I have another question. Is there a way to control the speed of the servo? I'm using some cheap micro servos from HK. The movement between positions is very quick. Is this something that can be changed in servoblaster or just a function of the servos? As an example, looking at Joan's original video of controlling multiple servos shows them rotating smoothly - is this just a better quality servo?

Re: Driving multiple servos from the RaspberryPi

Posted: Sun Feb 10, 2013 9:40 am
by mikerr
Servos move to a specified position ASAP.
To get smooth movement send it a series of intermediate positions with 0.1sec delays,

E.g have a function to do this in a loop (and track current servo positions in a variable)

servo.position( newposition, time-to-get-there)