Skip to main content
Share Your Experience: Take the 2024 Developer Survey
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 ...
Neil's user avatar
  • 361
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 ...
joan's user avatar
  • 71.1k
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 ...
joan's user avatar
  • 71.1k
5 votes

Control a 12V dc fan via PWM and a level shifter

Since everything is working now I want to post a summary of how I am controlling a 12V fan with my Pi. My Hardware for this is: 1x KeeYees 4-channel IIC I2C level shifter from 3.3V to 5V 1x Artic F9 ...
Kai's user avatar
  • 103
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 ...
goldilocks's user avatar
  • 59.1k
4 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 ...
stevec's user avatar
  • 41
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,...
joan's user avatar
  • 71.1k
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 ...
joan's user avatar
  • 71.1k
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 ...
Milliways's user avatar
  • 60.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 ...
Patrick Cook's user avatar
  • 6,365
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 ...
joan's user avatar
  • 71.1k
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, ...
joan's user avatar
  • 71.1k
4 votes
Accepted

Using GPIO PWM with sysfs

To use pwm, you need to use the pwm interface at /sys/class/pwm, not the gpio interface. Here is the relevant documentation. The startup would be something like export 1 > /sys/class/pwm/pwmchip0/0/...
PMF's user avatar
  • 896
4 votes

Using Hardware PWM in Raspberry Pi 4

The Pi has only two accessible hardware PWM channels. GPIO 12 and 18 share one setting, GPIO 13 and 19 the other. So if you set GPIO 12 to 15% dutycycle at 400Hz that will come out of GPIO 18 as ...
joan's user avatar
  • 71.1k
3 votes

PWM input in Raspberry Pi

The long answer: You actually can! (well with a little help from our friends resistor and capacitor) You can convert a PWM output to an analog voltage level, (DAC) and read it with ADC pin on your ...
Quest's user avatar
  • 370
3 votes

which driver can control 4-5 motors, different types of sensors, speakers?

The most capable motor controller board that gets closest to what you require is called the 4tronix Picon Zero. As you can see from the picture, it allows you to drive 2 DC motors (bottom right) and ...
recantha's user avatar
  • 4,479
3 votes
Accepted

GPIO reset needed for Servo?

If you don't set the mode, it will not work. No, it is not hazardous. No, you do not need to clean up GPIO after the script runs. Indeed, if you do so, the servo will not work properly.
joan's user avatar
  • 71.1k
3 votes

What is the pin number for PWM outputs on RPI3 model B?

There are two hardware PWM channels. Channel 0 is available on GPIO 12 and 18. Channel 1 is available on GPIO 13 and 19. You can use the pigs hp command to set hardware PWM (requires the pigpio ...
joan's user avatar
  • 71.1k
3 votes
Accepted

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

I suggest you put a hat on top of your raspberry pi. They communicate via I2C and multiply your PWM pins and you can stack them, there are already Java libraries popping out. Yesterday, I ...
Oscar Salguero's user avatar
3 votes
Accepted

Send PWM signal from Raspberry Pi 3 BEFORE boot

PWM (Pulse Width Modulation) applies to digital as well as analogue signals. Individually addressable LED strips, such as you want to use, are not controlled by PWM signals. They are controlled by ...
joan's user avatar
  • 71.1k
3 votes

Testing my low frequency generator

Use hardware PWM. There are two channels on the Pi. One channel is available from GPIO 12 and/or 18, the other channel is available from GPIO 13 and/or 19. pigpio and wiringPi both support hardware ...
joan's user avatar
  • 71.1k
3 votes

LED pwm fading is flickering

The RPi.GPIO Python module uses software timing for PWM. Occasionally the software will be delayed leaving the LED on or off for longer than expected. This will be seen as flickering. You could ...
joan's user avatar
  • 71.1k
3 votes
Accepted

3 PWM pins for RGB LED

My pigpio provides hardware timed PWM on any of GPIO 0-31. C, Python, and from the command line (pigs). No need to waste money on additional hardware.
joan's user avatar
  • 71.1k
3 votes

Turn a Raspberry Pi into a voltage tester

Question Let me first summarize the OP's question. He has a 220VAC water pump. He knows that a 555 IC can tell AC current on by blinking a LED. His question is how to let Rpi talk to 555 to find ...
tlfong01's user avatar
  • 4,695
3 votes

How can Rpi4B python UART talk to XY PWM Signal Generators?

Question How can Rpi4B python UART talk to XY PWM Signal Generators? Answer Contents (1) Introducing XY-LPWM, UART support version of XY-PWM (2) Using Win10 RealTerm terminal emulator to ...
tlfong01's user avatar
  • 4,695
3 votes

Can I reliably control four ESC with a servo driver board?

pigpio will let you control ESCs from the Pi. It uses hardware timed PWM. Python: use set_servo_pulsewidth C: use gpioServo Command line: use pigs s
joan's user avatar
  • 71.1k
3 votes
Accepted

PWM problem in a frequency less than 100Hz

I expect in reality the final state of the GPIO is pretty random. As you don't do a cleanup GPIO 17 will be left as an output. Its level will remain at whatever it was when the sleep elapses and RPi....
joan's user avatar
  • 71.1k
3 votes
Accepted

raspberry pi fan don't start to spin without hand help!

If it's connected as you claim, then the fan is probably faulty. There are things you could do to check, but you didn't say if you had a voltmeter or oscilloscope available. So - here is one check you ...
Seamus's user avatar
  • 22.2k
3 votes
Accepted

Audio via PWM pins?

Default audio uses PWM (AFAIK pins 40,41). It is POSSIBLE to enable PWM on header pins (which will disable headphone jack), and there are a few tutorials explaining this - mainly intended for those ...
Milliways's user avatar
  • 60.3k
3 votes
Accepted

How can I use dtoverlay=pwm

I recently discovered some kernel documentation Pulse Width Modulation (PWM) interface Like much kernel documentation this is inscrutable. It states This API controls both the PWM period/duty_cycle ...
Milliways's user avatar
  • 60.3k

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