Go to advanced search

by tom.slick
Tue Oct 25, 2016 10:16 pm
Forum: Python
Topic: Running a Python script from a webpage
Replies: 7
Views: 4136

Re: Running a Python script from a webpage

add a button to this

Code: Select all

<?php 

$command = escapeshellcmd('script.py');
$output = shell_exec($command);
echo $output;

?>
by tom.slick
Sun Oct 23, 2016 9:20 pm
Forum: Python
Topic: python function code for blink LED issue
Replies: 8
Views: 3182

Re: python function code for blink LED issue

I'm on my phone so I can't test this, but I think the following should work: import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) GPIO.setup(11, GPIO.OUT) speed = input("Enter length of each blink (second): ") times = input("Enter total number of times to blink: ") p...
by tom.slick
Thu Oct 13, 2016 9:19 am
Forum: Python
Topic: controlling 4-digit display with gpiozero
Replies: 20
Views: 3002

Re: controlling 4-digit display with gpiozero

Wow! All respect for tom.slick !!! When I first ran the code, the digits were displayed in an inverted way. What was on had to be off, and vice versa. So I've changed the on and off's in the code and..... It works!!!!! This is the working code for my 4-digit display of the 'common cathode' type. Th...
by tom.slick
Tue Oct 11, 2016 9:53 pm
Forum: Python
Topic: controlling 4-digit display with gpiozero
Replies: 20
Views: 3002

Re: controlling 4-digit display with gpiozero

Hello, Iim back again. I took on the advice of tom.slick and took a long look at the code... I decided to try out one solution and stopped mixing 2 types of code. Now, I understand a bit more what is happening, but I haven't reached a working code yet.... This is what I've got so far. The segmentpa...
by tom.slick
Mon Oct 10, 2016 9:02 pm
Forum: Python
Topic: A beginner needs help with the last function of the code
Replies: 2
Views: 563

Re: A beginner needs help with the last function of the code

you're setting numbers[0] to hekto but not resetting hekto when you set numbers[0] back to 5.0. I don't really understand why you have a list of only one value and why you duplicate it in hekto. There doesn't seem to be functionality to append to numbers so not clear why list and why for loop. Does...
by tom.slick
Tue Oct 04, 2016 2:54 am
Forum: Python
Topic: Parsing Weather info from XML
Replies: 4
Views: 1179

Re: Parsing Weather info from XML

Wow it worked thank you! I've added the option to automatically download the file from internet and show updated data through "urllib" and it's working fine. I've also added the "print" of "humidity" and "pression", but they belong to "situation" node, same as "temperature" Now I have 3 more questi...
by tom.slick
Mon Oct 03, 2016 8:28 pm
Forum: Python
Topic: Parsing Weather info from XML
Replies: 4
Views: 1179

Re: Parsing Weather info from XML

python has built-in support for xml

https://docs.python.org/2/library/xml.dom.minidom.html

Simple example

Code: Select all

from xml.dom import minidom
xmldoc = minidom.parse('yourxmlfile.xml')
entry = xmldoc.getElementsByTagName('situation')
print entry[0].attributes['temperature'].value
by tom.slick
Mon Oct 03, 2016 7:31 pm
Forum: Python
Topic: Problem: every script with camera runs fullscreen
Replies: 2
Views: 504

Re: Problem: every script with camera runs fullscreen

https://www.raspberrypi.org/documentation/usage/camera/python/README.md PREVIEW You can display a preview showing the camera feed on screen. Warning: this will overlay your Python session by default; if you have trouble stopping the preview, simply pressing Ctrl+D to terminate the Python session is...
by tom.slick
Mon Oct 03, 2016 8:30 am
Forum: Python
Topic: creating slideshow of images on RaspberryPi3 with Python3
Replies: 6
Views: 3998

Re: creating slideshow of images on RaspberryPi3 with Python

Hello and thank you in advance for help in this forum! I am very new to Python 3 Programming - and the Raspberry Pi3 that I just got. I would like to make a simple slide show of images that will be triggered by a capture image from the Pi Camera. (I just successfully saw live video from my PiCamera...
by tom.slick
Fri Sep 30, 2016 7:22 am
Forum: Python
Topic: How do I implement a Linux shutdown -h now command from pyth
Replies: 19
Views: 4391

Re: How do I implement a Linux shutdown -h now command from

So to recap for the benifet of others, you were importing a file you named subrpocess and not the built-in subprocess module. print subprocess <module 'subprocess' from '/home/pi/subprocess.pyc'> /home/pi/subprocess.pyc is the location of an old file you made and not something from the python path p...
by tom.slick
Fri Sep 30, 2016 7:08 am
Forum: Python
Topic: controlling 4-digit display with gpiozero
Replies: 20
Views: 3002

Re: controlling 4-digit display with gpiozero

Why try to combine to different examples for two different sets of hardware and try to make one working version of it? Take the working version for the 4 digit display and change the GPIO command to work with gpiozero. It's a library to library port. You don't need to worry about the code from one t...
by tom.slick
Fri Sep 30, 2016 6:46 am
Forum: Python
Topic: New to Python???
Replies: 18
Views: 2144

Re: New to Python???

Sorry if the examples are to basic. But it's better to assume no knowledge then to assume some knowledge and confuse a "beginner" and start in the middle. From your comments you seem to favor BASIC in one form or another. But once you get to know and use python you will find that it is the "GOTO" fo...
by tom.slick
Fri Sep 30, 2016 3:22 am
Forum: Python
Topic: New to Python???
Replies: 18
Views: 2144

Re: New to Python???

Not being sarcastic, but googles links are a great starting points for learning python. Links 4 through 1 (in that order) are really good statring points for a begginer. https://www.google.com/search?num=20&espv=2&q=python+tutorial&oq=learn+python&gs_l=serp.1.0.0i71k1l8.0.0.0.24414.0.0.0.0.0.0.0.0.....
by tom.slick
Fri Sep 30, 2016 1:21 am
Forum: Python
Topic: How do I implement a Linux shutdown -h now command from pyth
Replies: 19
Views: 4391

Re: How do I implement a Linux shutdown -h now command from

I see the problem Fri Sep 30 09:50:40 AEST 2016 Your RPI is upside down. But seriously the script works for me. Do you maybe have a file called subprocess.py in the same folder. Add these lines to just before subprocess.call(["shutdown", "-h", "now"]) print subprocees print type(subprocess) print su...
by tom.slick
Tue Sep 27, 2016 9:41 pm
Forum: Python
Topic: Python pyaudio and python-sounddevice modules
Replies: 1
Views: 1078

Re: Python pyaudio and python-sounddevice modules

Never tried python-sounddevice, but I have never had a problem with pyalsaaudio and USB sound cards. You might want to give it a try.
by tom.slick
Tue Sep 27, 2016 9:31 pm
Forum: Python
Topic: Timers counting seconds
Replies: 7
Views: 6854

Re: Timers counting seconds

This might be a little overkill, but should do exactly what you want. #!/usr/bin/env python import time # for convenience hours = "h" minutes = "m" seconds = "s" h = "h" m = "m" s = "s" class SimpleTimer(object): """A simple timer Provides a simple timer to keep track of elapsed time. It has methods...
by tom.slick
Tue Sep 27, 2016 8:36 am
Forum: Python
Topic: reading directory from pc on rpi with python
Replies: 7
Views: 1404

Re: reading directory from pc on rpi with python

Hi, I lnow there are Putty and Filezilla to read files on the RPI board and copy them on your PC but I want to do this in Python. I want to write a program in Python to start activity (a measurement) on the RPI and retrieving the data, stored in the RPI, to my PC. Are there any examples of doing th...
by tom.slick
Sun Sep 25, 2016 6:48 am
Forum: Python
Topic: Multiple Inputs
Replies: 2
Views: 621

Re: Multiple Inputs

If you have multiple RPI's sending then you have a way to identify each. What does the code look like? Post an example of what you are doing.
by tom.slick
Sun Sep 25, 2016 6:44 am
Forum: Python
Topic: Running a bash command from python with arguments
Replies: 5
Views: 1642

Re: Running a bash command from python with arguments

Try posting more code. You left a few holes.
by tom.slick
Sun Sep 25, 2016 6:35 am
Forum: Python
Topic: How do I implement a Linux shutdown -h now command from pyth
Replies: 19
Views: 4391

Re: How do I implement a Linux shutdown -h now command from

The shlex will give you the correct args to pass to subprocess.call import subprocess import shlex cmd = shlex.split("sudo shutdown -h now") subprocess.call(cmd) Indeed - it's a very good way of doing this when you have a command line that you know works. I don't know if that would cause the error ...
by tom.slick
Sat Sep 24, 2016 7:09 am
Forum: Python
Topic: How do I implement a Linux shutdown -h now command from pyth
Replies: 19
Views: 4391

Re: How do I implement a Linux shutdown -h now command from

The shlex will give you the correct args to pass to subprocess.call

Code: Select all

import subprocess
import shlex
cmd = shlex.split("sudo shutdown -h now")
subprocess.call(cmd)
by tom.slick
Fri Sep 23, 2016 6:29 pm
Forum: Python
Topic: Thread Problem
Replies: 2
Views: 435

Re: Thread Problem

Code: Select all

from threading import Thread
import time


def test():
    for i in range(3):
        print i
        time.sleep(1.0)


a = Thread(target=test)
b = Thread(target=test)

a.start()
b.start()
target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.
by tom.slick
Thu Sep 22, 2016 7:57 pm
Forum: Python
Topic: Reading two MCP3008 A/Ds
Replies: 7
Views: 1386

Re: Reading two MCP3008 A/Ds

Couldn't you just call wiringPiSPISetup twice, once for channel 0 and then again for channel 1
wiringPiSPISetup (int channel, int speed)

and then use wiringPiSPIDataRW
int wiringPiSPIDataRW (int channel, unsigned char *data, int len)

Go to advanced search