Go to advanced search

by mattrix
Wed Nov 25, 2015 9:20 pm
Forum: Python
Topic: Use of switches to redirect a Program
Replies: 11
Views: 1642

Re: Use of switches to redirect a Program

Try something like this (untested) import time from threading import Thread from itertools import cycle import RPi.GPIO as GPIO import mikezlcd class Pulse(object): PULSE_PIN = 18 BUTTON_PIN = 20 def __init__(self): self.count = 0 self.lcd = mikezlcd.lcd_module(2004, 17, 27, 25, 24, 23,22) self.info...
by mattrix
Wed Nov 25, 2015 1:24 am
Forum: Python
Topic: Use of switches to redirect a Program
Replies: 11
Views: 1642

Re: Use of switches to redirect a Program

Hi, It's probably best to have 2x threads Main thread monitors the sensor and records the data 2nd thread waits for button press to change the LCD display. First, can you see if this code works as usual. I have used wait_for_edge instead of your while loop to wait for any falling edge (pin going fro...
by mattrix
Wed Nov 25, 2015 1:07 am
Forum: Gaming
Topic: Minecraft Server on the RPi 2 B
Replies: 3
Views: 1385

Re: Minecraft Server on the RPi 2 B

You could give this a try: http://www.matthuisman.nz/2015/09/raspberry-pi2-minecraft-server-image.html Features Spigot 1.8 (stock) JRE 7 Automatically resizes SD card on first boot Automatically generates SSH keys on first boot Automatically starts Minecraft Server on boot Fits on 2GB+ SD Card
by mattrix
Mon Nov 23, 2015 3:46 am
Forum: General programming discussion
Topic: Pi as a 'down detector'?
Replies: 3
Views: 1933

Re: Pi as a 'down detector'?

Here is a simple python script to do it import urllib2 import RPi.GPIO as GPIO import time RELAY = 21 #RELAY PIN CHECK_EVERY = 300 #seconds GPIO.setmode(GPIO.BCM) GPIO.setup(RELAY, GPIO.OUT) def internet_on(): try: response=urllib2.urlopen('http://203.97.26.31',timeout=2) print "Internet OK" return ...
by mattrix
Sun Nov 22, 2015 11:36 pm
Forum: Python
Topic: Single button multifunctions
Replies: 3
Views: 739

Re: Single button multifunctions

Looks good. Only small thing I see is change GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP) to GPIO.setup(PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) Also, did you want it to start counting only after the first press? If so - this would be your new code import RPi.GPIO as GPIO import time, os from ti...
by mattrix
Sun Nov 22, 2015 9:26 pm
Forum: Python
Topic: Use of switches to redirect a Program
Replies: 11
Views: 1642

Re: Use of switches to redirect a Program

For the different display each time button is pressed I would use different functions. You can then cycle through these functions for each button press. Something like this import time from itertools import cycle import RPi.GPIO as GPIO def info_1(): print L1 def info_2(): print L2 def info_3(): pri...
by mattrix
Sun Nov 22, 2015 8:21 pm
Forum: Python
Topic: Temperature control and GUI
Replies: 3
Views: 1113

Re: Temperature control and GUI

I was more meaning have the Pi headless (no display) and running a small webserver (eg. python's bottle.py)
You then access it via other devices - cell phone, computer etc.
You could also make a small API and then even make an app to talk to it.
by mattrix
Fri Nov 20, 2015 10:09 am
Forum: Python
Topic: Help me play wav files
Replies: 22
Views: 32397

Re: Help me play wav files

Well. Remember you got that same error trying to play an HTML txt file. So its quite a generic error, nothing to do with bitrate or anything of the wav file. You have tried the files on a PC using vlc or something I assume? And most repeditive.tasks can be programmed. Eg. You could write a python pr...
by mattrix
Fri Nov 20, 2015 9:53 am
Forum: Python
Topic: Help me play wav files
Replies: 22
Views: 32397

Re: Help me play wav files

Yes. Do my original commands in python. Just change the filename to what you want. import os os.system ("aplay piano2.wav") Make sure the wav file.is in same folder as the python file. os.system pretty much just simulates you typing that command into terminal. Tedious clicking? Use terminal to delet...
by mattrix
Fri Nov 20, 2015 9:35 am
Forum: Python
Topic: Help me play wav files
Replies: 22
Views: 32397

Re: Help me play wav files

Was worth a go. Now we know aplay only plays local files. To get the actual download link, go to the first link and right click the download link and copy that URL. Sometimes it can be tricky with timed downloads that use JavaScript to start download so here is a little trick. Once you have download...
by mattrix
Fri Nov 20, 2015 9:20 am
Forum: Python
Topic: Help me play wav files
Replies: 22
Views: 32397

Re: Help me play wav files

I can also tell you that portal wav won't be downloading a wav file. If you open the excat link in web browser, it goes to a webpage, not a direct download link. So. The file is probably actually a HTML txt file. Hence the error trying to play that one. Do my commands correctly and report back. Edit...
by mattrix
Fri Nov 20, 2015 9:14 am
Forum: Python
Topic: Help me play wav files
Replies: 22
Views: 32397

Re: Help me play wav files

Updated my last post.
You copied my command wrong.

Code: Select all

wget http://www.kozco.com/tech/piano2.wav
aplay piano2.wav
by mattrix
Fri Nov 20, 2015 9:05 am
Forum: Python
Topic: Help me play wav files
Replies: 22
Views: 32397

Re: Help me play wav files

Odd. That file I used as sample a few hours earlier is now gone. Oh. You copied the address wrong. You missed the h in tech. wget http://www.kozco.com/tech/piano2.wav Anyway, are you using Raspbian? You have set the audio device to 3.5mm? I think aplay may need to be told to use 3.5mm. Try in termin...
by mattrix
Fri Nov 20, 2015 8:10 am
Forum: Python
Topic: Single button multifunctions
Replies: 3
Views: 739

Re: Single button multifunctions

Are you trying to count button presses within a certain time? For starters, you can move the GPIO setup before the loop starts. It only needs calling once. To count the button presses do something like this PIN = 8 #BUTTON PIN PRESSED = GPIO.LOW LENGTH = 5 #SECONDS #GPIO setup etc while True: print ...
by mattrix
Fri Nov 20, 2015 2:07 am
Forum: Python
Topic: Help me play wav files
Replies: 22
Views: 32397

Re: Help me play wav files

I'd forget about pyglet.
It looks like it doesn't like the Pi.

First try this in terminal

Code: Select all

wget http://www.kozco.com/tech/piano2.wav
aplay piano2.wav
I have confirmed that file plays back fine on my Raspberry Pi 2 via HDMI.

Are you using HDMI for the audio?
by mattrix
Fri Nov 20, 2015 12:41 am
Forum: Python
Topic: New pigpio Python module
Replies: 204
Views: 81098

Re: New pigpio Python module

If I recall (was a while ago), I had a reciever and used that library (can't remember name) to record the pulses.
But it errored.

I think it was due to the AirCon remote sends a lot of data?
by mattrix
Fri Nov 20, 2015 12:37 am
Forum: Python
Topic: Sounding OFF
Replies: 5
Views: 1786

Re: Sounding OFF

I confirmed pyglet.resource.media doesn't seem to find any files (maybe it appends some resource path or something?) When using: sound = pyglet.media.load('/home/pi/PLAYTIME/piano.wav', streaming=False) You get error: pyglet.canvas.xlib.NoSuchDisplayException: Cannot connect to "None" Looks like pyg...
by mattrix
Fri Nov 20, 2015 12:16 am
Forum: Python
Topic: Help me play wav files
Replies: 22
Views: 32397

Re: Help me play wav files

Code: Select all

import os
os.system('aplay /home/pi/sound.wav')
????
by mattrix
Fri Nov 20, 2015 12:10 am
Forum: Python
Topic: Threading and parallel functions
Replies: 5
Views: 4240

Re: Threading and parallel functions

Yes. You could have as many threads as you want. You can even have child threads spawn their own children Main Thread -> Child Thread -> Childs Child Thread eg. You could have your 1st blinking thread create the 2nd blinking thread I think of it like a tree with the main thread being the root node. ...
by mattrix
Thu Nov 19, 2015 11:19 pm
Forum: Python
Topic: New pigpio Python module
Replies: 204
Views: 81098

Re: New pigpio Python module

Would you library allow for accurately sending IR pulses?
I have an Odroid XU4 that I want to use to blast some IR at my heat-pump.
by mattrix
Thu Nov 19, 2015 9:58 pm
Forum: Python
Topic: Threading and parallel functions
Replies: 5
Views: 4240

Re: Threading and parallel functions

It will be because the GPIO cleanup is running before the other threads accessing the GPIO have finished. Here is what happening ### Main Thread ### GPIO.setmode (GPIO.BOARD) Thread(target = firstLED).start() Thread(target = secondLED).start() print ("All done") GPIO.cleanup() #The code above would ...
by mattrix
Thu Nov 19, 2015 9:51 pm
Forum: Python
Topic: Temperature control and GUI
Replies: 3
Views: 1113

Re: Temperature control and GUI

Did you consider having a website interface instead?
Allowing it to be controlled from any device on the network?
by mattrix
Wed Nov 18, 2015 10:43 pm
Forum: Python
Topic: hold push button code
Replies: 5
Views: 9120

Re: hold push button code

Do you just want to time how long the button is pressed for? import time import RPi.GPIO as GPIO PIN = 18 GPIO.setmode(GPIO.BCM) GPIO.setup(PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) while True: GPIO.wait_for_edge(PIN, GPIO.FALLING) print "Pressed" start = time.time() time.sleep(0.2) while GPIO.input(P...
by mattrix
Wed Nov 11, 2015 11:37 pm
Forum: Python
Topic: Tornado webserver
Replies: 4
Views: 2353

Re: Tornado webserver

I do something similar with bottle.py First I have one python file which just logs the temp when it changes to the database. This doesn't use the web-server at all and is started via rc.local on boot up. I then have a second file which is the bottle.py web-server which is also started in rc.local py...
by mattrix
Wed Nov 11, 2015 11:07 pm
Forum: Python
Topic: Start and stop application within python using the RPi GPIO?
Replies: 10
Views: 3052

Re: Start and stop application within python using the RPi G

shell=True is only really a concern if your passing in user input. As, it would give users access to your shell terminal. Think similar to SQL injection attack. rec_proc = subprocess.Popen("export AUDIODRIVER=alsa && rec -c 2 -r 48000 -C 320.30 --buffer 2000000 /mnt/usb/'%s'.mp3"%file_name, shell=Tr...

Go to advanced search