Go to advanced search

by ghp
Sun Jun 23, 2019 11:19 am
Forum: Python
Topic: Python code for Maxbotix HrXL-Wr (MB7360) Ultrasonic Sensor in I2C with raspberry pi.
Replies: 4
Views: 753

Re: Python code for Maxbotix HrXL-Wr (MB7360) Ultrasonic Sensor in I2C with raspberry pi.

The distance sensor should work with 3.3V also, according to the datasheet. You could power both ads1115 and MB7360 from 3.3V. You do not need R1, R2, as pullup are already provided on RPi for I2C signals. Option1 : power both chips from 3.3V, remove R1, R2. Option2 : power ADS1115 from 3.3V, remove...
by ghp
Sun Jun 23, 2019 10:18 am
Forum: Python
Topic: itertools(pemutations) in python
Replies: 1
Views: 104

Re: itertools(pemutations) in python

Writing the results into a set will remove 'duplicate' results. from itertools import permutations res = set() cnt = 0 for n in permutations("boss"): print(cnt, n) res.add(n) cnt += 1 print( len(res), res) Where 'duplicate' is a bit misleading. For the permutations, the two 's' are different symbols...
by ghp
Sat Jun 22, 2019 4:32 am
Forum: Python
Topic: Face Tracking OpenCv, Raspberry Pi, Arduino
Replies: 3
Views: 306

Re: Face Tracking OpenCv, Raspberry Pi, Arduino

There are multiple places where things could be improved. - Type Error, - data formatting, - Reading data on arduino side. The TypeError is thrown as you pass a string object to the arduino.write method. Writing to serial needs a bytes like object. Here you can convert by adding the encode-method of...
by ghp
Fri Jun 21, 2019 9:34 pm
Forum: Python
Topic: Face Tracking OpenCv, Raspberry Pi, Arduino
Replies: 3
Views: 306

Re: Face Tracking OpenCv, Raspberry Pi, Arduino

Hello, please observe that pasting python code needs to use the 'code'-tags which preserve identation. There is a sequence: data = "X{0:f}Y{1:f}Z".format(xx, yy) print ("output = '" +data+ "'") #send coordinates arduino.write(data) Would be great to see the console output of this print statement, as...
by ghp
Fri Jun 21, 2019 9:06 am
Forum: Python
Topic: Loop Trouble(s)
Replies: 4
Views: 566

Re: Loop Trouble(s)

Hello, instead of using os.system("sh print"), try to switch to subprocess.Popen:

Code: Select all

import subprocess
p = subprocess.Popen("sh print.sh", shell=True)
p.wait()
print("ok")
My print.sh is:

Code: Select all

echo "start "
sleep 10
echo "stop"
by ghp
Fri Jun 21, 2019 8:45 am
Forum: Python
Topic: Function going through twice
Replies: 18
Views: 884

Re: Function going through twice

Think the callback method is not always working as expected. In case multiple callbacks are attached to one pin, the code is not working as expected. What I did: connected an GPIO output(BCM 21) to another input(BCM 20) by using a wire. The code toggled the output in a slow rate in a thread. Followe...
by ghp
Sun Jun 16, 2019 7:31 am
Forum: Python
Topic: Function going through twice
Replies: 18
Views: 884

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: 249

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: 18
Views: 884

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: 403

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: 504

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: 208

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: 504

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: 504

Re: Moving 16 servos in a wave

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

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: 308

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: 239

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: 163

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: 352

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: 365

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: 178

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: 352

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: 352

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: 379

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: 1255

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'.

Go to advanced search