Go to advanced search

by MrYsLab
Sat Apr 13, 2019 2:30 pm
Forum: Python
Topic: Assistance with LED status to LCD screen required
Replies: 3
Views: 164

Re: Assistance with LED status to LCD screen required

You might want to try to get the LCD working and then add the LED code. Here is a link https://learn.adafruit.com/drive-a-16x2 ... ython-code from Adafruit to control the LCD. If this works, you can then try adding your LED control within the while loop.
by MrYsLab
Fri Apr 12, 2019 9:55 pm
Forum: Python
Topic: Websocket interfaces to devices using Arkady
Replies: 4
Views: 287

Re: Websocket interfaces to devices using Arkady

It is somewhat siimilar to a framework I developed called python-banyan. Documentation can be found here: https://mryslab.github.io/python_banyan/ I have compatible banyan frameworks for JavaScript https://github.com/MrYsLab/js-banyan , Ruby https://github.com/MrYsLab/rb_banyan and Java https://gith...
by MrYsLab
Thu Apr 11, 2019 2:09 pm
Forum: Python
Topic: Real time ECG filtering
Replies: 3
Views: 513

Re: Real time ECG filtering

Here is a link that might give you some ideas on how to smooth out your data within your code:
https://stackoverflow.com/questions/304 ... matplotlib
by MrYsLab
Wed Apr 10, 2019 1:01 pm
Forum: Python
Topic: How to check to see if a process is running via subprocess, and not do it if it already exists.
Replies: 4
Views: 886

Re: How to check to see if a process is running via subprocess, and not do it if it already exists.

You can also use psutil https://psutil.readthedocs.io/en/latest/index.html?highlight=cmdline#processes import psutil def find_name(name): for proc in psutil.process_iter(): try: pinfo = proc.as_dict(attrs=['pid', 'name']) if pinfo['name'] == name: return True else: continue except psutil.NoSuchProce...
by MrYsLab
Tue Apr 09, 2019 11:37 pm
Forum: Python
Topic: Set state of GPIO based on HMI serial input using lists.
Replies: 12
Views: 668

Re: Set state of GPIO based on HMI serial input using lists.

I am glad you got things working. Line 90 creates an instance of the Lights class. The instance is saved in the lights variable. With that variable, you can call any of the methods within the Lights class. If you remove that line, things simply will not work. I prefer using a class over a group of i...
by MrYsLab
Tue Apr 09, 2019 3:14 pm
Forum: Python
Topic: Physical push button and Button widget with tkinter
Replies: 1
Views: 138

Re: Physical push button and Button widget with tkinter

When you call tkinter's mainloop(), your program enters the tkinter event loop and any code after that is not executed. Also, although you have a set up a GPIO pin as an input, you probably want to associate an event callback (check this link for a quick example: https://raspi.tv/2014/rpi-gpio-updat...
by MrYsLab
Mon Apr 08, 2019 4:39 pm
Forum: Python
Topic: Help reading txt file lines
Replies: 3
Views: 526

Re: Help reading txt file lines

You have not provided a sample input file, but if shoot_config is not equal to 1 or 2 then interval_time is undefined and hence the exception. Either set interval_time to some warning string or assure that shoot_config is the appropriate expected value.
by MrYsLab
Tue Apr 02, 2019 5:18 pm
Forum: Python
Topic: Setting a max time for a while loop
Replies: 5
Views: 251

Re: Setting a max time for a while loop

Using a callback for the GPIO pin state change can help simplify things. I don't know which GPIO library you are using. Here is a link within gpioZero that demonstrates using a callback with a GPIO input: https://gpiozero.readthedocs.io/en/stable/faq.html?highlight=callback#how-do-i-keep-my-script-r...
by MrYsLab
Tue Apr 02, 2019 4:02 pm
Forum: Python
Topic: Setting a max time for a while loop
Replies: 5
Views: 251

Re: Setting a max time for a while loop

To answer your question, you will first have to ask yourself is, can your program can tolerate blocking while waiting for the timeout? I am guessing not, so you will need to perform some type of concurrency scheme. Take a look at this article that describes, threading, multiprocessing and asyncio ht...
by MrYsLab
Tue Apr 02, 2019 11:46 am
Forum: Python
Topic: Set state of GPIO based on HMI serial input using lists.
Replies: 12
Views: 668

Re: Set state of GPIO based on HMI serial input using lists.

Looking at the Nextion documentation, it appears the data is always terminated with 0xff0xff0xff: https://nextion.itead.cc/resources/documents/instruction-set/#s7 If I am interpreting that correctly, you can modify get_data as follows: def get_data(self): while True: # create an empty list to receiv...
by MrYsLab
Mon Apr 01, 2019 2:56 pm
Forum: Python
Topic: Connecting RFID with lcd monitor and Raspberry Pi
Replies: 1
Views: 275

Re: Connecting RFID with lcd monitor and Raspberry Pi

Looking at the code for the reader, it appears that the library is not using BCM mode https://github.com/pimylifeup/MFRC522-python/blob/f3c569946b51e3a1fb1f0e9a0a9b7eb4430ac567/mfrc522/MFRC522.py#L140 , but your code changes the mode to BCM. Not sure if this is your problem or not, but it looks susp...
by MrYsLab
Sun Mar 31, 2019 2:10 pm
Forum: Python
Topic: Set state of GPIO based on HMI serial input using lists.
Replies: 12
Views: 668

Re: Set state of GPIO based on HMI serial input using lists.

Since you are not using a '*' as a termination character for your data, how do you know when you have a full entry. Is it a fixed length string? If so, I don't see the code to limit the read to the correct number of bytes. Below is a modified version of get_data(). It assumes a 5-byte data length to...
by MrYsLab
Sun Mar 31, 2019 1:06 pm
Forum: Python
Topic: trigger camera from gpio input pulse
Replies: 5
Views: 417

Re: trigger camera from gpio input pulse

If the Arduino trigger is a digital output pulse, then instead of connecting a physical button switch to the digital input of the RPi, connect that trigger output. I would use a voltage divider or voltage level shifter so that the 5v coming out of the Arduino is compatible with the 3V expected by th...
by MrYsLab
Fri Mar 29, 2019 7:02 pm
Forum: Python
Topic: file opens but no data gets written - if using IDLE or THONY
Replies: 3
Views: 167

Re: file opens but no data gets written - if using IDLE or THONY

You left off the parens for the flush and close calls. Add them and it should work: print ("script is starting") f = open("myfile.txt","w") f.write("Write this line") f.flush() f.close() print("the script is at the end") You can also save some typing by using a context manager: print("script is star...
by MrYsLab
Fri Mar 29, 2019 1:49 pm
Forum: Python
Topic: trigger camera from gpio input pulse
Replies: 5
Views: 417

Re: trigger camera from gpio input pulse

You've given very little detail, but if you are looking to use the Raspberry Pi camera, this article addresses taking stop motion videos. You should be able to easily adapt it to your needs.

https://projects.raspberrypi.org/en/pro ... top-motion
by MrYsLab
Thu Mar 28, 2019 3:02 pm
Forum: Python
Topic: Set state of GPIO based on HMI serial input using lists.
Replies: 12
Views: 668

Re: Set state of GPIO based on HMI serial input using lists.

I think the code below is what you may be looking for. Note that I have not tested the interaction with the serial port, but I believe it should work. I added a method, get_data, that is called at the end of __init__. I also instantiated a serial object within __init__ as well. The get_data method i...
by MrYsLab
Tue Mar 26, 2019 7:30 pm
Forum: Python
Topic: Set state of GPIO based on HMI serial input using lists.
Replies: 12
Views: 668

Re: Set state of GPIO based on HMI serial input using lists.

Glad to help. As far as learning materials, there are many online videos and courses. Everyone's learning style is different, so try a few out and see what works for you. You may wish to check the tutorial on python.org https://docs.python.org/3/tutorial/index.html if you prefer a guidebook.
by MrYsLab
Sun Mar 24, 2019 3:05 pm
Forum: Python
Topic: Set state of GPIO based on HMI serial input using lists.
Replies: 12
Views: 668

Re: Set state of GPIO based on HMI serial input using lists.

You might wish to use a nested dictionary as shown in the code below. Hopefully by reading the comments and looking at the output, it should be clear what is going on, but if not, please ask any questions you have. class Lights: def __init__(self): # Build a nested dictionary with serial command as ...
by MrYsLab
Sat Mar 23, 2019 3:30 pm
Forum: Python
Topic: Occasional I/O Error using I2C
Replies: 1
Views: 116

Re: Occasional I/O Error using I2C

I don't know the cause of the error, but if you google "python smbus Remote I/O error" you will see many links that may help you address the issue.
by MrYsLab
Mon Mar 18, 2019 2:11 pm
Forum: Python
Topic: Changing the colour of a tkinter button
Replies: 13
Views: 976

Re: Changing the colour of a tkinter button

You can also use partials: # !/usr/bin/python3 import tkinter as tk from tkinter import ttk from functools import partial root = tk.Tk() def which_button(i): print("button %d" % i) for i in range(0, 5): button = ttk.Button(root, text="Button %d" % i, command=partial(which_button, i)) button.pack() r...
by MrYsLab
Sun Mar 17, 2019 4:59 pm
Forum: Python
Topic: How do I install IDLE for Python 3.7.2?
Replies: 17
Views: 10636

Re: How do I install IDLE for Python 3.7.2?

Absolutely no need to wait if you use pyenv. It allows you to activate a selected version globally, locally to within a given directory or within a given shell session. By selecting either local or shell, the "non-standard" version will not interfere with any calls to python that the system may make...
by MrYsLab
Sun Mar 17, 2019 3:46 pm
Forum: Python
Topic: Installing a library from Github that requires Python 3.5
Replies: 2
Views: 385

Re: Installing a library from Github that requires Python 3.5

First, make sure that you have the version of python3 installed that you wish to use. To do this, open a terminal and type:

Code: Select all

python3 -V
This will print out the version number.
If you have the correct version, to install the library type:

Code: Select all

sudo pip3 install qiskit-terra
by MrYsLab
Sun Mar 17, 2019 2:15 pm
Forum: Python
Topic: Pyserial read second to last line and save to variable Tkinter
Replies: 4
Views: 586

Re: Pyserial read second to last line and save to variable Tkinter

Actually, you can have a loop running within a tkinter program by using the "after" method. Here is a working demo, that will show the "current and previous" values being generated while keeping the gui active. # !/usr/bin/python3 from tkinter import * from tkinter import messagebox class CurrentAnd...
by MrYsLab
Sun Mar 17, 2019 1:44 pm
Forum: Python
Topic: When Python 3.7 will officially arrive to Raspbian?
Replies: 6
Views: 3230

Re: When Python 3.7 will officially arrive to Raspbian?

You can install pyenv to manage different versions of python as described in this article https://realpython.com/intro-to-pyenv/?__s=mn5fwg3kucceiosrqohb . You can enable a specific version of python at different levels - globally, that is "everywhere", or locally, that is, limit it to the current d...
by MrYsLab
Sun Mar 17, 2019 1:38 pm
Forum: Python
Topic: How do I install IDLE for Python 3.7.2?
Replies: 17
Views: 10636

Re: How do I install IDLE for Python 3.7.2?

I just installed pyenv as described here: https://realpython.com/intro-to-pyenv/? ... ceiosrqohb. After enabling 3.7.2, I ran idle3 and it worked seamlessly.

Go to advanced search