Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

120
votes
1answer
297k 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?
37
votes
7answers
156k 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. ...
36
votes
5answers
67k 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 ...
31
votes
6answers
43k 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, ...
29
votes
9answers
112k 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 ...
29
votes
2answers
41k 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 ...
25
votes
9answers
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?...
25
votes
2answers
8k 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 ...
22
votes
6answers
96k 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 ...
22
votes
2answers
39k 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 ...
20
votes
6answers
9k 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 ...
19
votes
4answers
33k 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 ...
17
votes
3answers
23k 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 ...
17
votes
5answers
17k 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 ...
15
votes
3answers
79k 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 ...
15
votes
3answers
22k 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 ...
15
votes
2answers
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'...
14
votes
4answers
44k 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 ...
14
votes
4answers
26k 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 ...
14
votes
4answers
14k 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 ...
14
votes
1answer
11k 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?
14
votes
4answers
61k 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 ...
14
votes
4answers
10k views

Falls off network (“Destination host unreachable”)

I am running my 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 Pi and come back a few hours ...
12
votes
3answers
170k 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 ...
12
votes
4answers
14k 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 ...
12
votes
3answers
40k 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 ...
12
votes
4answers
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 ...
12
votes
2answers
24k 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 ...
12
votes
2answers
5k 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 ...
11
votes
2answers
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,...
11
votes
3answers
19k views

Why cleanup the GPIO pins?

When running a program in Python, why would I want the cleanup command when using the GPIO's?
11
votes
4answers
58k 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 ...
11
votes
1answer
16k 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 ...
10
votes
2answers
5k 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 ...
10
votes
1answer
13k 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 ...
10
votes
1answer
10k 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 ...
10
votes
3answers
34k 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. ...
9
votes
3answers
9k views

Pi Camera - how to create a flash?

I have a need to take photos with the Pi camera, but to illuminate the subject. The subject will be 1m or so away, but will be in total darkness most of the time. Therefore, I need a flash of some ...
9
votes
6answers
37k views

Python and OpenSSL error on import

So I'm trying to add SSL to my web server running on my pi B+ (using cherrypy) I made sure that OpenSSL was installed with: sudo apt-get install openssl Then I installed pyOpenSSL with: sudo apt-...
9
votes
3answers
22k 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 ...
9
votes
2answers
11k views

Can I run Selenium webdriver using Firefox as the browser?

I would like to set up the Raspberry Pi as a client that exclusively runs FireFox as a client in a Selenium grid. Has anyone tried and got this to work? Are there any tips or pitfalls that I will ...
9
votes
4answers
10k 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 ...
9
votes
1answer
1k views

Is it possible to communicate with i2c devices via the GPIO? [duplicate]

Is it possible to communicate with i2c devices via the GPIO? Also, are there any existing drivers or libraries that make this possible from Python?
9
votes
2answers
11k 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 ...
8
votes
14answers
41k 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 ...
8
votes
2answers
28k views

installing OpenCV 3.0 on raspberry pi b+

Is it possible to install OpenCV 3.0, opencv python on Raspberry pi b+? How to install and are there any precompiled binaries available ?
8
votes
2answers
23k views

Toggling a GPIO pin set as output

I read here that I could toggle the state of a GPIO pin set to output in Python using the following command: GPIO.output(LED, not GPIO.input(LED)) where LED is the pin value. I can turn the LED on ...
8
votes
3answers
80k views

How do I display an image file (PNG) in a simple window?

I've got a prototype I need to show for an RFID project. I've got the RFID (Parallax USB) working, and the sample Python script (my first) is displaying the ID of the card just like it's supposed to......
8
votes
5answers
52k 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 ...
8
votes
4answers
27k views

Why is Python the preferred language for the pi

Why is python perceived as the preferred language to control and manipulate Raspberry Pi? Why is Python language chosen over other other programming languages like PERL, etc. (which are included ...