Hot answers tagged

63 votes
Accepted

Access GPIO pins without root. No access to /dev/mem. Try running as root!

You probably need to be running Raspbian to use RPi.GPIO as a non-root user, possibly it needs to be jessie as well. Does /dev/gpiomem exist? If so RPi.GPIO should use this device to access the GPIO....
user avatar
  • 66.6k
51 votes

Loop doesn't work unless I use 'print'

Unroll your loop to understand what's happening here: for number in range(0,10): GPIO.output(21,GPIO.LOW) time.sleep(1) GPIO.output(21,GPIO.HIGH) turns into: GPIO.output(21,GPIO.LOW)...
user avatar
  • 15.5k
44 votes

Power a 5V relay from GPIO pins

Why not simply like this? Raspberry Pi switches between 0 and 3V3, more than enough to saturate Q1, which takes over the "heavy" work: switching the +5V relay on/off. Depending on the relays you're ...
user avatar
  • 916
43 votes
Accepted

GPIO Pinout Orientation RaspberyPi Zero W

In your image, the SD-card reader would be positioned to the left and the front side of the card would be facing the viewer. Here's a better image which can't be misinterpreted:
user avatar
  • 546
34 votes
Accepted

Why do the Pi GPIO pins use/give 3.3V and not 5V?

The ATMega chips specify Operating Voltage: ̶ 1.8 - 5.5V. If you read deeper the operating speed is dependent on voltage. They work at 3.3V but you have to limit the clock speed. The Arduino team ...
user avatar
  • 53.6k
29 votes
Accepted

DS18B20 not listed in /sys/bus/w1/devices

Found it! sudo nano /boot/config.txt add : dtoverlay=w1-gpio this has to do with kernel update, find more info in this link
user avatar
  • 306
29 votes
Accepted

Why are some GPIO pins HIGH when the Raspberry Pi boots up?

At powerup the GPIOs are pulled either high or low through the internal resistors. Whether the pull is high or low for a particular GPIO is detailed on page 102 of BCM2835 ARM Peripherals. As the ...
user avatar
  • 66.6k
25 votes
Accepted

How often to reboot raspberry and is it even necessary

I've got a couple of Pis running my Ham Radio repeater and irrigation system - realistically, I'm rebooting them maybe once every 6 months for security updates or some other "maintenance" reason; but ...
user avatar
  • 266
25 votes

How often to reboot raspberry and is it even necessary

In terms of hardware, the only reason you should ever need to reboot an ARMHF-y board is firmware changes, necessary changes to ROM, or possibly new devices that must be present at boot. For instance,...
user avatar
  • 397
22 votes
Accepted

Loop doesn't work unless I use 'print'

Try to replace your print by a time.sleep(0.05). You may occur this strange behavior as GPIO.output is switched too quickly from HIGH to LOW to be set/detected/seen. Increase/reduce the sleep duration ...
user avatar
  • 1,400
22 votes
Accepted

How to Run pigpiod on boot

sudo systemctl enable pigpiod will enable it to auto-start on boot. sudo systemctl start pigpiod will start it immediately (just a posh way of doing sudo pigpiod :) If you change your mind, ...
user avatar
  • 336
20 votes

Do all GPIO pins have a internal pull-up/pull-down resistors?

Yes, all of the B+'s GPIO pins have internal pull-up or pull-down resistors that can be controlled from your code. Pull-up is 50K min – 65K max. Pull-down is 50K min – 60K max. More info on the GPIO ...
user avatar
19 votes
Accepted

Why cleanup the GPIO pins?

As mentioned in this article RPi.GPIO basics 3 – How to Exit GPIO programs cleanly, avoid warnings and protect your Pi, correct use of GPIO.cleanup(), Correct use of GPIO.cleanup() RPi.GPIO provides ...
user avatar
  • 2,793
19 votes
Accepted

conflicting dtoverlays

As it turns out several overlays can be loaded by adding multiple dtoverlay variables: In this case: dtoverlay=4dpi-3x dtoverlay=w1-gpio
user avatar
19 votes

GPIO pin voltage is too low to energize relay

If you want to drive a single low-voltage relay, using a 7-channel driver chip will be an overkill. You'll be perfectly fine with a single NPN transistor and a flyback diode: simulate this circuit &...
user avatar
19 votes

GPIO Pinout Orientation RaspberyPi Zero W

Pin 1 has a square solder pad, all the rest are circular. This is a general convention in electronics.
user avatar
  • 191
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
18 votes
Accepted

Why are there 8 ground pins on the Raspberry Pi?

It's a breakout on a development oriented board, and ground is probably required more than anything -- everytime you connect one of the power rails, you need a ground connection, but in addition, ...
user avatar
  • 55.8k
17 votes

What components would I need for my Pi to safely detect a 12V automotive circuit on GPIO?

A very secure solution uses an optocouple. A 1kΩ resistor is good for an input voltage range of 5 to 20 volts. You may connect the two grounds, but it's not required. The output is inverted, that ...
user avatar
  • 1,643
16 votes
Accepted

PiGPIO Library Example for Bit-Banging a UART

Here is some Python I used to test the reliability of software serial. The input side is fairly trivial. You just make the appropriate bit bang serial open calls in Python or C. The output side is ...
user avatar
  • 66.6k
16 votes
Accepted

GPIO: Warning Channel already in use

This code helped me get rid of the warning (the "finally" part at the end): import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) # Broadcom pin-numbering scheme GPIO.setup(6, GPIO.OUT) # ...
user avatar
16 votes
Accepted

Compare and contrast Python GPIO APIs

Warning. I am the author of pigpio so will be biased. You might get a taste by looking at elinux. RPi.GPIO was the first and is the most popular. It will be the one you most often see examples for....
user avatar
  • 66.6k
14 votes
Accepted

Properly wiring a solid-state relay to the GPIO pins?

Your wiring diagram is correct, as (per the Sainsmart.com website you linked) the specs of the device are: Input control signal voltage: 0V - 0.5V Low stage (SSR is OFF), 0.5V – 2.5V (unknown ...
user avatar
  • 4,993
14 votes
Accepted

GPIO pin voltage is too low to energize relay

You should not directly drive a relay from the Raspberry Pi. An individual GPIO can only safely provide about 16mA at 3V3 which is unlikely to be enough to energise the coils of a standard ...
user avatar
  • 66.6k
14 votes

rPi2 model B v1.1 smoke comes out near power port

The Raspberry Pi requires 5 Volts - if you've fed it 12 Volts you've killed it. Powering the Pi using the GPIO pins bypasses the fuses that might have saved the Pi if you had used the micro USB ...
user avatar
  • 6,161
14 votes

What's the difference between soft PWM and PWM

Note that I am the author of pigpio so will be biased in my assessment of the different types of PWM. Actually there are three different types of PWM supported on the Pi. Fully hardware PWM This type ...
user avatar
  • 66.6k
14 votes
Accepted

How do I avoid a temporary short circuit from destroying the PI?

How do I avoid a temporary short circuit from destroying the PI? It's very easy really: power down your Pi alter the connections power on the Pi again Electronics are not hot-pluggable by nature, ...
user avatar
13 votes
Accepted

Should GPIO pins 13 and 14 be soldered together?

No they should not be soldered together (this is called a solder bridge). You should initiate a return request. You could cut or rework the trace yourself, but I would still suggest returning it - if ...
user avatar
13 votes
Accepted

GPIO Pin Explanation

The Broadcom datasheet linked from raspberrypi.org in Boštjan Jerko answer is a great reference; for example, section 6.2 describes the various functions that can be assigned to each pin as per joan's ...
user avatar
  • 55.8k
13 votes
Accepted

Plug a 5 V fan to GPIO 1 and 2

The diagram does not show pin numbers. Neither can I find anything on the diagram labelled 1. The diagram does appear to correctly label the ground and 5V pins. You can power a 5V fan by connecting ...
user avatar
  • 66.6k

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