Code: Select all
led = LED(27)Code: Select all
def my_callback_pressed():
global numberOfButtonPresses, buttonTimerStart
print("BUTTON PRESSED")
numberOfButtonPresses=numberOfButtonPresses+1
buttonTimerStart=time.time()
def my_callback_released():
global buttonHoldTime, buttonTimerStart
print("BUTTON RELEASED")
buttonHoldTime = time.time() - buttonTimerStart
buttonTimerStart=0
Code: Select all
led = LED(23)
Right think i might have got a bit mixed up there for a second with numbers. But i have now changed it to GPIO 27 after looking at my first led.py script (listed below) and the led is flashing.jehutting wrote: ↑Sat Aug 08, 2020 11:16 amor when the LED is connected to pin 16Code: Select all
led = LED(23)
Code: Select all
from gpiozero import LED, Button
from signal import pause
led = LED(27)
button = Button(20)
button.when_pressed = led.on
button.when_released = led.off
pause()Code: Select all
#!/usr/bin/python
#Imports
import pygame, random, math, time, pygame.mixer, os
import time
import sys
time.sleep(5)
gpioAvailable = True
try:
from gpiozero import LED, Button
except:
gpioAvailable = False
from audio import TrackerAudio
from pygame.locals import *
from resources import resources
from graphics import TrackerGraphics
from pyscope import pyscope
from startup import StartupGraphics
from calibration import Calibration
from calibrationGraphics import CalibrationGraphics
# GPIO numbering is Broadcom (BCM) based!
# GPIO27, GPIO header pin 13
led = LED(27)
led.blink(on_time=0.5, off_time=0.5, n=None, background=True)
os.environ["SDL_FBDEV"] = "/dev/fb1"
os.environ['SDL_VIDEO_CENTERED'] = '1'
if gpioAvailable:
# GPIO20, GPIO header pin 38
button_1 = Button(20, bounce_time = 0.3)
buttonTimerStart = 0
buttonTimerCurrent = 0
buttonHoldTime = 0
stateString="TRACK"
changeState=True
numberOfButtonPresses=0
buttonHoldTime=0
def my_callback_pressed():
global numberOfButtonPresses, buttonTimerStart
numberOfButtonPresses=numberOfButtonPresses+1
buttonTimerStart=time.time()
def my_callback_released():
global buttonHoldTime, buttonTimerStart
buttonHoldTime = time.time() - buttonTimerStart
buttonTimerStart=0
if gpioAvailable:
button_1.when_pressed = my_callback_pressed
button_1.when_released = my_callback_released
#initialise pygame
pygame.init()
#initialise required game classes
scope=pyscope()
resources=resources() #get a resources object instance
ca=Calibration(scope, resources)
cg=CalibrationGraphics(scope, resources, ca)
sg=StartupGraphics(scope, resources) #get the startup graphics instance
tg=TrackerGraphics(scope, resources, ca) #get the tracker graphics instance
ta=TrackerAudio(resources) #get the tracker audio instance
pygame.mouse.set_visible(False) # Hide the mouse pointer
#initialise a clock instance so we can control the game loop
my_clock=pygame.time.Clock()
#enter the game loop
wave_size = 0
args=[]
done=False
currentState=True
startupTimerStart=time.time()
startupTimerCurrent=time.time()
qPress = False
os.system("fbcp &")
#show the startup gracphics
sg.draw()
while done==False:
if numberOfButtonPresses>1:
addContact = True
numberOfButtonPresses=0
else:
addContact = False
#process pygame events
keys=pygame.key.get_pressed()
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done=True # Flag that we are done so we exit this loop
pass
if event.type == pygame.KEYDOWN:
if event.key==K_q:
qPress = True
buttonTimerStart=time.time()
buttonTimerCurrent=time.time()
buttonHoldTime=0
if event.key==K_x:
done=True
if event.key==K_UP:
addContact = True
if event.type == pygame.KEYUP:
if event.key==K_q:
qPress=False
if qPress:
buttonHoldTime = time.time() - buttonTimerStart
if buttonHoldTime>4:
buttonHoldTime=0
stateString="CALIBRATE"
ca.initCalibration()
calibrationStep = 0
if stateString=="CALIBRATE":
xy = ca.calibrate(calibrationStep)
if calibrationStep==0:
cg.initBackground()
cg.update(xy, ca)
if calibrationStep==500:
stateString="TRACK"
else:
cg.update(xy, ca)
calibrationStep=calibrationStep+1
else:
#process tracker graphics
args = tg.update(wave_size, addContact, ca)
if args!=999:
#process audio
ta.update(wave_size, args)
#check the wave size, if it's 16 then reset otherwise increment
if wave_size==15:
wave_size=0
else:
wave_size+=1
my_clock.tick(21)
scope.pySurface.fill((0,0,0))
scope.screen.blit(scope.pySurface,(0,0))
os.system("killall fbcp")
pygame.quit()
Code: Select all
if numberOfButtonPresses>1:
addContact = False ### JUST FOR TESTPUPOSE!!! True
numberOfButtonPresses=0
else:
addContact = False
Code: Select all
self.contactsArray.addContact(self.compass.smbusAvailable)
Again thanks for all the help. I will try changing the line you suggested. I have tried many times contacting Marinr1000but but reply and even the person who first started the project.jehutting wrote: ↑Sat Aug 08, 2020 12:54 pmI don't think the button code (gpiozero or RPi.GPIO) causes the 30 seconds black screen.
You could try that out by not using "addContact = True" which occurs in the main loop after you have pressed the button (which increments the numberOfButtonPresses variable in the button event handler my_callback).
If the 30 sec black screen doesn't appear the next call would be to look at the graphics.py callCode: Select all
if numberOfButtonPresses>1: addContact = False ### JUST FOR TESTPUPOSE!!! True numberOfButtonPresses=0 else: addContact = Falseand so on....Code: Select all
self.contactsArray.addContact(self.compass.smbusAvailable)
Better try to contact martinr1000, the author, through his github account or PM him. Or create a specific new post about this (and fbcp) which could trigger other users already requesting for help on this aliens motion tracker on this forum.
the-gimp-master wrote: ↑Sat Aug 08, 2020 3:38 pmA bit more or a update on the black screen. The 30 seconds of black screen is still there when i change it to true or false. It`s like the PI is freezing for 30 seconds when i put gpio 20 to ground. because once it shows the screen again everything is still in the same place nothing has moved. like the PI is in some sort of protection for 30 seconds.
That might explain why its crashing. here is another screen shot with the tracker running.jehutting wrote: ↑Sun Aug 09, 2020 12:17 pmHmm... I'm not sure if you can use GPIO20 (pin #38) as it is also defined as DIN-signal by the I2S interface. This interface drives your MAX98357A audio module.
Is the gpio readall screenshot made while the tracker is running? GPIO27 is showing as IN, and I am in doubt that GPIO28 should be shown as ALT.
Is this correct ?
Code: Select all
# GPIO numbering is Broadcom (BCM) based!
# GPIO27, GPIO header pin 13
led = LED(27)
led.blink(on_time=0.5, off_time=0.5, n=None, background=True)
os.environ["SDL_FBDEV"] = "/dev/fb1"
os.environ['SDL_VIDEO_CENTERED'] = '1'
if gpioAvailable:
# GPIO22, GPIO header pin 15
button_1 = Button(22, bounce_time = 0.3)
I have a second PI. The tv dose the same as my display in the tracker. i have sent you a video showing the black screen thats after putting gpio22 to ground. It`s aways the same time the black screen is there for. same on the trackers display.