Go to advanced search

by paddyg
Wed Feb 21, 2018 8:26 pm
Forum: Python
Topic: Checking for keyboard input while in a control loop
Replies: 1
Views: 57

Re: Checking for keyboard input while in a control loop

curses is 'built in' to python so it's not such a hardship to import it and then it's only a couple of lines of code.
by paddyg
Tue Feb 20, 2018 12:29 pm
Forum: Python
Topic: Python issue: Getting a "cannot import name ttk" error
Replies: 2
Views: 77

Re: Python issue: Getting a "cannot import name ttk" error

what''s the full error message? there might be some clue in there as to where the interpreter is looking. You don't have a file in the directory of your script with a confusing name such as tk.py, tikinter.py or suchlike?
by paddyg
Mon Feb 19, 2018 3:39 pm
Forum: Python
Topic: Bitcoin Ticker Project Guidance
Replies: 1
Views: 79

Re: Bitcoin Ticker Project Guidance

Following that link there looks to be info on change over past hour, day, week as well as time of quote and lots else i.e [ { "id": "bitcoin", "name": "Bitcoin", "symbol": "BTC", "rank": "1", "price_usd": "11019.1", "price_btc": "1.0", "24h_volume_usd": "7499090000.0", "market_cap_usd": "18593615015...
by paddyg
Sun Feb 11, 2018 8:49 am
Forum: Python
Topic: Robot web control and distance sensor working in parallel
Replies: 19
Views: 841

Re: Robot web control and distance sensor working in parallel

interesting idea, and I know that there is a buffering delay between file operations in code and the physical read write (which is why you have to eject drives before unplugging them) so it might not burn a hole in your SD card and be very quick. For my app I want to pass a float value that is chang...
by paddyg
Sun Feb 11, 2018 12:04 am
Forum: Python
Topic: Help with VL53L0X Library
Replies: 5
Views: 251

Re: Help with VL53L0X Library

Ideally the code would be installed as a module but it doesn't look like it's been designed like that; more of a python wrapper for some C code. You might be able to get it to work by 'hard coding' the path on line 68 of /home/pi/python/VL53L0X/python/VL53L0X.py so it reads tof_lib = CDLL("/home/pi/...
by paddyg
Fri Feb 02, 2018 2:34 pm
Forum: Python
Topic: How to display python program output on HDMI
Replies: 4
Views: 374

Re: How to display python program output on HDMI

@ghans, actually, at some stage I realised that the layer argument to the display setup could be used to move the pi3d output 'behind' the x server output. This is what happens in the PyQtCube and GtkCube demos where the pi3d output is dumped to pixels then re-rendered inside an x11 application. I'v...
by paddyg
Fri Feb 02, 2018 1:56 pm
Forum: Python
Topic: Best way to program python on Raspberry pi?
Replies: 17
Views: 708

Re: Best way to program python on Raspberry pi?

aivarannamaa wrote:
Fri Feb 02, 2018 5:59 am
This gave me an idea..
That would be brilliant if you could get Thonny to work with curses. Thanks for looking into it.
by paddyg
Thu Feb 01, 2018 8:57 pm
Forum: Python
Topic: Best way to program python on Raspberry pi?
Replies: 17
Views: 708

Re: Best way to program python on Raspberry pi?

The problem I have found with Thonny (and IDLE before that) is that a simple program that starts import curses key = curses.initscr() ... crashes out with an error, despite running perfectly well from a terminal or from Geany. It makes me think there might be other 'normal' bits of code that just do...
by paddyg
Thu Feb 01, 2018 1:27 pm
Forum: Python
Topic: wx issue
Replies: 3
Views: 150

Re: wx issue

Using any 'special' names such as 'int' or 'wx' as file names is a sure way to produce indecipherable error messages such as 'no module named ...'
by paddyg
Thu Feb 01, 2018 11:28 am
Forum: Python
Topic: Best way to program python on Raspberry pi?
Replies: 17
Views: 708

Re: Best way to program python on Raspberry pi?

The python2 v python3 confusion is such a massive issue and barrier to learning that I'm surprised that Debian and/or maintainers of Raspbian haven't taken the simple expedient of switching the symbolic link for 'python' from 'python2' to 'python3'. The existing policy (page 2, first sentence) seems...
by paddyg
Thu Feb 01, 2018 8:29 am
Forum: Python
Topic: Best way to program python on Raspberry pi?
Replies: 17
Views: 708

Re: Best way to program python on Raspberry pi?

I have found that both IDLE and Thony fail to run certain, infrequently encountered bits of code so I always use Geany. Have you changed the setup to use python3? It's a brown ladder icon left of the run icon. see https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=194664&p=1219098&hilit=geany#p...
by paddyg
Thu Feb 01, 2018 8:18 am
Forum: Python
Topic: Robot web control and distance sensor working in parallel
Replies: 19
Views: 841

Re: Robot web control and distance sensor working in parallel

Hi, glad you sorted it. I hadn't got round to looking at your code but things like that are difficult to spot. Your code looks much tighter and easy to follow than your original, by the way. Did you use mmap inside your myfunc file? After my experiments I wasn't sure how much physical disk access it...
by paddyg
Sat Jan 27, 2018 6:52 pm
Forum: Python
Topic: Move Bytes within a Block of Bytes
Replies: 3
Views: 196

Re: Move Bytes within a Block of Bytes

Even using bytearray there might be other problems, do you mean that you want to do something like data = bytearray([70, 50, 65, 56, 89, 44, 56]) # b'F2A8Y,8' for example y = 3 data = data[:y] + data[y+1:]]) # b'F2AY,8' ? There is a potential issue shunting the bytes along while you're actually iter...
by paddyg
Fri Jan 26, 2018 6:31 pm
Forum: Python
Topic: Robot web control and distance sensor working in parallel
Replies: 19
Views: 841

Re: Robot web control and distance sensor working in parallel

Well done getting it to work. It might be simpler, given that you have a running system using file reads and writes, to bolt on mmap functionality see https://docs.python.org/3.5/library/mmap.html but I've not used that and don't know how or if it works in this circumstance (but it sounds like it sh...
by paddyg
Thu Jan 25, 2018 9:36 pm
Forum: Python
Topic: Robot web control and distance sensor working in parallel
Replies: 19
Views: 841

Re: Robot web control and distance sensor working in parallel

You could write to a file but a) an in-memory database is faster b) writing and reading from 'disk' at high frequency is a bad idea on the RPi where the disk is an SD card c) sqlite does all the work for you. It would be possible to set something up yourself with a 'ram disk', multiprocessing or equ...
by paddyg
Wed Jan 24, 2018 10:59 pm
Forum: Python
Topic: Robot web control and distance sensor working in parallel
Replies: 19
Views: 841

Re: Robot web control and distance sensor working in parallel

This is the kind of thing I had to do with the recent code I mentioned. You (obviously) shouldn't do this slack security style writing (using format()) to insert values into a real online multiuser sql database https://xkcd.com/327/ import sqlite3 ... conn = sqlite3.connect(':memory:', check_same_th...
by paddyg
Tue Jan 23, 2018 10:11 pm
Forum: Python
Topic: Robot web control and distance sensor working in parallel
Replies: 19
Views: 841

Re: Robot web control and distance sensor working in parallel

Something like the following. I've not sorted out your motor switching functionality, which needs to be thought through, possibly looking in the imported functions. Ideally you would pull out all the variables into dictionary and list variables. @app.route('/') def index(): return render_template('i...
by paddyg
Tue Jan 23, 2018 9:04 am
Forum: Python
Topic: Robot web control and distance sensor working in parallel
Replies: 19
Views: 841

Re: Robot web control and distance sensor working in parallel

I didn't explain that very clearly, the loop forever has to go inside a threaded function so it runs all the time INDEPENDENT of the Flask triggered functions. I will post an example when I get back tonight.
by paddyg
Mon Jan 22, 2018 5:20 pm
Forum: Python
Topic: Multithreading guidiance
Replies: 12
Views: 567

Re: Multithreading guidiance

Ah yes there are a couple of things. It's a bit trickier because Qt has a 'hidden' loop system designed to make it hard to figure out what's going on. You can do threading two ways. First as you did originally by inheriting Thread and overriding start() and or run(). That's quite a tidy way that avo...
by paddyg
Mon Jan 22, 2018 10:42 am
Forum: Python
Topic: Robot web control and distance sensor working in parallel
Replies: 19
Views: 841

Re: Robot web control and distance sensor working in parallel

As the Flask functions only run when requested by the web request you are probably best off moving the contents of your drive function to a different thread with a loop forever in it and make your Flask get() functionality in drive() simply set various state values to effect the behaviour. In someth...
by paddyg
Mon Jan 22, 2018 12:30 am
Forum: Python
Topic: Multithreading guidiance
Replies: 12
Views: 567

Re: Multithreading guidiance

It looks quite complicated code so I might have missed this in your code but I would expect to see a thread function that has an infinite loop which keeps reading from your sensor and writing the result into a global variable (or, better an object that you passed to the function when you started it,...
by paddyg
Sat Jan 13, 2018 7:23 pm
Forum: Python
Topic: crop image problem
Replies: 1
Views: 100

Re: crop image problem

With tk you need to use the built in loop system and get it to do regular updates using the 'after' function to recursively call a function. This is rather hacky mod of your code that works on this laptop. import tkinter as tk from PIL import Image, ImageTk deneme = tk.Tk() deneme.geometry("400x400"...
by paddyg
Sun Dec 24, 2017 8:52 am
Forum: Python
Topic: Calling specific int in python
Replies: 3
Views: 243

Re: Calling specific int in python

You may be better describing what you want to do with words as well/instead of using pseudocode. Obviously I am familiar with odes as a form of archaic poetry and I know how to solve differential equations but I don't know what i, s, and d are. Also l can't really tell what your 'this' and 'it', tha...
by paddyg
Sat Dec 23, 2017 12:05 pm
Forum: Python
Topic: Calling specific int in python
Replies: 3
Views: 243

Re: Calling specific int in python

Hi, you can't use f1, f2 etc without defining them first. You can just xx=np.array([0.01,0.012,0.014,0.016]) yy=np.array([32.95388698,33.87900347,33.84214074,34.11856704]) f = xx + yy print(f) ## gives ## array([ 32.96388698, 33.89100347, 33.85614074, 34.13456704]) and you can access elements of f u...
by paddyg
Fri Dec 15, 2017 9:41 am
Forum: Python
Topic: Can't create callback thread. Too many simultaneous pigpio connections
Replies: 2
Views: 312

Re: Can't create callback thread. Too many simultaneous pigpio connections

Try doing all your setup stuff once, at the beginning, and limit your while loop function to checking. No idea if this will help but it seems very wasteful to do all the setup each time you call the function. def displaystops(): try: if topstop.value: # don't need to check if True ==True set_pixel(7...

Go to advanced search