the-gimp-master
Posts: 60
Joined: Wed Jul 15, 2020 1:03 pm

Re: Help with led.

Sat Aug 08, 2020 10:40 am

Thanks for the new file. the program loads still. but the gpio20 dose nothing. and no blinking led on gpio 23.

jehutting
Posts: 163
Joined: Sun Feb 15, 2015 8:37 am
Location: The Netherlands

Re: Help with led.

Sat Aug 08, 2020 11:11 am

According to https://gpiozero.readthedocs.io/en/stab ... -numbering
pin 13 is GPIO27, so the statement #26 should be

Code: Select all

led = LED(27)

The button is connected to pin 38 and is indeed GPIO20, and it is defaulted to be pulled-up, so that one should be working... here I'm a little bit puzzled.

Try to add below print statements

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
 
These print messages should be shown on your console (/terminal).

jehutting
Posts: 163
Joined: Sun Feb 15, 2015 8:37 am
Location: The Netherlands

Re: Help with led.

Sat Aug 08, 2020 11:16 am

or when the LED is connected to pin 16

Code: Select all

led = LED(23)

the-gimp-master
Posts: 60
Joined: Wed Jul 15, 2020 1:03 pm

Re: Help with led.

Sat Aug 08, 2020 12:13 pm

jehutting wrote:
Sat Aug 08, 2020 11:16 am
or when the LED is connected to pin 16

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.

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()
The script below is now working but when GPIO 20 is pressed it`s causing the screen to go black for around 30 seconds. before re displaying the tracker app. and almost like the button is delayed. If i run in termanal i get a error fbcp: no process found.
But once again thank you so far for all the help and the scrips so far.

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()

the-gimp-master
Posts: 60
Joined: Wed Jul 15, 2020 1:03 pm

Re: Help with led.

Sat Aug 08, 2020 12:37 pm

jehutting do you have a email or Facebook account. So i can send you some video.

jehutting
Posts: 163
Joined: Sun Feb 15, 2015 8:37 am
Location: The Netherlands

Re: Help with led.

Sat Aug 08, 2020 12:54 pm

I 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).

Code: Select all

    if numberOfButtonPresses>1:
        addContact = False ### JUST FOR TESTPUPOSE!!! True
        numberOfButtonPresses=0
    else:
        addContact = False 
 
If the 30 sec black screen doesn't appear the next call would be to look at the graphics.py call

Code: Select all

self.contactsArray.addContact(self.compass.smbusAvailable)
and so on....

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
Posts: 60
Joined: Wed Jul 15, 2020 1:03 pm

Re: Help with led.

Sat Aug 08, 2020 3:38 pm

jehutting wrote:
Sat Aug 08, 2020 12:54 pm
I 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).

Code: Select all

    if numberOfButtonPresses>1:
        addContact = False ### JUST FOR TESTPUPOSE!!! True
        numberOfButtonPresses=0
    else:
        addContact = False 
 
If the 30 sec black screen doesn't appear the next call would be to look at the graphics.py call

Code: Select all

self.contactsArray.addContact(self.compass.smbusAvailable)
and so on....

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.
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
Posts: 163
Joined: Sun Feb 15, 2015 8:37 am
Location: The Netherlands

Re: Help with led.

Sat Aug 08, 2020 4:20 pm

If you have a dropbox account you can share a folder with your videos.
Allow <you got my email address>. Or send me an email and I will give you access to a shared folder of mine.

the-gimp-master
Posts: 60
Joined: Wed Jul 15, 2020 1:03 pm

Re: Help with led.

Sun Aug 09, 2020 10:19 am

the-gimp-master wrote:
Sat Aug 08, 2020 3:38 pm
jehutting wrote:
Sat Aug 08, 2020 12:54 pm
I don't think the button code (gpiozero or RPi.GPIO) causes the 30 seconds black screen.
A 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.

the-gimp-master
Posts: 60
Joined: Wed Jul 15, 2020 1:03 pm

Re: Help with led.

Sun Aug 09, 2020 10:57 am

Dose this help ? GPIO readall
[/img]https://photos.app.goo.gl/rXDarchkthECuCuX8[/img]

jehutting
Posts: 163
Joined: Sun Feb 15, 2015 8:37 am
Location: The Netherlands

Re: Help with led.

Sun Aug 09, 2020 12:17 pm

Hmm... 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.

the-gimp-master
Posts: 60
Joined: Wed Jul 15, 2020 1:03 pm

Re: Help with led.

Sun Aug 09, 2020 2:03 pm

jehutting wrote:
Sun Aug 09, 2020 12:17 pm
Hmm... 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.
That might explain why its crashing. here is another screen shot with the tracker running.
Image

So can i use any of the GPIO`s below.
gpio 4 /pin7
gpio 17 /pin11
gpio 16 /pin36
gpio 22 /pin15
gpio 23 /pin16
Last edited by the-gimp-master on Mon Aug 10, 2020 5:43 am, edited 3 times in total.

jehutting
Posts: 163
Joined: Sun Feb 15, 2015 8:37 am
Location: The Netherlands

Re: Help with led.

Mon Aug 10, 2020 5:30 am

Could you update the link to the image as it is shown as (text) Image.

the-gimp-master
Posts: 60
Joined: Wed Jul 15, 2020 1:03 pm

Re: Help with led.

Mon Aug 10, 2020 5:38 am

jehutting wrote:
Mon Aug 10, 2020 5:30 am
Could you update the link to the image as it is shown as (text) Image.
Image
https://photos.app.goo.gl/DNgc5yPZSVfE6ZxY8

jehutting
Posts: 163
Joined: Sun Feb 15, 2015 8:37 am
Location: The Netherlands

Re: Help with led.

Mon Aug 10, 2020 5:51 am

Still strange... as when I run "gpio readall" I see my LED output changed to mode OUT, whereas your LED still persist on mode IN.

the-gimp-master
Posts: 60
Joined: Wed Jul 15, 2020 1:03 pm

Re: Help with led.

Mon Aug 10, 2020 6:26 am

My led is now blinking, and updated the gpio readall image now reads out.
https://photos.app.goo.gl/fRi5dFfyqMjCvx6KA

jehutting
Posts: 163
Joined: Sun Feb 15, 2015 8:37 am
Location: The Netherlands

Re: Help with led.

Mon Aug 10, 2020 7:02 am

Ha ha... yes now GPIO27 has mode OUT, but PIN38 shows mode IN whereas I expect mode ALT0 as for the audio interface.

Looking at all your hardware, you can try to use GPIO22 pin#15 for the button.

the-gimp-master
Posts: 60
Joined: Wed Jul 15, 2020 1:03 pm

Re: Help with led.

Mon Aug 10, 2020 7:31 am

jehutting wrote:
Mon Aug 10, 2020 7:02 am
Ha ha... yes now GPIO27 has mode OUT, but PIN38 shows mode IN whereas I expect mode ALT0 as for the audio interface.

Looking at all your hardware, you can try to use GPIO22 pin#15 for the button.
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)

jehutting
Posts: 163
Joined: Sun Feb 15, 2015 8:37 am
Location: The Netherlands

Re: Help with led.

Mon Aug 10, 2020 7:42 am

Yes... and hopefully it works :-)

the-gimp-master
Posts: 60
Joined: Wed Jul 15, 2020 1:03 pm

Re: Help with led.

Mon Aug 10, 2020 8:14 am

jehutting wrote:
Mon Aug 10, 2020 7:42 am
Yes... and hopefully it works :-)
It works but i get the black screen still. Try tapping gpio22 to ground a few times and see if it crashes for you

jehutting
Posts: 163
Joined: Sun Feb 15, 2015 8:37 am
Location: The Netherlands

Re: Help with led.

Mon Aug 10, 2020 8:24 am

I only have a LED and a Button connected to my Raspberry Pi testrig; no display, no audio and no compass sensor.

the-gimp-master
Posts: 60
Joined: Wed Jul 15, 2020 1:03 pm

Re: Help with led.

Mon Aug 10, 2020 8:43 am

jehutting wrote:
Mon Aug 10, 2020 8:24 am
I only have a LED and a Button connected to my Raspberry Pi testrig; no display, no audio and no compass sensor.
Give it a go because i have just checked mine just using my hdmi tv and nothing connected to the PI.

jehutting
Posts: 163
Joined: Sun Feb 15, 2015 8:37 am
Location: The Netherlands

Re: Help with led.

Mon Aug 10, 2020 8:59 am

You get a black screen on your HDMI screen???
What happens on the TFT display?
How did you managed to get it on the HDMI?

the-gimp-master
Posts: 60
Joined: Wed Jul 15, 2020 1:03 pm

Re: Help with led.

Mon Aug 10, 2020 9:48 am

jehutting wrote:
Mon Aug 10, 2020 8:59 am
You get a black screen on your HDMI screen???
What happens on the TFT display?
How did you managed to get it on the HDMI?
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.

Return to “Python”