Savoo
Savoo

Reputation: 11

Terminal errors when running my project code, which uses GPIO

I have a school project to create code in Arduino on the OrangePi PC model. The objective is for the code to make three buttons play an audio, where you must pause, rewind and fast forward. For this I used the OPi.GPIO libraries to configure the pins, and pygame for the buttons. But I have made a lot of mistakes, as I am not at all an expert at this.

The error that appears in the terminal is the following:

_frozen_importlib:219: RuntimeWarning: Your system is neon capable but pygame was not built with support for it. The performance of some of your blits could be adversely affected. Consider enabling compile time detection with environment variables like PYGAME_DETECT_AVX2=1 if you are compiling without cross compilation.
pygame 2.5.2 (SDL 2.0.8, Python 3.6.9)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "codigoOPi.py", line 11, in <module>
    GPIO.setup(7, GPIO.OUT)
  File "/home/orangepi/.local/lib/python3.6/site-packages/OPi/GPIO.py", line 480, in setup
    raise e
  File "/home/orangepi/.local/lib/python3.6/site-packages/OPi/GPIO.py", line 472, in setup
    sysfs.export(pin)
  File "/home/orangepi/.local/lib/python3.6/site-packages/OPi/sysfs.py", line 37, in export
    with open(path, "w") as fp:

The code I built is this:

import OPi.GPIO as GPIO
import time 
import pygame

GPIO.setmode(GPIO.BOARD)

proximo = 7;
pausa = 8;
volta = 9;

GPIO.setup(7, GPIO.OUT);
GPIO.setup(8, GPIO.OUT);
GPIO.setup(9, GPIO.OUT);
GPIO.setup(7, GPIO.IN, pull_up_down=GPIO.PUD_UP);
GPIO.setup(8, GPIO.IN, pull_up_down=GPIO.PUD_UP);
GPIO.setup(9, GPIO.IN, pull_up_down=GPIO.PUD_UP);

GPIO.output(7, GPIO.HIGH);
GPIO.output(8, GPIO.HIGH);
GPIO.output(9, GPIO.HIGH);

pygame.mixer.init()
caminho_do_audio = "/home/orangepi/msc/"
pygame.mixer.music.load(caminho_do_audio)

def iniciar_pausar_callback(pausa):
    print("Botao iniciar ou pausar pressionado")
    if pygame.mixer.music.getbusy():
        pygame.mixer.music.pause()
    else:
        pygame.mixer.music.play()

def adiantar_callback(proximo):
        print ("botao de adiantar pressionado")
        pygame.mixer.music.pause()
        pygame.mixer.music.set_pos(pygame.mixer.music.set_pos() + 10)
        pygame.mixer.music.unpause()
        
def retroceder_callback(volta):
    print("botao retroceder pressionado")
    pygame.mixer.music.pause()
    pygame.mixer.music.set_pos(pygame.mixer.music.set_pos() - 10)
    pygame.mixer.music.unpause()

gpio.add_event_detect(8, GPIO.FALLING, callback=iniciar_pausar_callback, bouncetime=300)
gpio.add_event_detect(7, GPIO.FALLING, callback=adiantar_callback, bouncetime=300)
gpio.add_event_detect(9, GPIO.FALLING, callback=retroceder_callback, bouncetime=300)

try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    print ("programa encerrado pelo usuario")
finally:
        gpio.cleanup()

I believe that the circuit has no error, but just in case I leave here a Tinkercad link demonstrating a little of how it is:

https://www.tinkercad.com/things/huVmXOblYqK-projetobiosemfroteiras

If you know of a different method that might be easier to program something like this, I would be grateful for the advice and any help you may have.

Upvotes: 0

Views: 75

Answers (0)

Related Questions