Lightning button on the rear...?

Here is all the tutorials, FAQ and support for RaspiBoy Kit
User avatar
Admin
Administrateur du site
Posts: 505
Joined: Sat 10 Dec 2016 13:12

Re: Lightning button on the rear...?

Post by Admin »

About this issue I am not sure what can be the problem. It could be the button itself or the associated pogo pin but it would not be my first guess.

Are you sure everything is correct in your attempts? There could be quite a lot of software reasons for it not working.

When you run the python install have you check if install is OK?
sudo apt-get install python-dev
sudo apt-get install python3-dev
sudo apt-get install gcc
sudo apt-get install python-pip
Are you connected to internet while doing it?
Have you checked if the python version you installed (maybe installed from first tutorial) is same version with the latest script posted on the forum? If oone is 2.7 and other is 3.x there can be some syntax problems.

Best to confirm if it's hardware defect would be to make a script that print some string in the console when buttons is pushed. So you can see if there are errors or if button just don't work.
Just put this example script (name file test.py) to your root folder of your SD card then type in the console "sudo python /boot/test.py"
See if the script is launching.

Not sure of the code I have not tried it.

Code: Select all

#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import subprocess

GPIO.setmode(GPIO.BOARD)  

GPIO.setup(11, GPIO.IN, pull_up_down = GPIO.PUD_UP)  

oldButtonState1 = True

print("script started")

while True:
    #grab the current button state
    buttonState1 = GPIO.input(11)

    # check to see if button has been pushed
    if buttonState1 != oldButtonState1 and buttonState1 == False:
      print("button working!")
      oldButtonState1 = buttonState1

    time.sleep(.1)
roostaar
Posts: 31
Joined: Tue 2 Jan 2018 00:39

Re: Lightning button on the rear...?

Post by roostaar »

Thanks Pierre.

Have followed your steps on both the Raspiboy (pin11) & my RPi3 (pin5).

The Raspiboy reports nothing. :(

The RPi3 reports the following; :mrgreen:

Code: Select all

pi@retropie:~ $ sudo nano /boot/test.py
pi@retropie:~ $ sudo python /boot/test.py
/boot/test.py:8: RuntimeWarning: A physical pull up resistor is fitted on this channel!
  GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_UP)
script started
button working!
Surely hardware now?
User avatar
Admin
Administrateur du site
Posts: 505
Joined: Sat 10 Dec 2016 13:12

Re: Lightning button on the rear...?

Post by Admin »

On pi zero the script launch correctly? Do you have the "script started" message?

Also to check if it's not rpi zero hardware problem can you try the GPIO when the raspberry pi zero is sitting by itself. You just have to take a wire, connect it to ground on one side (hold it with your finger there, no need to solder) and then with other side of wire touch the GPIO hole pin to simulate a button.
roostaar
Posts: 31
Joined: Tue 2 Jan 2018 00:39

Re: Lightning button on the rear...?

Post by roostaar »

Sorry, I was not clear. :oops:

The script did run correctly on the Zero and did report ‘script started’.

The Zero and the RPi3 do everything the same, except the Zero does not respond at all when the BiB is pushed.

To setup the Zero on its own, not sure how to do this as I do not have any way of getting it on the network. All my peripherals are USB, not micro USB.

I could setup the raspiboy components and gently clamp them together? As in, really gently!!
User avatar
Admin
Administrateur du site
Posts: 505
Joined: Sat 10 Dec 2016 13:12

Re: Lightning button on the rear...?

Post by Admin »

You don't need internet connection to test. But you need a keyboard to go to console and type the command line.

You can stack them together if you'r gentle it's ok, I usually use insulated metallic wire that I put through both PCB holes to tight the PCB together.
roostaar
Posts: 31
Joined: Tue 2 Jan 2018 00:39

Re: Lightning button on the rear...?

Post by roostaar »

Admin wrote:You don't need internet connection to test. But you need a keyboard to go to console and type the command line.

You can stack them together if you'r gentle it's ok, I usually use insulated metallic wire that I put through both PCB holes to tight the PCB together.

Cheers Pierre. Really appreciate the support here.

I will try clamping, as I do not have micro usb -> usb adapter for keyboard.

Will report back soon!
Vilikt
Posts: 15
Joined: Mon 15 Jan 2018 11:13

Re: Lightning button on the rear...?

Post by Vilikt »

Sleep 10; simply means "wait for 10 milliseconds".

Afterall it's important to put the brackets ! So the script will run in background.
roostaar
Posts: 31
Joined: Tue 2 Jan 2018 00:39

Re: Lightning button on the rear...?

Post by roostaar »

So I rigged up the PCB, Zero, LCD & Battery outside of the case and gently clamped the Zero to the PCB using insulated copper wire.

The Zero booted perfectly and i can see the pogo pins are lined up correctly to the Zero.

I connected a keyboard and ran "sudo python /boot/test.py script"

Terminal says "script started"

Pressed the BiB and no response.

My 'shutdown.py' script is still set to load at boot.

Then I grounded pin11 manually with a copper wire, the Zero instantly went into shutdown process, just like my RPi3.

So the Zero pins and the script are definitely both working.

I can only conclude from this that there is an issue with the PCB? :(
Attachments
IMG_1733.jpg
IMG_1733.jpg (124.91 KiB) Viewed 8593 times
IMG_1732.jpg
IMG_1732.jpg (120.39 KiB) Viewed 8593 times
IMG_1731.JPG
IMG_1731.JPG (123.38 KiB) Viewed 8593 times
KillerHenne
Posts: 4
Joined: Sun 28 Jan 2018 08:51

Re: Lightning button on the rear...?

Post by KillerHenne »

Thank thomas, your guid works perfect. is there a way to set a little delay before the button activate the script (press the button for 5 sec and shut down). Is a little bit dangerous now to play Mario kart :D
thomas
Posts: 3
Joined: Thu 4 Jan 2018 13:15

Re: Lightning button on the rear...?

Post by thomas »

KillerHenne wrote:Thank thomas, your guid works perfect. is there a way to set a little delay before the button activate the script (press the button for 5 sec and shut down). Is a little bit dangerous now to play Mario kart :D
Hi KillerHenne i find a solution for your needs.

first you need online connection then type in

Code: Select all

sudo apt update && sudo apt install python3-rpi.gpio:armhf 
next you need to delete the old script with

Code: Select all

rm /home/pi/off-button.py
then download then new script

Code: Select all

wget "https://github.com/obgm/smart-button/raw/master/smart-button.py" -O /home/pi/off-button.py
and the last thing you need to edit the rc.local script. to do so.

Code: Select all

sudo nano /etc/rc.local
delete the line

Code: Select all

python /home/pi/off-button.py & 
and instead add the line

Code: Select all

python3 /home/pi/off-button.py -P 17 -c 'echo "short press"' -l 'sudo shutdown -h now' & 
on my pi the file looks like this

Code: Select all

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

python3 /home/pi/off-button.py -P 17 -c 'echo "short press"' -l 'sudo shutdown -h now' &

exit 0
greetings from germany.
Post Reply