Go to advanced search

by paddyg
Tue Oct 16, 2018 1:23 pm
Forum: Python
Topic: stop solenoid valve with flow meter pulse
Replies: 62
Views: 9974

Re: stop solenoid valve with flow meter pulse

Hi, I glad (and maybe slightly surprised) it worked with only minor indent mismatch! For your own sanity you should get used to putting all your imports at the top (but after the `#!/usr/bin/env python3`) then globals, constants etc. If you stick to a system it will make debugging easier; sensible t...
by paddyg
Mon Oct 15, 2018 10:26 pm
Forum: Python
Topic: stop solenoid valve with flow meter pulse
Replies: 62
Views: 9974

Re: stop solenoid valve with flow meter pulse

well you might find a better example among all the recipes in the docs but I would do something along the lines of this (untested), using LED as generic output and Button for input, may be more appropriate ones (i.e. digitalInputDevice, digitalOutputDevice) from gpiozero import Button, LED from sign...
by paddyg
Mon Oct 15, 2018 8:18 pm
Forum: Python
Topic: stop solenoid valve with flow meter pulse
Replies: 62
Views: 9974

Re: stop solenoid valve with flow meter pulse

Hi, I would use the https://gpiozero.readthedocs.io/en/stable/recipes.html module it breaks each 'action' out into a function like you've done with your pulse meter. Have a look at that and post again if you get stuck or something doesn't make sense.

Paddy
by paddyg
Mon Oct 15, 2018 8:03 pm
Forum: Python
Topic: OMXplayer wrapper - Keeping process alive after video ends
Replies: 3
Views: 1009

Re: OMXplayer wrapper - Keeping process alive after video ends

This https://www.raspberrypi.org/forums/view ... =omxplayer poster had some issues wrapping omxplayer in python and, I think, managed to sort something out. Not the same specific problem as yours but might have similar solution.
by paddyg
Mon Oct 15, 2018 7:59 pm
Forum: Python
Topic: help i dont know python.
Replies: 2
Views: 308

Re: help i dont know python.

Did you get an error message when you ran the program? If you did that will probably tell you what the problem was. If you didn't then you should add print() statements to try to figure out what's not working. However if you really know no python then you will find it very difficult and I would sugg...
by paddyg
Sun Oct 14, 2018 6:09 pm
Forum: Python
Topic: variable modification thru GPIO
Replies: 4
Views: 564

Re: variable modification thru GPIO

well, at a guess something like (not tested): ... # this is a global 'const' so conventionally uses CAPS SEGMENT_PATTERN = [[0,1,2,3,4,5],[1,2],[0,1,6,4,3],[0,1,2,3,6],[1,2,5,6],[0,2,3,5,6], #0 to 5 [0,2,3,4,5,6],[0,1,2],[0,1,2,3,4,5,6],[0,1,2,5,6],[0,1,2,4,5,6], #6 to A [2,3,4,5,6],[0,3,4,5],[1,2,3...
by paddyg
Fri Oct 12, 2018 11:30 am
Forum: Python
Topic: variable modification thru GPIO
Replies: 4
Views: 564

Re: variable modification thru GPIO

With gpiozero you 'attach' functions to the Button instance to do the work for you https://gpiozero.readthedocs.io/en/stable/recipes.html#button. For your code, approximately (not tested) import RPi.GPIO as IO from gpiozero import LED from gpiozero import Button import time # you can do this - googl...
by paddyg
Fri Oct 12, 2018 9:12 am
Forum: Python
Topic: picamera and Flask - numpy issue
Replies: 4
Views: 991

Re: picamera and Flask - numpy issue

I was really just going by the error message the OP quoted But isn't frame a instance of type Mat? You may well ask! I find the python opencv docs almost impenetrable; they unhelpfully show Python: cv2.imdecode(buf, flags) → retval If you want to find out what a 'retval' is the only way seems to be ...
by paddyg
Fri Oct 05, 2018 9:41 pm
Forum: Python
Topic: No module named 'smbus' on Python3.6.2
Replies: 18
Views: 26142

Re: No module named 'smbus' on Python3.6.2

Well that doesn't sound too weired at all. You almost certainly didn't use pip3 on your old card.

I haven't needed to use smbus but I would heed the advice of a 'regular' like @bensimmo
by paddyg
Fri Oct 05, 2018 8:33 am
Forum: Python
Topic: No module named 'smbus' on Python3.6.2
Replies: 18
Views: 26142

Re: No module named 'smbus' on Python3.6.2

Assuming that you are using `$ python3 simple_smbus2_test.py` on both and `/usr/local/lib/..*../dist-packages/` is the same on both then it's not obvious. Once or twice I've had a missing module error message that was solved by deleting all the *.pyc files
by paddyg
Thu Oct 04, 2018 9:22 pm
Forum: Python
Topic: opening file into python project using cvl and matplotlib
Replies: 6
Views: 941

Re: opening file into python project using cvl and matplotlib

It's hard to know what you actually did but '...I copied the text from the Leafpad to the Nano...' sounds a little bit odd. What I would do is first open a terminal then $ cd '/home/pi/Python-Programs/tutorials/matplotlib tutorial (sentdex)/' $ nano stuff_for_part7 ####### now in the editor delete t...
by paddyg
Thu Oct 04, 2018 10:37 am
Forum: Python
Topic: Error Handling PyQt
Replies: 4
Views: 697

Re: Error Handling PyQt

Hmm, python is normally good at telling you exactly what the problem is and which line is causing it; does that help? I would expect you to need to do def remove(): r = table.currentRow() if r >= 0: dlg.lineEdit_Budget.setText(str(float(table.item(r,1).text()) + float(dlg.lineEdit_Budget.text()))) d...
by paddyg
Thu Oct 04, 2018 10:22 am
Forum: Python
Topic: Error Handling PyQt
Replies: 4
Views: 697

Re: Error Handling PyQt

After the line where you `r = table.currentRow()` check that it's >= 0 (I think it will be -1 if no row is selected) You can then either pop up an alert or change a label field accordingly.
by paddyg
Wed Oct 03, 2018 3:18 pm
Forum: Python
Topic: opening file into python project using cvl and matplotlib
Replies: 6
Views: 941

Re: opening file into python project using cvl and matplotlib

you probably need to edit the file with nano (or other editor that doesn't add extraneous characters)
by paddyg
Tue Oct 02, 2018 3:04 pm
Forum: Python
Topic: opening file into python project using cvl and matplotlib
Replies: 6
Views: 941

Re: opening file into python project using cvl and matplotlib

Maybe it's notepad. Try opening your file from a terminal with nano and tidy up any extraneous characters see https://stackoverflow.com/questions/46427317/notepad-adds-ufeff0-to-the-beginning-of-some-files-making-it-unable-to-merg PS numpy has genfromtxt() which might allow you to bypass your csv im...
by paddyg
Mon Oct 01, 2018 11:51 am
Forum: Python
Topic: picamera and Flask - numpy issue
Replies: 4
Views: 991

Re: picamera and Flask - numpy issue

Not really sure what you are intending to yield, or how it is to be consumed... but if you want to concatenate your b'Content...' with a numpy array you might have to convert it to raw bytes with something like tobytes() b'Content-Type: image/jpeg\r\n\r\n' + frame.tobytes() + b'\r\n') It's probably ...
by paddyg
Wed Sep 26, 2018 6:32 am
Forum: Python
Topic: Queues and clean up.
Replies: 4
Views: 765

hiRe: Queues and clean up.

it migh work if you added to your while condition in threads.. or not q.empty (): but it still won't clear the queue after the gpiozero goes down (would loop forever) maybe better to put the two lines I suggested previously just before the return. You could put the same in your clear up instead of t...
by paddyg
Tue Sep 25, 2018 8:26 pm
Forum: Python
Topic: Queues and clean up.
Replies: 4
Views: 765

Re: Queues and clean up.

can you just

Code: Select all

while not q.empty():
   q.get()
How are you stopping your threads, presumably there is a signal passed through the Queue.
by paddyg
Sat Sep 22, 2018 7:18 pm
Forum: Python
Topic: Python clock
Replies: 1
Views: 373

Re: Python clock

The standard way would be to put all of your pre-defined stuff at the beginning like WHITE = Color(255, 255, 255) RED = Color(255, 0, 0) GREEN = Color(0, 255, 0) # etc, then DIGITS = [(BLACK, WHITE, YELLOW, WHITE, YELLOW, WHITE, YELLOW), (RED, BLACK, GREEN... (WHITE, GREEN... )] while True: for c, i...
by paddyg
Sat Sep 22, 2018 12:13 am
Forum: Python
Topic: alsamixer volume control via GPIO buttons
Replies: 14
Views: 5968

Re: alsamixer volume control via GPIO buttons

OK, after a quick google https://linux.die.net/man/1/amixer I would suggest using 'amixer set Speaker mute' and '... unmute' instead of toggling. i.e. something like (again untested. And you see how I've tried to reduce the duplication in the increase and decrease functions by having a change functi...
by paddyg
Fri Sep 21, 2018 3:25 pm
Forum: Python
Topic: alsamixer volume control via GPIO buttons
Replies: 14
Views: 5968

Re: alsamixer volume control via GPIO buttons

hi. the obvious solution would be to use amixer to determine state rather than a variable in the python code. I will have a look at some stage.
by paddyg
Tue Sep 18, 2018 12:07 pm
Forum: Python
Topic: alsamixer volume control via GPIO buttons
Replies: 14
Views: 5968

Re: alsamixer volume control via GPIO buttons

Ah, you need to set the global variable and check it in the other functions so something along the lines of: (not checked or tested) #!/bin/python from gpiozero import Button from signal import pause from subprocess import Popen def increase_volume(): global is_muted if is_muted: toggle_volume() Pop...
by paddyg
Tue Sep 18, 2018 8:03 am
Forum: Python
Topic: alsamixer volume control via GPIO buttons
Replies: 14
Views: 5968

Re: alsamixer volume control via GPIO buttons

Hi, I don't think you need to set up a different `Button` as you're not using an additional physical button. You just need to add to the existing behavior of your existing button(s). I would try something like ... def mute_volume(): Popen(['amixer', 'set', 'Speaker', 'toggle']) button_up = Button(20...
by paddyg
Mon Sep 17, 2018 2:15 pm
Forum: Python
Topic: alsamixer volume control via GPIO buttons
Replies: 14
Views: 5968

Re: alsamixer volume control via GPIO buttons

If you want to keep on triggering increase or decrease then you will need to keep your program running in a loop. In gpiozero (or GPIO using callback functions) then the loop can just be a pause as in the code below. Alternatively it could be a `while True:` kind of thing. It might not matter most o...
by paddyg
Sun Sep 16, 2018 6:45 pm
Forum: Python
Topic: alsamixer volume control via GPIO buttons
Replies: 14
Views: 5968

Re: alsamixer volume control via GPIO buttons

In python you can run terminal commands quite easily using the subprocess module. Best look up the documentation but you might do something like import subprocess ... def change_volume_function(percent_change): if percent_change < 0: sign_char = '-' else: sign_char = '+' change_str = '{}%{}'.format(...

Go to advanced search