Go to advanced search

by paddyg
Sun Sep 16, 2018 9:25 am
Forum: Python
Topic: Multiple add_event_detect for single GPIO pin and multiple callbacks
Replies: 3
Views: 559

Re: Multiple add_event_detect for single GPIO pin and multiple callbacks

From your description of what you want to happen I would have thought the loop should record the times that objects pass each sensor and the logic count accordingly i.e if tm1 > tm2 and (tm1 - tm2) < MAXTM: count += 1 elif tm2 > tm1 and (tm2 - tm1) < MAXTM: count -= 1 You also need to take into acco...
by paddyg
Sat Sep 15, 2018 6:22 pm
Forum: Python
Topic: Python Logic + GPIO help maybe?
Replies: 3
Views: 435

Re: Python Logic + GPIO help maybe?

Also your code has lots of repetition in it which is a good indication that you will find it difficult to figure out logic, debug problems etc etc. In your situation I would opt for using a 'class' to represent each door and have a list of them. I know this might be more advanced than you want to ta...
by paddyg
Fri Sep 07, 2018 8:30 pm
Forum: Python
Topic: Running Flask in a separate threat
Replies: 1
Views: 337

Re: Running Flask in a separate threat

I think Flask has to run in the main thread. If that's an issue you can put it in its own process and communicate via queue objects. I will see if I can find a github repo I once worked on which did that kind of thing. Paddy here's the link, if you can make anything of it. Feel free to ask, though i...
by paddyg
Tue Sep 04, 2018 6:45 pm
Forum: Python
Topic: Python scripting
Replies: 1
Views: 457

Re: Python scripting

I suspect nobody has replied because they are rather confused by the equation and explanation. My advice would be to do a bit of simple programming, maybe follow an introduction to python course. Most programming languages will do arithmetic operations in approximately BODMAS order so in your exampl...
by paddyg
Thu Aug 16, 2018 10:17 pm
Forum: Python
Topic: Adding inputs to existing tkinter stopwatch code
Replies: 10
Views: 1484

Re: Adding inputs to existing tkinter stopwatch code

John, sounds like progress of some kind. Does it work ok if you comment out all the gpio stuff and just use the tk buttons? Try to add code back in a bit at time to narrow down the point where it stops working.
Paddy
by paddyg
Thu Aug 16, 2018 7:34 pm
Forum: Python
Topic: Adding inputs to existing tkinter stopwatch code
Replies: 10
Views: 1484

Re: Adding inputs to existing tkinter stopwatch code

That's odd. I can't reproduce that error but I do get errors further on. Essentially a) the functions need to be defined before allocating to buttons (obviously!!) b) when_pressed is used differently, basically set equal to a function. See my revised code at the bottom which I've just checked on thi...
by paddyg
Sat Aug 11, 2018 2:32 pm
Forum: Python
Topic: Dynamic video playlist with OMXplayer and OSC
Replies: 12
Views: 6520

Re: Dynamic video playlist with OMXplayer and OSC

Hi, I've not had chance to sort this out but did have a look around last night. Using OMXPlayer (the python wrapper module) I found that I could get useful info and control when only one instance of omxplayer was instantiated but when I created a second one then they both returned the same negative ...
by paddyg
Thu Aug 09, 2018 11:46 am
Forum: Python
Topic: Dynamic video playlist with OMXplayer and OSC
Replies: 12
Views: 6520

Re: Dynamic video playlist with OMXplayer and OSC

busy now but will look later. I would expect you to need to use the subprocess module to run OMXPlayer twice. That's slightly trickier but not too bad
by paddyg
Wed Aug 08, 2018 9:08 pm
Forum: Python
Topic: Dynamic video playlist with OMXplayer and OSC
Replies: 12
Views: 6520

Re: Dynamic video playlist with OMXplayer and OSC

The thing most likely to cause confusion for the python interpreter is using the same names for different things. Python will let you do this and will attempt to work out what to do but it will almost certainly confuse you! Typical issues are naming the program or imported file with a name that clas...
by paddyg
Sun Aug 05, 2018 9:48 pm
Forum: Python
Topic: Threading problem
Replies: 5
Views: 621

Re: Threading problem

You only have to wait a hundredth of a second plus whatever the response time of the mote is. You could have a toggle variable that you set with the GPIO button def LightThread(): global lights_on, lights_hide # don't need to have this line as you're not updating these but it makes it explicit while...
by paddyg
Sun Aug 05, 2018 9:19 pm
Forum: Python
Topic: Threading problem
Replies: 5
Views: 621

Re: Threading problem

Global variables usually work ok with Threads, or you can pass an object type of argument (i.e. an instance of a class or a list, but not a simple boolean) to the thread or you can use a Queue. Maybe post your code?
by paddyg
Sat Aug 04, 2018 8:39 pm
Forum: Python
Topic: Adding inputs to existing tkinter stopwatch code
Replies: 10
Views: 1484

Re: Adding inputs to existing tkinter stopwatch code

Well most people will be put off by your un-formatted post. You need to use code tags (see sticky post at the top). Unless you have a very strong reason not to (and I couldn't see one in your code) you should use python3. i.e. import tkinter as tk. w.r.t your GPIO question you should, IMO, use https...
by paddyg
Fri Aug 03, 2018 10:33 pm
Forum: Python
Topic: Python script CPU usage is growing over time
Replies: 2
Views: 764

Re: Python script CPU usage is growing over time

maybe cputemp() is creating new instances of Text objects that somehow evade garbage collection (I've come across this with tk before) You should create one instance of your temerature Text and update that each loop along the lines of this example https://lawsie.github.io/guizero/blocking/
by paddyg
Fri Aug 03, 2018 9:30 pm
Forum: Python
Topic: Calling variables from different functions
Replies: 6
Views: 897

Re: Calling variables from different functions

When I've done similar things I've done the database connection at the beginning of the program when it starts so that conn and c are available to all functions (the alternative would be to make them 'belong' to your UI class and create them when you set it up (so they would be self.conn and self.c)...
by paddyg
Thu Jul 26, 2018 8:01 pm
Forum: Python
Topic: Switch with Raspberry Pi - Python
Replies: 32
Views: 2829

Re: Switch with Raspberry Pi - Python

Well spotted. I just used code that you posted but you just posted some code from Matt Richardson that you didn't understand! Hopefully you've learned something in the process.
by paddyg
Thu Jul 26, 2018 6:52 pm
Forum: Python
Topic: Switch with Raspberry Pi - Python
Replies: 32
Views: 2829

Re: Switch with Raspberry Pi - Python

Well google (or other search engine) 'should I connect 5V to raspberry pi gpio, even through a resistor' and see what other people think. Strange that your system doesn't work, it works fine for me as you can see on the video, and also when I put in the pull_up_down argument in and touched pin12 the...
by paddyg
Thu Jul 26, 2018 4:37 pm
Forum: Python
Topic: Switch with Raspberry Pi - Python
Replies: 32
Views: 2829

Re: Switch with Raspberry Pi - Python

Hmm 5V sounds a lot!!

The best way is to use internal pull up like you do in some of your code snippets and keep even 3V3 away.
by paddyg
Thu Jul 26, 2018 9:25 am
Forum: Python
Topic: Switch with Raspberry Pi - Python
Replies: 32
Views: 2829

Re: Switch with Raspberry Pi - Python

Did yo check program on your system ? Fair cop, I just assumed that if the GPIO stuff worked ok for you then my code would probably be ok too. So I quickly copied the code to my Raspberry Pi to test it. Surprise, surprise it works fine! https://youtu.be/YQvqGKlydx0 EDIT - kids, don't do what I'm do...
by paddyg
Wed Jul 25, 2018 9:54 pm
Forum: Python
Topic: Switch with Raspberry Pi - Python
Replies: 32
Views: 2829

Re: Switch with Raspberry Pi - Python

Really you should heed our earlier advice and get comfortable with simpler programming concepts before becoming too confused with this kind of thing but here is a minimalist web page that polls another web page every 1000ms. The other web page runs your GPIO checking. There are various javascript li...
by paddyg
Wed Jul 25, 2018 7:25 am
Forum: Python
Topic: Switch with Raspberry Pi - Python
Replies: 32
Views: 2829

Re: Switch with Raspberry Pi - Python

When you say 'press the push button' I assume (having read and understood @topguy's explanation above) that you mean 'press the push button and hold it down while I refresh the page'. In which case it's not clear why it's not working. I would put in print() statements a various places to try to trac...
by paddyg
Tue Jul 24, 2018 12:18 pm
Forum: Python
Topic: Switch with Raspberry Pi - Python
Replies: 32
Views: 2829

Re: Switch with Raspberry Pi - Python

What url are you typing into the browser? When you say 'refresh' it sounds like you are just reloading main.html. If you want the pin status on the main page you will (obviously) have to put the gpio reading code into that function (hello()). Otherwise you will have to enter the route to readPin12()...
by paddyg
Tue Jul 24, 2018 9:26 am
Forum: Python
Topic: Switch with Raspberry Pi - Python
Replies: 32
Views: 2829

Re: Switch with Raspberry Pi - Python

Well, if you don't want a variable pin number then it's not a 'variable'. Most (all) languages can't cope with variables named '12'. At this point I should say that if you are just getting into programming then learning to make interactive web pages is a bad place to start. A sound investment on you...
by paddyg
Tue Jul 24, 2018 6:59 am
Forum: Python
Topic: Switch with Raspberry Pi - Python
Replies: 32
Views: 2829

Re: Switch with Raspberry Pi - Python

he uses a system now pretty universal with dynamic Web apps where routing to different 'pages' and arguments are passed in the url. In the example you posted putting pin in angle brackets does the magic @app.route("/readPin/<pin>") def readPin(pin): try: means you can feed a url such as .../readPin/...
by paddyg
Mon Jul 23, 2018 11:05 pm
Forum: Python
Topic: Switch with Raspberry Pi - Python
Replies: 32
Views: 2829

Re: Switch with Raspberry Pi - Python

As @topguy says, web pages aren't normally 'running' like a python loop, you have to manually refresh them to see if any changes have happened. You can put some javascript on your display page that can loop and read an information serving page but generally speaking the way web pages work takes a wh...

Go to advanced search