Jump to content

GPIO Interrupt not recognized on OP-5B


thatsimonsguy

Recommended Posts

I've been struggling to get interrupt to work on my 5b with a water flow sensor. Any suggestions or help is appreciated.

 

Here's what I've tried and validated so far:

  • Hardware:
    • The flow sensor signal wire is connected to wiringpi pin 2, which is physical pin 7, gpio pin 54
    • I've put in a pull-down resistor between the gpio pin and GND
    • I've confirmed with a multi-meter that the signal line has a voltage of 0 when the sensor isn't spinning.
      • I've confirmed that "gpio read 2" shows the pin as 0 in that state
    • I've confirmed that the signal line voltage peaks to around 1.5 vdc when the sensor is spinning.
      • I've confirmed that "gpio read 2" shows the pin pulsing in that state between 1 and 0.
  • Docker:
    • I've exported gpio 54 and set it to in
    • The container runs in privileged mode with volumes to all the important bits mapped
  • Python:
    • I wrote a stupidly simple script just to increment a counter and print its value when the interrupt is called
    • wiringpi correctly reads and sets values for all the other gpio stuff I'm doing on the board (temp sensors and relays), it's only the interrupt job that isn't working

 

Docs for above assertions:

  • Python script:
    import wiringpi
    import time
    
    # The pin number to which your sensor is connected
    SENSOR_PIN = 2
    
    # Initialize wiringpi
    wiringpi.wiringPiSetup()
    
    # Set the pin to input mode
    wiringpi.pinMode(SENSOR_PIN, wiringpi.GPIO.INPUT)
    
    # Initialize the counter and the tick
    counter = 0
    
    
    def count_pulse():
        global counter
        counter += 1
        print(counter)
    
    
    # Set the interrupt to be triggered when the pin's voltage rises from LOW to HIGH
    wiringpi.wiringPiISR(SENSOR_PIN, wiringpi.GPIO.INT_EDGE_RISING, count_pulse)
    
    # To keep the script running
    try:
        while True:
            time.sleep(1)
    except (KeyboardInterrupt, SystemExit):
        print(f'Total pulses: {counter}')
        print('Exiting...')

     

  • GPIO test output:
    Pin 2 state: 1
    Pin 2 state: 1
    Pin 2 state: 1
    Pin 2 state: 0
    Pin 2 state: 0
    Pin 2 state: 0
    Pin 2 state: 0
    Pin 2 state: 0
    Pin 2 state: 0
    Pin 2 state: 0
    Pin 2 state: 0
    Pin 2 state: 1
    Pin 2 state: 1
    Pin 2 state: 1
    Pin 2 state: 1
    Pin 2 state: 1
    Pin 2 state: 1
    Pin 2 state: 1
    Pin 2 state: 1
    Pin 2 state: 0
    Pin 2 state: 0
    Pin 2 state: 0
    Pin 2 state: 0
    Pin 2 state: 0

     

  • Dockerfile:
    FROM python:3.9-slim
    WORKDIR /usr/src/app/squirtgun
    LABEL maintainer="github.com/thatsimonsguy"
    
    # Prep for downloading and installing wiringOP & wiringOP-python
    RUN apt-get update && apt-get install -y \
        git \
        gcc \
        swig \
        python3-dev \
        python3-setuptools \
        make \
        sudo \
        && rm -rf /var/lib/apt/lists/*
    
    # Set up wiringOP
    WORKDIR /usr/src/app/squirtgun
    RUN git clone https://github.com/orangepi-xunlong/wiringOP.git -b next
    WORKDIR /usr/src/app/squirtgun/wiringOP
    RUN ./build clean
    RUN ./build
    
    # Set up wiringOP-Python
    WORKDIR /usr/src/app/squirtgun
    RUN git clone --recursive https://github.com/orangepi-xunlong/wiringOP-Python -b next
    WORKDIR /usr/src/app/squirtgun/wiringOP-Python
    RUN python3 generate-bindings.py > bindings.i
    RUN python3 setup.py install
    
    # Export GPIO for pin 2
    RUN echo 54 > /sys/class/gpio/export
    RUN echo "in" > /sys/class/gpio/gpio54/direction
    
    # Install app and python deps
    WORKDIR /usr/src/app/squirtgun
    COPY . .
    RUN pip install -r requirements.txt
    
    EXPOSE 80
    ENTRYPOINT ["python", "run.py"]

     

  • Docker compose:
    version: '3'
    services:
      squirtgun_test:
        image: squirtgun_test:latest
        privileged: true
        volumes:
          - squirtgun_config:/usr/src/app/squirtgun/config
          - squirtgun_db:/usr/src/app/squirtgun/db
          - /etc/orangepi-release:/etc/orangepi-release
          - /etc/armbian-release:/etc/armbian-release
        environment:
          - REGISTRATION_OTP=####
          - PARENT_BASE_URL=####
          - ZONE_RELAY_PINS=5
          - TRANSFORMER_RELAY_PIN=7
          - TEMP_SENSOR_PIN_1=8
          - TEMP_SENSOR_PIN_2=9
          - FLOW_SENSOR_PIN=2
          - DEBUG_NO_MTLS=True
        ports:
          - "5000:5000"
    volumes:
      squirtgun_config:
      squirtgun_db:

 

 

(I realize the port mapping between the docker compose and the dockerfile are not aligned. That's on my TODO list, but isn't a factor for this problem. I'm testing by exec'ing into the running docker container after build and executing the test script)

 

Cheers and thanks!

Edited by thatsimonsguy
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines