Go to advanced search

by MrYsLab
Tue Jul 09, 2019 3:41 pm
Forum: Python
Topic: DHT22 script error handling
Replies: 2
Views: 166

Re: DHT22 script error handling

How about adding a try/except block as shown below. For the degree symbol - that is easy: degree_sign= u'\N{DEGREE SIGN}' temp = 34.5 print(str(temp) + degree_sign) ~ Try/except block added to your code: ##!/usr/bin/python # -*- coding: utf-8 -*- import time import Adafruit_DHT DHT_SENSOR = Adafruit...
by MrYsLab
Sun Jul 07, 2019 2:40 pm
Forum: Python
Topic: tkinter and GPIO, how to set up a physical input button
Replies: 8
Views: 653

Re: tkinter and GPIO, how to set up a physical input button

Wow! You are doing a lot of research. I don't have a lot of experience in this realm, but found a posting that may be of some help:
https://www.raspberrypi.org/forums/view ... p?t=205523

You may also want to look at something like this sensor: https://www.adafruit.com/product/2168
by MrYsLab
Fri Jul 05, 2019 1:06 pm
Forum: Python
Topic: label with textvariable doesn't refresh (tkinter)
Replies: 4
Views: 181

Re: label with textvariable doesn't refresh (tkinter)

I modified your code to just run the tkinter elements and it seems to work without issue.
If you print out the value of InputValue in your getValue function after the readline, what do you get?
by MrYsLab
Mon Jul 01, 2019 11:53 am
Forum: Python
Topic: Doing multiple jobs at the same time
Replies: 3
Views: 352

Re: Doing multiple jobs at the same time

To run the loops concurrently, one solution is to use threading. Here is a great article with working examples: https://pymotw.com/3/threading/ . Your GUI would be the main thread and in its initialization method would spawn and start separate threads for the other 2 loops before starting its own ma...
by MrYsLab
Sun Jun 30, 2019 2:49 pm
Forum: Python
Topic: tkinter and GPIO, how to set up a physical input button
Replies: 8
Views: 653

Re: tkinter and GPIO, how to set up a physical input button

I believe the book you are using, uses the RPi.GPIO library. If I am correct then, RPi.GPIO has a very similar construct to pigpio and instead of callback, they use different terminology and call it interrupt . You may read about it here - just scroll down the page to find the section on interrupts:...
by MrYsLab
Sat Jun 29, 2019 10:57 am
Forum: Python
Topic: Run a asyncio socket function a a thread
Replies: 21
Views: 1380

Re: Run a asyncio socket function a a thread

The previous poster is partially correct. It is true, there is no native implementation of ZMQ for MicroPython. Banyan provides a MircoPython script that runs on the ESP and it communicates with a Banyan component called the ESP gateway over TCP/IP. The gateway publishes the information on the Banya...
by MrYsLab
Fri Jun 28, 2019 10:50 pm
Forum: Python
Topic: Restart Race-timer script
Replies: 1
Views: 153

Re: Restart Race-timer script

I am not sure why you are comparing the input values to >0.5 since an input value will be either a 0 or a 1. Not that the would not work, it's just that for digital input values one would not expect to see a floating point number. Below is some code (untested) that may meet your needs. I moved the i...
by MrYsLab
Fri Jun 28, 2019 10:16 pm
Forum: Python
Topic: tkinter and GPIO, how to set up a physical input button
Replies: 8
Views: 653

Re: tkinter and GPIO, how to set up a physical input button

Below is a small tkinter program that converts feet to meters. It also includes code to set a pin as a GPIO input (connected to a pushbutton) and another connected to an LED. Anytime the pushbutton is pressed it will light the LED and when it is released, it will turn off the LED. It uses the pigpio...
by MrYsLab
Fri Jun 28, 2019 11:55 am
Forum: Python
Topic: Run a asyncio socket function a a thread
Replies: 21
Views: 1380

Re: Run a asyncio socket function a a thread

You may want to look at python-banyan https://mryslab.github.io/python_banyan/# It is being used by Palace Games and there is an article on the RPi blog that mentions it https://www.raspberrypi.org/blog/raspberry-pi-escape-room/ Banyan requires neither threading or asyncio since it provides concurre...
by MrYsLab
Wed Jun 26, 2019 4:43 pm
Forum: Python
Topic: Python IDE
Replies: 2
Views: 403

Re: Python IDE

If you are a student or contribute to or publish open source software, PyCharm Professional is available free of charge. If not, you can use visual studio code https://code.visualstudio.com/ . It supposedly supports remote debugging: https://code.visualstudio.com/docs/remote/ssh . I have not used th...
by MrYsLab
Wed Jun 26, 2019 4:37 pm
Forum: Python
Topic: Doing multiple jobs at the same time
Replies: 3
Views: 352

Re: Doing multiple jobs at the same time

It is not clear from the code you provided, but your main method which contains a while True loop may be blocking the GUI. Tkinter has its own event loop and you probably should incorporate your while True loop into the tkinter loop by using the tkinter "after" method. Here is one article that provi...
by MrYsLab
Fri Jun 21, 2019 5:14 pm
Forum: Python
Topic: how do you add a module in python
Replies: 4
Views: 412

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Go to advanced search