GPIO interrupt triggered by different pin

时间:2016-04-04 18:14:00

标签: python-3.x raspberry-pi gpio

tl;dr:

Listening to a RISING event on GPIO PIN14 (with 10K pulldown resistor); Ghost RISING events when sending/receiving data on different GPIO pin;


I have the following issue:

In my technical room I have a Raspberry Pi 1B, and Raspberry Pi 3; I tested this on both units and I get the same results;

My mains meter has a flashing LED, 1000/kWh; I want to measure this using a photo resistor; The photo resistor is connected to GPIO PIN14; This setup works just fine, as long as I don't use any of the other GPIO pins.

Using the same unit I want to send some data over 433Mhz (GPIO PIN7, but as soon as I transmit data, I get RISING events on PIN14...

Across the internet I found different solutions, none of which seem to be working:

  • Use a different Raspberry Pi (B1 is a tad bit old)
  • Use a 10K pull down resistor on PIN14
  • Use a different power supply
  • Use separate power supplies for the raspberry pi, photo resistor, and 433Mhz transmitter

Using the code below, I can see expected behavior of the photo resistor and PIN14; But as soon as I startup the transmissions, the events of sending a message and RISING events on PIN14 synchronize. When I stop sending messages the listener on PIN14 stops working.

Does anyone have any idea how to fix this?

Diagram

PIN14 Listener code:

import datetime
import time

try:
    import RPi.GPIO as GPIO
except RuntimeError:
    print(
        'Error importing RPi.GPIO!  This is probably because you need superuser privileges.')

delta = datetime.timedelta(microseconds=100000)
global last_electric_ping
last_electric_ping = datetime.datetime.now()

GPIO.setmode(GPIO.BCM)
GPIO.setup(14, GPIO.IN)


def electric_ping(channel):
    if GPIO.input(14):
        global last_electric_ping
        now = datetime.datetime.now()
        if delta + last_electric_ping <= now:
            print(delta + last_electric_ping, end=" ")
            print('ELECTRIC')
        last_electric_ping = now

GPIO.add_event_detect(14, GPIO.RISING, callback=electric_ping)

while True:
    continue

GPIO.cleanup()

Transmission code:

import time
from pi_switch import RCSwitchSender

sender = RCSwitchSender()
sender.enableTransmit(15) # use WiringPi pin 0

num = 1
while True:
        time.sleep(1)
        print("Woei!")
        sender.sendDecimal(num, 24)
        num += 1

0 个答案:

没有答案