Go to advanced search

by Garvan
Tue Apr 07, 2020 10:43 am
Forum: Python
Topic: Deck of Cards
Replies: 5
Views: 547

Re: Deck of Cards

I would add an extra parameter to the class called cardvalue so the Card class can be used with any card game. And create an instance of the class like this, giving the card value my_card = Card("hearts","j",10) I am also learning python, and used the same tutorial as you, so if ...
by Garvan
Tue Apr 07, 2020 8:25 am
Forum: Python
Topic: Average temp every x minutes
Replies: 2
Views: 255

Re: Average temp every x minutes

Lets try with a list, 1. Calculate average 2. Printing out the list and average to see what data we have. 3. Generating a random temp between 25 and 35 C 4. Add random temp to first element. 5. Rotate list to left by splitting it and adding 6. Print out 10 loops import random random.seed() lst = [30...
by Garvan
Mon Apr 06, 2020 3:01 am
Forum: Python
Topic: world time schedule with user input
Replies: 2
Views: 200

Re: world time schedule with user input

[[Deleted]] See response below for reason code does not work.
by Garvan
Thu Apr 02, 2020 12:13 pm
Forum: Python
Topic: How can I shorten variable data
Replies: 3
Views: 241

Re: How can I shorten variable data

Code: Select all

firstname = "Ben"
letter1= firstname[0]
print("The first letter in your name is",  letter1)
by Garvan
Sun Mar 29, 2020 1:04 pm
Forum: Python
Topic: [How to] Control stepper motor 28BYJ-48 with keyboard and PS4 controller
Replies: 9
Views: 816

Re: [How to] Control stepper motor 28BYJ-48 with keyboard and PS4 controller

You followed the code, as it is presented in the tutorial, but it does not show a working counterclockwise function,.

If it works, it works.

If you motor does not run correctly counterclockwise (I expect vibration), when you have sent up the correct power supply, then post again here.

Raven
by Garvan
Sun Mar 29, 2020 3:29 am
Forum: Python
Topic: [How to] Control stepper motor 28BYJ-48 with keyboard and PS4 controller
Replies: 9
Views: 816

Re: Can anybody help me to run stepper motor while keyboard key is pressed?

Your clockwise code is correct, but counterclockwise is producing the wrong sequence (as far as I understand). arr1 = [1,1,0,0] arr2 = [0,1,0,0] def counterclockwise(): global arr1 # enables the edit of arr1 var inside a function global arr2 # enables the edit of arr2 var inside a function arrOUT = ...
by Garvan
Sat Mar 28, 2020 2:45 pm
Forum: Python
Topic: [How to] Control stepper motor 28BYJ-48 with keyboard and PS4 controller
Replies: 9
Views: 816

Re: Can anybody help me to run stepper motor while keyboard key is pressed?

Keep the code to check keyboard state separate from the code to control the motor. Do you understand the sample code below? import pygame pygame.init() screen = pygame.display.set_mode((100,100)) def clockwise(): print ("Clockwise") def anticlockwise(): print ("AntiClockwise") de...
by Garvan
Sat Mar 28, 2020 10:36 am
Forum: Python
Topic: Issue when setting up a crontab entry - python script
Replies: 24
Views: 899

Re: Issue when setting up a crontab entry - python script

Two days, and no progress. I think you will have to solve this issue yourself. I would start by inserting debug code everyplace (logging the results of every single line of code to file), or make a simple basic script that does nothing, and add functionality line by line until you identify what fail...
by Garvan
Wed Mar 25, 2020 3:06 pm
Forum: Python
Topic: how to exit signal.pause() in code [SOLVED]
Replies: 7
Views: 981

Re: how to exit signal.pause() in code

scotty101 wrote:
Wed Mar 25, 2020 2:45 pm
You could just have a small while loop with a time.sleep in it.

Code: Select all

running = True

def say_bye():
    global running
    print("Exit")
    running = False

while running:
    time.sleep(0.1)
Thanks, I will try this.
by Garvan
Wed Mar 25, 2020 2:32 pm
Forum: Python
Topic: how to exit signal.pause() in code [SOLVED]
Replies: 7
Views: 981

Re: how to exit signal.pause() in code

I want to exit the program when a button is pressed in BlueDot. Is there a way to exit signal.pause()? Or an alternative to signal.pause()?

I can exit the program using Ctrl-C, but I will not have a keyboard attached in the finished project.
by Garvan
Wed Mar 25, 2020 1:18 pm
Forum: Python
Topic: how to exit signal.pause() in code [SOLVED]
Replies: 7
Views: 981

how to exit signal.pause() in code [SOLVED]

The BlueDot documentation https://bluedot.readthedocs.io/en/latest/recipes.html uses pause() to pause program flow while threads are waiting for signals. You can "exit" pause() by pressing Ctrl-C to terminate the program. How do I cause pause() to exit in code? For example, if I want a dou...
by Garvan
Wed Mar 25, 2020 10:51 am
Forum: Python
Topic: Pyton script crashes after 4 hours
Replies: 13
Views: 888

Re: Pyton script crashes after 4 hours

Should f.close() & g.close() be inside the wile loop? It looks to me that you are repeatedly opening URL's without closing them. This might be unrelated to your error.
by Garvan
Sun Mar 15, 2020 11:04 am
Forum: Python
Topic: Can you customize "exit" action using guizero?
Replies: 4
Views: 665

Re: Can you customize "exit" action using guizero?

You can put your cleanup code after app.display() and it will run when app.display() closes.

Code: Select all

from guizero import App, Text

app = App()
text = Text(app, text="hello world")
app.display()
print ("Cleanup")
by Garvan
Sun Mar 15, 2020 10:11 am
Forum: Python
Topic: [SOLVED] "Segmentation fault" running a Python3 script
Replies: 12
Views: 1504

Re: "Segmentation fault" running a Python3 script

Do you have a "thingspeak_key"? You could push the results in the try section for testing, and when you have it working, adjust to your liking. thingspeak_key = 'XXXXXXXXXXXXXXXX' try: humidity, temperature = Adafruit_DHT.read_retry(sensormodel, sensorpin) if humidity is None or temperatur...
by Garvan
Sun Mar 15, 2020 9:36 am
Forum: Python
Topic: [SOLVED] "Segmentation fault" running a Python3 script
Replies: 12
Views: 1504

Re: "Segmentation fault" running a Python3 script

Ok. I recommend holding the web code until you get the sensor and switches working. # Imports import Adafruit_DHT from energenie import radio, encoder sensormodel = Adafruit_DHT.AM2302 sensorpin = 4 tempthreshold = 20 GREEN_ON = encoder.build_switch_msg(True, device_address=1) GREEN_OFF = encoder.bu...
by Garvan
Sun Mar 15, 2020 9:01 am
Forum: Python
Topic: [SOLVED] "Segmentation fault" running a Python3 script
Replies: 12
Views: 1504

Re: "Segmentation fault" running a Python3 script

I find it difficult to tell what is working and what is not working, so forgive the silly questions. Does this work? # Imports import Adafruit_DHT # Attempt to get a sensor reading. The read_retry method will # retry up to 15 times, waiting 2 seconds between attempts sensormodel = Adafruit_DHT.AM230...
by Garvan
Sun Mar 15, 2020 7:29 am
Forum: Python
Topic: same equation giving different answers
Replies: 2
Views: 235

Re: same equation giving different answers

This is an error

Code: Select all

    t=time.time()
    r=time.time()-t
Every time you call time.time() it returns the current time, so r will be equal to a tiny number.

What you should do is move r=time.time()-t down to after the button is pressed, so it is equal to the reaction time.
by Garvan
Sun Mar 15, 2020 6:43 am
Forum: Python
Topic: [SOLVED] "Segmentation fault" running a Python3 script
Replies: 12
Views: 1504

Re: "Segmentation fault" running a Python3 script

A segmentation fault is a memory error, you are accessing (reading or writing) an un-initialized function or memory address. Normally in this case you will go through your code commenting out one line at a time, until you find our which line is causing the error. You might insert print statements to...
by Garvan
Sun Mar 15, 2020 5:59 am
Forum: Beginners
Topic: Can a python script edit itself?
Replies: 2
Views: 439

Re: Can a python script edit itself?

You should just try it, it would be quicker than asking, but it wont work the way you are hoping. The python source code is loaded into memory on start, so any edits you make to the source will not be executed until the program is run a second time.
by Garvan
Fri Mar 13, 2020 2:58 pm
Forum: General discussion
Topic: Why USB-C ?
Replies: 33
Views: 2630

Re: Why USB-C ?

<snip> https://www.raspberrypi.org/products/type-c-power-supply/ Clicking on this link and selecting the type I need tells me "there are no global supplies for this model".That said, I do have a working wart, official or otherwise, I don't really know. What I want is more options in desig...
by Garvan
Thu Mar 12, 2020 6:57 am
Forum: Python
Topic: alsa warnings and error in running speech recolonization code
Replies: 4
Views: 1416

Re: alsa warnings and error in running speech recolonization code

You might get some information on the issue in this thread https://www.raspberrypi.org/forums/viewtopic.php?t=241919 from last year. The first line of the error message is the same. First thing I would make sure that my system is up-to-date. See: https://www.raspberrypi.org/documentation/raspbian/up...
by Garvan
Mon Mar 09, 2020 2:53 pm
Forum: Python
Topic: time.sleep
Replies: 4
Views: 611

Re: time.sleep

In your code you open a file, write to it, close it and then open it again. This will not work. Everything you wrote to the file the first time is deleted when you open it for writing a second time. And as mentioned above, you have no loop. Study this simple program. It opens a file, writes two line...
by Garvan
Sat Mar 07, 2020 4:06 am
Forum: Beginners
Topic: BlueDot with Raspberry Pi4 [SOLVED]
Replies: 10
Views: 1354

Re: BlueDot with Raspberry Pi4 [SOLVED]

And what is output by the Python script? Mr.Ohanlon used to check in here, he may yet pop up. The script prints out the raspberry pi Bluetooth address, in my case DC:A6:32:20:9E:C6, then it sits there waiting for a connection. I got it working. In the BlueDot application on my phone, I selected &qu...
by Garvan
Sat Mar 07, 2020 3:09 am
Forum: Beginners
Topic: BlueDot with Raspberry Pi4 [SOLVED]
Replies: 10
Views: 1354

Re: BlueDot with Raspberry Pi4

Do you have a Blue Dot application (such as the sample app) running when you try to connect from the phone? Yes, I run the script provided. from bluedot import BlueDot bd = BlueDot() bd.wait_for_press() print("Hello World") 1. My phone pairs successfully with RPi4 GUI interface . 2. I sta...
by Garvan
Fri Mar 06, 2020 12:56 pm
Forum: Beginners
Topic: BlueDot with Raspberry Pi4 [SOLVED]
Replies: 10
Views: 1354

Re: BlueDot with Raspberry Pi4

I tried a third time, just to confirm the python script was running. It does not connect, no error message, nothing. So what do I report to the author/developer/maintainer on https://github.com/martinohanlon/BlueDot? I would feel like a fool saying "it does not work", with nothing useful t...

Go to advanced search