Go to advanced search

by MrYsLab
Fri Jun 21, 2019 5:14 pm
Forum: Python
Topic: how do you add a module in python
Replies: 4
Views: 287

Re: how do you add a module in python

A few things. First, you only need to import a package once, at the top of your file.
When you installed pyautogui did you use pip or pip3?

You probably want to execute:

Code: Select all

sudo pip3 install pyautogui
by MrYsLab
Fri Jun 21, 2019 2:51 pm
Forum: Python
Topic: python code in raspberry pi 2
Replies: 1
Views: 171

Re: python code in raspberry pi 2

Did you enable i2c using raspi-config?
To see if your i2c device is recognized, you can use i2c-tools. If you do not have that installed, you can install with

Code: Select all

sudo apt-get install -y i2c-tools
Then run:

Code: Select all

i2cdetect -y 1
You should 53 displayed in the command output.
by MrYsLab
Mon Jun 03, 2019 12:01 am
Forum: Python
Topic: Multiple subprocesses
Replies: 10
Views: 307

Re: Multiple subprocesses

Was the 1 frame per second caused by the delay in the read command? If you just read one sensor continuously, what is the maximum number of samples you can read per second? Do you have sample code that runs at the higher fps rate and does it work for you?
by MrYsLab
Sun Jun 02, 2019 10:47 pm
Forum: Python
Topic: Multiple subprocesses
Replies: 10
Views: 307

Re: Multiple subprocesses

Why do you need 4 instances of your C++ code to be running? Does each instance perform different operations on the 4 i2c addresses? If the operations are identical with the exception of the i2c address involved, could you not sequentially call the C++ within the read method? Not being familiar with ...
by MrYsLab
Sun Jun 02, 2019 5:51 am
Forum: Python
Topic: Multiple subprocesses
Replies: 10
Views: 307

Re: Multiple subprocesses

Are you able to retrieve data successfully if you do not use pygame and simply print the data to the console?

If yes, then the problem is integrating your code with the pygame event loop. I am not very familiar with pygame, so perhaps someone else could provide that guidance.
by MrYsLab
Sat Jun 01, 2019 10:18 pm
Forum: Python
Topic: Multiple subprocesses
Replies: 10
Views: 307

Re: Multiple subprocesses

It is not clear to me what you mean when you say Currently, I can get it to work with only one sensor . From what I can see, you are creating 4 objects, each one running the subprocess and then utilizing the objects in your while True loop: while True: for i in range(len(sensors)): print(str(sensors...
by MrYsLab
Fri May 31, 2019 8:32 pm
Forum: Python
Topic: Seeking assistance getting tKinter to play nice
Replies: 7
Views: 256

Re: Seeking assistance getting tKinter to play nice

Glad that I was able to help. BTW, when you see intermittent crashes generally it means there is some timing issue in the code. It took me years to figure that out ;)
by MrYsLab
Fri May 31, 2019 5:46 pm
Forum: Python
Topic: Seeking assistance getting tKinter to play nice
Replies: 7
Views: 256

Re: Seeking assistance getting tKinter to play nice

Here is a quick (and dirty) illustration. I normally write things totally within a class, but this hodgepodge should illustrate the point. from threading import Lock, Thread from time import sleep from tkinter import Tk, Label, Button # create a lock object the_lock = Lock() # acquire the lock def g...
by MrYsLab
Fri May 31, 2019 4:01 pm
Forum: Python
Topic: Seeking assistance getting tKinter to play nice
Replies: 7
Views: 256

Re: Seeking assistance getting tKinter to play nice

I don't have a definitive answer for you, but the fact that the program is constantly playing with "after" in addition to being mixed with asynchronous events, looks somewhat suspicious. Perhaps, you need to provide a lock around the after calls that would prevent one call from clobbering another. I...
by MrYsLab
Wed May 29, 2019 9:04 pm
Forum: Python
Topic: Using 7 segment display inside Python code
Replies: 8
Views: 1184

Re: Using 7 segment display inside Python code

It appears you did not install the library properly. You can find detailed install instructions here: https://luma-led-matrix.readthedocs.io/en/latest/
by MrYsLab
Thu May 16, 2019 11:07 pm
Forum: Python
Topic: How to run a servo motor if a particular condition is satisfied
Replies: 15
Views: 509

Re: How to run a servo motor if a particular condition is satisfied

If you correct your code on Github and provide a link, I can take a look. You may also want to run your code through a PEP-8 (linter) tool that will point out where your code does not conform to the PEP8 standards - http://pep8online.com/
by MrYsLab
Tue May 14, 2019 6:35 pm
Forum: Python
Topic: How to run a servo motor if a particular condition is satisfied
Replies: 15
Views: 509

Re: How to run a servo motor if a particular condition is satisfied

Most likely. Put a breakpoint where the PWM mode is being set, and see if it occurs more than once, that is how you are getting the error.
by MrYsLab
Mon May 13, 2019 1:44 pm
Forum: Python
Topic: Retrieving counts from an [Absolute Rotary Encoder]
Replies: 3
Views: 183

Re: Retrieving counts from an [Absolute Rotary Encoder]

I don't have any experience with this encoder, but I did find a Git repository that handles it for the Arduino. https://github.com/heavydetail/EMS22A_Arduino Hopefully it should give you some ideas about how to control the device, but of course you will need to port the C++ to Python. You might want...
by MrYsLab
Mon May 13, 2019 1:22 pm
Forum: Python
Topic: How to run a servo motor if a particular condition is satisfied
Replies: 15
Views: 509

Re: How to run a servo motor if a particular condition is satisfied

The camera2.py script has several other errors in addition to the indentation issues that need to be addressed. In addition,the code possesses no cohesive structure, making it difficult to read and debug. Here are my suggestions: 1. Take a look at this article https://dbader.org/blog/how-to-structur...
by MrYsLab
Mon May 13, 2019 1:55 am
Forum: Python
Topic: How to run a servo motor if a particular condition is satisfied
Replies: 15
Views: 509

Re: How to run a servo motor if a particular condition is satisfied

The indentation is not correct, and when I run the file through PyCharm inspection there are 4 errors after I fixed the indentation. The move function should probably be moved to the top of your file and the GPIO.cleanup should probably be delayed until the end of your program.
by MrYsLab
Sun May 12, 2019 11:22 pm
Forum: Python
Topic: Hall-Effect Sensor pulse input limits with Python
Replies: 5
Views: 246

Re: Hall-Effect Sensor pulse input limits with Python

I totally agree with Joan - never argue with genius! (Joan, not me). Take a look at https://github.com/MrYsLab/razmq/blob/master/razmq/encoders/encoders_pigpio.py . I built a class a while ago that might just do what you want. It uses an early version of the python-banyan framework https://mryslab.g...
by MrYsLab
Sun May 12, 2019 8:47 pm
Forum: Python
Topic: How to run a servo motor if a particular condition is satisfied
Replies: 15
Views: 509

Re: How to run a servo motor if a particular condition is satisfied

I just ran the following code on my RPi. import time import RPi.GPIO as GPIO def move_servo(p): p.start(2.5) # Initialization try: p.ChangeDutyCycle(5) time.sleep(4) p.ChangeDutyCycle(10) time.sleep(4) except KeyboardInterrupt: p.stop() servoPIN = 17 GPIO.setmode(GPIO.BCM) GPIO.setup(servoPIN, GPIO....
by MrYsLab
Sun May 12, 2019 8:17 pm
Forum: Python
Topic: How to run a servo motor if a particular condition is satisfied
Replies: 15
Views: 509

Re: How to run a servo motor if a particular condition is satisfied

I reordered your code somewhat. Having the function defined within the loop created a new PWM instance with each iteratation. import time def move_servo(p): p.start(2.5) # Initialization try: p.ChangeDutyCycle(5) time.sleep(4) p.ChangeDutyCycle(10) time.sleep(4) except KeyboardInterrupt: p.stop() se...
by MrYsLab
Sun May 12, 2019 7:21 pm
Forum: Python
Topic: How to run a servo motor if a particular condition is satisfied
Replies: 15
Views: 509

Re: How to run a servo motor if a particular condition is satisfied

The PWM object, in your case p p = GPIO.PWM(servoPIN, 50) # GPIO 17 for PWM with 50Hz Should be established outside of the loop - it should only be done once. If that is what you are doing, perhaps if you provide the code that includes the servo integration in the camera, that might help for others ...
by MrYsLab
Sun May 12, 2019 6:55 pm
Forum: Python
Topic: How to run a servo motor if a particular condition is satisfied
Replies: 15
Views: 509

Re: How to run a servo motor if a particular condition is satisfied

You could add a function to your code to do the servo moves. Instead of a function, I prefer to do things within a class - avoids the whole global rabbit hole. Below is a sample of what I mean (not tested). If you don't want to use the class, just initialize the servo pin somewhere in your camera co...
by MrYsLab
Sun May 12, 2019 2:57 pm
Forum: Python
Topic: Python rfid media player script woes
Replies: 2
Views: 168

Re: Python rfid media player script woes

There is a package called python-vlc that you can use. https://pypi.org/project/python-vlc/ I just ran this script to play an .mp3 and it works for me import vlc import time player = vlc.MediaPlayer("/home/Music/01. All Souls Night.mp3") player.play() while True: time.sleep(.1) The music plays fine,...
by MrYsLab
Wed May 08, 2019 9:11 pm
Forum: Python
Topic: Distance sensor does not work after introducing the keypress function
Replies: 2
Views: 173

Re: Distance sensor does not work after introducing the keypress function

Please don't take this the wrong way, but your code is a bit of a mess. You are initializing the GPIO within a while loop as well as defining functions within that loop. You probably want to do all the GPIO initialization in your init function and just break out all the defs out of the loop. You sho...
by MrYsLab
Wed May 08, 2019 6:02 pm
Forum: Python
Topic: Bittrex API and Python
Replies: 2
Views: 192

Re: Bittrex API and Python

You have a typo in your code : my_bittrex = Bittrex("apikey", "secretkey, api_version="API_V1_1") should be: my_bittrex = Bittrex("apikey", "secretkey", api_version="API_V1_1") Not a big deal, but just thought I would point that out. Now on to your question. When your code executes: with my_bittrex....
by MrYsLab
Wed May 08, 2019 5:09 pm
Forum: Python
Topic: Rpi read status from alarm
Replies: 1
Views: 112

Re: Rpi read status from alarm

There are several ways of doing this, but I prefer to use a package called apscheduler. The background scheduler feature works well for me https://apscheduler.readthedocs.io/en/latest/userguide.html?highlight=backgroundscheduler What you could do is to have your sensor use a callback that when the s...
by MrYsLab
Mon May 06, 2019 1:49 pm
Forum: Python
Topic: Interrupts not behaving as expected
Replies: 5
Views: 327

Re: Interrupts not behaving as expected

The reason I do not add the pull-downs is because the circuity I am using does not require it. What I would suggest you do is first make sure that your button code works. You can use the code I provided, just change the pull-down and pin numbers. If that works, then add the things that I left out, o...

Go to advanced search