prem111
Posts: 16
Joined: Fri Dec 27, 2019 4:44 pm

Two servos in perl example.

Sat Dec 28, 2019 2:22 pm

Hi. I would like an example of using 2 servos via gpio (PWM) in perl. Thanks.

im use:

use Term::ReadKey;
use WiringPi::API qw(:all);
use RPi::Const qw(:all);
use Math::Round;

use constant {
MIN => 130,
MAX => 210,
ESC1_PIN => 12,
ESC2_PIN => 6,
NEUTRAL => 161,
RANGE => 2000,
SKIP => 1,
};

setup_gpio();

pin_mode(ESC1_PIN, PWM_OUT);
pin_mode(ESC2_PIN, PWM_OUT);

pwm_set_mode(PWM_MODE_MS);
pwm_set_clock(NEUTRAL);
pwm_set_range(RANGE);


pwm_write(ESC1_PIN, 176);
pwm_write(ESC2_PIN, 176);


But not working...

User avatar
scruss
Posts: 2823
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Two servos in perl example.

Sat Dec 28, 2019 3:30 pm

What are the error messages?
What's your wiring like?
Do you have enough power to drive the servos? Can you get one servo to work?
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

prem111
Posts: 16
Joined: Fri Dec 27, 2019 4:44 pm

Re: Two servos in perl example.

Sat Dec 28, 2019 3:35 pm

There are no errors. Both ESCs just don't work. When he hash

#pin_mode (ESC2_PIN, PWM_OUT);
and
#pwm_write (ESC2_PIN, 176);

First ESC works fine.


That's exactly what ESC is about, I wrote a servo for example.

prem111
Posts: 16
Joined: Fri Dec 27, 2019 4:44 pm

Re: Two servos in perl example.

Sat Dec 28, 2019 6:18 pm

Ok problem solved. The problem was wrong connection of the PWM pins.

I have one more question, what is the solution for pwm software? I know there are two pwm hardware outputs. I need more. Do I have to use the rpi::pigpio library? I don't want to run daemons.

User avatar
joan
Posts: 14686
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Two servos in perl example.

Sat Dec 28, 2019 6:22 pm

As you say there are two hardware PWM channels. You will have to use software PWM for any additional ESCs. Unless there is a RPIO module for PERL (n.b. RPIO, not RPi.GPIO).

prem111
Posts: 16
Joined: Fri Dec 27, 2019 4:44 pm

Re: Two servos in perl example.

Sat Dec 28, 2019 6:29 pm

Is there something for RPIO in perl?

prem111
Posts: 16
Joined: Fri Dec 27, 2019 4:44 pm

Re: Two servos in perl example.

Sat Dec 28, 2019 7:50 pm

i found only RPi::PIGPIO with daemon pigpiod, but write_pwm function is only for volate level for pins.....

User avatar
DougieLawson
Posts: 37097
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Two servos in perl example.

Sun Dec 29, 2019 1:38 am

What Raspberry Pi are you using?
What OS?

Does your unsupported perl WiringPi module have a hack for your RPi model? Hint: WiringPi is sensitive to RPi models and even the last version (v2.52) won't work on a RPi 4B 4GB v1.2.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

prem111
Posts: 16
Joined: Fri Dec 27, 2019 4:44 pm

Re: Two servos in perl example.

Sun Dec 29, 2019 11:08 am

Hi,

Rpi 3b
Os: Linux raspberrypi 4.19.75-v7+

Im trying RPi::WiringPi perl module, but I don't see the possibility of assigning pwm to any pin (as pwm software).

Pigpio run as a daemon works fine (with the pigs bash-command).

User avatar
joan
Posts: 14686
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Two servos in perl example.

Sun Dec 29, 2019 11:23 am

The obvious solutions for additional hardware PWM on the non-PWM GPIO are RPIO, servoblaster, and pigpio.

RPIO would be a non-daemon solution but there does not appear to be a way to use it from PERL.

servoblaster and pigpio are both daemon based. However servoblaster is a lot "lighter" than pigpio. Both servoblaster and pigpio offer a pipe based command interface which will be accessible from PERL.

Return to “Other programming languages”