Go to advanced search

by MrYsLab
Mon Apr 01, 2019 2:56 pm
Forum: Python
Topic: Connecting RFID with lcd monitor and Raspberry Pi
Replies: 1
Views: 162

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

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

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

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

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

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

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

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

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

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: 7
Views: 1206

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

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

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

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: 7
Views: 1206

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.
by MrYsLab
Sun Mar 17, 2019 1:33 pm
Forum: Python
Topic: change butron text color when pressed
Replies: 3
Views: 296

Re: change butron text color when pressed

I am not sure if you are asking how do you programmatically change a button's foreground, but if that is your question, here is a short program that demonstrates toggling the buttons foreground color as well as text. You should be able to adapt this to interacting with GPIO changes. #!/usr/bin/pytho...
by MrYsLab
Fri Mar 15, 2019 7:21 pm
Forum: Python
Topic: Pyserial read second to last line and save to variable Tkinter
Replies: 4
Views: 515

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

What you would do is to create 1 variable, previous_value. After each line is read, you would do your calculations based on the new value just read and the value stored in previous_value. You would then store the current value into previous value and look for the next line of data.
by MrYsLab
Wed Mar 06, 2019 11:25 pm
Forum: Python
Topic: JSON
Replies: 2
Views: 149

Re: JSON

You can capture the .png file by using the Python requests package http://docs.python-requests.org/en/master/ Here is a sample script to retrieve an icon based on its ID. import requests url = 'http://openweathermap.org/img/w/10n.png' r = requests.get(url, allow_redirects=True) open('icon.png', 'wb'...
by MrYsLab
Wed Mar 06, 2019 11:03 pm
Forum: Python
Topic: Printing time left on web page - Traffic Light System Python
Replies: 1
Views: 123

Re: Printing time left on web page - Traffic Light System Python

To communicate between your Python script and your web page, you can use Websockets. I have used the following WebSocket server with success: https://github.com/dpallot/simple-websocket-server There is a simple webpage example that the author provides here: https://github.com/dpallot/simple-websocke...
by MrYsLab
Sat Mar 02, 2019 1:22 am
Forum: Python
Topic: Reading Data back from a .csv file
Replies: 5
Views: 296

Re: Reading Data back from a .csv file

Code: Select all

f = open("HourlyData.csv", "r")
line = f.readline()
items = line.split(',')
items = items[1:]
for x in range(len(items)):
    items[x] = int(items[x])

print(items)
by MrYsLab
Fri Mar 01, 2019 3:33 pm
Forum: Python
Topic: Raspberry Pi and Python to control stepper motor and encoder
Replies: 4
Views: 294

Re: Raspberry Pi and Python to control stepper motor and encoder

Please repost your code using code tags so we can see the indentation.
by MrYsLab
Fri Mar 01, 2019 3:30 pm
Forum: Python
Topic: Please help with get_color Function
Replies: 1
Views: 143

Re: Please help with this Function

You may need to adjust things to your liking, but here is my stab at it: def get_color(color): keep_looping = True no_of_try = 1 while no_of_try < 4: color_str = input("Enter the value of the " + color + " color for message (0 to 255):") no_of_try += 1 # break if int(color_str) in range(0, 256): pri...
by MrYsLab
Thu Feb 28, 2019 2:22 pm
Forum: Python
Topic: Raspberry Pi Overlay Problems
Replies: 1
Views: 126

Re: Raspberry Pi Overlay Problems

I have found that pyimagesearch is an excellent source for information. Here is an article "Install OpenCV 4 on your Raspberry Pi", https://www.pyimagesearch.com/2018/09/26/install-opencv-4-on-your-raspberry-pi/ , that may provide most of what you are looking for. The author, Adrian Rosebrock, has w...
by MrYsLab
Wed Feb 27, 2019 3:29 pm
Forum: Python
Topic: Python GUI application reset-button and run at startup
Replies: 13
Views: 477

Re: Python GUI application reset-button and run at startup

There may be easier ways to do this, but I here is what I would do. On a spare SD card install the full Raspbian OS. Boot your Pi with the new OS. Place your old SD card (the one with the problems) into an SD reader and then plug the reader into your Raspberry pi. You will probably see an "Error Ope...

Go to advanced search