0

I'm using a raspberry pi, wheezy, raspbian, revision B. I'm

I'm connecting a servo motor with these specs:

Required Pulse: 3-5 Volt Peak to Peak Square Wave Operating Voltage: 4.8-6.0 Volts

Required Pulse: 3-5 Volt Peak to Peak Square Wave Operating Voltage: 4.8-6.0 Volts I want to turn the motor, play a sound, repeat.

Every time I turn the motor, then try to play the sound, the audio won't work (it spits out data in the command line as though it has worked, but it doesn't actually work).

What I've tried:

command line using wiringPi gpio pwm 1 1000 gpio pwm 1 0 omxplayer my_mp3.mp3 gpio pwm 1 1000 gpio pwm 1 0 omxplayer my_mp3.mp3

I tried writing a python script from RPIO import PWM

from RPIO import PWM

servo = PWM.Servo()

# Add servo pulse for GPIO 17 with 1200µs (1.2ms)
servo.set_servo(17, 1200)

# Add servo pulse for GPIO 17 with 2000µs (2.0ms)
servo.set_servo(17, 2000)

# Clear servo on GPIO17
servo.stop_servo(17)

and when the script was done executing, I typed omxplayer my_mp3.mp3

omxplayer my_mp3.mp3 I tried both omxplayer and mpg321. It does the same thing regardless.

I thought maybe it was a focus issue, so I tried the screen command, creating a new instance of the screen, and closing it each time.

I also considered that since pin 18 is the hardware pwm, that perhaps trying a software pwm might help. NOPE. It's

It's as though the sound drivers are crashing once the motors move. Any ideas?

1 Answer 1

1

Audio uses the Broadcom PWM peripheral to provide the sound to the audio jack. RPIO.GPIO uses the Broadcom PWM peripheral to provide the timing for the servo pulses. The PWM peripheral can't do both duties at the same time.

I don't know why wiringPi seems to be giving the same problem with software PWM. However software PWM will cause servos to twitch.

One solution is to use my pigpio library.

For gpio17 (Broadcom numbering).

sudo pigpiod # start daemon

pigs s 17 1500 # move servo to centre
pigs s 17 1000 # move servo anti-clockwise
pigs s 17 2000 # move servo clockwise

man pigs # for help

EDITED TO ADD

The wiringPi gpio pwm command will be using hardware PWM on gpio 18. This uses the Broadcom PWM peripheral so will also conflict with audio usage.

4
  • OH, Great, if nothing else, this gives me a lot more info to help troubleshoot. I ran sudo ./x_pigpio and got two failed tests. TEST 5.4 failed, got 45 callback 50; and TEST 5.11 failed got -16 wave to busy serial read: 0. Nov 4, 2014 at 15:33
  • For now just ignore those failures. They should not affect the operation of servos and may be more related to your set-up than anything else. I use them for confidence tests in a known clean environment.
    – joan
    Nov 4, 2014 at 16:59
  • OKAY! it's working, thank you very much. I don't want to push my luck, but I've got one shell script: #!/bin/bash sudo python counterclockwise.py mpg321 mymp3.mp3 sudo python clockwise.py mpg321 mymp32.mp3 sudo python counterclockwise.py is there any way to have the audio play while the motor is moving? Nov 4, 2014 at 17:23
  • You'd need to run one of the processes in parallel. The simplest thing to do is experiment at the command line, e.g. start the audio in the background with mpg321 mymp32.mp3 & (note the &). By the way you do not need to use sudo to run a pigpio Python script.
    – joan
    Nov 4, 2014 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.