Quantcast
Viewing all articles
Browse latest Browse all 4700

Beginners • 6 weeks and out of time

Hey everybody, so sorry I'm not sure where to post this. I've been working on this project for about 6 weeks now. I've had absolutely no experience and somehow still managed to get this point.. but I'm at a loss for time and desperately need help. The project is intended to be a Christmas gift for my husband.

I'm building Talaexe's Modern Day Record Player using a 3d printed mini record player and little vinyl records. I don't know if I can link here (again, new) but it's easy to google if needed for reference -- comes up as a YouTube video. I had to make some modifications to her tutorial. Specifically, I'm running a PN532 nfc hat. Inside of Thonny, everything works perfectly, some duplication warnings but full functionality. When I run the script in terminal I get several errors. The entire project is built in a virtual environment; all libraries and dependencies

Is there a way to run this entirely in Thonny? If so, is it possible to have it run at startup? If not, how can I fix this and have it run at startup?

Code:

#!/usr/bin/env pythonfrom pn532 import *import RPi.GPIO as GPIOimport spotipyfrom spotipy.oauth2 import SpotifyOAuthfrom time import sleep#pn532 = PN532_SPI(reset=20, cs=4, debug=False)pn532 = PN532_I2C(debug=False, reset=20, req=16)#pn532 = PN532_UART(reset=20, debug=False)p3, p7, i0i1 = pn532.read_gpio()DEVICE_ID="xxxxxxxxxxx"CLIENT_ID="xxxxxxxxxxx"CLIENT_SECRET="xxxxxxxxxx"while True:    try:        # Configure PN532 to communicate with MiFare cards        pn532.SAM_configuration()                reader=p3, p7, i0i1 = pn532.read_gpio()        sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=CLIENT_ID,                                                       client_secret=CLIENT_SECRET,                                                       redirect_uri="http://localhost:8080",                                                       scope="user-read-playback-state,user-modify-playback-state"))                # create an infinite while loop that will always be waiting for a new scan        while True:            print("Waiting for record scan...")            uid= pn532.read_passive_target()            print("Card Value is:",uid)                        # DONT include the quotation marks around the card's ID value, just paste the number            if (uid==b'\x04,1\x9d\xc1*\x81'):                                # playing a song                sp.start_playback(device_id=DEVICE_ID, uris=['spotify:track:1rNSCrsOoWyhKH4g47mehU'])                sleep(3)                            elif (uid==b'\x04,\x17\x9d\xc1*\x81'):                                # playing an album                sp.start_playback(device_id=DEVICE_ID, context_uri='spotify:album:4utJOX1ShFfRa6oQA1ADh0')                #sleep(2)                            elif (uid==b'\x04\x1e*\x9d\xc1*\x81'):                                # playing an album                sp.start_playback(device_id=DEVICE_ID, context_uri='spotify:album:6DEjYFkNZh67HP7R9PSZvv')                #sleep(2)                            elif (uid==b'\x04\x1a\x1d\x9d\xc1*\x81'):                                # playing an album                sp.start_playback(device_id=DEVICE_ID, context_uri='spotify:album:1NAmidJlEaVgA3MpcPFYGq')                #sleep(2)                            # continue adding as many "elifs" for songs/albums that you want to play                # if there is an error, skip it and try the code again (i.e. timeout issues, no active device error, etc)    except Exception as e:        print(e)        pass    finally:        print("Cleaning  up...")        GPIO.cleanup()
I'm aware that the asterisk in "from pn532 import *" could potentially lead to problems, but I'm not seeing how as changing that leads to a whole host of other issues.. it does work in Thonny. I'm also learning through all of this so if theres time for an explanation that'd be awesome.

Here's are the errors I'm getting in terminal
Traceback (most recent call last):
File "/home/xxxxx/my_venv/lib64/python3.11/site-packages/player.py", line 3, in <module>
from pn532 import *
File "/home/xxxxx/my_venv/lib/python3.11/site-packages/pn532/__init__.py", line 10, in <module>
from . import pn532
File "/home/xxxxx/my_venv/lib/python3.11/site-packages/pn532/pn532.py", line 35, in <module>
import RPi.GPIO as GPIO
ModuleNotFoundError: No module named 'RPi'
RPI.GPIO is installed. Originally in just the environment but now also outside the environment (one of my duplication warnings I presume)

PN532 is installed, but only in the environment. I can't seem to get it to install outside the environment. Changing the asterisk to "i2c" or "pn532" (located in the pn532 library, also in the environment) leads to
Traceback (most recent call last):
File "/home/xxxxx/my_venv/lib/python3.11/site-packages/player.py", line 11, in <module>
pn532 = PN532_I2C(debug=False, reset=20, req=16)
NameError: name 'PN532_I2C' is not defined
It's saturday 12/21.. If I had more time I'd continue searching across Google for help. But, its taken 6 weeks to get this far and I'm running around in circles at this point trying to solve this.. all help is so very much appreciated.

Statistics: Posted by just_a_beginner — Sun Dec 22, 2024 3:12 am — Replies 3 — Views 116



Viewing all articles
Browse latest Browse all 4700

Trending Articles