andrea29
Posts: 10
Joined: Wed Sep 04, 2019 1:38 pm

Switching On led on GIPO when I push my 433Mhz button

Fri Sep 06, 2019 12:57 pm

Hi,

I want to control a Pin for exemple a LED on my raspberry B+ when I push a 433 button.

I have this receiver : https://www.amazon.it/Aukru-Wireless-Ri ... 6743&psc=1

Some help whit code ?


andrea29
Posts: 10
Joined: Wed Sep 04, 2019 1:38 pm

Re: Switching On led on GIPO when I push my 433Mhz button

Fri Sep 06, 2019 1:25 pm

I have been searching online for a long time but I haven't found anything that can help me.
I installed rip-rf, and I was able to see the codes of 433 devices but I would like to create a python script that when I receive an impulse from my remote control one pin GPIO with led turn on.

I saw this code but I don't know how to tell him when I get this code - do that.


from rpi_rf import RFDevice
rfdevice = RFDevice (SEND_PIN)
 
rfdevice.enable_tx ()
rfdevice.tx_code (SWITCH_CODE, 1, PULSE_LENGTH)

Online I found only code for transmit signal...

User avatar
joan
Posts: 14265
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Switching On led on GIPO when I push my 433Mhz button

Fri Sep 06, 2019 4:35 pm

Do you want to detect a particular button or will any button do? I.e. do you just want to detect a signal has been transmitted?

andrea29
Posts: 10
Joined: Wed Sep 04, 2019 1:38 pm

Re: Switching On led on GIPO when I push my 433Mhz button

Fri Sep 06, 2019 5:20 pm

Thanks for the reply,
with a 4-channel remote control I would like to control a GPIO output, for example the code of the first channel of the control 433 is 5330700 this channel turns on LED 1, channel 530701 turns on LED 2 and so on...

User avatar
joan
Posts: 14265
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Switching On led on GIPO when I push my 433Mhz button

Fri Sep 06, 2019 5:34 pm

Download the following code.

http://abyz.me.uk/rpi/pigpio/examples.h ... on__433_py

Edit line 322 which is RX=20 and change 20 to the Broadcom number (BCM) of the GPIO attached to the receiver.

https://pinout.xyz/

Run the pigpio daemon.

sudo pigpiod

Run the code (default name assumed)

./_433.py

Do you get repeatable codes for the key presses?

andrea29
Posts: 10
Joined: Wed Sep 04, 2019 1:38 pm

Re: Switching On led on GIPO when I push my 433Mhz button

Fri Sep 06, 2019 6:03 pm

Yes, I have code for every button pressed

button 1 - 6792737
button 2 - 6792740

if I do a long press I have a sequence

User avatar
joan
Posts: 14265
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Switching On led on GIPO when I push my 433Mhz button

Fri Sep 06, 2019 8:02 pm

Well you should be able write a script to handle the codes.

Leave _433.py as is and create a new script, e.g. myscript.py

Code: Select all

#!/usr/bin/env python

import time
import pigpio
import _433

RX=20

pi = pigpio.pi() # Connect to local Pi.
if not pi.connected:
   exit()

rx=_433.rx(pi, gpio=RX)

while True:

   # check to see if new key press available

   if rx.ready():

      code = rx.code()

      if code == 6792737:
         print("button 1")
      elif code == 6792740:
         print("button 2")

   time.sleep(0.1)

rx.cancel() # Cancel the receiver.

pi.stop() # Disconnect from local Pi.
Then

chmod +x myscript.py

./myscript.py

andrea29
Posts: 10
Joined: Wed Sep 04, 2019 1:38 pm

Re: Switching On led on GIPO when I push my 433Mhz button

Sat Sep 07, 2019 3:36 pm

Thanks for the reply,

I tried your advice and everything was ok.

Then I tried to change the code to start a call when I press a button

I start pigpoid daemon, but works only one time, pressing the first key. then it does nothing

Where am I wrong?

Code: Select all

#!/usr/bin/env python
import RPi.GPIO as gpio
import time
import pigpio
import _433
import subprocess
import os

gpio.setmode(gpio.BCM)
gpio.setwarnings(False)

RX=4

led_blau = 5
led_rot = 6
led_gruen = 13

gpio.setup(led_blau, gpio.OUT)
gpio.setup(led_rot, gpio.OUT)
gpio.setup(led_gruen, gpio.OUT)



pi = pigpio.pi() # Connect to local Pi.
if not pi.connected:
   exit()

rx=_433.rx(pi, gpio=RX)

while True:

   # check to see if new key press available

   if rx.ready():

      code = rx.code()

      if code == 8301745:
        time.sleep (0.5)
        gpio.output(led_blau, gpio.LOW)
        gpio.output(led_rot, gpio.LOW)
        gpio.output(led_gruen, gpio.HIGH)
        subprocess.call("twinkle -cli --user 501xxxxxxxx --sip-port 5160 --rtp-port 8010 --call xxxxxxx --immediate &", shell=True)
        
      elif code == 8301745:
        subprocess.call("pkill -f twinkle", shell=True)
        subprocess.call("sudo killall twinkle", shell=True)
        gpio.output(led_blau, gpio.LOW)
        gpio.output(led_rot, gpio.HIGH)
        gpio.output(led_gruen, gpio.LOW)

   time.sleep(0.1)


User avatar
joan
Posts: 14265
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Switching On led on GIPO when I push my 433Mhz button

Sat Sep 07, 2019 4:08 pm

Perhaps put a print(code) after the code = rx.code() line. If a code is being received it is down to the added code.

andrea29
Posts: 10
Joined: Wed Sep 04, 2019 1:38 pm

Re: Switching On led on GIPO when I push my 433Mhz button

Sun Sep 08, 2019 8:47 am

I insert the code print, now i see the button code, but when i press the button whit the code that have to do the function subprocess.call("Twinkle...) it run the action one time and then don't receive nothing.

If I run _433 I don't see nothing and I have to restart the raspberry

User avatar
joan
Posts: 14265
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Switching On led on GIPO when I push my 433Mhz button

Sun Sep 08, 2019 9:08 am

Does the original myscript.py I posted work? I.e. if you run that script does it keep reporting button presses until you stop the script?

andrea29
Posts: 10
Joined: Wed Sep 04, 2019 1:38 pm

Re: Switching On led on GIPO when I push my 433Mhz button

Sun Sep 08, 2019 9:19 am

Yes, still running...

could be problem whit my Mic+ board ? ( https://www.raspiaudio.com/raspiaudio-aiy )
Cause when i start pigpio daemon audio don't work well

User avatar
joan
Posts: 14265
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Switching On led on GIPO when I push my 433Mhz button

Sun Sep 08, 2019 9:25 am

pigpio uses either the PWM or PCM peripheral for internal purposes. By default it uses PCM. It seems likely that your audio also uses PCM.

You can tell pigpio to use PWM rather than PCM by starting the daemon as follows.

sudo pigpiod -t0

See if that cures the problem.

If you need to use PWM and PCM then you will need to find another solution.

andrea29
Posts: 10
Joined: Wed Sep 04, 2019 1:38 pm

Re: Switching On led on GIPO when I push my 433Mhz button

Sun Sep 08, 2019 9:38 am

Yes Now it's WORK !!!
thank you so much for your time,

how I can run (sudo pigpiod -t0) at the startup automatically, I can put this in the script ?

User avatar
joan
Posts: 14265
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Switching On led on GIPO when I push my 433Mhz button

Sun Sep 08, 2019 9:58 am

There are a variety of ways.

I tend to just put an entry in the root cron table to start the daemon at boot.

sudo crontab -e

Add the line

@reboot /usr/local/bin/pigpiod -t0

andrea29
Posts: 10
Joined: Wed Sep 04, 2019 1:38 pm

Re: Switching On led on GIPO when I push my 433Mhz button

Sun Sep 08, 2019 10:21 am

I put here but when I run the script say : did you start the pigpiod daemon ?

/temp/crontab.En5lgt/crontab

User avatar
joan
Posts: 14265
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Switching On led on GIPO when I push my 433Mhz button

Sun Sep 08, 2019 10:41 am

If you use nano you need to add the line then press ctrl o, return, ctrl x. It will then say

crontab: installing new crontab

You then need to reboot.

If that didn't work perhaps your version of pigpiod is in /usr/bin rather than /usr/local/bin.

Use which pigpiod to check.

Return to “Beginners”