2022 Developer Survey is open! Take survey.

Hot answers tagged

18 votes

Driving PWM output frequency

I finally got a complete(ish) understanding from the bcm2835.h driver header file, so thought I would post and answer my own question for others. The relevant bits from the header: PWM The ...
user avatar
  • 361
12 votes

Control Hardware PWM frequency

According to this formula: pwmFrequency in Hz = 19.2e6 Hz / pwmClock / pwmRange We can set pwmClock=1920 and pwmRange=200 to get pwmFrequency=50Hz: 50 Hz = 19.2e6 Hz / 1920 / 200 I test it on ...
user avatar
  • 316
12 votes

Can I use the GPIO for pulse width modulation (PWM)?

Recent Pis have two hardware PWM channels. In addition hardware timed PWM pulses may be independently generated on all the GPIO connected to the 40 pin expansion header. In practice this means there ...
user avatar
  • 66.3k
9 votes
Accepted

How to use pigpio to control a servo motor with a keyboard?

I'm not sure if anyone will write the code for you. It's too broad a question. You need to acquire a basic understanding of Python programming first, otherwise you'll be forever asking questions. ...
user avatar
  • 66.3k
8 votes

Driving PWM output frequency

On recent Pis (those with the 40 pin expansion header and the compute module) GPIO 12/13/18/19 may be used to provide hardware PWM signals. The PWM clock source does not need to be the 19.2MHz ...
user avatar
  • 66.3k
7 votes
Accepted

pigpio - set_PWM_dutycycle vs hardware_PWM

hardware_PWM >>> set_PWM_dutycycle >>> software PWM where >>> is orders of magnitude better pulse stability. hardware_PWM rock solid pulses large choice and range of frequencies large number of ...
user avatar
  • 66.3k
5 votes

RPIO does not work on Python 3, only in Python 2.7

The library needs to be installed for Python 3. The two Python versions 2.7 and 3.x don't share packages (because most code written for Python 3 is not backward compatible. To install the RPIO ...
user avatar
5 votes
Accepted

PWM Control on Raspberry PI

I doubt you'll need to use the PWM capability of gpio 18. There are many ways to provide hardware timed PWM on the Pi on all the user gpios. They are all variations on a theme and use DMA transfers ...
user avatar
  • 66.3k
5 votes
Accepted

PWM stop respond after hundreds of start/stop

I am fairly sure it is a bug in the RPi.GPIO module. Look through https://sourceforge.net/p/raspberry-gpio-python/tickets/ As a workaround I suggest you do not use the start() and stop() methods in ...
user avatar
  • 66.3k
4 votes

Can I control this ESC/Brushless Motor with a Raspberry Pi and/or Arduino

ESCs (Electronic Speed Controllers) are typically controlled just like you would control a hobby servo -- with a PWM signal. There are many guides to controlling a servo that should be applicable to ...
user avatar
  • 2,984
4 votes

Max number of RC motors controlled by Raspberry PI

Simple. The maximum number is 0 (zero). You will need at least a transistor or a relay to drive the DC motor, as the GPIO pins on the rPi do not provide enough power to drive the motor. You will also ...
user avatar
  • 4,993
4 votes

PWM Fan causes clicking sound

At a PWM frequency of a nominal 10 Hz I'm not surprised you can hear clicks. You will be switching the fan on and off 10 times a second. Experiment with frequencies in the range 100 to 1000 Hz.
user avatar
  • 66.3k
4 votes
Accepted

pigpio PWM and ALSA

By default pigpio uses the PCM peripheral to time the DMA leaving the PWM peripheral free for standard audio. Perhaps your ALSA device is using high quality audio. If that's the case you need to use ...
user avatar
  • 66.3k
4 votes

Output Accurate, Detailed PWM signal

The Pis with 40 pin expansion header (and the compute module) have two hardware PWM channels which you should be able to use with wiringPi. That would give you control of two ESCs. From the software ...
user avatar
  • 66.3k
4 votes
Accepted

PWM control of motors with PHP front end

Will I need to have a Python script You do not need python, you just need something with a module that wraps one or more of the following C libraries: pigpio wiringPi libbcm2835 All of which ...
user avatar
  • 55.6k
4 votes
Accepted

PWM conflicts with I2C?

PWM should not conflict with I2C. Everything below presumes the (predominant) Broadcom pin numbering scheme, which does not correlate to the physical arrangement of the pins. I've never used GPIO 4 ...
user avatar
  • 55.6k
4 votes

Controlling servo with Raspberry Pi but it doesn't stand still

You are using the wrong tool for the job. Servos require accurately timed pulses. The RPi.GPIO module uses software timing which leads to all sorts of timing jitter, which leads to a twitching servo,...
user avatar
  • 66.3k
4 votes

Raspberry pi PWM stability

You need to use hardware timed pulses for servos. Software timed pulses will lead to jitter and a shorter servo lifetime. Try pigpio, servoblaster, RPIO.GPIO, or similar which use hardware timed ...
user avatar
  • 66.3k
4 votes

Android Things: How many PWM pins on Pi 3 Model B?

All Pi models have identical GPIO, even though the pinout varies between models. PWM can be assigned to different pins, but there are still only 2 channels. See http://www.panu.it/raspberry/ for ...
user avatar
  • 53.3k
4 votes

PWM on 5V GPIO pin

If you take a look at the spec sheet for that fan (the fan you linked is a 4-pin varient): You'll see that the PWM signal pin must be 5V. Now why it works with 3.3V (GPIO voltage) is likely because ...
user avatar
  • 6,185
4 votes

What is the relationship between angle and servo motor duty cycle? How do I implement this?

Servos are controlled by pulse width, the pulse width determines the horn angle. A typical servo responds to pulse widths in the range 1000 to 2000 µs. A pulse width of 1500 µs moves the servo to ...
user avatar
  • 66.3k
4 votes
Accepted

Can unstable PWM timing be corrected?

pigpio supports DMA timed PWM on GPIO 0-31. This has restricted frequencies and resolution. http://abyz.me.uk/rpi/pigpio/python.html#set_PWM_frequency pigpio also drives hardware PWM on GPIO 12, 13, ...
user avatar
  • 66.3k
3 votes
Accepted

Controlling a servo and playing sounds

RPIO, like pigpio, servoblaster, piblaster, and possibly others, use DMA to time the servo pulses. In effect the pulses are hardware timed. In contrast to software PWM they suffer little if any ...
user avatar
  • 66.3k
3 votes

More Software PWM

pigpio provides DMA timed PWM on all 21 user gpios, from C, Python, or any language supporting sockets. video of PWM for 16 LEDs. What do you mean by precautions?
user avatar
  • 66.3k
3 votes
Accepted

How to control a Traxxas XL-5 ESC directly from the GPIO?

I have resolved this. Thanks varesa for the note. Your information is correct but there are 2 elements that I think miss in all of the documentation I've ever found on this. 1) The pi is not the ...
user avatar
  • 126
3 votes

PWM input in Raspberry Pi

I can do fairly accurate pulse width measurement using the piGpio C library: http://abyz.me.uk/rpi/pigpio/index.html This library enables you to install a callback function that will trigger on any ...
user avatar
  • 31
3 votes

How can I control an RC servo?

Knowledge of how to do things on the Pi has improved quite a lot in the years since this question was asked. There are at least four ways of generating hardware timed PWM/Servo pulses on the Pi's ...
user avatar
  • 66.3k
3 votes

Lighting a LED slowly with GPIO

To achieve slow dimming or brightening of your LED you will require (as others have posted before) PWM. Introduction to PWM There are primarily two types of modulation software and hardware. There ...
user avatar
3 votes
Accepted

Default duty cycle of hardware PWM using wiring-pi

Based on RyanO suggestion, I setup pi-gpio with the commands cd /opt/ sudo mkdir piscope cd piscope sudo wget abyz.me.uk/rpi/pigpio/pigpio.zip sudo unzip pigpio.zip cd PIGPIO sudo make sudo make ...
user avatar
  • 192
3 votes

I'm looking for a serial input type "polychromatic" LED as an output for my raspberry pi. Does such a device exist?

All I've heard of is RGB LEDs which are a red, a green, and a blue LED in one package. Using PWM you can give each colour 256 different intensities to make the RGB LED appear to be any colour you ...
user avatar
  • 66.3k

Only top scored, non community-wiki answers of a minimum length are eligible