Questions tagged [python]

Python is a general-purpose, dynamically typed, object-oriented high-level programming language. Interpreters for versions 3.x and 2.x come installed on the Raspberry Pi's most popular operating system distributions.

Filter by
Sorted by
Tagged with
172 votes
1 answer
466k views

What is the difference between BOARD and BCM for GPIO pin numbering?

When using the RPi.GPIO library in Python you have to call import RPi.GPIO as GPIO and then GPIO.setmode(GPIO.BOARD) or GPIO.setmode(GPIO.BCM) What is the difference between these two options?
mirams's user avatar
  • 3,878
48 votes
7 answers
206k views

Playing audio files with Python

I am looking for a well maintained Python library with allows me to play audio files on my Raspberry Pi using the standard audio output. So far I've tried several, but none of them seem to work. ...
Stein's user avatar
  • 1,768
43 votes
6 answers
96k views

How do I update my RPi3 to Python 3.6?

Python 3.6 just came out. I tried following these instructions to build from a tarball, but it got hung up on the make command, so I terminated the process after 20 minutes or so. I also noticed that ...
Justin Palmer's user avatar
37 votes
10 answers
25k views

Detect that a python program is running on the pi

I've got a python script that uses sys.platform.startswith('linux') to test if it is on linux or not, but then I can't tell the difference between the x86/64 processor, and the raspberry pi's ARM ...
jnesselr's user avatar
  • 473
34 votes
6 answers
51k views

Recommended GUI toolkit for Python development on the Raspberry Pi

I am teaching my daughter Python (and myself to some degree) using the Pi, and we have had a great time so far - but the CLI can only take us so far. I have started looking at other toolkits, ...
Goyuix's user avatar
  • 755
33 votes
10 answers
147k views

Running a Python script at startup

This question has been asked quite a few times before but I didn't seem to get it working using the existing information. My Pi runs Raspbian. I have a Python script named dnscheck.py which loops ...
Vlad Schnakovszki's user avatar
33 votes
2 answers
44k views

How to program a USB device with Debian/Python

The Pi is being promoted as an educational device primarily for Python. Inline with this, there have already been some great examples online of people accessing the GPIO from Python. However, most ...
winwaed's user avatar
  • 1,459
31 votes
3 answers
9k views

How can I use the GPIO pins as digital outputs?

I've read that the Raspberry Pi has a number of input and output pins. How can I switch them? (from Python?) What voltage logic? Do I need pull-up or pull-down resistors? Do I need to switch the pins ...
Alex L's user avatar
  • 7,595
29 votes
9 answers
25k views

How can I control an RC servo?

I'd like to control a small RC servo (5 V, 500 mA) from the GPIO pins via Python. Hardware What are the required electrical connections? Can I connect multiple servos to the Raspberry Pi?...
Alex L's user avatar
  • 7,595
27 votes
2 answers
49k views

How to get Python to work with Lighttpd?

I've got Lighttpd setup on my Raspberry Pi, but I'd like to get server-side code working now. I'm familiar with PHP, but I figure I should try Python as it's supposed to be the "go to" language for ...
Mark Ingram's user avatar
25 votes
5 answers
149k views

ImportError: No module named RPi

I am trying to run a package on my Raspberry Pi: At the terminal, I typed in “sudo apt-get install picap” followed by enter. I get it installed but cannot execute "picap-setup" – instead an error ...
99centsdreams's user avatar
23 votes
7 answers
101k views

Raspberry Pi starting programs automatically on startup

I've built a wireless sensor network consisting of two Raspberry Pi's (runnnig Raspbian) with sensors on and a base station Raspberry Pi that collects the data. Each time I want to run the system I ...
Kersakov's user avatar
  • 415
22 votes
5 answers
133k views

How to correctly install the python RPi.GPIO library

I downloaded RPi.GPIO 5.3a from here: https://pypi.python.org/pypi/RPi.GPIO I extracted the tar file, cd into the folder and ran: sudo python setup.py install It ran through a bunch of stuff and ...
FoamyGuy's user avatar
  • 429
22 votes
3 answers
34k views

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

I have an easy circuit wired up, with an LED connected to pin 18 on the BOARD reference. I run a simple program to put pin 18 to HIGH, which turns the LED on, and then a couple of seconds later, I set ...
Viktor Raspberry's user avatar
21 votes
3 answers
47k views

Why cleanup the GPIO pins?

When running a program in Python, why would I want the cleanup command when using the GPIO's?
Human's user avatar
  • 1,188
21 votes
5 answers
18k views

Which Python IDEs/interactive shells are best suited to the Pi?

I know this is perhaps slightly dodgy teritory, but I'm going to go ahead. I'm wondering which of the many python IDEs/interactive shells are best suited to the RPi? By this I mean low RAM, and ...
ACarter's user avatar
  • 2,350
20 votes
4 answers
36k views

Using Raspberry Pi to control my AC via infrared

When I'm on my way back home from somewhere, I want to be able to switch my AC on a few minutes before I arrive at my apartment, probably by using my phone to connect to my Raspberry Pi on my desk ...
Ram Rachum's user avatar
17 votes
3 answers
255k views

How do I run a command line command in a Python script?

I'm using 2 separate scripts, Scale1.py and Scale2.py. To run them I enter sudo python Scale1.py or sudo python Scale2.py from the terminal command line. I would like to have a line in the Scale2.py ...
Rico's user avatar
  • 273
17 votes
3 answers
29k views

How to Run pigpiod on boot

In order to use pigpio Module in Python (remote GPIO for Raspberry Pi ), pigpiod has to be loaded to memory on each RPi. what is the right way to to it ? during Ubuntu's boot or a part of Python's ...
guyd's user avatar
  • 568
17 votes
3 answers
112k views

GPIO: Warning Channel already in use

gpio.py:5: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(8, GPIO.OUT) That is what I get after I run: import RPi....
LilVinny's user avatar
  • 420
17 votes
4 answers
17k views

How can I use more GPIO ports on the Raspberry Pi?

I am currently planning a project for a course at school which involves using the Raspberry Pi - however I'm worried that I will not have enough GPIO connectors for the inputs and outputs that I will ...
ChaoticPanda's user avatar
17 votes
2 answers
8k views

How do I read a button through the GPIO?

I considered myself out of this sort of beginner level stuff a long time ago, but I guess I'm not as smart as I thought I was because I seem to be having an exceptional level of trouble with it! So I'...
Michael's user avatar
  • 171
16 votes
4 answers
74k views

How can I lower the usage of CPU for this Python program?

I will be having a Python run 24/7 in a while loop, here is an example of the sort of program: while True: print ("me again...") But when I run it, my CPU goes to 100%! But I don't want that ...
user151324's user avatar
  • 1,270
16 votes
5 answers
72k views

How do I install pandas on Raspberry Pi?

I'm trying to install Python Pandas on my Raspi and I'm finding strange errors. ~ $ pip install pandas Downloading/unpacking pandas Downloading pandas-0.13.1.tar.gz (6.1Mb): 6.1Mb downloaded Running ...
Jamie Bull's user avatar
  • 1,097
16 votes
3 answers
32k views

Can anyone recommend a simple image viewer?

My boss asked me to find a cheap mediaplayer for some stuff at work. That inspired me to build something on my own, using a Raspberry Pi. My plan is to use udev-rules, to detect usb/sdcard and then ...
aztekk's user avatar
  • 163
16 votes
3 answers
67k views

Execute Python Scripts Via Web interface

I have seen a lot of projects which claim to control the GPIO pins, but I want something a bit different, for example, to be able to blink an LED. Is there a system out there where, via a web ...
J.Zil's user avatar
  • 271
15 votes
8 answers
71k views

How to directly get CPU temp in Python?

Goal is to switch an exhaust fan at an outside data-logging station at a solar power station. The data-collection program is written in Python under Raspbian. For reading CPU temp at a command line, ...
SDsolar's user avatar
  • 2,328
15 votes
4 answers
31k views

Can Python control normal Minecraft, or only the RasPi Edition?

My son wants to make a game in Python that is materialized in Minecraft. If he does that using the RasPi Edition, can that same Python code control the normal Minecraft on a PC? My guess is that ...
Jim L.'s user avatar
  • 325
15 votes
6 answers
86k views

Installed pyusb, still: 'ImportError: no module named core'

On my Raspberry Pi I installed libusb and pyusb via sudo apt-get install libusb-dev python-usb. But running some Python code (pyrow, to read data from a rowing machine) gives me this error at import ...
A. Goossens's user avatar
15 votes
1 answer
16k views

How do I update Python to version 3?

Is there any way to update Python on the Raspberry Pi (Wheezy) to Python 3.3?
xxmbabanexx's user avatar
  • 3,258
15 votes
5 answers
12k views

Falls off network ("Destination host unreachable")

I am running my Raspberry Pi headlessly, connecting via SSH over the network. I am having a problem that I can consistently reproduce. I will leave a Python script running on my Raspberry Pi and come ...
Andy Smith's user avatar
15 votes
4 answers
67k views

How can I connect to a USB serial device?

I have a device with a USB serial port cable that I'd like to connect to my Raspberry Pi. The chipset for this USB to serial cable it the PL-2303 from Prolific Technology, Inc. How can I read data ...
Swinders's user avatar
  • 255
14 votes
5 answers
66k views

PyQt5 on a Raspberry Pi

I have a Raspberry Pi 3 with Raspbian installed, along with a 7" touch screen. I'm in the process of creating an application in Python to read several DS18B20 Thermocouples to monitor the temperature ...
CharlieHorse's user avatar
14 votes
2 answers
11k views

Compare and contrast Python GPIO APIs

I'm just starting with Pi and want to program GPIO in Python. So far I've come across five libraries: WiringPi-Python RPi.GPIO RPIO gpiozero pigpio Before I commit time to learning one, I want to ...
spinkus's user avatar
  • 311
14 votes
1 answer
12k views

Raspberry pi GPIO input pins give random values

I've been playing a lot with the Raspberry Pi lately. But I have a problem. When I set up an input pin to check whether electricity is sent to it or not, it gives me rather unstable answers. A few ...
Gustaf's user avatar
  • 141
14 votes
4 answers
6k views

How to include RPi.GPIO in a python CGI script with lighttpd?

I've recently setup python to work with lighttpd via CGI (see here). But the minute I go to include RPi.GPIO, the script stops executing (I'm assuming because no HTML gets output), but there is no ...
Mark Ingram's user avatar
13 votes
4 answers
22k views

How to boot into own python script (GUI) only?

I have the following problem: Using a RaspPi 3B running Raspbian Jessie (version 4.4.26-v7+) I would like the GUI of a self-written python script to be executed on startup. I know that this question ...
Fantilein1990's user avatar
13 votes
3 answers
45k views

Installing Python 3.4 on Raspberry Pi

Is it possible to run python 3.4 on a Raspberry Pi? Currently I have python 3.2, but the odd thing is that running sudo apt-get update sudo apt-get install python3 results in my Raspberry Pi ...
starbeamrainbowlabs's user avatar
13 votes
2 answers
25k views

Using OpenCV with RasPiCam and python

Has any one been able to get OpenCV to directly play video from the RasPiCam board using python? I've seen some projects involving workarounds, but what I'm interested in is being able to use the ...
Ryan's user avatar
  • 233
13 votes
2 answers
6k views

Why does python run relatively slowly?

I've been benchmarking the Pi on some of my simulation codes, relative to a couple of laptops I have. My codes tend to be floating point intensive, so I've been using Raspbian (which turns out to be ...
Darren Wilkinson's user avatar
12 votes
4 answers
42k views

How to get the Raspberry Pi's IP address for SSH

I am using Mac OSx to access my Pi via SSH. To access it, I know that I need the Pi's IP address. So, I decided to use a few Python commands which have always succeeded in giving me the local IP. ...
xxmbabanexx's user avatar
  • 3,258
12 votes
4 answers
12k views

12V device to a Raspberry Pi

For my school engineering project, I have a coin acceptor device which I would like to link to the Raspberry Pi. However the device requires 12V in power. I have an idea of what to do to power the ...
ChaoticPanda's user avatar
12 votes
1 answer
1k views

Is it possible to communicate with I²C devices via the GPIO? [duplicate]

Is it possible to communicate with I²C devices via the GPIOs? Also, are there any existing drivers or libraries that make this possible from Python?
Damian Powell's user avatar
12 votes
1 answer
19k views

Sound recording using python

I'm trying to record some sound with RPI using python and pyaudio library and facing a few interesting issues - junky console output when attempting to use pyaudio and lots of noise mixing into the ...
abolotnov's user avatar
  • 952
11 votes
2 answers
5k views

Loop doesn't work unless I use 'print'

This code does not turn the led on and off. import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(21,GPIO.OUT) for number in range(0,10): GPIO.output(21,...
tazboy's user avatar
  • 221
11 votes
14 answers
69k views

PiCamera not Working

For starting the camera I am doing >>> import picamera >>> camera = picamera.PiCamera() mmal: mmal_vc_component_enable: failed to enable compononent : ENOSPC Traceback (most ...
Coderaemon's user avatar
11 votes
2 answers
18k views

Pi camera v2 - fast, full sensor capture mode with downsampling

I've a Pi camera v2 which I'm planning to use with an RPi3 for a computer vision project. I need to capture full sensor images from the camera - no cropping. The resolution actually used by the ...
Florin Andrei's user avatar
11 votes
2 answers
19k views

PiGPIO Library Example for Bit-Banging a UART

The PiGPIO library http://abyz.me.uk/rpi/pigpio/index.html mentions that one of it's features is "software serial links using any user gpio". I take this to mean that you can use it to generate a ...
PhilBot's user avatar
  • 371
11 votes
2 answers
13k views

Develop a Raspberry python script from a windows

I want to develop a Raspberry python script from the windows side, for several reasons: I want to keep all the code (more) secure on my computer, in case I fry the RPi/try another project/reinstall ...
J4N's user avatar
  • 293
10 votes
5 answers
37k views

gpio library on windows while developing

I am new to Python so maybe this is not an appropriate question. I am working on a project on Python that will use GPIO functionalities of the raspberry Pi. Right now, I am developing the python code ...
luisgepeto's user avatar

1
2 3 4 5
65