Go to advanced search

by MrYsLab
Wed Apr 24, 2019 6:21 pm
Forum: Python
Topic: help with interrupts
Replies: 1
Views: 36

Re: help with interrupts

When writing a program, it is good practice to write small amounts of code and then test them to make sure that things work the way you expect. To do so for a button press, here is some input code that should work. I do have some questions about your code - are you using BCM numbering? If so, you ne...
by MrYsLab
Mon Apr 22, 2019 1:38 pm
Forum: Python
Topic: python to binary file from ubuntu
Replies: 5
Views: 145

Re: python to binary file from ubuntu

I don't think installing Ubuntu on the Pi solves the OP's problem. If I understand the problem, it is the desire to cross-compile for ARM on a PC. There are ARM cross-compilers available to do that, but not being very familiar with pyinstaller, I am not sure if that is possible. Changing the OS on t...
by MrYsLab
Sun Apr 21, 2019 2:29 pm
Forum: Python
Topic: python to binary file from ubuntu
Replies: 5
Views: 145

Re: python to binary file from ubuntu

From https://realpython.com/pyinstaller-python/ : PyInstaller supports making executables for Windows, Linux, and macOS, but it cannot cross compile. Therefore, you cannot make an executable targeting one Operating System from another Operating System. So, to distribute executables for multiple type...
by MrYsLab
Fri Apr 19, 2019 4:27 pm
Forum: Python
Topic: Using pi as a loop relay timer
Replies: 1
Views: 39

Re: Using pi as a loop relay timer

I am assuming you already know how to control the relays through GPIO without adding any timing. If not, you can see an example at this link: https://gist.github.com/johnwargo/ea5edc8516b24e0658784ae116628277 As far as the scheduling goes you have a few options. One is to to use cron as described he...
by MrYsLab
Tue Apr 16, 2019 3:06 pm
Forum: Python
Topic: Websocket interfaces to devices using Arkady
Replies: 4
Views: 130

Re: Websocket interfaces to devices using Arkady

I am still working on documenting my gateways (which includes one for WebSockets). I can write hundreds of lines of quality code in a day, but it takes me a week to write one paragraph of documentation ;-). When I finish the docs, I will take a look a serious look at your package. If it makes sense,...
by MrYsLab
Sun Apr 14, 2019 10:51 pm
Forum: Python
Topic: how to run python file from new terminal with subprocess ???
Replies: 3
Views: 116

Re: how to run python file from new terminal with subprocess ???

Try:

Code: Select all

subprocess.call(['lxterminal -e  python3 try.py'], cwd='/home/pi/try', shell=True)
by MrYsLab
Sun Apr 14, 2019 3:46 pm
Forum: Python
Topic: Threading
Replies: 2
Views: 98

Re: Threading

I am not sure if you are running this code within a debugger or not, but if I run your code in PyCharm with Python 3 on my PC without the debugger, all runs as expected including your last line. However, if I run in the debugger and set a breakpoint on the last line, that breakpoint is never reached...
by MrYsLab
Sat Apr 13, 2019 2:30 pm
Forum: Python
Topic: Assistance with LED status to LCD screen required
Replies: 3
Views: 86

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

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: 4
Views: 180

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Go to advanced search