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
164 votes
1 answer
436k 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?
user avatar
  • 3,748
47 votes
7 answers
199k 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. ...
user avatar
  • 1,748
44 votes
5 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 ...
user avatar
36 votes
8 answers
21k 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 ...
user avatar
  • 463
34 votes
6 answers
50k 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, ...
user avatar
  • 735
32 votes
10 answers
144k 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 ...
user avatar
31 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 ...
user avatar
  • 1,399
29 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 ...
user avatar
  • 7,385
28 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?...
user avatar
  • 7,385
27 votes
2 answers
47k 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 ...
user avatar
23 votes
7 answers
100k 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 ...
user avatar
  • 415
21 votes
3 answers
32k 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 ...
user avatar
21 votes
5 answers
122k 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 ...
user avatar
20 votes
5 answers
117k 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 ...
user avatar
  • 409
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 ...
user avatar
19 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 ...
user avatar
  • 2,220
18 votes
3 answers
41k views

Why cleanup the GPIO pins?

When running a program in Python, why would I want the cleanup command when using the GPIO's?
user avatar
  • 1,138
17 votes
3 answers
251k 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 ...
user avatar
  • 273
17 votes
4 answers
16k 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 ...
user avatar
17 votes
5 answers
12k 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 ...
user avatar
16 votes
4 answers
69k 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 ...
user avatar
  • 1,250
16 votes
5 answers
62k 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 ...
user avatar
  • 1,087
16 votes
4 answers
66k 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 ...
user avatar
  • 271
16 votes
3 answers
31k 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 ...
user avatar
  • 163
16 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'...
user avatar
  • 161
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 ...
user avatar
  • 325
15 votes
3 answers
23k 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 ...
user avatar
  • 548
15 votes
6 answers
83k 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 ...
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?
user avatar
  • 3,188
14 votes
5 answers
63k 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 ...
user avatar
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 ...
user avatar
13 votes
7 answers
57k 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, ...
user avatar
  • 2,190
13 votes
2 answers
9k 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 ...
user avatar
  • 301
13 votes
1 answer
11k 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 ...
user avatar
  • 131
13 votes
4 answers
21k 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 ...
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 ...
user avatar
13 votes
4 answers
66k 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 ...
user avatar
  • 235
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 ...
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 ...
user avatar
12 votes
3 answers
92k 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....
user avatar
  • 370
12 votes
4 answers
40k 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. ...
user avatar
  • 3,188
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 ...
user avatar
12 votes
1 answer
18k 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 ...
user avatar
  • 942
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,...
user avatar
  • 221
11 votes
14 answers
65k 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 ...
user avatar
11 votes
2 answers
16k 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 ...
user avatar
11 votes
2 answers
18k 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 ...
user avatar
  • 361
11 votes
1 answer
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?
user avatar
11 votes
2 answers
12k 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 ...
user avatar
  • 273
10 votes
5 answers
31k 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 ...
user avatar

1
2 3 4 5
62