Go to advanced search

by MrYsLab
Mon Feb 18, 2019 11:50 pm
Forum: Python
Topic: time.sleep function problem
Replies: 9
Views: 363

Re: time.sleep function problem

No problem. It just sometimes needs a second set of eyes. Hope things are now working.
by MrYsLab
Mon Feb 18, 2019 11:30 pm
Forum: Python
Topic: time.sleep function problem
Replies: 9
Views: 363

Re: time.sleep function problem

A few questions:
1. What value do you see for TimeElapsed?
2. Under __main__, in your while True loop, you are calling distance and assigning the return value to dist, but you are never using dist. Instead, the code is calling distance() and then doing a compare. Is this what you intended to do?
by MrYsLab
Mon Feb 18, 2019 11:16 pm
Forum: Python
Topic: Using python scripts in html / javascript
Replies: 4
Views: 363

Re: Using python scripts in html / javascript

I am not clear what you mean by " incorporate the python code ". If you mean somehow executing in HTML, you can't, however, you can use websockets. I did this for one of my projects and is shown in the get_message method of this file https://github.com/MrYsLab/pymata-aio/blob/015081a4628b9d47dfe3f8d...
by MrYsLab
Mon Feb 18, 2019 2:35 pm
Forum: Python
Topic: Problem with Relay and GPIO
Replies: 5
Views: 213

Re: Problem with Relay and GPIO

Looking at the info about your board:
"Standard interface that can be controlled directly by microcontroller (Arduino , 8051, AVR, PIC, DSP, ARM, ARM, MSP430, TTL logic active low)"

The relays are active low .
by MrYsLab
Mon Feb 18, 2019 1:34 pm
Forum: Python
Topic: Pygubu
Replies: 1
Views: 170

Re: Pygubu

What version of python are you using - 2 or 3? Did you install for that version? To check, if you installed for python2, type:

Code: Select all

pip freeze | grep pygubu
If you installed for python 3:

Code: Select all

pip3 freeze | grep pygubu
If you do not see pygubu come back then it was not installed.
by MrYsLab
Mon Feb 18, 2019 1:29 pm
Forum: Python
Topic: Problem with Relay and GPIO
Replies: 5
Views: 213

Re: Problem with Relay and GPIO

Perhaps the "on" is a low and off is a "high". Try reversing the sense of the outputs.
by MrYsLab
Sun Feb 17, 2019 1:49 pm
Forum: Python
Topic: Introducing a large quantity of Variables
Replies: 13
Views: 434

Re: Introducing a large quantity of Variables

Depending upon how you wish to access your data, you may also want to consider using a dictionary. Al Sweigart does a nice job comparing lists and dictionaries https://automatetheboringstuff.com/chapter5/ Nothing wrong with lists, but you need to know the index into the list to access the data. In m...
by MrYsLab
Fri Feb 15, 2019 9:16 am
Forum: Python
Topic: Need help modifying a Gmail message retrieval script
Replies: 16
Views: 598

Re: Need help modifying a Gmail message retrieval script

Another link to look at: https://pymotw.com/3/imaplib/#search-criteria . There is a sample of code searching for "from". # imaplib_search_from.py import imaplib import imaplib_connect from imaplib_list_parse import parse_list_response with imaplib_connect.open_connection() as c: typ, mbox_data = c.l...
by MrYsLab
Thu Feb 14, 2019 8:48 pm
Forum: Python
Topic: Need help modifying a Gmail message retrieval script
Replies: 16
Views: 598

Re: Need help modifying a Gmail message retrieval script

Take a look at this link in the python docs. Perhaps it is what you are looking for. https://docs.python.org/3.7/library/ima ... AP4.search
by MrYsLab
Wed Feb 13, 2019 2:36 pm
Forum: Python
Topic: Problem with Piscope (pigpio) and spidev
Replies: 10
Views: 521

Re: Problem with Piscope (pigpio)

I am not sure how you installed piscope. Here is what I did, and it comes up.

1:

Code: Select all

wget abyz.me.uk/rpi/pigpio/piscope.tar
tar xvf piscope.tar
cd PISCOPE
make hf
make install

2. Start pigpio:

Code: Select all

sudo pigpiod
3. Start piscope by typing:

Code: Select all

piscope Live
by MrYsLab
Mon Feb 11, 2019 5:32 pm
Forum: Python
Topic: Class questions
Replies: 11
Views: 406

Re: Class questions

I modified your code somewhat to help illustrate this: class MyClass: glo_class = 11 def method(self): """ Instance methods need a class instance and can access the instance through `self`. """ print("method1: " + str(self.glo_class)) self.glo_class = 1 print("method2: " + str(self.glo_class)) print...
by MrYsLab
Mon Feb 11, 2019 5:30 pm
Forum: Python
Topic: Class questions
Replies: 11
Views: 406

Re: Class questions

When you use self with the class variable, an instance variable with the same name as the class variable is created within the instance. It is initially a local copy of the class variable. If you modify it, you are modifying the instance variable and not the class variable. As you can see in you met...
by MrYsLab
Sat Feb 09, 2019 8:11 pm
Forum: Python
Topic: Converting python 2.7 code to python 3.4
Replies: 11
Views: 607

Re: Converting python 2.7 code to python 3.4

I don't fully appreciate what should be happening in convert_MICROCHIP_32bit_to_float(). What value would you expect to see returned when convert_MICROCHIP_32bit_to_float(0) is called? Or any other value passed in that you choose. Some general questions first. In the line: hex_val = hex(int(val, 2))...
by MrYsLab
Sat Feb 09, 2019 2:18 pm
Forum: Python
Topic: Converting python 2.7 code to python 3.4
Replies: 11
Views: 607

Re: Converting python 2.7 code to python 3.4

What you are dealing with is perhaps the most difficult part of going from Python 2 to Python 3 and that is the change in dealing with data representation - specifically, strings are Unicode in Python 3, and so we sometimes need to convert things to and from Unicode representations. It was a lot mor...
by MrYsLab
Sat Feb 09, 2019 12:10 pm
Forum: Python
Topic: Converting python 2.7 code to python 3.4
Replies: 11
Views: 607

Re: Converting python 2.7 code to python 3.4

Ok, that helps quite a bit. Below is a simple example that may help. The program below simulates getting a byte as if that returned from a pyserial read().To append this to the array, this must be converted to an integer type value. The ord() method is probably what you are looking for. If you need ...
by MrYsLab
Fri Feb 08, 2019 4:04 pm
Forum: Python
Topic: Class questions
Replies: 11
Views: 406

Re: Class questions

Just one more point. If you are coming from the OOP world of C++ or Java, OOP in Python is somewhat similar but there are differences. The underpinnings of Python sometimes provides unexpected results. The lesson I have learned from Python, although the language does not enforce this in any way, is ...
by MrYsLab
Fri Feb 08, 2019 3:59 pm
Forum: Python
Topic: Class questions
Replies: 11
Views: 406

Re: Class questions

Maybe not so much luck as having touched a hot stove enough times, I sometimes know when to avoid the next touch. ;-). So, I still don't understand the application of using double underbar variables when using containment : class B: def __init__(self, class_a): In this definition, class B contains a...
by MrYsLab
Thu Feb 07, 2019 10:50 pm
Forum: Python
Topic: Class questions
Replies: 11
Views: 406

Re: Class questions

Trying to learn is a good thing - keep asking questions. In some of my projects, I use inheritance and sometimes multiple levels of inheritance (a very rare occurrence), but have never found the need to perform name mangling. Maybe I just got lucky ;)
by MrYsLab
Thu Feb 07, 2019 10:21 pm
Forum: Python
Topic: Class questions
Replies: 11
Views: 406

Re: Class questions

It is not clear why you are using name mangling (the variables with the leading double underscore). You are also trying to refer to the variables using the mangled name - again it is unclear what you are trying to do. Usually, name mangling is used in conjunction with inheritance, but your example u...
by MrYsLab
Thu Feb 07, 2019 4:10 pm
Forum: Python
Topic: Syntax for running shell command in Python
Replies: 2
Views: 156

Re: Syntax for running shell command in Python

If you wish to us Popen, this will work: import subprocess # execute the command using Popen sb = subprocess.Popen(['vcgencmd', 'measure_temp'], stdout=subprocess.PIPE) # get the command output cmd_out = sb.communicate() # convert from byte string to string temp = cmd_out[0].decode() print(temp) And...
by MrYsLab
Mon Feb 04, 2019 6:52 pm
Forum: Python
Topic: Converting python 2.7 code to python 3.4
Replies: 11
Views: 607

Re: Converting python 2.7 code to python 3.4

If I look at the man page for python 2.7.15 for array.array, here is what I see: class array.array(typecode[, initializer]) A new array whose items are restricted by typecode, and initialized from the optional initializer value, which must be a list, string, or iterable over elements of the appropri...
by MrYsLab
Sat Feb 02, 2019 3:31 pm
Forum: Python
Topic: reading the output of vcgencmd get_throttled and trigger shutdown, when != 0
Replies: 4
Views: 435

Re: reading the output of vcgencmd get_throttled and trigger shutdown, when != 0

To shutdown, you can use Popen as well:

Code: Select all

subprocess.Popen(['sudo', 'shutdown', '-h', 'now'])
by MrYsLab
Sat Feb 02, 2019 3:22 pm
Forum: Python
Topic: reading the output of vcgencmd get_throttled and trigger shutdown, when != 0
Replies: 4
Views: 435

Re: reading the output of vcgencmd get_throttled and trigger shutdown, when != 0

Also, if you need to understand the bits of the report, I found this information in the forum: Re: Raspbian Jessie linux 4.4.9 Severe Performance Degradati Report this postQuote Thu May 12, 2016 6:04 am Heater wrote: Code: Select all $ vcgencmd get_throttled throttled=0x50005 Okay, the bits in this ...
by MrYsLab
Sat Feb 02, 2019 3:18 pm
Forum: Python
Topic: reading the output of vcgencmd get_throttled and trigger shutdown, when != 0
Replies: 4
Views: 435

Re: reading the output of vcgencmd get_throttled and trigger shutdown, when != 0

There may be a shorter way to get this, but I think this is what you are looking for: import subprocess # execute the command using Popen sb = subprocess.Popen(['vcgencmd', 'get_throttled'], stdout=subprocess.PIPE) # get the command output cmd_out = sb.communicate() # retrieve the good stuff and spl...
by MrYsLab
Thu Jan 31, 2019 5:04 pm
Forum: Python
Topic: Running another program with a button
Replies: 1
Views: 129

Re: Running another program with a button

I think your usage of Popen may be incorrect. I changed your lines: rpistr = "python3 /home/pi/Desktop/CurrentTesting/Experiment.py" p=subprocess.Popen(rpistr, shell=True, preexec_fn=os.setsid) to rpi_list = ['xterm', '-e', 'python3', '/home/pi/Desktop/CurrentTesting/Experiment.py'] p = subprocess.P...

Go to advanced search