Skip to content
View in the app

A better way to browse. Learn more.

Armbian Community Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

GPIO Buttons does not work

Featured Replies

Hi. I have made a system with O Pi Lite and Armbian to automate an aquarium from where to control the light, the bubbles and with a webcam I can see the system through the web, everything automated from Cron. From a web page I can turn on and off the lights and bubbles from web buttons. Everything is fine.

The problem arises when I want to put some phisical buttons for 3 things: turn off the system, change the state of light and bubbles. I have used a code in Python and the PYA20 library. This is the code. It works very well, but when I start it with the system, the program stop working soon and the buttons stop to work.

 

#!/usr/bin/env python
from pyA20.gpio import gpio
from pyA20.gpio import port
import subprocess
import time
import os

# PIN 29 - IN Light (luz)
onoff = port.PA7
# PIN 7  - IN Bubbles (burbujas)
luzboton = port.PA6
# PIN 8  - IN Shutdown
burbujasboton = port.PA13
# OUT Pins
luzvivo = port.PA8
burbujasvivo = port.PA9

gpio.init()
#Button ON-OFF
gpio.setcfg(onoff, gpio.INPUT)
gpio.pullup(onoff, gpio.PULLUP)
#Button light
gpio.setcfg(luzboton, gpio.INPUT)
gpio.pullup(luzboton, gpio.PULLUP)
#Button bubbles
gpio.setcfg(burbujasboton, gpio.INPUT)
gpio.pullup(burbujasboton, gpio.PULLUP)
# OUT
gpio.setcfg(luzvivo, gpio.OUTPUT)
gpio.setcfg(burbujasvivo, gpio.OUTPUT)

while True:
    # PROCESS ON-OFF need 5 seconds to avoid mistaken shutdowns
    if gpio.input(onoff) == 0:
        #start counting pressed time
        print ("pulsado")
        time.sleep(5)
        if gpio.input(onoff) == 0 :
            os.system("shutdown now -h")

    # PROCESS LIGHT
    if gpio.input(luzboton) == 0:
        print ("pulsado luz")
        estadoluz = gpio.input(luzvivo)
        gpio.output(luzvivo, not estadoluz)
        time.sleep(1)

    # PROCESS bubbles
    if gpio.input(burbujasboton) == 0:
        print ("pulsado bubbles")
        estadoburbujas = gpio.input(burbujasvivo)
        gpio.output(burbujasvivo, not estadoburbujas)
        # To avoid bounce
        time.sleep(1)

If i check the procces, i can see it, but i can also see that consumes a lot of CPU:

 

ps aux | grep botones
root       652 95.1  0.6   8552  3412 ?        Rs   10:53   2:36 python /etc/init.d/botones.py start

What i am doing wrong?

 

Thank you in advance.

  • Author

Well, now the consume of CPU lower to 0,1%... thank you very much.

 

BUT... still dying. The file is in /etc/init.d/ and have +x permission. The file starts but after a while dies.... The Python file is called "botones.py". In syslog:

 

Nov  7 16:31:03 localhost systemd[1]: botones.py.service start operation timed out. Terminating.
Nov  7 16:31:03 localhost rsyslogd-2007: action 'action 17' suspended, next retry is Tue Nov  7 16:31:33 2017 [try http://www.rsyslog.com/e/2007 ]
Nov  7 16:31:03 localhost systemd[1]: Failed to start (null).
Nov  7 16:31:03 localhost systemd[1]: Unit botones.py.service entered failed state.

If i run from the monitor, never dies....

  • Author

I can not make it work from rc.local... i tried to launch with:

 

nohup python /home/orangepi/scripts/botones.py &

and with and without sudo but nothing never runs. I tried too to run from /etc/init.d/....

 

What am i lossing?

 

  • Author

With:

nohup python /home/orangepi/scripts/botones.py > /tmp/botones.log 2>&1

in rc.local, nothing in /tmp folder..... And the script does not run at boot.

  • Author

By the way, in my rc.local i have other scripts that runs normally:

 

#!/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.

/etc/init.d/entrehoras.sh
# CÁMARA HP
/etc/init.d/runmjpg.sh
# Cámara GEMBIRD
#/etc/init.d/runmjpgGEMBIRD.sh
nohup python /home/orangepi/scripts/botones.py > /tmp/botones.log 2>&1
#/etc/init.d/botones.sh
exit 0

 

  • Author

Yes!. It was the "&" at the end of the calls to the scripts. The 3 of them... Now i have too a "/tmp/botones.log".

 

With that and the "sleep.time(0.1)" at the end of the while, all works fine.

 

Thank you both!!!

Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.