Go to advanced search

by ghp
Sun Jun 16, 2019 7:31 am
Forum: Python
Topic: Function going through twice
Replies: 17
Views: 473

Re: Funtion going through twice

I was curious to see how these callback work. Especially in case the runtime in the callback is longer than the event input. The setup is: use a microcontroller (arduino zero) and produce a square wave with 3 sec low and 3 sec high. At each edge, I added some jitter (50 times, 2 ms period). Code in ...
by ghp
Sat Jun 15, 2019 11:04 pm
Forum: Scratch
Topic: scratchClient mpr121, time from event till scratch2 reacts
Replies: 0
Views: 93

scratchClient mpr121, time from event till scratch2 reacts

There was ticket on scratchClient on unacceptable long times from touch input on MPR121 till scratch reacts. The user "trying to make an interactive touch game but the delay between touch and register of events is delayed by a few second.. " Good idea to measure reaction time. The approach was to ad...
by ghp
Sat Jun 15, 2019 6:44 am
Forum: Python
Topic: Function going through twice
Replies: 17
Views: 473

Re: Funtion going through twice

For checking the behavior, you could add a print-statement just at the beginning of my_callbackp18.
Your full code could possibly help to help.
Most possibly you checked the connection to your button (?) many times. Is it the only code running on this pi ?
by ghp
Tue Jun 11, 2019 7:29 pm
Forum: Python
Topic: How to print without newline
Replies: 6
Views: 270

Re: How to print without newline

Hello, by using the triple quotes all whitespace and newline is in the string. You can't avoid it. So either use a different statement, single line is already mentioned, or remove it. #remove whitespace import re raise TypeError( re.sub(r" *[\n] *", " ", """The sentence should be of type str and not...
by ghp
Tue Jun 11, 2019 4:26 am
Forum: Python
Topic: Moving 16 servos in a wave
Replies: 11
Views: 342

Re: Moving 16 servos in a wave

I can't find anything on adafruit re. driving the servos directly from the GPIO but we'll see. The servo hat is best driven with the adafruit library. There are possibilities (pigpiod) to drive servo with GPIO directly, but then the servo hat is obsolete. Servo hat provides convenient pin connectio...
by ghp
Sun Jun 09, 2019 5:34 pm
Forum: Python
Topic: picamera & ILI9341 - change picamera encoder
Replies: 2
Views: 149

Re: picamera & ILI9341 - change picamera encoder

Possibly multithreading could help.
build 3 processes, acquire, convert and display.
Connect them with multiprocessing queues and send data acquire --> convert --> display.
Helps to use three cores instead only one core in a standard python process.
by ghp
Sun Jun 09, 2019 10:25 am
Forum: Python
Topic: Moving 16 servos in a wave
Replies: 11
Views: 342

Re: Moving 16 servos in a wave

test_image.gif import math import time # the time a sweep cycle shall take is total_time = 5.0 # there will not be too frequent updates, the update cycle is wait_time = 0.2 # the number of updates in a cycle will be approximate N = int( total_time / wait_time) # # Number of Servo # SERVO = 16 # bui...
by ghp
Sun Jun 09, 2019 9:07 am
Forum: Python
Topic: Moving 16 servos in a wave
Replies: 11
Views: 342

Re: Moving 16 servos in a wave

Something like this ?
anicircle.gif
anicircle.gif (81.69 KiB) Viewed 324 times
by ghp
Fri Jun 07, 2019 6:42 pm
Forum: Python
Topic: Running multiple while true loops
Replies: 5
Views: 208

Re: Running multiple while true loops

Just to increase complexity: modern concepts are asynchronous. See https://docs.python.org/3/library/asyncio.html
by ghp
Fri Jun 07, 2019 4:55 pm
Forum: Python
Topic: Reading LDR with MCP3008
Replies: 6
Views: 200

Re: Reading LDR with MCP3008

Perhaps you try
r = spi.xfer2([1, (8 + adcnum) << 4, 0])
instead of
r = spi.xfer2([1, 8 + adcnum << 4, 0])
by ghp
Thu Jun 06, 2019 5:05 pm
Forum: Python
Topic: Exception or if statement
Replies: 3
Views: 177

Re: Exception or if statement

Hello, looks good. It depends a bit on how this method is used. When looking to what this code is doing, there is a read and write combined. The method name does not give an idea about this. def temp_humidity_read_and_write(): """ read temp. If available, write it. If not available, just do nothing"...
by ghp
Wed Jun 05, 2019 8:55 pm
Forum: Python
Topic: ATM Tracking Issue
Replies: 1
Views: 121

Re: ATM Tracking Issue

Hello, your code has some elements which make a test on a different system cumbersome. - there is a database used, but you do not provide schema definition and data - there is a rfid used which is unfortunately missing on my system - and tkinter is in full screen. No cursor makes my mouse useless. -...
by ghp
Tue Jun 04, 2019 6:56 pm
Forum: Python
Topic: DS18B20 temp alarm, schedule problem, reminder variables not getting updated(v2.0 w/BBcode)
Replies: 8
Views: 229

Re: DS18B20 temp alarm, schedule problem, reminder variables not getting updated(v2.0 w/BBcode)

There was a queston on whai I did with the scheduler status commands. Something like this, but I'r recommend not to use something like this in production code. def sched_start(): if sched.state == apscheduler.schedulers.base.STATE_STOPPED: sched.start() print ("STATE_STOPPED", "start", "start") elif...
by ghp
Tue Jun 04, 2019 4:39 am
Forum: Python
Topic: Python library not found: libpython3.7.so.1.0, libpython3.7m.so.1.0, libpython3.7mu.so.1.0
Replies: 4
Views: 215

Re: Python library not found: libpython3.7.so.1.0, libpython3.7m.so.1.0, libpython3.7mu.so.1.0

The last few lines of the error listing give a quite good hint:

* On Debian/Ubuntu, you would need to install Python development packages
* apt-get install python3-dev
* apt-get install python-dev

Just add a "sudo" before the apt-get in order to work properly.
by ghp
Tue Jun 04, 2019 4:06 am
Forum: Python
Topic: I'm having trouble with my code turning my relays on and of repeating any suggestions?
Replies: 2
Views: 119

Re: I'm having trouble with my code turning my relays on and of repeating any suggestions?

Identation is important in python. Please re-edit your post and add Code-Tag viewtopic.php?f=32&t=84477

Which relay-board are you using and how are the connections between RPi and the board ?
by ghp
Mon Jun 03, 2019 7:10 pm
Forum: Python
Topic: DS18B20 temp alarm, schedule problem, reminder variables not getting updated(v2.0 w/BBcode)
Replies: 8
Views: 229

Re: DS18B20 temp alarm, schedule problem, reminder variables not getting updated(v2.0 w/BBcode)

Ok, with the formatted code the things look less strange. I removed the read-sensor code and replced by a simple random function. Removed email-send and replaced by a print(message). There are a few errors which stop part of the code. # TODO ValueError: Invalid format string #hr = int(currenttime.hs...
by ghp
Mon Jun 03, 2019 5:42 pm
Forum: Python
Topic: DS18B20 temp alarm, schedule problem, reminder variables not getting updated(v2.0 w/BBcode)
Replies: 8
Views: 229

Re: DS18B20 temp alarm, schedule problem, reminder variables not getting updated(v2.0)

Code formatting would help. Think the problem is related to the way the message is prepared. The scheduler calls periodially the reminder function (each 20 secs, little bit nervous for a reminder...). The message variable is prepared outside of the 'reminder' loop formed by scheduler and reminder me...
by ghp
Sun Jun 02, 2019 8:47 am
Forum: Python
Topic: Multiple subprocesses
Replies: 10
Views: 284

Re: Multiple subprocesses

Hello, think there are a few problems. - Reading data twice, as already stated. - Too many delays. In the Thermal_Cam, there is a time.sleep(1.0 / fps), which is fine for one sensor, but this is accumulating for four sensors. So with 4 sensors, the delay is 4 * 1/fps. As you read the correct number ...
by ghp
Thu May 30, 2019 3:39 pm
Forum: Python
Topic: Using 7 segment display inside Python code
Replies: 8
Views: 1159

Re: Using 7 segment display inside Python code

Is it a python2-python3 problem? When installing with 'pip', the library goes into the python==python2 modules collection. When starting the application code then with python3, the library is not found.

Install with 'pip' and run with 'python'.
Install with 'pip3' and run with 'python3'.
by ghp
Thu May 30, 2019 6:51 am
Forum: Python
Topic: Using 7 segment display inside Python code
Replies: 8
Views: 1159

Re: Using 7 segment display inside Python code

Common problem is that the own python program has same name as an import. In your case, is your file named luma.py ? Then rename it and retry.
by ghp
Wed May 29, 2019 4:03 pm
Forum: Python
Topic: Do more than one thing on GPIO zero PIR
Replies: 5
Views: 340

Re: Do more than one thing on GPIO zero PIR

I'd propose a solution like this: def base_motion(): """all the actions which need to be done when motion is detected""" r = requests.post("http://bit.ly/xxxxxxx") # motion has been detected by the basement PIR sensor # add code here to switch LED ON baseled.on() # def base_no_motion(): """all the a...
by ghp
Tue May 28, 2019 7:04 pm
Forum: Python
Topic: controlling number of times loop is executed?
Replies: 12
Views: 615

Re: controlling number of times loop is executed?

Code: Select all

print("start")
t = 0.0
while True:
    t += 0.001
    if t > 1000:
        break
    # some other stuff here
print ("complete")
by ghp
Sun May 26, 2019 2:20 pm
Forum: Python
Topic: Cut power to USB ports w/ Python
Replies: 3
Views: 601

Re: Cut power to USB ports w/ Python

Code: Select all

try:
    subprocess.call( "echo '1-1' |sudo tee /sys/bus/usb/drivers/usb/unbind", shell=True)
except ItIsASunnySundayAndNotWorkingAtAllException:
    pass
by ghp
Sat May 25, 2019 4:27 am
Forum: Python
Topic: How to get a very accurate delay from 1 milli second in python
Replies: 3
Views: 641

Re: How to get a very accurate delay from 1 milli second in python

python delay are not very accurate. If you control signals with python, there is a noticeable jitter. When controlling a triac on 50 Hz ( BE CAREFUL AND OBSERVE ALL TECHNICAL RULES when working with mains) you also need to synchronize the on-pulses with zero crossing of input signal which introduces...
by ghp
Fri May 24, 2019 8:02 pm
Forum: Python
Topic: No errors but the window doesn't even open.
Replies: 1
Views: 479

Re: No errors but the window doesn't even open.

My formula car is currently not available to test this piece of software. Hence a proposal to make the code testable. # some code cut off from the start print('\n\rLets Go Racing!') print('\n\rBring up CAN0...') #bring up can interface at 500mbps time.sleep(0.1) print('\n\rReady') class Message: def...

Go to advanced search